diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index fc3025615a7..8dd5adf7e3b 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -625,7 +625,7 @@ impl Document { // Really what needs to happen is that this needs to go through layout to ask which // layer the element belongs to, and have it send the scroll message to the // compositor. - let rect = element.upcast::().bounding_content_box(); + let rect = element.upcast::().bounding_content_box_or_zero(); // In order to align with element edges, we snap to unscaled pixel boundaries, since // the paint thread currently does the same for drawing elements. This is important diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index bd3925c04f9..e51b8908189 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1604,7 +1604,7 @@ impl ElementMethods for Element { // https://drafts.csswg.org/cssom-view/#dom-element-getboundingclientrect fn GetBoundingClientRect(&self) -> Root { let win = window_from_node(self); - let rect = self.upcast::().bounding_content_box(); + let rect = self.upcast::().bounding_content_box_or_zero(); DOMRect::new(win.upcast(), rect.origin.x.to_f64_px(), rect.origin.y.to_f64_px(), diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs index ab237f702dd..91ebadbd0f2 100644 --- a/components/script/dom/htmlanchorelement.rs +++ b/components/script/dom/htmlanchorelement.rs @@ -544,7 +544,7 @@ impl Activatable for HTMLAnchorElement { if let Some(element) = target.downcast::() { if target.is::() && element.has_attribute(&local_name!("ismap")) { let target_node = element.upcast::(); - let rect = target_node.bounding_content_box(); + let rect = target_node.bounding_content_box_or_zero(); ismap_suffix = Some( format!("?{},{}", mouse_event.ClientX().to_f32().unwrap() - rect.origin.x.to_f32_px(), mouse_event.ClientY().to_f32().unwrap() - rect.origin.y.to_f32_px()) diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 629d5d50fb6..27fe846ec11 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -358,7 +358,7 @@ impl HTMLImageElementMethods for HTMLImageElement { // https://html.spec.whatwg.org/multipage/#dom-img-width fn Width(&self) -> u32 { let node = self.upcast::(); - let rect = node.bounding_content_box(); + let rect = node.bounding_content_box_or_zero(); rect.size.width.to_px() as u32 } @@ -370,7 +370,7 @@ impl HTMLImageElementMethods for HTMLImageElement { // https://html.spec.whatwg.org/multipage/#dom-img-height fn Height(&self) -> u32 { let node = self.upcast::(); - let rect = node.bounding_content_box(); + let rect = node.bounding_content_box_or_zero(); rect.size.height.to_px() as u32 } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 940f98fc8fd..71547c860bc 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -526,10 +526,13 @@ impl Node { /// Returns the rendered bounding content box if the element is rendered, /// and none otherwise. - pub fn bounding_content_box(&self) -> Rect { + pub fn bounding_content_box(&self) -> Option> { window_from_node(self) .content_box_query(self.to_trusted_node_address()) - .unwrap_or_else(Rect::zero) + } + + pub fn bounding_content_box_or_zero(&self) -> Rect { + self.bounding_content_box().unwrap_or_else(Rect::zero) } pub fn content_boxes(&self) -> Vec> { diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 9bc4586dc38..c8e4ccc832d 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -970,7 +970,7 @@ impl Window { let body = self.Document().GetBody(); let (x, y) = match body { Some(e) => { - let content_size = e.upcast::().bounding_content_box(); + let content_size = e.upcast::().bounding_content_box_or_zero(); let content_height = content_size.size.height.to_f64_px(); let content_width = content_size.size.width.to_f64_px(); (xfinite.max(0.0f64).min(content_width - width),