On Web, cache commonly used values (#2947)
This commit is contained in:
parent
c4d70d75c1
commit
af26f01b95
7 changed files with 131 additions and 126 deletions
|
|
@ -7,7 +7,7 @@ use crate::window::{
|
|||
};
|
||||
|
||||
use raw_window_handle::{RawDisplayHandle, RawWindowHandle, WebDisplayHandle, WebWindowHandle};
|
||||
use web_sys::HtmlCanvasElement;
|
||||
use web_sys::{CssStyleDeclaration, Document, HtmlCanvasElement};
|
||||
|
||||
use super::r#async::Dispatcher;
|
||||
use super::{backend, monitor::MonitorHandle, EventLoopWindowTarget, Fullscreen};
|
||||
|
|
@ -27,6 +27,8 @@ pub struct Window {
|
|||
|
||||
pub struct Inner {
|
||||
pub window: web_sys::Window,
|
||||
document: Document,
|
||||
style: CssStyleDeclaration,
|
||||
canvas: Rc<RefCell<backend::Canvas>>,
|
||||
previous_pointer: RefCell<&'static str>,
|
||||
register_redraw_request: Box<dyn Fn()>,
|
||||
|
|
@ -46,7 +48,10 @@ impl Window {
|
|||
let prevent_default = platform_attr.prevent_default;
|
||||
|
||||
let window = target.runner.window();
|
||||
let canvas = backend::Canvas::create(id, window.clone(), &attr, platform_attr)?;
|
||||
let document = target.runner.document();
|
||||
let canvas =
|
||||
backend::Canvas::create(id, window.clone(), document.clone(), &attr, platform_attr)?;
|
||||
let style = canvas.style().clone();
|
||||
let canvas = Rc::new(RefCell::new(canvas));
|
||||
|
||||
let register_redraw_request = Box::new(move || runner.request_redraw(RootWI(id)));
|
||||
|
|
@ -62,6 +67,8 @@ impl Window {
|
|||
has_focus,
|
||||
inner: Dispatcher::new(Inner {
|
||||
window: window.clone(),
|
||||
document: document.clone(),
|
||||
style,
|
||||
canvas,
|
||||
previous_pointer: RefCell::new("auto"),
|
||||
register_redraw_request,
|
||||
|
|
@ -130,24 +137,16 @@ impl Window {
|
|||
let mut position = position.to_logical::<f64>(inner.scale_factor());
|
||||
|
||||
let canvas = inner.canvas.borrow();
|
||||
let document = inner.window.document().expect("Failed to obtain document");
|
||||
|
||||
if document.contains(Some(canvas.raw())) {
|
||||
let style = inner
|
||||
.window
|
||||
.get_computed_style(canvas.raw())
|
||||
.expect("Failed to obtain computed style")
|
||||
// this can't fail: we aren't using a pseudo-element
|
||||
.expect("Invalid pseudo-element");
|
||||
|
||||
if style.get_property_value("display").unwrap() != "none" {
|
||||
position.x -= backend::style_size_property(&style, "margin-left")
|
||||
+ backend::style_size_property(&style, "border-left-width")
|
||||
+ backend::style_size_property(&style, "padding-left");
|
||||
position.y -= backend::style_size_property(&style, "margin-top")
|
||||
+ backend::style_size_property(&style, "border-top-width")
|
||||
+ backend::style_size_property(&style, "padding-top");
|
||||
}
|
||||
if inner.document.contains(Some(canvas.raw()))
|
||||
&& inner.style.get_property_value("display").unwrap() != "none"
|
||||
{
|
||||
position.x -= backend::style_size_property(&inner.style, "margin-left")
|
||||
+ backend::style_size_property(&inner.style, "border-left-width")
|
||||
+ backend::style_size_property(&inner.style, "padding-left");
|
||||
position.y -= backend::style_size_property(&inner.style, "margin-top")
|
||||
+ backend::style_size_property(&inner.style, "border-top-width")
|
||||
+ backend::style_size_property(&inner.style, "padding-top");
|
||||
}
|
||||
|
||||
canvas.set_attribute("position", "fixed");
|
||||
|
|
@ -172,7 +171,7 @@ impl Window {
|
|||
self.inner.dispatch(move |inner| {
|
||||
let size = size.to_logical(inner.scale_factor());
|
||||
let canvas = inner.canvas.borrow();
|
||||
backend::set_canvas_size(canvas.window(), canvas.raw(), size);
|
||||
backend::set_canvas_size(canvas.document(), canvas.raw(), canvas.style(), size);
|
||||
});
|
||||
|
||||
None
|
||||
|
|
@ -324,7 +323,7 @@ impl Window {
|
|||
if fullscreen.is_some() {
|
||||
inner.canvas.borrow().request_fullscreen();
|
||||
} else if inner.canvas.borrow().is_fullscreen() {
|
||||
backend::exit_fullscreen(&inner.window);
|
||||
backend::exit_fullscreen(&inner.document);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue