script: Rename bounding_content_box to bounding_content_box_or_zero.

And make bounding_content_box preserve whether the element is rendered.
This commit is contained in:
Emilio Cobos Álvarez 2017-01-17 00:27:49 +01:00
parent 485fe874e8
commit bdd7cb9753
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
6 changed files with 11 additions and 8 deletions

View file

@ -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

View file

@ -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(),

View file

@ -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())

View file

@ -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
}
@ -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
}

View file

@ -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>> {

View file

@ -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),