Truly independent web browser
LibWeb: Tell plain sizes apart from calculations by their kind
Aliaksandr Kalenik0a483ae09d8f
diff --git a/Libraries/LibWeb/Rust/src/css/computed_value_views.rs b/Libraries/LibWeb/Rust/src/css/computed_value_views.rsindex eba21b21182..a0b9d48860a 100644--- a/Libraries/LibWeb/Rust/src/css/computed_value_views.rs+++ b/Libraries/LibWeb/Rust/src/css/computed_value_views.rs@@ -249,6 +249,12 @@ impl ComputedSize {}}+ /// Whether the size is a calculation holding an anchor function. Only a calculation can hold one, so a plain length or+ /// percentage answers without reading its value.+ pub(crate) fn contains_anchor_function(&self) -> bool {+ self.kind == ComputedSizeKind::Calculated && self.length_percentage().contains_anchor_function()+ }+pub(crate) fn contains_percentage(&self) -> bool {match self.kind {ComputedSizeKind::Auto@@ -258,10 +264,9 @@ impl ComputedSize {// NB: A stretch size depends on the size of the containing block, and behaves as auto, zero or none// wherever a percentage of it would not resolve.// https://drafts.csswg.org/css-sizing-3/#stretch-fit-sizing- ComputedSizeKind::Stretch => true,- ComputedSizeKind::Calculated | ComputedSizeKind::Length | ComputedSizeKind::Percentage => {- self.length_percentage().contains_percentage()- }+ ComputedSizeKind::Stretch | ComputedSizeKind::Percentage => true,+ ComputedSizeKind::Length => false,+ ComputedSizeKind::Calculated => self.length_percentage().contains_percentage(),ComputedSizeKind::FitContent => self.fit_content_available_space().is_some_and(|available_space| available_space.contains_percentage()),diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex 1843b492568..60b8ed563a8 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -926,7 +926,7 @@ impl AbsposEngine<'_> {// https://drafts.csswg.org/css-anchor-position-1/#anchor-size-resolution// If no fallback value is specified, it makes the declaration referencing it invalid at computed-value time.let resolve_size = |size: &ComputedSize, is_horizontal: bool, initial: ComputedSizeKind| {- if !size.is_length_percentage() || !size.length_percentage().contains_anchor_function() {+ if !size.contains_anchor_function() {return None;}let extent = if is_horizontal { inline_size } else { block_size };diff --git a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rsindex 68802211ab2..973791eb4ee 100644--- a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs+++ b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs@@ -571,9 +571,6 @@ impl LayoutNodeArena {return None;}// Anchor functions resolve against anchors this path does not look up.- let size_contains_anchor_function = |size: &crate::layout::ComputedSize| {- size.is_length_percentage() && size.length_percentage().contains_anchor_function()- };let side_contains_anchor_function = |side: &crate::layout::ComputedLengthPercentageOrAuto| {side.length_percentage().is_some_and(|length_percentage| length_percentage.contains_anchor_function())@@ -588,7 +585,7 @@ impl LayoutNodeArena {style.max_height(),].into_iter()- .any(size_contains_anchor_function)+ .any(crate::layout::ComputedSize::contains_anchor_function)|| [&surround.inset, &surround.margin].into_iter().any(|sides| {[&sides.top, &sides.right, &sides.bottom, &sides.left].into_iter()diff --git a/Libraries/LibWeb/Rust/src/layout/style_values.rs b/Libraries/LibWeb/Rust/src/layout/style_values.rsindex 42637a269a2..fbc08d2065a 100644--- a/Libraries/LibWeb/Rust/src/layout/style_values.rs+++ b/Libraries/LibWeb/Rust/src/layout/style_values.rs@@ -684,7 +684,7 @@ impl<'a> StyleValues<'a> {/// If no fallback value is specified, it makes the declaration referencing it invalid at computed-value time./// NB: Outside of the resolutions the abspos engine installs, an anchor function is unresolvable.fn unresolvable_anchor_size_or<'a>(size: &'a ComputedSize, initial: &'static ComputedSize) -> &'a ComputedSize {- if !size.is_length_percentage() || !size.length_percentage().contains_anchor_function() {+ if !size.contains_anchor_function() {return size;}let mut percentage_basis = CssPixels::default();