commit e8702c723d3d5985a1263a37325578a21f061a5b
parent 5462742b3ea5cc18c876e9a76e0beded8bff694c
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date: Fri, 12 Dec 2025 13:22:59 +0000
Bug 2005461 - Prevent anchoring a fixed pos to its own descendant. r=jwatt
Will add a test if there's none.
Differential Revision: https://phabricator.services.mozilla.com/D276008
Diffstat:
3 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/layout/base/AnchorPositioningUtils.cpp b/layout/base/AnchorPositioningUtils.cpp
@@ -208,7 +208,8 @@ bool IsAnchorLaidOutStrictlyBeforeElement(
// possible anchor's containing block isn't.
if (positionedContainingBlock->IsViewportFrame() &&
!anchorContainingBlock->IsViewportFrame()) {
- return true;
+ return !nsLayoutUtils::IsProperAncestorFrame(aPositionedFrame,
+ aPossibleAnchorFrame);
}
auto isLastContainingBlockOrderable =
diff --git a/testing/web-platform/tests/css/css-anchor-position/anchor-fixed-pos-descendant-ref.html b/testing/web-platform/tests/css/css-anchor-position/anchor-fixed-pos-descendant-ref.html
@@ -0,0 +1,30 @@
+<!doctype html>
+<title>CSS Test Reference</title>
+<style>
+p {
+ display: block;
+ outline: 1px solid;
+ height: 1lh;
+ anchor-name: --foo;
+ anchor-scope: --foo;
+ overflow: hidden;
+ resize: horizontal;
+}
+
+p > span {
+ position: fixed;
+ pointer-events: none;
+ inset: anchor(--foo inside);
+ right: anchor(--foo right, 0);
+ left: 0;
+
+ &::before {
+ content: "";
+ position: absolute;
+ inset: 0;
+ width: 10px;
+ background-color: pink;
+ }
+}
+</style>
+<p style="width: 100px"><span></span></p>
diff --git a/testing/web-platform/tests/css/css-anchor-position/anchor-fixed-pos-descendant.html b/testing/web-platform/tests/css/css-anchor-position/anchor-fixed-pos-descendant.html
@@ -0,0 +1,36 @@
+<!doctype html>
+<title>Anchor positioning to your own descendant shouldn't work</title>
+<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=2005461">
+<link rel="help" href="https://drafts.csswg.org/css-anchor-position-1/#target">
+<link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez">
+<link rel="author" href="https://mozilla.com" title="Mozilla">
+<link rel="match" href="anchor-fixed-pos-descendant-ref.html">
+<style>
+p {
+ display: block;
+ outline: 1px solid;
+ height: 1lh;
+ anchor-name: --foo;
+ anchor-scope: --foo;
+ overflow: hidden;
+ resize: horizontal;
+}
+
+p > span {
+ position: fixed;
+ pointer-events: none;
+ inset: anchor(--foo inside);
+ left: anchor(--anchor right, 0);
+ right: anchor(--foo right, 0);
+
+ &::before {
+ content: "";
+ position: absolute;
+ inset: 0;
+ anchor-name: --anchor;
+ width: 10px;
+ background-color: pink;
+ }
+}
+</style>
+<p style="width: 100px"><span></span></p>