Fix keyboard focus lock-out with HTML5 canvas in iframe

This commit is contained in:
Leon Krause 2018-05-09 15:57:10 +02:00
parent 0f930f8314
commit 9080e96bc8
3 changed files with 10 additions and 6 deletions

View file

@ -195,7 +195,7 @@ $GODOT_HEAD_INCLUDE
</head> </head>
<body> <body>
<div id="container"> <div id="container">
<canvas id="canvas" oncontextmenu="event.preventDefault();" width="640" height="480"> <canvas id="canvas" width="640" height="480">
HTML5 canvas appears to be unsupported in the current browser.<br /> HTML5 canvas appears to be unsupported in the current browser.<br />
Please try updating or use a different browser. Please try updating or use a different browser.
</canvas> </canvas>

View file

@ -161,6 +161,10 @@
actualCanvas.style.padding = 0; actualCanvas.style.padding = 0;
actualCanvas.style.borderWidth = 0; actualCanvas.style.borderWidth = 0;
actualCanvas.style.borderStyle = 'none'; actualCanvas.style.borderStyle = 'none';
// disable right-click context menu
actualCanvas.addEventListener('contextmenu', function(ev) {
ev.preventDefault();
}, false);
// until context restoration is implemented // until context restoration is implemented
actualCanvas.addEventListener('webglcontextlost', function(ev) { actualCanvas.addEventListener('webglcontextlost', function(ev) {
alert("WebGL context lost, please reload the page"); alert("WebGL context lost, please reload the page");

View file

@ -167,10 +167,9 @@ static EM_BOOL _mousebutton_callback(int event_type, const EmscriptenMouseEvent
int mask = _input->get_mouse_button_mask(); int mask = _input->get_mouse_button_mask();
int button_flag = 1 << (ev->get_button_index() - 1); int button_flag = 1 << (ev->get_button_index() - 1);
if (ev->is_pressed()) { if (ev->is_pressed()) {
// since the event is consumed, focus manually // Since the event is consumed, focus manually. The containing iframe,
if (!is_canvas_focused()) { // if used, may not have focus yet, so focus even if already focused.
focus_canvas(); focus_canvas();
}
mask |= button_flag; mask |= button_flag;
} else if (mask & button_flag) { } else if (mask & button_flag) {
mask &= ~button_flag; mask &= ~button_flag;
@ -181,7 +180,8 @@ static EM_BOOL _mousebutton_callback(int event_type, const EmscriptenMouseEvent
ev->set_button_mask(mask); ev->set_button_mask(mask);
_input->parse_input_event(ev); _input->parse_input_event(ev);
// prevent selection dragging // Prevent multi-click text selection and wheel-click scrolling anchor.
// Context menu is prevented through contextmenu event.
return true; return true;
} }