commit 23038681a70bfaf04f53cc7f40c42486777475e0
parent 9761a76f2452e9c719aedafc351618b098b9c278
Author: Cristina Horotan <chorotan@mozilla.com>
Date: Mon, 8 Dec 2025 07:51:38 +0200
Revert "Bug 2004040: Properly nudge overflowing abspos elements into IMCB. r=layout-anchor-positioning-reviewers,layout-reviewers,emilio" for causing wpt failures on align-self-default-overflow-htb-ltr-htb.html
This reverts commit e338585458bfdf4a7530fd75a5363fe6cd7c423d.
Revert "Bug 2004040: Improve handling of orthogonal anchor-center alignment r=layout-anchor-positioning-reviewers,firefox-style-system-reviewers,layout-reviewers,emilio"
This reverts commit 275da674fe527ff459c0475864e6d24e91e9a541.
Diffstat:
10 files changed, 54 insertions(+), 56 deletions(-)
diff --git a/layout/generic/AbsoluteContainingBlock.cpp b/layout/generic/AbsoluteContainingBlock.cpp
@@ -780,9 +780,9 @@ static nscoord OffsetToAlignedStaticPos(
aKidSizeInAbsPosCBWM.ConvertTo(kidWM, aAbsPosCBWM);
const LogicalAxis kidAxis = aAbsPosCBWM.ConvertAxisTo(aAbsPosCBAxis, kidWM);
- // Build an Inset Modified anchor info from the anchor which can be used to
- // align to the anchor-center, if AlignJustifySelf is AnchorCenter.
- Maybe<CSSAlignUtils::AnchorAlignInfo> anchorAlignInfo;
+ // Build an Inset Modified rect from the anchor which can be used to align
+ // to the anchor-center, if AlignJustifySelf is AnchorCenter.
+ Maybe<LogicalRect> insetModifiedAnchorRect;
if (alignConst == StyleAlignFlags::ANCHOR_CENTER &&
aKidReflowInput.mAnchorPosResolutionCache) {
const auto* referenceData =
@@ -793,23 +793,14 @@ static nscoord OffsetToAlignedStaticPos(
if (cachedData && *cachedData) {
const auto& data = cachedData->ref();
if (data.mOffsetData) {
- const nsSize containerSize =
- aAbsPosCBSize.GetPhysicalSize(aAbsPosCBWM);
- const nsRect anchorRect(data.mOffsetData->mOrigin, data.mSize);
- const LogicalRect logicalAnchorRect{aAbsPosCBWM, anchorRect,
- containerSize};
- const auto axisInAbsPosCBWM =
- kidWM.ConvertAxisTo(kidAxis, aAbsPosCBWM);
- const auto anchorStart =
- logicalAnchorRect.Start(axisInAbsPosCBWM, aAbsPosCBWM);
- const auto anchorSize =
- logicalAnchorRect.Size(axisInAbsPosCBWM, aAbsPosCBWM);
- anchorAlignInfo =
- Some(CSSAlignUtils::AnchorAlignInfo{anchorStart, anchorSize});
+ nsSize containerSize = aAbsPosCBSize.GetPhysicalSize(aAbsPosCBWM);
+ nsRect anchorRect(data.mOffsetData->mOrigin, data.mSize);
+ LogicalRect logicalAnchorRect(kidWM, anchorRect, containerSize);
if (aNonAutoAlignParams) {
- anchorAlignInfo->mAnchorStart -=
+ logicalAnchorRect.Start(kidAxis, kidWM) -=
aNonAutoAlignParams->mCurrentStartInset;
}
+ insetModifiedAnchorRect = Some(logicalAnchorRect);
}
}
}
@@ -817,7 +808,7 @@ static nscoord OffsetToAlignedStaticPos(
nscoord offset = CSSAlignUtils::AlignJustifySelf(
alignConst, kidAxis, flags, baselineAdjust, alignAreaSizeInAxis,
- aKidReflowInput, kidSizeInOwnWM, anchorAlignInfo);
+ aKidReflowInput, kidSizeInOwnWM, insetModifiedAnchorRect);
// Safe alignment clamping for anchor-center.
// When using anchor-center with the safe keyword, or when both insets are
@@ -867,13 +858,11 @@ static nscoord OffsetToAlignedStaticPos(
// 1. We fit inside the IMCB, no action needed.
} else if (kidSize <= overflowLimitRectEnd - overflowLimitRectStart) {
// 2. We overflowed IMCB, try to cover IMCB completely, if it's not.
- if (kidEnd < imcbEnd && kidStart < imcbStart) {
- // Space to end, overflowing on start - nudge to end.
- offset += std::min(imcbStart - kidStart, imcbEnd - kidEnd);
- } else if (kidStart > imcbStart && kidEnd > imcbEnd) {
- // Space to start, overflowing on end - nudge to start.
- offset -= std::min(kidEnd - imcbEnd, kidStart - imcbStart);
- } else if (kidStart >= imcbStart && kidEnd <= imcbEnd) {
+ if (kidEnd < imcbEnd) {
+ offset += imcbEnd - kidEnd;
+ } else if (kidStart > imcbStart) {
+ offset -= kidStart - imcbStart;
+ } else {
// IMCB already covered, ensure that we aren't escaping the limit rect.
if (kidStart < overflowLimitRectStart) {
offset += overflowLimitRectStart - kidStart;
diff --git a/layout/generic/CSSAlignUtils.cpp b/layout/generic/CSSAlignUtils.cpp
@@ -19,11 +19,13 @@ static nscoord SpaceToFill(WritingMode aWM, const LogicalSize& aSize,
return aCBSize - (size + aMargin);
}
-nscoord CSSAlignUtils::AlignJustifySelf(
- const StyleAlignFlags& aAlignment, LogicalAxis aAxis,
- AlignJustifyFlags aFlags, nscoord aBaselineAdjust, nscoord aCBSize,
- const ReflowInput& aRI, const LogicalSize& aChildSize,
- const Maybe<AnchorAlignInfo>& aAnchorInfo) {
+nscoord CSSAlignUtils::AlignJustifySelf(const StyleAlignFlags& aAlignment,
+ LogicalAxis aAxis,
+ AlignJustifyFlags aFlags,
+ nscoord aBaselineAdjust,
+ nscoord aCBSize, const ReflowInput& aRI,
+ const LogicalSize& aChildSize,
+ const Maybe<LogicalRect>& aAnchorRect) {
MOZ_ASSERT(aAlignment != StyleAlignFlags::AUTO,
"auto values should have resolved already");
MOZ_ASSERT(aAlignment != StyleAlignFlags::LEFT &&
@@ -132,9 +134,9 @@ nscoord CSSAlignUtils::AlignJustifySelf(
} else if (alignment == StyleAlignFlags::END) {
nscoord size = aChildSize.Size(aAxis, wm);
offset = aCBSize - (size + marginEnd);
- } else if (alignment == StyleAlignFlags::ANCHOR_CENTER && aAnchorInfo) {
- const nscoord anchorSize = aAnchorInfo->mAnchorSize;
- const nscoord anchorStart = aAnchorInfo->mAnchorStart;
+ } else if (alignment == StyleAlignFlags::ANCHOR_CENTER && aAnchorRect) {
+ const nscoord anchorSize = aAnchorRect->Size(aAxis, wm);
+ const nscoord anchorStart = aAnchorRect->Start(aAxis, wm);
const nscoord size = aChildSize.Size(aAxis, wm);
// Offset relative to the anchors center, accounting for margins
diff --git a/layout/generic/CSSAlignUtils.h b/layout/generic/CSSAlignUtils.h
@@ -47,15 +47,6 @@ class CSSAlignUtils {
using AlignJustifyFlags = EnumSet<AlignJustifyFlag>;
/**
- * Additional information required to resolve anchor-center on a particular
- * axis.
- */
- struct AnchorAlignInfo {
- nscoord mAnchorStart;
- nscoord mAnchorSize;
- };
-
- /**
* This computes the aligned offset of a CSS-aligned child within its
* alignment container. The returned offset is distance between the
* logical "start" edge of the alignment container & the logical "start" edge
@@ -71,14 +62,15 @@ class CSSAlignUtils {
* @param aCBSize The size of the alignment container, in its aAxis.
* @param aRI A ReflowInput for the child.
* @param aChildSize The child's LogicalSize (in its own writing mode).
- * @param aAnchorInfo When specified, an inset-modified anchor start and size
- * (in the child's writing mode) to use for anchor-center alignment.
+ * @param aAnchorRect When specified, an inset-modified anchor rect (in the
+ * child's writing mode) to use for anchor-center
+ * alignment.
*/
static nscoord AlignJustifySelf(
const StyleAlignFlags& aAlignment, LogicalAxis aAxis,
AlignJustifyFlags aFlags, nscoord aBaselineAdjust, nscoord aCBSize,
const ReflowInput& aRI, const LogicalSize& aChildSize,
- const Maybe<AnchorAlignInfo>& aAnchorRect = Nothing());
+ const Maybe<LogicalRect>& aAnchorRect = Nothing());
};
} // namespace mozilla
diff --git a/layout/generic/ReflowInput.cpp b/layout/generic/ReflowInput.cpp
@@ -60,7 +60,7 @@ void ComputeAnchorCenterUsage(
}
const auto* stylePos = aFrame->StylePosition();
- const auto parentWM = parent->GetWritingMode();
+ WritingMode wm = aFrame->GetWritingMode();
auto checkAxis = [&](LogicalAxis aAxis) {
StyleAlignFlags alignment =
@@ -69,10 +69,12 @@ void ComputeAnchorCenterUsage(
StyleAlignFlags::ANCHOR_CENTER) {
return false;
}
- LogicalSide startSide = MakeLogicalSide(aAxis, LogicalEdge::Start);
- LogicalSide endSide = MakeLogicalSide(aAxis, LogicalEdge::End);
- return stylePos->mOffset.Get(parentWM.PhysicalSide(startSide)).IsAuto() ||
- stylePos->mOffset.Get(parentWM.PhysicalSide(endSide)).IsAuto();
+ LogicalSide startSide = aAxis == LogicalAxis::Inline ? LogicalSide::IStart
+ : LogicalSide::BStart;
+ LogicalSide endSide =
+ aAxis == LogicalAxis::Inline ? LogicalSide::IEnd : LogicalSide::BEnd;
+ return stylePos->mOffset.Get(wm.PhysicalSide(startSide)).IsAuto() ||
+ stylePos->mOffset.Get(wm.PhysicalSide(endSide)).IsAuto();
};
aInlineUsesAnchorCenter = checkAxis(LogicalAxis::Inline);
diff --git a/layout/style/nsStyleStruct.cpp b/layout/style/nsStyleStruct.cpp
@@ -34,7 +34,6 @@
#include "nsCOMPtr.h"
#include "nsCRTGlue.h"
#include "nsCSSProps.h"
-#include "nsContainerFrame.h"
#include "nsDeviceContext.h"
#include "nsIURI.h"
#include "nsIURIMutator.h"
@@ -1333,12 +1332,8 @@ bool AnchorResolvedInsetHelper::SideUsesAnchorCenter(
if (!frame) {
return false;
}
- const nsIFrame* parent = frame->GetParent();
- if (!parent) {
- return false;
- }
- WritingMode wm = parent->GetWritingMode();
+ WritingMode wm = frame->GetWritingMode();
LogicalSide logicalSide = wm.LogicalSideForPhysicalSide(aSide);
LogicalAxis axis = GetAxis(logicalSide);
diff --git a/testing/web-platform/meta/css/css-anchor-position/anchor-center-htb-vrl.html.ini b/testing/web-platform/meta/css/css-anchor-position/anchor-center-htb-vrl.html.ini
@@ -0,0 +1,6 @@
+[anchor-center-htb-vrl.html]
+ [.target 2]
+ expected: FAIL
+
+ [.target 6]
+ expected: FAIL
diff --git a/testing/web-platform/meta/css/css-anchor-position/anchor-center-overflow-001.html.ini b/testing/web-platform/meta/css/css-anchor-position/anchor-center-overflow-001.html.ini
@@ -0,0 +1,2 @@
+[anchor-center-overflow-001.html]
+ expected: FAIL
diff --git a/testing/web-platform/meta/css/css-anchor-position/anchor-center-overflow-002.html.ini b/testing/web-platform/meta/css/css-anchor-position/anchor-center-overflow-002.html.ini
@@ -0,0 +1,2 @@
+[anchor-center-overflow-002.html]
+ expected: FAIL
diff --git a/testing/web-platform/meta/css/css-anchor-position/anchor-center-overflow-004.html.ini b/testing/web-platform/meta/css/css-anchor-position/anchor-center-overflow-004.html.ini
@@ -0,0 +1,2 @@
+[anchor-center-overflow-004.html]
+ expected: FAIL
diff --git a/testing/web-platform/meta/css/css-anchor-position/anchor-center-vrl-htb.html.ini b/testing/web-platform/meta/css/css-anchor-position/anchor-center-vrl-htb.html.ini
@@ -0,0 +1,6 @@
+[anchor-center-vrl-htb.html]
+ [.target 2]
+ expected: FAIL
+
+ [.target 6]
+ expected: FAIL