layout: Merge BoxFragment::used_overflow into ComputedValuesExt::effective_overflow (#35670) (#35670)

* Update wpt-test



* Merge used_overflow to effective_overflow; remove duplicate call



* Remove more duplicate calls; update effective_overflow logic



* Update reference link&style



* Apply final review suggestions

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
Euclid Ye 2025-03-03 05:44:59 +08:00 committed by GitHub
parent b56a3caea0
commit 28cea920ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 54 additions and 47 deletions

View file

@ -25,6 +25,7 @@ use crate::dom_traversal::{
use crate::flow::float::FloatBox;
use crate::flow::{BlockContainer, BlockFormattingContext, BlockLevelBox};
use crate::formatting_contexts::IndependentFormattingContext;
use crate::fragment_tree::FragmentFlags;
use crate::layout_box_base::LayoutBoxBase;
use crate::positioned::AbsolutelyPositionedBox;
use crate::style_ext::{ComputedValuesExt, DisplayGeneratingBox, DisplayInside, DisplayOutside};
@ -493,7 +494,11 @@ where
let kind = match contents {
Contents::NonReplaced(contents) => match display_inside {
DisplayInside::Flow { is_list_item }
if !info.style.establishes_block_formatting_context() =>
// Fragment flags are just used to indicate that the element is not replaced, so empty
// flags are okay here.
if !info.style.establishes_block_formatting_context(
FragmentFlags::empty()
) =>
{
BlockLevelCreator::SameFormattingContextBlock(
IntermediateBlockContainer::Deferred {

View file

@ -54,7 +54,7 @@ impl BoxTree {
// Zero box for `:root { display: none }`, one for the root element otherwise.
assert!(boxes.len() <= 1);
// From https://drafts.csswg.org/css-overflow/#overflow-propagation:
// From https://www.w3.org/TR/css-overflow-3/#overflow-propagation:
// > UAs must apply the overflow-* values set on the root element to the viewport when the
// > root elements display value is not none. However, when the root element is an [HTML]
// > html element (including XML syntax for HTML) whose overflow value is visible (in both
@ -63,10 +63,11 @@ impl BoxTree {
// > element to the viewport. The element from which the value is propagated must then have a
// > used overflow value of visible.
let root_style = root_element.style(context);
let root_overflow = root_style.effective_overflow();
let mut viewport_overflow = root_overflow;
if root_overflow.x == Overflow::Visible &&
root_overflow.y == Overflow::Visible &&
let mut viewport_overflow_x = root_style.clone_overflow_x();
let mut viewport_overflow_y = root_style.clone_overflow_y();
if viewport_overflow_x == Overflow::Visible &&
viewport_overflow_y == Overflow::Visible &&
!root_style.get_box().display.is_none()
{
for child in iter_child_nodes(root_element) {
@ -80,7 +81,9 @@ impl BoxTree {
let style = child.style(context);
if !style.get_box().display.is_none() {
viewport_overflow = style.effective_overflow();
viewport_overflow_x = style.clone_overflow_x();
viewport_overflow_y = style.clone_overflow_y();
break;
}
}
@ -94,9 +97,12 @@ impl BoxTree {
contains_floats,
},
canvas_background: CanvasBackground::for_root_element(context, root_element),
// From https://www.w3.org/TR/css-overflow-3/#overflow-propagation:
// > If visible is applied to the viewport, it must be interpreted as auto.
// > If clip is applied to the viewport, it must be interpreted as hidden.
viewport_scroll_sensitivity: AxesScrollSensitivity {
x: viewport_overflow.x.to_scrollable().into(),
y: viewport_overflow.y.to_scrollable().into(),
x: viewport_overflow_x.to_scrollable().into(),
y: viewport_overflow_y.to_scrollable().into(),
},
}
}