mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
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:
parent
485fe874e8
commit
bdd7cb9753
6 changed files with 11 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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>> {
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue