Skip to content

Truly independent web browser

LibWeb: Include relative offsets in anchor rectangles

sideshowbarker9f5870caf955
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index 14beb9b2abc..ffddf4e3a86 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -552,12 +552,21 @@ pub(crate) fn place_child(
abspos_boxes_placed_with_it.extend(lay_out_pending_abspos_children(run, batch));
}
let node_facts = NodeFacts::new(pass, node);
+ let committed_offset = point_add(
+ offset,
+ committed_offset_delta_at_placement(
+ pass,
+ node,
+ facts_decided_by_parent.used_insets,
+ offset_from_relatively_positioned_inline_ancestors,
+ ),
+ );
let own_anchor_candidate_border_box_rect = (node_facts.is_box() && node_facts.has_anchor_names()).then(|| {
let metrics = &geometry.cells;
let collapsed = metrics.uses_collapsing_borders_model();
CssPixelRect {
- x: offset.x - metrics.border_box_left(collapsed),
- y: offset.y - metrics.border_box_top(collapsed),
+ x: committed_offset.x - metrics.border_box_left(collapsed),
+ y: committed_offset.y - metrics.border_box_top(collapsed),
width: metrics.border_box_inline_size(collapsed),
height: metrics.border_box_block_size(collapsed),
}
@@ -570,15 +579,7 @@ pub(crate) fn place_child(
facts_decided_by_parent,
abspos_layout_inputs,
resolve_containing_line_box_index(pass, node, containing_line_box_fragment),
- point_add(
- offset,
- committed_offset_delta_at_placement(
- pass,
- node,
- facts_decided_by_parent.used_insets,
- offset_from_relatively_positioned_inline_ancestors,
- ),
- ),
+ committed_offset,
own_anchor_candidate_border_box_rect,
physical_contents_shift,
);
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index c456c0dd4cc..359de172a77 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -1323,6 +1323,8 @@ Text/input/SiteIsolation/iframe/mixed-content-of-an-isolated-iframes-navigation-
Text/input/wpt-import/webmessaging/broadcastchannel/opaque-origin.html
[Skipped]
+; Need position-visibility: no-overflow to hide a target that overflows after scrolling
+Ref/input/wpt-import/css/css-anchor-position/position-visibility-no-overflow-scroll.html
; Need absolutely positioned boxes fragmented across columns
Ref/input/wpt-import/css/css-position/position-absolute-in-inline-010.html
Ref/input/wpt-import/css/css-position/position-absolute-in-inline-011.html
diff --git a/Tests/LibWeb/Text/expected/anchor-relative-position-offsets.txt b/Tests/LibWeb/Text/expected/anchor-relative-position-offsets.txt
new file mode 100644
index 00000000000..a359f324669
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/anchor-relative-position-offsets.txt
@@ -0,0 +1,5 @@
+relative block anchor: true, true
+relative inline-block anchor: true, true
+relative anchor moved: true, true
+relative inline ancestor: true, true
+relative anchor functions: true, true, true
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-003.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-003.txt
index f6d36d8c196..fd5463b69c4 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-003.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-003.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail .target 1
\ No newline at end of file
+1 Pass
+Pass .target 1
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-004.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-004.txt
index 97d2549b9e7..2b2f005a1b1 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-004.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-004.txt
@@ -2,6 +2,6 @@ Harness status: OK
Found 2 tests
-2 Fail
-Fail .target 1
-Fail .target 2
\ No newline at end of file
+2 Pass
+Pass .target 1
+Pass .target 2
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-htb-htb.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-htb-htb.txt
index dff61fa0d3b..eaec421192f 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-htb-htb.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-htb-htb.txt
@@ -2,10 +2,10 @@ Harness status: OK
Found 10 tests
-8 Pass
-2 Fail
+9 Pass
+1 Fail
Pass .target 1
-Fail .target 2
+Pass .target 2
Pass .target 3
Pass .target 4
Pass .target 5
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-htb-vrl.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-htb-vrl.txt
index dff61fa0d3b..eaec421192f 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-htb-vrl.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-htb-vrl.txt
@@ -2,10 +2,10 @@ Harness status: OK
Found 10 tests
-8 Pass
-2 Fail
+9 Pass
+1 Fail
Pass .target 1
-Fail .target 2
+Pass .target 2
Pass .target 3
Pass .target 4
Pass .target 5
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-vrl-htb.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-vrl-htb.txt
index dff61fa0d3b..eaec421192f 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-vrl-htb.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-vrl-htb.txt
@@ -2,10 +2,10 @@ Harness status: OK
Found 10 tests
-8 Pass
-2 Fail
+9 Pass
+1 Fail
Pass .target 1
-Fail .target 2
+Pass .target 2
Pass .target 3
Pass .target 4
Pass .target 5
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-vrl-vrl.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-vrl-vrl.txt
index dff61fa0d3b..eaec421192f 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-vrl-vrl.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/anchor-center-vrl-vrl.txt
@@ -2,10 +2,10 @@ Harness status: OK
Found 10 tests
-8 Pass
-2 Fail
+9 Pass
+1 Fail
Pass .target 1
-Fail .target 2
+Pass .target 2
Pass .target 3
Pass .target 4
Pass .target 5
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-animation.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-animation.txt
index 11c867cb1cf..96feab10718 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-animation.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-animation.txt
@@ -2,7 +2,8 @@ Harness status: OK
Found 3 tests
-3 Fail
-Fail Starts rendering with flip-block
+2 Pass
+1 Fail
+Pass Starts rendering with flip-block
Fail No successful position, keep flip-block
-Fail Base position without fallback now successful
\ No newline at end of file
+Pass Base position without fallback now successful
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-basic.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-basic.txt
index 11c867cb1cf..96feab10718 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-basic.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-basic.txt
@@ -2,7 +2,8 @@ Harness status: OK
Found 3 tests
-3 Fail
-Fail Starts rendering with flip-block
+2 Pass
+1 Fail
+Pass Starts rendering with flip-block
Fail No successful position, keep flip-block
-Fail Base position without fallback now successful
\ No newline at end of file
+Pass Base position without fallback now successful
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-change-fallbacks-position-area.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-change-fallbacks-position-area.txt
index d39f88cd094..08d783055ab 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-change-fallbacks-position-area.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-change-fallbacks-position-area.txt
@@ -2,7 +2,7 @@ Harness status: OK
Found 3 tests
-3 Fail
-Fail Starts rendering with fallback
-Fail Both base and fallback works, position-try-fallbacks is set to the same value, keeps fallback
-Fail position-try-fallbacks is set to a different value, both base and fallback works, uses base because last successful position option is invalidated
\ No newline at end of file
+3 Pass
+Pass Starts rendering with fallback
+Pass Both base and fallback works, position-try-fallbacks is set to the same value, keeps fallback
+Pass position-try-fallbacks is set to a different value, both base and fallback works, uses base because last successful position option is invalidated
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-change-fallbacks.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-change-fallbacks.txt
index 90b1b214139..1f7b61146c8 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-change-fallbacks.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-change-fallbacks.txt
@@ -2,7 +2,8 @@ Harness status: OK
Found 3 tests
-3 Fail
-Fail Starts rendering with flip-block
+1 Pass
+2 Fail
+Pass Starts rendering with flip-block
Fail No successful position, keep flip-block
Fail No successful position, last successful invalidated by position-try-fallbacks change
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-change-try-rule.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-change-try-rule.txt
index 918e04f7763..25038ee1870 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-change-try-rule.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-change-try-rule.txt
@@ -2,7 +2,8 @@ Harness status: OK
Found 3 tests
-3 Fail
-Fail Starts rendering with --try
+1 Pass
+2 Fail
+Pass Starts rendering with --try
Fail No successful position, keep --try
Fail No successful position, last successful invalidated by @position-try change
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-fallback-to-base-style.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-fallback-to-base-style.txt
index baefb33c859..8649990ba39 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-fallback-to-base-style.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-fallback-to-base-style.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 3 tests
-1 Pass
-2 Fail
-Fail Starts rendering with flip-inline fallback
-Fail Base position without fallback now successful
+3 Pass
+Pass Starts rendering with flip-inline fallback
+Pass Base position without fallback now successful
Pass Both base position and flip-inline works, keep base position since it's the last successful option
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-iframe.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-iframe.txt
index 11c867cb1cf..96feab10718 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-iframe.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-iframe.txt
@@ -2,7 +2,8 @@ Harness status: OK
Found 3 tests
-3 Fail
-Fail Starts rendering with flip-block
+2 Pass
+1 Fail
+Pass Starts rendering with flip-block
Fail No successful position, keep flip-block
-Fail Base position without fallback now successful
\ No newline at end of file
+Pass Base position without fallback now successful
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-intermediate-ignored.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-intermediate-ignored.txt
index 24076f4f27b..fe93838e741 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-intermediate-ignored.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-intermediate-ignored.txt
@@ -2,6 +2,7 @@ Harness status: OK
Found 2 tests
-2 Fail
-Fail Starts rendering with flip-block
+1 Pass
+1 Fail
+Pass Starts rendering with flip-block
Fail No successful position (with intermediate successful), keep flip-block
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-pseudo-element-basic.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-pseudo-element-basic.txt
index 11c867cb1cf..0b93041f049 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-pseudo-element-basic.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-pseudo-element-basic.txt
@@ -2,7 +2,7 @@ Harness status: OK
Found 3 tests
-3 Fail
-Fail Starts rendering with flip-block
-Fail No successful position, keep flip-block
-Fail Base position without fallback now successful
\ No newline at end of file
+3 Pass
+Pass Starts rendering with flip-block
+Pass No successful position, keep flip-block
+Pass Base position without fallback now successful
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-pseudo-element-fallbacks.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-pseudo-element-fallbacks.txt
index 90b1b214139..e261df30dad 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-pseudo-element-fallbacks.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-anchor-position/last-successful-pseudo-element-fallbacks.txt
@@ -2,7 +2,7 @@ Harness status: OK
Found 3 tests
-3 Fail
-Fail Starts rendering with flip-block
-Fail No successful position, keep flip-block
-Fail No successful position, last successful invalidated by position-try-fallbacks change
\ No newline at end of file
+3 Pass
+Pass Starts rendering with flip-block
+Pass No successful position, keep flip-block
+Pass No successful position, last successful invalidated by position-try-fallbacks change
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/anchor-relative-position-offsets.html b/Tests/LibWeb/Text/input/anchor-relative-position-offsets.html
new file mode 100644
index 00000000000..8e79dee02ad
--- /dev/null
+++ b/Tests/LibWeb/Text/input/anchor-relative-position-offsets.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<script src="include.js"></script>
+<style>
+body { margin: 0; }
+#out { position: absolute; }
+#anchor { position: relative; left: 100px; top: 80px; width: 100px; height: 40px; anchor-name: --anchor; }
+#target { position: absolute; inset: auto; margin: 0; width: 60px; height: 20px; position-anchor: --anchor; position-area: top left; }
+</style>
+<div id="anchor"></div>
+<div id="target"></div>
+<script>
+test(() => {
+ const anchor = document.getElementById("anchor");
+ const target = document.getElementById("target");
+ function reportArea(label) {
+ const a = anchor.getBoundingClientRect();
+ const t = target.getBoundingClientRect();
+ println(`${label}: ${t.right === a.left}, ${t.bottom === a.top}`);
+ }
+ reportArea("relative block anchor");
+ anchor.style.display = "inline-block";
+ reportArea("relative inline-block anchor");
+ anchor.style.left = "160px";
+ anchor.style.top = "120px";
+ reportArea("relative anchor moved");
+ const wrapper = document.createElement("span");
+ wrapper.style.cssText = "position: relative; left: 35px; top: 25px;";
+ anchor.before(wrapper);
+ wrapper.append(anchor);
+ reportArea("relative inline ancestor");
+ target.style.positionArea = "none";
+ target.style.left = "anchor(left)";
+ target.style.top = "anchor(bottom)";
+ target.style.width = "anchor-size(width)";
+ const a = anchor.getBoundingClientRect();
+ const t = target.getBoundingClientRect();
+ println(`relative anchor functions: ${t.left === a.left}, ${t.top === a.bottom}, ${t.width === a.width}`);
+});
+</script>