Bug 1269046 part 9: Add a flag to control whether CSSAlignUtils::AlignJustifySelf() expands "auto" margins. r?mats
MozReview-Commit-ID: I0UdEIfiOqX
--- a/layout/generic/CSSAlignUtils.cpp
+++ b/layout/generic/CSSAlignUtils.cpp
@@ -79,20 +79,24 @@ CSSAlignUtils::AlignJustifySelf(uint8_t
marginStart = margin.IEnd(wm);
marginEnd = margin.IStart(wm);
}
}
const auto& styleMargin = aRI.mStyleMargin->mMargin;
bool hasAutoMarginStart;
bool hasAutoMarginEnd;
- if (aAxis == eLogicalAxisBlock) {
+ if (aFlags & AlignJustifyFlags::eIgnoreAutoMargins) {
+ // (Note: ReflowInput will have treated "auto" margins as 0, so we
+ // don't need to do anything special to avoid expanding them.)
+ hasAutoMarginStart = hasAutoMarginEnd = false;
+ } else if (aAxis == eLogicalAxisBlock) {
hasAutoMarginStart = styleMargin.GetBStartUnit(wm) == eStyleUnit_Auto;
hasAutoMarginEnd = styleMargin.GetBEndUnit(wm) == eStyleUnit_Auto;
- } else {
+ } else { /* aAxis == eLogicalAxisInline */
hasAutoMarginStart = styleMargin.GetIStartUnit(wm) == eStyleUnit_Auto;
hasAutoMarginEnd = styleMargin.GetIEndUnit(wm) == eStyleUnit_Auto;
}
// https://drafts.csswg.org/css-align-3/#overflow-values
// This implements <overflow-position> = 'safe'.
// And auto-margins: https://drafts.csswg.org/css-grid/#auto-margins
if ((MOZ_UNLIKELY(isOverflowSafe) && aAlignment != NS_STYLE_ALIGN_START) ||
--- a/layout/generic/CSSAlignUtils.h
+++ b/layout/generic/CSSAlignUtils.h
@@ -19,16 +19,20 @@ public:
*/
enum class AlignJustifyFlags {
eNoFlags = 0,
// Indicates that we have <overflow-position> = safe.
eOverflowSafe = 1 << 0,
// Indicates that the container's start side in aAxis is the same
// as the child's start side in the child's parallel axis.
eSameSide = 1 << 1,
+ // Indicates that AlignJustifySelf() shouldn't expand "auto" margins.
+ // (By default, AlignJustifySelf() *will* expand such margins, to fill the
+ // available space before any alignment is done.)
+ eIgnoreAutoMargins = 1 << 2,
};
/**
* 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
* of the aligned child (in terms of the alignment container's writing mode).
*
--- a/layout/generic/nsAbsoluteContainingBlock.cpp
+++ b/layout/generic/nsAbsoluteContainingBlock.cpp
@@ -418,17 +418,17 @@ OffsetToAlignedStaticPos(const ReflowInp
NS_ERROR("Unsupported container for abpsos CSS Box Alignment");
return 0; // (leave the child at the start of its alignment container)
}
nscoord alignAreaSizeInAxis = (pcAxis == eLogicalAxisInline)
? alignAreaSize.ISize(pcWM)
: alignAreaSize.BSize(pcWM);
- AlignJustifyFlags flags = AlignJustifyFlags::eNoFlags;
+ AlignJustifyFlags flags = AlignJustifyFlags::eIgnoreAutoMargins;
uint16_t alignConst =
aPlaceholderContainer->CSSAlignmentForAbsPosChild(aKidReflowInput, pcAxis);
// XXXdholbert: Handle <overflow-position> in bug 1311892 (by conditionally
// setting AlignJustifyFlags::eOverflowSafe in |flags|.) For now, we behave
// as if "unsafe" was the specified value (which is basically equivalent to
// the default behavior, when no value is specified -- though the default
// behavior also has some [at-risk] extra nuance about scroll containers...)
// For now we ignore & strip off <overflow-position> bits, until bug 1311892.