Skip to content

Truly independent web browser

LibWeb: Measure abspos static positions from the containing block edge

Andreas Kling9ba675f88b9e
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
index c53253af81c..f42f297198b 100644
--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs
@@ -49,6 +49,32 @@ pub(crate) fn aligned_static_offset(
offset
}
+/// The static position rect relative to the containing block rect that insets are measured from, as the sizing
+/// rules take it.
+/// https://www.w3.org/TR/CSS22/visudet.html#abs-non-replaced-width
+/// The static position for 'left' is the distance from the left edge of the containing block to the left margin edge
+/// of a hypothetical box that would have been the first box of the element if its 'position' property had been
+/// 'static' and 'float' had been 'none'.
+/// NB: An axis that is not placed at its static position adds the containing block rect offset to its used inset, so
+/// its static position rect already stands relative to the containing block rect.
+fn static_position_rect_for_sizing(inputs: &abspos_inputs::AbsposLayoutInputs) -> abspos_inputs::StaticPositionRect {
+ let info = &inputs.containing_block_info;
+ let translation = |mode: abspos_inputs::AbsposAxisMode, origin: CssPixels| {
+ if mode == abspos_inputs::AbsposAxisMode::StaticPosition {
+ CssPixels::default() - origin
+ } else {
+ CssPixels::default()
+ }
+ };
+ formatting_context::translate_static_position_rect(
+ inputs.static_position_rect,
+ FfiCssPixelPoint {
+ x: translation(info.inline_axis_mode, info.rect.offset.inline_offset),
+ y: translation(info.block_axis_mode, info.rect.offset.block_offset),
+ },
+ )
+}
+
fn out_of_flow_root_space(inputs: abspos_inputs::AbsposLayoutInputs) -> (AvailableSpace, ContainingBlockConstraints) {
let containing_block_size = geometry::LogicalSize {
inline_size: clamp_to_max_dimension_value(inputs.containing_block_info.rect.size.inline_size),
@@ -1853,14 +1879,14 @@ impl<'pass> AbsposEngine<'pass> {
node,
available_space,
constraints,
- inputs.static_position_rect,
+ static_position_rect_for_sizing(&inputs),
resolved,
);
self.compute_block_size(
node,
available_space,
constraints,
- inputs.static_position_rect,
+ static_position_rect_for_sizing(&inputs),
BlockSizePass::BeforeInsideLayout,
resolved,
);
@@ -1917,7 +1943,7 @@ impl<'pass> AbsposEngine<'pass> {
node,
available_space,
constraints,
- inputs.static_position_rect,
+ static_position_rect_for_sizing(&inputs),
BlockSizePass::AfterInsideLayout {
automatic_content_block_size_of_inside_layout,
},
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom/getComputedStyle-insets-absolute.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom/getComputedStyle-insets-absolute.txt
index e2fef9591dc..65da5e0fe90 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/cssom/getComputedStyle-insets-absolute.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom/getComputedStyle-insets-absolute.txt
@@ -2,8 +2,8 @@ Harness status: OK
Found 324 tests
-288 Pass
-36 Fail
+300 Pass
+24 Fail
Pass horizontal-tb ltr inside horizontal-tb ltr - Pixels resolve as-is
Pass horizontal-tb ltr inside horizontal-tb ltr - Relative lengths are absolutized into pixels
Pass horizontal-tb ltr inside horizontal-tb ltr - Percentages are absolutized into pixels
@@ -12,7 +12,7 @@ Pass horizontal-tb ltr inside horizontal-tb ltr - Pixels resolve as-is when over
Pass horizontal-tb ltr inside horizontal-tb ltr - Percentages absolutize the computed value when overconstrained
Pass horizontal-tb ltr inside horizontal-tb ltr - If start side is 'auto' and end side is not, 'auto' resolves to used value
Pass horizontal-tb ltr inside horizontal-tb ltr - If end side is 'auto' and start side is not, 'auto' resolves to used value
-Fail horizontal-tb ltr inside horizontal-tb ltr - If opposite sides are 'auto', they resolve to used value
+Pass horizontal-tb ltr inside horizontal-tb ltr - If opposite sides are 'auto', they resolve to used value
Pass horizontal-tb ltr inside horizontal-tb rtl - Pixels resolve as-is
Pass horizontal-tb ltr inside horizontal-tb rtl - Relative lengths are absolutized into pixels
Pass horizontal-tb ltr inside horizontal-tb rtl - Percentages are absolutized into pixels
@@ -30,7 +30,7 @@ Pass horizontal-tb ltr inside vertical-lr ltr - Pixels resolve as-is when overco
Pass horizontal-tb ltr inside vertical-lr ltr - Percentages absolutize the computed value when overconstrained
Pass horizontal-tb ltr inside vertical-lr ltr - If start side is 'auto' and end side is not, 'auto' resolves to used value
Pass horizontal-tb ltr inside vertical-lr ltr - If end side is 'auto' and start side is not, 'auto' resolves to used value
-Fail horizontal-tb ltr inside vertical-lr ltr - If opposite sides are 'auto', they resolve to used value
+Pass horizontal-tb ltr inside vertical-lr ltr - If opposite sides are 'auto', they resolve to used value
Pass horizontal-tb ltr inside vertical-lr rtl - Pixels resolve as-is
Pass horizontal-tb ltr inside vertical-lr rtl - Relative lengths are absolutized into pixels
Pass horizontal-tb ltr inside vertical-lr rtl - Percentages are absolutized into pixels
@@ -66,7 +66,7 @@ Pass horizontal-tb rtl inside horizontal-tb ltr - Pixels resolve as-is when over
Pass horizontal-tb rtl inside horizontal-tb ltr - Percentages absolutize the computed value when overconstrained
Pass horizontal-tb rtl inside horizontal-tb ltr - If start side is 'auto' and end side is not, 'auto' resolves to used value
Pass horizontal-tb rtl inside horizontal-tb ltr - If end side is 'auto' and start side is not, 'auto' resolves to used value
-Fail horizontal-tb rtl inside horizontal-tb ltr - If opposite sides are 'auto', they resolve to used value
+Pass horizontal-tb rtl inside horizontal-tb ltr - If opposite sides are 'auto', they resolve to used value
Pass horizontal-tb rtl inside horizontal-tb rtl - Pixels resolve as-is
Pass horizontal-tb rtl inside horizontal-tb rtl - Relative lengths are absolutized into pixels
Pass horizontal-tb rtl inside horizontal-tb rtl - Percentages are absolutized into pixels
@@ -84,7 +84,7 @@ Pass horizontal-tb rtl inside vertical-lr ltr - Pixels resolve as-is when overco
Pass horizontal-tb rtl inside vertical-lr ltr - Percentages absolutize the computed value when overconstrained
Pass horizontal-tb rtl inside vertical-lr ltr - If start side is 'auto' and end side is not, 'auto' resolves to used value
Pass horizontal-tb rtl inside vertical-lr ltr - If end side is 'auto' and start side is not, 'auto' resolves to used value
-Fail horizontal-tb rtl inside vertical-lr ltr - If opposite sides are 'auto', they resolve to used value
+Pass horizontal-tb rtl inside vertical-lr ltr - If opposite sides are 'auto', they resolve to used value
Pass horizontal-tb rtl inside vertical-lr rtl - Pixels resolve as-is
Pass horizontal-tb rtl inside vertical-lr rtl - Relative lengths are absolutized into pixels
Pass horizontal-tb rtl inside vertical-lr rtl - Percentages are absolutized into pixels
@@ -120,7 +120,7 @@ Pass vertical-lr ltr inside horizontal-tb ltr - Pixels resolve as-is when overco
Pass vertical-lr ltr inside horizontal-tb ltr - Percentages absolutize the computed value when overconstrained
Pass vertical-lr ltr inside horizontal-tb ltr - If start side is 'auto' and end side is not, 'auto' resolves to used value
Pass vertical-lr ltr inside horizontal-tb ltr - If end side is 'auto' and start side is not, 'auto' resolves to used value
-Fail vertical-lr ltr inside horizontal-tb ltr - If opposite sides are 'auto', they resolve to used value
+Pass vertical-lr ltr inside horizontal-tb ltr - If opposite sides are 'auto', they resolve to used value
Pass vertical-lr ltr inside horizontal-tb rtl - Pixels resolve as-is
Pass vertical-lr ltr inside horizontal-tb rtl - Relative lengths are absolutized into pixels
Pass vertical-lr ltr inside horizontal-tb rtl - Percentages are absolutized into pixels
@@ -138,7 +138,7 @@ Pass vertical-lr ltr inside vertical-lr ltr - Pixels resolve as-is when overcons
Pass vertical-lr ltr inside vertical-lr ltr - Percentages absolutize the computed value when overconstrained
Pass vertical-lr ltr inside vertical-lr ltr - If start side is 'auto' and end side is not, 'auto' resolves to used value
Pass vertical-lr ltr inside vertical-lr ltr - If end side is 'auto' and start side is not, 'auto' resolves to used value
-Fail vertical-lr ltr inside vertical-lr ltr - If opposite sides are 'auto', they resolve to used value
+Pass vertical-lr ltr inside vertical-lr ltr - If opposite sides are 'auto', they resolve to used value
Pass vertical-lr ltr inside vertical-lr rtl - Pixels resolve as-is
Pass vertical-lr ltr inside vertical-lr rtl - Relative lengths are absolutized into pixels
Pass vertical-lr ltr inside vertical-lr rtl - Percentages are absolutized into pixels
@@ -174,7 +174,7 @@ Pass vertical-lr rtl inside horizontal-tb ltr - Pixels resolve as-is when overco
Pass vertical-lr rtl inside horizontal-tb ltr - Percentages absolutize the computed value when overconstrained
Pass vertical-lr rtl inside horizontal-tb ltr - If start side is 'auto' and end side is not, 'auto' resolves to used value
Pass vertical-lr rtl inside horizontal-tb ltr - If end side is 'auto' and start side is not, 'auto' resolves to used value
-Fail vertical-lr rtl inside horizontal-tb ltr - If opposite sides are 'auto', they resolve to used value
+Pass vertical-lr rtl inside horizontal-tb ltr - If opposite sides are 'auto', they resolve to used value
Pass vertical-lr rtl inside horizontal-tb rtl - Pixels resolve as-is
Pass vertical-lr rtl inside horizontal-tb rtl - Relative lengths are absolutized into pixels
Pass vertical-lr rtl inside horizontal-tb rtl - Percentages are absolutized into pixels
@@ -192,7 +192,7 @@ Pass vertical-lr rtl inside vertical-lr ltr - Pixels resolve as-is when overcons
Pass vertical-lr rtl inside vertical-lr ltr - Percentages absolutize the computed value when overconstrained
Pass vertical-lr rtl inside vertical-lr ltr - If start side is 'auto' and end side is not, 'auto' resolves to used value
Pass vertical-lr rtl inside vertical-lr ltr - If end side is 'auto' and start side is not, 'auto' resolves to used value
-Fail vertical-lr rtl inside vertical-lr ltr - If opposite sides are 'auto', they resolve to used value
+Pass vertical-lr rtl inside vertical-lr ltr - If opposite sides are 'auto', they resolve to used value
Pass vertical-lr rtl inside vertical-lr rtl - Pixels resolve as-is
Pass vertical-lr rtl inside vertical-lr rtl - Relative lengths are absolutized into pixels
Pass vertical-lr rtl inside vertical-lr rtl - Percentages are absolutized into pixels
@@ -228,7 +228,7 @@ Pass vertical-rl ltr inside horizontal-tb ltr - Pixels resolve as-is when overco
Pass vertical-rl ltr inside horizontal-tb ltr - Percentages absolutize the computed value when overconstrained
Pass vertical-rl ltr inside horizontal-tb ltr - If start side is 'auto' and end side is not, 'auto' resolves to used value
Pass vertical-rl ltr inside horizontal-tb ltr - If end side is 'auto' and start side is not, 'auto' resolves to used value
-Fail vertical-rl ltr inside horizontal-tb ltr - If opposite sides are 'auto', they resolve to used value
+Pass vertical-rl ltr inside horizontal-tb ltr - If opposite sides are 'auto', they resolve to used value
Pass vertical-rl ltr inside horizontal-tb rtl - Pixels resolve as-is
Pass vertical-rl ltr inside horizontal-tb rtl - Relative lengths are absolutized into pixels
Pass vertical-rl ltr inside horizontal-tb rtl - Percentages are absolutized into pixels
@@ -246,7 +246,7 @@ Pass vertical-rl ltr inside vertical-lr ltr - Pixels resolve as-is when overcons
Pass vertical-rl ltr inside vertical-lr ltr - Percentages absolutize the computed value when overconstrained
Pass vertical-rl ltr inside vertical-lr ltr - If start side is 'auto' and end side is not, 'auto' resolves to used value
Pass vertical-rl ltr inside vertical-lr ltr - If end side is 'auto' and start side is not, 'auto' resolves to used value
-Fail vertical-rl ltr inside vertical-lr ltr - If opposite sides are 'auto', they resolve to used value
+Pass vertical-rl ltr inside vertical-lr ltr - If opposite sides are 'auto', they resolve to used value
Pass vertical-rl ltr inside vertical-lr rtl - Pixels resolve as-is
Pass vertical-rl ltr inside vertical-lr rtl - Relative lengths are absolutized into pixels
Pass vertical-rl ltr inside vertical-lr rtl - Percentages are absolutized into pixels
@@ -282,7 +282,7 @@ Pass vertical-rl rtl inside horizontal-tb ltr - Pixels resolve as-is when overco
Pass vertical-rl rtl inside horizontal-tb ltr - Percentages absolutize the computed value when overconstrained
Pass vertical-rl rtl inside horizontal-tb ltr - If start side is 'auto' and end side is not, 'auto' resolves to used value
Pass vertical-rl rtl inside horizontal-tb ltr - If end side is 'auto' and start side is not, 'auto' resolves to used value
-Fail vertical-rl rtl inside horizontal-tb ltr - If opposite sides are 'auto', they resolve to used value
+Pass vertical-rl rtl inside horizontal-tb ltr - If opposite sides are 'auto', they resolve to used value
Pass vertical-rl rtl inside horizontal-tb rtl - Pixels resolve as-is
Pass vertical-rl rtl inside horizontal-tb rtl - Relative lengths are absolutized into pixels
Pass vertical-rl rtl inside horizontal-tb rtl - Percentages are absolutized into pixels
@@ -300,7 +300,7 @@ Pass vertical-rl rtl inside vertical-lr ltr - Pixels resolve as-is when overcons
Pass vertical-rl rtl inside vertical-lr ltr - Percentages absolutize the computed value when overconstrained
Pass vertical-rl rtl inside vertical-lr ltr - If start side is 'auto' and end side is not, 'auto' resolves to used value
Pass vertical-rl rtl inside vertical-lr ltr - If end side is 'auto' and start side is not, 'auto' resolves to used value
-Fail vertical-rl rtl inside vertical-lr ltr - If opposite sides are 'auto', they resolve to used value
+Pass vertical-rl rtl inside vertical-lr ltr - If opposite sides are 'auto', they resolve to used value
Pass vertical-rl rtl inside vertical-lr rtl - Pixels resolve as-is
Pass vertical-rl rtl inside vertical-lr rtl - Relative lengths are absolutized into pixels
Pass vertical-rl rtl inside vertical-lr rtl - Percentages are absolutized into pixels