Increase accuracy of various Web APIs (#2946)
This commit is contained in:
parent
db8de03142
commit
c4d70d75c1
9 changed files with 73 additions and 38 deletions
|
|
@ -28,6 +28,7 @@ pub struct Canvas {
|
|||
common: Common,
|
||||
id: WindowId,
|
||||
pub has_focus: Arc<AtomicBool>,
|
||||
pub is_intersecting: Option<bool>,
|
||||
on_touch_start: Option<EventListenerHandle<dyn FnMut(Event)>>,
|
||||
on_touch_end: Option<EventListenerHandle<dyn FnMut(Event)>>,
|
||||
on_focus: Option<EventListenerHandle<dyn FnMut(FocusEvent)>>,
|
||||
|
|
@ -97,6 +98,7 @@ impl Canvas {
|
|||
},
|
||||
id,
|
||||
has_focus: Arc::new(AtomicBool::new(false)),
|
||||
is_intersecting: None,
|
||||
on_touch_start: None,
|
||||
on_touch_end: None,
|
||||
on_blur: None,
|
||||
|
|
@ -134,11 +136,29 @@ impl Canvas {
|
|||
|
||||
pub fn position(&self) -> LogicalPosition<f64> {
|
||||
let bounds = self.common.raw.get_bounding_client_rect();
|
||||
|
||||
LogicalPosition {
|
||||
let mut position = LogicalPosition {
|
||||
x: bounds.x(),
|
||||
y: bounds.y(),
|
||||
};
|
||||
|
||||
let document = self.window().document().expect("Failed to obtain document");
|
||||
|
||||
if document.contains(Some(self.raw())) {
|
||||
let style = self
|
||||
.window()
|
||||
.get_computed_style(self.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 += super::style_size_property(&style, "border-left-width")
|
||||
+ super::style_size_property(&style, "padding-left");
|
||||
position.y += super::style_size_property(&style, "border-top-width")
|
||||
+ super::style_size_property(&style, "padding-top");
|
||||
}
|
||||
}
|
||||
|
||||
position
|
||||
}
|
||||
|
||||
pub fn old_size(&self) -> PhysicalSize<u32> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue