layout: Use overflow: visible if overflow was propagated to viewport (#38598)

The `overflow-*` values of either the root element or the `<body>` get
propagated to the viewport. However, we were missing this part:
> The element from which the value is propagated must then have a used
`overflow` value of `visible`.

See https://drafts.csswg.org/css-overflow/#overflow-propagation

Testing:
 - `css/cssom-view/scrolling-quirks-vs-nonquirks.html`
 - `css/css-overflow/overflow-body-propagation-007.html`
 - `css/css-overflow/overflow-body-propagation-008.html`
 - `css/css-overflow/overflow-body-propagation-009.html`
 - `css/css-overflow/scrollable-overflow-with-nested-elements-001.html` 
 - `css/css-overflow/scrollable-overflow-with-nested-elements-002.html` 
 - `css/css-overflow/scrollable-overflow-with-nested-elements-003.html`
 - `css/css-overflow/scrollable-overflow-with-nested-elements-004.html`
 - `css/css-overflow/scrollbar-gutter-scroll-into-view.html`

Failures:
 - `css/css-overflow/overflow-body-propagation-010.html`
   Failing because of missing support for `contain: paint`.
- `css/css-overflow/scrollable-overflow-with-nested-elements-005.html`
Failing because of wrong `data-expected-height`, but correct
`data-expected-scroll-height` which is core of this PR.
`data-expected-height` can be dealt separately.


Fixes: #38248

---------

Signed-off-by: Shubham Gupta <shubham13297@gmail.com>
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Shubham Gupta 2025-08-20 22:21:51 +08:00 committed by GitHub
parent 37088aa4c3
commit d8ff9c7a08
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 373 additions and 72 deletions

View file

@ -27,6 +27,7 @@ use crate::flow::BlockLevelBox;
use crate::flow::inline::{InlineItem, SharedInlineStyles};
use crate::fragment_tree::Fragment;
use crate::geom::PhysicalSize;
use crate::layout_box_base::LayoutBoxBase;
use crate::replaced::CanvasInfo;
use crate::table::TableLevelBox;
use crate::taffy::TaffyItemBox;
@ -73,7 +74,7 @@ impl InnerDOMLayoutData {
self.self_box
.borrow()
.as_ref()
.map(LayoutBox::fragments)
.map(|layout_box| layout_box.with_base_flat(LayoutBoxBase::fragments))
.unwrap_or_default()
}
@ -139,17 +140,38 @@ impl LayoutBox {
}
}
pub(crate) fn fragments(&self) -> Vec<Fragment> {
pub(crate) fn with_base_flat<T>(&self, callback: impl Fn(&LayoutBoxBase) -> Vec<T>) -> Vec<T> {
match self {
LayoutBox::DisplayContents(..) => vec![],
LayoutBox::BlockLevel(block_level_box) => block_level_box.borrow().fragments(),
LayoutBox::BlockLevel(block_level_box) => block_level_box.borrow().with_base(callback),
LayoutBox::InlineLevel(inline_items) => inline_items
.iter()
.flat_map(|inline_item| inline_item.borrow().fragments())
.flat_map(|inline_item| inline_item.borrow().with_base(&callback))
.collect(),
LayoutBox::FlexLevel(flex_level_box) => flex_level_box.borrow().fragments(),
LayoutBox::TaffyItemBox(taffy_item_box) => taffy_item_box.borrow().fragments(),
LayoutBox::TableLevelBox(table_box) => table_box.fragments(),
LayoutBox::FlexLevel(flex_level_box) => flex_level_box.borrow().with_base(callback),
LayoutBox::TaffyItemBox(taffy_item_box) => taffy_item_box.borrow().with_base(callback),
LayoutBox::TableLevelBox(table_box) => table_box.with_base(callback),
}
}
pub(crate) fn with_base_mut(&mut self, callback: impl Fn(&mut LayoutBoxBase)) {
match self {
LayoutBox::DisplayContents(..) => {},
LayoutBox::BlockLevel(block_level_box) => {
block_level_box.borrow_mut().with_base_mut(callback);
},
LayoutBox::InlineLevel(inline_items) => {
for inline_item in inline_items {
inline_item.borrow_mut().with_base_mut(&callback);
}
},
LayoutBox::FlexLevel(flex_level_box) => {
flex_level_box.borrow_mut().with_base_mut(callback)
},
LayoutBox::TableLevelBox(table_level_box) => table_level_box.with_base_mut(callback),
LayoutBox::TaffyItemBox(taffy_item_box) => {
taffy_item_box.borrow_mut().with_base_mut(callback)
},
}
}