Skip to content

Commit

Permalink
[HTML5] Fix focus (again) in Firefox's iframes.
Browse files Browse the repository at this point in the history
This actually makes sense(?), when running inside an iframe the active
element might be our canvas, while the iframe itself is not active in
the parent window. Since we consume the event, the iframe does not get
focused in Firefox (but does in Chromium-based browsers), so we must
always call focus to handle such occasions.

(cherry picked from commit 63e2db2)
  • Loading branch information
Faless authored and akien-mga committed Nov 26, 2021
1 parent 81d1d5a commit f11bed2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions platform/javascript/js/libs/library_godot_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,9 @@ const GodotInput = {
const rect = canvas.getBoundingClientRect();
const pos = GodotInput.computePosition(evt, rect);
const modifiers = GodotInput.getModifiers(evt);
if (p_pressed && document.activeElement !== GodotConfig.canvas) {
// Since the event is consumed, focus manually.
// NOTE: The iframe container may not have focus yet, so focus even when already active.
if (p_pressed) {
GodotConfig.canvas.focus();
}
if (func(p_pressed, evt.button, pos[0], pos[1], modifiers)) {
Expand All @@ -412,7 +414,9 @@ const GodotInput = {
const func = GodotRuntime.get_func(callback);
const canvas = GodotConfig.canvas;
function touch_cb(type, evt) {
if (type === 0 && document.activeElement !== GodotConfig.canvas) {
// Since the event is consumed, focus manually.
// NOTE: The iframe container may not have focus yet, so focus even when already active.
if (type === 0) {
GodotConfig.canvas.focus();
}
const rect = canvas.getBoundingClientRect();
Expand Down

0 comments on commit f11bed2

Please sign in to comment.