aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/element.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-01-28 05:52:56 -0600
committerGitHub <noreply@github.com>2018-01-28 05:52:56 -0600
commit2a46067587d63aec176621ab3b6112ef5200a248 (patch)
treee5b4a8b24ef7ec251cdd9123221e1c28b9a6c965 /components/script/dom/element.rs
parent025e5d773313e16ffe73ae63efc068b79b82d531 (diff)
parentfe583fc5d0aa667b40ecddfb1cbff3c5f65649d7 (diff)
downloadservo-2a46067587d63aec176621ab3b6112ef5200a248.tar.gz
servo-2a46067587d63aec176621ab3b6112ef5200a248.zip
Auto merge of #19881 - jonleighton:issue-19811, r=emilio
Add layout RPC query for getting an element's style This enables us to implement Element::has_css_layout_box() in a more direct way, and also enables us to remove some of the existing more specific queries. Fixes #19811. r? @emilio <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19881) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/element.rs')
-rw-r--r--components/script/dom/element.rs62
1 files changed, 30 insertions, 32 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index c6224e7dc87..a1bcaa0437e 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -348,27 +348,24 @@ impl Element {
}
// https://drafts.csswg.org/cssom-view/#css-layout-box
- //
- // We'll have no content box if there's no fragment for the node, and we use
- // bounding_content_box, for simplicity, to detect this (rather than making a more specific
- // query to the layout thread).
fn has_css_layout_box(&self) -> bool {
- self.upcast::<Node>().bounding_content_box().is_some()
+ let style = self.upcast::<Node>().style();
+
+ // style will be None for elements in a display: none subtree. otherwise, the element has a
+ // layout box iff it doesn't have display: none.
+ style.map_or(false, |s| !s.get_box().clone_display().is_none())
}
// https://drafts.csswg.org/cssom-view/#potentially-scrollable
fn potentially_scrollable(&self) -> bool {
- self.has_css_layout_box() &&
- !self.overflow_x_is_visible() &&
- !self.overflow_y_is_visible()
+ self.has_css_layout_box() && !self.has_any_visible_overflow()
}
// https://drafts.csswg.org/cssom-view/#scrolling-box
fn has_scrolling_box(&self) -> bool {
// TODO: scrolling mechanism, such as scrollbar (We don't have scrollbar yet)
// self.has_scrolling_mechanism()
- self.overflow_x_is_hidden() ||
- self.overflow_y_is_hidden()
+ self.has_any_hidden_overflow()
}
fn has_overflow(&self) -> bool {
@@ -376,32 +373,33 @@ impl Element {
self.ScrollWidth() > self.ClientWidth()
}
- // used value of overflow-x is "visible"
- fn overflow_x_is_visible(&self) -> bool {
- let window = window_from_node(self);
- let overflow_pair = window.overflow_query(self.upcast::<Node>().to_trusted_node_address());
- overflow_pair.x == overflow_x::computed_value::T::Visible
- }
+ // TODO: Once #19183 is closed (overflow-x/y types moved out of mako), then we could implement
+ // a more generic `fn has_some_overflow(&self, overflow: Overflow)` rather than have
+ // these two `has_any_{visible,hidden}_overflow` methods which are very structurally
+ // similar.
- // used value of overflow-y is "visible"
- fn overflow_y_is_visible(&self) -> bool {
- let window = window_from_node(self);
- let overflow_pair = window.overflow_query(self.upcast::<Node>().to_trusted_node_address());
- overflow_pair.y == overflow_y::computed_value::T::Visible
- }
+ /// Computed value of overflow-x or overflow-y is "visible"
+ fn has_any_visible_overflow(&self) -> bool {
+ let style = self.upcast::<Node>().style();
- // used value of overflow-x is "hidden"
- fn overflow_x_is_hidden(&self) -> bool {
- let window = window_from_node(self);
- let overflow_pair = window.overflow_query(self.upcast::<Node>().to_trusted_node_address());
- overflow_pair.x == overflow_x::computed_value::T::Hidden
+ style.map_or(false, |s| {
+ let box_ = s.get_box();
+
+ box_.clone_overflow_x() == overflow_x::computed_value::T::Visible ||
+ box_.clone_overflow_y() == overflow_y::computed_value::T::Visible
+ })
}
- // used value of overflow-y is "hidden"
- fn overflow_y_is_hidden(&self) -> bool {
- let window = window_from_node(self);
- let overflow_pair = window.overflow_query(self.upcast::<Node>().to_trusted_node_address());
- overflow_pair.y == overflow_y::computed_value::T::Hidden
+ /// Computed value of overflow-x or overflow-y is "hidden"
+ fn has_any_hidden_overflow(&self) -> bool {
+ let style = self.upcast::<Node>().style();
+
+ style.map_or(false, |s| {
+ let box_ = s.get_box();
+
+ box_.clone_overflow_x() == overflow_x::computed_value::T::Hidden ||
+ box_.clone_overflow_y() == overflow_y::computed_value::T::Hidden
+ })
}
}