Web: account for canvas being focused already (#3369)

This commit is contained in:
daxpedda 2024-01-06 16:14:27 +01:00 committed by GitHub
parent 787b2d7362
commit d39528aa69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,8 @@ use std::iter;
use std::marker::PhantomData;
use std::rc::{Rc, Weak};
use web_sys::Element;
use super::runner::{EventWrapper, Execution};
use super::{
super::{monitor::MonitorHandle, KeyEventExtra},
@ -118,6 +120,25 @@ impl<T> EventLoopWindowTarget<T> {
}
});
// It is possible that at this point the canvas has
// been focused before the callback can be called.
let focused = canvas
.document()
.active_element()
.filter(|element| {
let canvas: &Element = canvas.raw();
element == canvas
})
.is_some();
if focused {
canvas.has_focus.set(true);
self.runner.send_event(Event::WindowEvent {
window_id: RootWindowId(id),
event: WindowEvent::Focused(true),
})
}
let runner = self.runner.clone();
let modifiers = self.modifiers.clone();
canvas.on_keyboard_press(