Skip to content

Commit

Permalink
script: Rename bounding_content_box to bounding_content_box_or_zero.
Browse files Browse the repository at this point in the history
And make bounding_content_box preserve whether the element is rendered.
  • Loading branch information
emilio committed Jan 18, 2017
1 parent 485fe87 commit bdd7cb9
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion components/script/dom/document.rs
Expand Up @@ -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::<Node>().bounding_content_box();
let rect = element.upcast::<Node>().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
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/element.rs
Expand Up @@ -1604,7 +1604,7 @@ impl ElementMethods for Element {
// https://drafts.csswg.org/cssom-view/#dom-element-getboundingclientrect
fn GetBoundingClientRect(&self) -> Root<DOMRect> {
let win = window_from_node(self);
let rect = self.upcast::<Node>().bounding_content_box();
let rect = self.upcast::<Node>().bounding_content_box_or_zero();
DOMRect::new(win.upcast(),
rect.origin.x.to_f64_px(),
rect.origin.y.to_f64_px(),
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/htmlanchorelement.rs
Expand Up @@ -544,7 +544,7 @@ impl Activatable for HTMLAnchorElement {
if let Some(element) = target.downcast::<Element>() {
if target.is::<HTMLImageElement>() && element.has_attribute(&local_name!("ismap")) {
let target_node = element.upcast::<Node>();
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())
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/htmlimageelement.rs
Expand Up @@ -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::<Node>();
let rect = node.bounding_content_box();
let rect = node.bounding_content_box_or_zero();
rect.size.width.to_px() as u32
}

Expand All @@ -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::<Node>();
let rect = node.bounding_content_box();
let rect = node.bounding_content_box_or_zero();
rect.size.height.to_px() as u32
}

Expand Down
7 changes: 5 additions & 2 deletions components/script/dom/node.rs
Expand Up @@ -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<Au> {
pub fn bounding_content_box(&self) -> Option<Rect<Au>> {
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<Au> {
self.bounding_content_box().unwrap_or_else(Rect::zero)
}

pub fn content_boxes(&self) -> Vec<Rect<Au>> {
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/window.rs
Expand Up @@ -970,7 +970,7 @@ impl Window {
let body = self.Document().GetBody();
let (x, y) = match body {
Some(e) => {
let content_size = e.upcast::<Node>().bounding_content_box();
let content_size = e.upcast::<Node>().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),
Expand Down

0 comments on commit bdd7cb9

Please sign in to comment.