mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
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.
This commit is contained in:
parent
c9ba16f9fb
commit
fe583fc5d0
10 changed files with 88 additions and 136 deletions
|
@ -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.
|
||||
|
||||
/// Computed value of overflow-x or overflow-y is "visible"
|
||||
fn has_any_visible_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::Visible ||
|
||||
box_.clone_overflow_y() == overflow_y::computed_value::T::Visible
|
||||
})
|
||||
}
|
||||
|
||||
// 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 "hidden"
|
||||
fn has_any_hidden_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();
|
||||
|
||||
// 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
|
||||
box_.clone_overflow_x() == overflow_x::computed_value::T::Hidden ||
|
||||
box_.clone_overflow_y() == overflow_y::computed_value::T::Hidden
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue