diff options
author | Jimmy D. Buckets <50691404+JimmyDdotEXE@users.noreply.github.com> | 2025-05-05 08:50:42 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-05 12:50:42 +0000 |
commit | 1f6050f9314c84745ab6451ddb78b8cebe8237e5 (patch) | |
tree | 6ef73f0eda46150a02203324196a33aace6be244 /components/script/dom/element.rs | |
parent | 7ea5951e3436a60980661cc63a25cec976e727e9 (diff) | |
download | servo-1f6050f9314c84745ab6451ddb78b8cebe8237e5.tar.gz servo-1f6050f9314c84745ab6451ddb78b8cebe8237e5.zip |
Implement `document.scrollingElement` (#35994)
<!-- Please describe your changes on the following line: -->
This implements `document.scrollingElement`
(https://drafts.csswg.org/cssom-view/#dom-document-scrollingelement).
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by
`[X]` when the step is complete, and replace `___` with appropriate
data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #35700
- [x] There are tests for these changes
<!-- Also, please make sure that "Allow edits from maintainers" checkbox
is checked, so that we can help you if you get stuck somewhere along the
way.-->
<!-- Pull requests that do not address these steps are welcome, but they
will require additional verification as part of the review process. -->
---------
Signed-off-by: JimmyDdotEXE <50691404+JimmyDdotEXE@users.noreply.github.com>
Diffstat (limited to 'components/script/dom/element.rs')
-rw-r--r-- | components/script/dom/element.rs | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index d92d5c124d1..b2168846fad 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -50,6 +50,7 @@ use style::selector_parser::{ use style::shared_lock::{Locked, SharedRwLock}; use style::stylesheets::layer_rule::LayerOrder; use style::stylesheets::{CssRuleType, UrlExtraData}; +use style::values::computed::Overflow; use style::values::generics::NonNegative; use style::values::generics::position::PreferredRatio; use style::values::generics::ratio::Ratio; @@ -455,8 +456,25 @@ impl Element { .is_some_and(|s| !s.get_box().clone_display().is_none()) } - // https://drafts.csswg.org/cssom-view/#potentially-scrollable - fn is_potentially_scrollable_body(&self, can_gc: CanGc) -> bool { + /// <https://drafts.csswg.org/cssom-view/#potentially-scrollable> + pub(crate) fn is_potentially_scrollable_body(&self, can_gc: CanGc) -> bool { + self.is_potentially_scrollable_body_shared_logic(false, can_gc) + } + + /// <https://drafts.csswg.org/cssom-view/#potentially-scrollable> + pub(crate) fn is_potentially_scrollable_body_for_scrolling_element( + &self, + can_gc: CanGc, + ) -> bool { + self.is_potentially_scrollable_body_shared_logic(true, can_gc) + } + + /// <https://drafts.csswg.org/cssom-view/#potentially-scrollable> + fn is_potentially_scrollable_body_shared_logic( + &self, + treat_overflow_clip_on_parent_as_hidden: bool, + can_gc: CanGc, + ) -> bool { let node = self.upcast::<Node>(); debug_assert!( node.owner_doc().GetBody().as_deref() == self.downcast::<HTMLElement>(), @@ -474,9 +492,21 @@ impl Element { // overflow-y properties is neither visible nor clip." if let Some(parent) = node.GetParentElement() { if let Some(style) = parent.style(can_gc) { - if !style.get_box().clone_overflow_x().is_scrollable() && - !style.get_box().clone_overflow_y().is_scrollable() - { + let mut overflow_x = style.get_box().clone_overflow_x(); + let mut overflow_y = style.get_box().clone_overflow_y(); + + // This fulfills the 'treat parent element overflow:clip as overflow:hidden' stipulation + // from the document.scrollingElement specification. + if treat_overflow_clip_on_parent_as_hidden { + if overflow_x == Overflow::Clip { + overflow_x = Overflow::Hidden; + } + if overflow_y == Overflow::Clip { + overflow_y = Overflow::Hidden; + } + } + + if !overflow_x.is_scrollable() && !overflow_y.is_scrollable() { return false; } }; |