Bug 1611583 - Use cbindgen for css-align types. r=dholbert

This provides stronger typing and removes a bunch of subtle constants matching.

Differential Revision: https://phabricator.services.mozilla.com/D61058

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2020-01-31 00:56:49 +00:00
Родитель 983a71b2a4
Коммит 4812f9408a
20 изменённых файлов: 672 добавлений и 826 удалений

Просмотреть файл

@ -18,40 +18,38 @@ static nscoord SpaceToFill(WritingMode aWM, const LogicalSize& aSize,
return aCBSize - (size + aMargin);
}
nscoord CSSAlignUtils::AlignJustifySelf(uint8_t aAlignment, LogicalAxis aAxis,
nscoord CSSAlignUtils::AlignJustifySelf(const StyleAlignFlags& aAlignment,
LogicalAxis aAxis,
AlignJustifyFlags aFlags,
nscoord aBaselineAdjust,
nscoord aCBSize, const ReflowInput& aRI,
const LogicalSize& aChildSize) {
MOZ_ASSERT(aAlignment != NS_STYLE_ALIGN_AUTO,
MOZ_ASSERT(aAlignment != StyleAlignFlags::AUTO,
"auto values should have resolved already");
MOZ_ASSERT(
aAlignment != NS_STYLE_ALIGN_LEFT && aAlignment != NS_STYLE_ALIGN_RIGHT,
"caller should map that to the corresponding START/END");
MOZ_ASSERT(aAlignment != StyleAlignFlags::LEFT &&
aAlignment != StyleAlignFlags::RIGHT,
"caller should map that to the corresponding START/END");
// Promote aFlags to convenience bools:
const bool isOverflowSafe = !!(aFlags & AlignJustifyFlags::OverflowSafe);
const bool isSameSide = !!(aFlags & AlignJustifyFlags::SameSide);
StyleAlignFlags alignment = aAlignment;
// Map some alignment values to 'start' / 'end'.
switch (aAlignment) {
case NS_STYLE_ALIGN_SELF_START: // align/justify-self: self-start
aAlignment =
MOZ_LIKELY(isSameSide) ? NS_STYLE_ALIGN_START : NS_STYLE_ALIGN_END;
break;
case NS_STYLE_ALIGN_SELF_END: // align/justify-self: self-end
aAlignment =
MOZ_LIKELY(isSameSide) ? NS_STYLE_ALIGN_END : NS_STYLE_ALIGN_START;
break;
if (alignment == StyleAlignFlags::SELF_START) {
// align/justify-self: self-start
alignment =
MOZ_LIKELY(isSameSide) ? StyleAlignFlags::START : StyleAlignFlags::END;
} else if (alignment == StyleAlignFlags::SELF_END) {
alignment =
MOZ_LIKELY(isSameSide) ? StyleAlignFlags::END : StyleAlignFlags::START;
// flex-start/flex-end are the same as start/end, in most contexts.
// (They have special behavior in flex containers, so flex containers
// should map them to some other value before calling this method.)
case NS_STYLE_ALIGN_FLEX_START:
aAlignment = NS_STYLE_ALIGN_START;
break;
case NS_STYLE_ALIGN_FLEX_END:
aAlignment = NS_STYLE_ALIGN_END;
break;
} else if (alignment == StyleAlignFlags::FLEX_START) {
alignment = StyleAlignFlags::START;
} else if (alignment == StyleAlignFlags::FLEX_END) {
alignment = StyleAlignFlags::END;
}
// XXX try to condense this code a bit by adding the necessary convenience
@ -97,7 +95,7 @@ nscoord CSSAlignUtils::AlignJustifySelf(uint8_t aAlignment, LogicalAxis aAxis,
// 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) ||
if ((MOZ_UNLIKELY(isOverflowSafe) && alignment != StyleAlignFlags::START) ||
hasAutoMarginStart || hasAutoMarginEnd) {
nscoord space =
SpaceToFill(wm, aChildSize, marginStart + marginEnd, aAxis, aCBSize);
@ -106,46 +104,39 @@ nscoord CSSAlignUtils::AlignJustifySelf(uint8_t aAlignment, LogicalAxis aAxis,
if (space < 0) {
// "Overflowing elements ignore their auto margins and overflow
// in the end directions"
aAlignment = NS_STYLE_ALIGN_START;
alignment = StyleAlignFlags::START;
} else if (hasAutoMarginEnd) {
aAlignment = hasAutoMarginStart ? NS_STYLE_ALIGN_CENTER
: (isSameSide ? NS_STYLE_ALIGN_START
: NS_STYLE_ALIGN_END);
alignment = hasAutoMarginStart ? StyleAlignFlags::CENTER
: (isSameSide ? StyleAlignFlags::START
: StyleAlignFlags::END);
} else if (hasAutoMarginStart) {
aAlignment = isSameSide ? NS_STYLE_ALIGN_END : NS_STYLE_ALIGN_START;
alignment = isSameSide ? StyleAlignFlags::END : StyleAlignFlags::START;
}
}
// Determine the offset for the child frame (its border-box) which will
// achieve the requested alignment.
nscoord offset = 0;
switch (aAlignment) {
case NS_STYLE_ALIGN_BASELINE:
case NS_STYLE_ALIGN_LAST_BASELINE:
if (MOZ_LIKELY(isSameSide == (aAlignment == NS_STYLE_ALIGN_BASELINE))) {
offset = marginStart + aBaselineAdjust;
} else {
nscoord size = aChildSize.Size(aAxis, wm);
offset = aCBSize - (size + marginEnd) - aBaselineAdjust;
}
break;
case NS_STYLE_ALIGN_STRETCH:
[[fallthrough]]; // ComputeSize() deals with it
case NS_STYLE_ALIGN_START:
offset = marginStart;
break;
case NS_STYLE_ALIGN_END: {
if (alignment == StyleAlignFlags::BASELINE ||
alignment == StyleAlignFlags::LAST_BASELINE) {
if (MOZ_LIKELY(isSameSide == (alignment == StyleAlignFlags::BASELINE))) {
offset = marginStart + aBaselineAdjust;
} else {
nscoord size = aChildSize.Size(aAxis, wm);
offset = aCBSize - (size + marginEnd);
break;
offset = aCBSize - (size + marginEnd) - aBaselineAdjust;
}
case NS_STYLE_ALIGN_CENTER: {
nscoord size = aChildSize.Size(aAxis, wm);
offset = (aCBSize - size + marginStart - marginEnd) / 2;
break;
}
default:
MOZ_ASSERT_UNREACHABLE("unknown align-/justify-self value");
} else if (alignment == StyleAlignFlags::STRETCH ||
alignment == StyleAlignFlags::START) {
// ComputeSize() deals with stretch
offset = marginStart;
} else if (alignment == StyleAlignFlags::END) {
nscoord size = aChildSize.Size(aAxis, wm);
offset = aCBSize - (size + marginEnd);
} else if (alignment == StyleAlignFlags::CENTER) {
nscoord size = aChildSize.Size(aAxis, wm);
offset = (aCBSize - size + marginStart - marginEnd) / 2;
} else {
MOZ_ASSERT_UNREACHABLE("unknown align-/justify-self value");
}
return offset;

Просмотреть файл

@ -14,6 +14,7 @@
namespace mozilla {
struct ReflowInput;
struct StyleAlignFlags;
class CSSAlignUtils {
public:
@ -41,7 +42,7 @@ class CSSAlignUtils {
*
* @param aAlignment An enumerated value representing a keyword for
* "align-self" or "justify-self". The values
* NS_STYLE_ALIGN_{AUTO,LEFT,RIGHT} must *not* be
* StyleAlignFlags::{AUTO,LEFT,RIGHT} must *not* be
* passed here; this method expects the caller to have
* already resolved those to 'start', 'end', or 'stretch'.
* @param aAxis The container's axis in which we're doing alignment.
@ -50,8 +51,8 @@ class CSSAlignUtils {
* @param aRI A ReflowInput for the child.
* @param aChildSize The child's LogicalSize (in its own writing mode).
*/
static nscoord AlignJustifySelf(uint8_t aAlignment, LogicalAxis aAxis,
AlignJustifyFlags aFlags,
static nscoord AlignJustifySelf(const StyleAlignFlags& aAlignment,
LogicalAxis aAxis, AlignJustifyFlags aFlags,
nscoord aBaselineAdjust, nscoord aCBSize,
const ReflowInput& aRI,
const LogicalSize& aChildSize);

Просмотреть файл

@ -2428,10 +2428,10 @@ void ReflowInput::InitConstraints(
// in its inline axis.
auto inlineAxisAlignment =
wm.IsOrthogonalTo(cbwm)
? mStylePosition->UsedAlignSelf(alignCB->Style())
: mStylePosition->UsedJustifySelf(alignCB->Style());
if ((inlineAxisAlignment != NS_STYLE_ALIGN_STRETCH &&
inlineAxisAlignment != NS_STYLE_ALIGN_NORMAL) ||
? mStylePosition->UsedAlignSelf(alignCB->Style())._0
: mStylePosition->UsedJustifySelf(alignCB->Style())._0;
if ((inlineAxisAlignment != StyleAlignFlags::STRETCH &&
inlineAxisAlignment != StyleAlignFlags::NORMAL) ||
mStyleMargin->mMargin.GetIStart(wm).IsAuto() ||
mStyleMargin->mMargin.GetIEnd(wm).IsAuto()) {
computeSizeFlags = ComputeSizeFlags(computeSizeFlags |

Просмотреть файл

@ -522,16 +522,17 @@ static nscoord OffsetToAlignedStaticPos(const ReflowInput& aKidReflowInput,
: alignAreaSize.BSize(pcWM);
AlignJustifyFlags flags = AlignJustifyFlags::IgnoreAutoMargins;
uint16_t alignConst = aPlaceholderContainer->CSSAlignmentForAbsPosChild(
aKidReflowInput, pcAxis);
StyleAlignFlags alignConst =
aPlaceholderContainer->CSSAlignmentForAbsPosChild(aKidReflowInput,
pcAxis);
// If the safe bit in alignConst is set, set the safe flag in |flags|.
// Note: If no <overflow-position> is specified, we behave as 'unsafe'.
// This doesn't quite match the css-align spec, which has an [at-risk]
// "smart default" behavior with some extra nuance about scroll containers.
if (alignConst & NS_STYLE_ALIGN_SAFE) {
if (alignConst & StyleAlignFlags::SAFE) {
flags |= AlignJustifyFlags::OverflowSafe;
}
alignConst &= ~NS_STYLE_ALIGN_FLAG_BITS;
alignConst &= ~StyleAlignFlags::FLAG_BITS;
// Find out if placeholder-container & the OOF child have the same start-sides
// in the placeholder-container's pcAxis.

Просмотреть файл

@ -1729,7 +1729,7 @@ bool nsContainerFrame::ResolvedOrientationIsVertical() {
return false;
}
uint16_t nsContainerFrame::CSSAlignmentForAbsPosChild(
StyleAlignFlags nsContainerFrame::CSSAlignmentForAbsPosChild(
const ReflowInput& aChildRI, LogicalAxis aLogicalAxis) const {
MOZ_ASSERT(aChildRI.mFrame->IsAbsolutelyPositioned(),
"This method should only be called for abspos children");
@ -1739,7 +1739,7 @@ uint16_t nsContainerFrame::CSSAlignmentForAbsPosChild(
// In the unexpected/unlikely event that this implementation gets invoked,
// just use "start" alignment.
return NS_STYLE_ALIGN_START;
return StyleAlignFlags::START;
}
#ifdef ACCESSIBILITY

Просмотреть файл

@ -433,7 +433,7 @@ class nsContainerFrame : public nsSplittableFrame {
* @param aLogicalAxis The axis (of this container frame) in which the caller
* would like to align the child frame.
*/
virtual uint16_t CSSAlignmentForAbsPosChild(
virtual mozilla::StyleAlignFlags CSSAlignmentForAbsPosChild(
const ReflowInput& aChildRI, mozilla::LogicalAxis aLogicalAxis) const;
#ifdef ACCESSIBILITY

Просмотреть файл

@ -80,44 +80,46 @@ static CSSOrderAwareFrameIterator::OrderingProperty OrderingPropertyForIter(
// Returns the "align-items" value that's equivalent to the legacy "box-align"
// value in the given style struct.
static uint8_t ConvertLegacyStyleToAlignItems(const nsStyleXUL* aStyleXUL) {
static StyleAlignFlags ConvertLegacyStyleToAlignItems(
const nsStyleXUL* aStyleXUL) {
// -[moz|webkit]-box-align corresponds to modern "align-items"
switch (aStyleXUL->mBoxAlign) {
case StyleBoxAlign::Stretch:
return NS_STYLE_ALIGN_STRETCH;
return StyleAlignFlags::STRETCH;
case StyleBoxAlign::Start:
return NS_STYLE_ALIGN_FLEX_START;
return StyleAlignFlags::FLEX_START;
case StyleBoxAlign::Center:
return NS_STYLE_ALIGN_CENTER;
return StyleAlignFlags::CENTER;
case StyleBoxAlign::Baseline:
return NS_STYLE_ALIGN_BASELINE;
return StyleAlignFlags::BASELINE;
case StyleBoxAlign::End:
return NS_STYLE_ALIGN_FLEX_END;
return StyleAlignFlags::FLEX_END;
}
MOZ_ASSERT_UNREACHABLE("Unrecognized mBoxAlign enum value");
// Fall back to default value of "align-items" property:
return NS_STYLE_ALIGN_STRETCH;
return StyleAlignFlags::STRETCH;
}
// Returns the "justify-content" value that's equivalent to the legacy
// "box-pack" value in the given style struct.
static uint8_t ConvertLegacyStyleToJustifyContent(const nsStyleXUL* aStyleXUL) {
static StyleContentDistribution ConvertLegacyStyleToJustifyContent(
const nsStyleXUL* aStyleXUL) {
// -[moz|webkit]-box-pack corresponds to modern "justify-content"
switch (aStyleXUL->mBoxPack) {
case StyleBoxPack::Start:
return NS_STYLE_ALIGN_FLEX_START;
return {StyleAlignFlags::FLEX_START};
case StyleBoxPack::Center:
return NS_STYLE_ALIGN_CENTER;
return {StyleAlignFlags::CENTER};
case StyleBoxPack::End:
return NS_STYLE_ALIGN_FLEX_END;
return {StyleAlignFlags::FLEX_END};
case StyleBoxPack::Justify:
return NS_STYLE_ALIGN_SPACE_BETWEEN;
return {StyleAlignFlags::SPACE_BETWEEN};
}
MOZ_ASSERT_UNREACHABLE("Unrecognized mBoxPack enum value");
// Fall back to default value of "justify-content" property:
return NS_STYLE_ALIGN_FLEX_START;
return {StyleAlignFlags::FLEX_START};
}
// Helper-function to find the first non-anonymous-box descendent of aFrame.
@ -543,8 +545,8 @@ class nsFlexContainerFrame::FlexItem : public LinkedListElement<FlexItem> {
bool IsBlockAxisCrossAxis() const { return mIsInlineAxisMainAxis; }
WritingMode GetWritingMode() const { return mWM; }
uint8_t AlignSelf() const { return mAlignSelf; }
uint8_t AlignSelfFlags() const { return mAlignSelfFlags; }
StyleAlignSelf AlignSelf() const { return mAlignSelf; }
StyleAlignFlags AlignSelfFlags() const { return mAlignSelfFlags; }
// Returns the flex factor (flex-grow or flex-shrink), depending on
// 'aIsUsingFlexGrow'.
@ -888,10 +890,10 @@ class nsFlexContainerFrame::FlexItem : public LinkedListElement<FlexItem> {
// My "align-self" computed value (with "auto" swapped out for parent"s
// "align-items" value, in our constructor).
uint8_t mAlignSelf = NS_STYLE_ALIGN_AUTO;
StyleAlignSelf mAlignSelf{StyleAlignFlags::AUTO};
// Flags for 'align-self' (safe/unsafe/legacy).
uint8_t mAlignSelfFlags = 0;
StyleAlignFlags mAlignSelfFlags{0};
};
/**
@ -1045,7 +1047,7 @@ class nsFlexContainerFrame::FlexLine : public LinkedListElement<FlexLine> {
void ResolveFlexibleLengths(nscoord aFlexContainerMainSize,
ComputedFlexLineInfo* aLineInfo);
void PositionItemsInMainAxis(uint8_t aJustifyContent,
void PositionItemsInMainAxis(const StyleContentDistribution& aJustifyContent,
nscoord aContentBoxMainSize,
const FlexboxAxisTracker& aAxisTracker);
@ -1121,55 +1123,48 @@ static void BuildStrutInfoFromCollapsedItems(const FlexLine* aFirstLine,
}
}
static uint8_t SimplifyAlignOrJustifyContentForOneItem(uint16_t aAlignmentVal,
bool aIsAlign) {
static mozilla::StyleAlignFlags SimplifyAlignOrJustifyContentForOneItem(
const StyleContentDistribution& aAlignmentVal, bool aIsAlign) {
// Mask away any explicit fallback, to get the main (non-fallback) part of
// the specified value:
uint16_t specified = aAlignmentVal & NS_STYLE_ALIGN_ALL_BITS;
StyleAlignFlags specified = aAlignmentVal.primary;
// XXX strip off <overflow-position> bits until we implement it (bug 1311892)
specified &= ~NS_STYLE_ALIGN_FLAG_BITS;
specified &= ~StyleAlignFlags::FLAG_BITS;
// FIRST: handle a special-case for "justify-content:stretch" (or equivalent),
// which requires that we ignore any author-provided explicit fallback value.
if (specified == NS_STYLE_ALIGN_NORMAL) {
if (specified == StyleAlignFlags::NORMAL) {
// In a flex container, *-content: "'normal' behaves as 'stretch'".
// Do that conversion early, so it benefits from our 'stretch' special-case.
// https://drafts.csswg.org/css-align-3/#distribution-flex
specified = NS_STYLE_ALIGN_STRETCH;
specified = StyleAlignFlags::STRETCH;
}
if (!aIsAlign && specified == NS_STYLE_ALIGN_STRETCH) {
if (!aIsAlign && specified == StyleAlignFlags::STRETCH) {
// In a flex container, in "justify-content Axis: [...] 'stretch' behaves
// as 'flex-start' (ignoring the specified fallback alignment, if any)."
// https://drafts.csswg.org/css-align-3/#distribution-flex
// So, we just directly return 'flex-start', & ignore explicit fallback..
return NS_STYLE_ALIGN_FLEX_START;
return StyleAlignFlags::FLEX_START;
}
// Now check for an explicit fallback value (and if it's present, use it).
uint16_t explicitFallback = aAlignmentVal >> NS_STYLE_ALIGN_ALL_SHIFT;
if (explicitFallback) {
// XXX strip off <overflow-position> bits until we implement it
// (bug 1311892)
explicitFallback &= ~NS_STYLE_ALIGN_FLAG_BITS;
return explicitFallback;
}
// TODO: Check for an explicit fallback value (and if it's present, use it)
// here once we parse it, see https://github.com/w3c/csswg-drafts/issues/1002.
// There's no explicit fallback. Use the implied fallback values for
// If there's no explicit fallback, use the implied fallback values for
// space-{between,around,evenly} (since those values only make sense with
// multiple alignment subjects), and otherwise just use the specified value:
switch (specified) {
case NS_STYLE_ALIGN_SPACE_BETWEEN:
return NS_STYLE_ALIGN_START;
case NS_STYLE_ALIGN_SPACE_AROUND:
case NS_STYLE_ALIGN_SPACE_EVENLY:
return NS_STYLE_ALIGN_CENTER;
default:
return specified;
if (specified == StyleAlignFlags::SPACE_BETWEEN) {
return StyleAlignFlags::START;
}
if (specified == StyleAlignFlags::SPACE_AROUND ||
specified == StyleAlignFlags::SPACE_EVENLY) {
return StyleAlignFlags::CENTER;
}
return specified;
}
uint16_t nsFlexContainerFrame::CSSAlignmentForAbsPosChild(
StyleAlignFlags nsFlexContainerFrame::CSSAlignmentForAbsPosChild(
const ReflowInput& aChildRI, LogicalAxis aLogicalAxis) const {
WritingMode wm = GetWritingMode();
const FlexboxAxisTracker axisTracker(
@ -1185,59 +1180,60 @@ uint16_t nsFlexContainerFrame::CSSAlignmentForAbsPosChild(
const bool isAxisReversed = isMainAxis ? axisTracker.IsMainAxisReversed()
: axisTracker.IsCrossAxisReversed();
uint8_t alignment;
uint8_t alignmentFlags = 0;
StyleAlignFlags alignment{0};
StyleAlignFlags alignmentFlags{0};
if (isMainAxis) {
alignment = SimplifyAlignOrJustifyContentForOneItem(
containerStylePos->mJustifyContent,
/*aIsAlign = */ false);
} else {
const uint8_t alignContent = SimplifyAlignOrJustifyContentForOneItem(
containerStylePos->mAlignContent,
/*aIsAlign = */ true);
const StyleAlignFlags alignContent =
SimplifyAlignOrJustifyContentForOneItem(
containerStylePos->mAlignContent,
/*aIsAlign = */ true);
if (StyleFlexWrap::Nowrap != containerStylePos->mFlexWrap &&
alignContent != NS_STYLE_ALIGN_STRETCH) {
alignContent != StyleAlignFlags::STRETCH) {
// Multi-line, align-content isn't stretch --> align-content determines
// this child's alignment in the cross axis.
alignment = alignContent;
} else {
// Single-line, or multi-line but the (one) line stretches to fill
// container. Respect align-self.
alignment = aChildRI.mStylePosition->UsedAlignSelf(Style());
alignment = aChildRI.mStylePosition->UsedAlignSelf(Style())._0;
// Extract and strip align flag bits
alignmentFlags = alignment & NS_STYLE_ALIGN_FLAG_BITS;
alignment &= ~NS_STYLE_ALIGN_FLAG_BITS;
alignmentFlags = alignment & StyleAlignFlags::FLAG_BITS;
alignment &= ~StyleAlignFlags::FLAG_BITS;
if (alignment == NS_STYLE_ALIGN_NORMAL) {
if (alignment == StyleAlignFlags::NORMAL) {
// "the 'normal' keyword behaves as 'start' on replaced
// absolutely-positioned boxes, and behaves as 'stretch' on all other
// absolutely-positioned boxes."
// https://drafts.csswg.org/css-align/#align-abspos
alignment = aChildRI.mFrame->IsFrameOfType(nsIFrame::eReplaced)
? NS_STYLE_ALIGN_START
: NS_STYLE_ALIGN_STRETCH;
? StyleAlignFlags::START
: StyleAlignFlags::STRETCH;
}
}
}
// Resolve flex-start, flex-end, auto, left, right, baseline, last baseline;
if (alignment == NS_STYLE_ALIGN_FLEX_START) {
alignment = isAxisReversed ? NS_STYLE_ALIGN_END : NS_STYLE_ALIGN_START;
} else if (alignment == NS_STYLE_ALIGN_FLEX_END) {
alignment = isAxisReversed ? NS_STYLE_ALIGN_START : NS_STYLE_ALIGN_END;
} else if (alignment == NS_STYLE_ALIGN_LEFT ||
alignment == NS_STYLE_ALIGN_RIGHT) {
if (alignment == StyleAlignFlags::FLEX_START) {
alignment = isAxisReversed ? StyleAlignFlags::END : StyleAlignFlags::START;
} else if (alignment == StyleAlignFlags::FLEX_END) {
alignment = isAxisReversed ? StyleAlignFlags::START : StyleAlignFlags::END;
} else if (alignment == StyleAlignFlags::LEFT ||
alignment == StyleAlignFlags::RIGHT) {
if (aLogicalAxis == eLogicalAxisInline) {
const bool isLeft = (alignment == NS_STYLE_ALIGN_LEFT);
alignment = (isLeft == wm.IsBidiLTR()) ? NS_STYLE_ALIGN_START
: NS_STYLE_ALIGN_END;
const bool isLeft = (alignment == StyleAlignFlags::LEFT);
alignment = (isLeft == wm.IsBidiLTR()) ? StyleAlignFlags::START
: StyleAlignFlags::END;
} else {
alignment = NS_STYLE_ALIGN_START;
alignment = StyleAlignFlags::START;
}
} else if (alignment == NS_STYLE_ALIGN_BASELINE) {
alignment = NS_STYLE_ALIGN_START;
} else if (alignment == NS_STYLE_ALIGN_LAST_BASELINE) {
alignment = NS_STYLE_ALIGN_END;
} else if (alignment == StyleAlignFlags::BASELINE) {
alignment = StyleAlignFlags::START;
} else if (alignment == StyleAlignFlags::LAST_BASELINE) {
alignment = StyleAlignFlags::END;
}
return (alignment | alignmentFlags);
@ -1902,18 +1898,18 @@ FlexItem::FlexItem(ReflowInput& aFlexItemReflowInput, float aFlexGrow,
// So, each FlexItem simply copies the container's converted "align-items"
// value and disregards their own "align-self" property.
const nsStyleXUL* containerStyleXUL = containerRS->mFrame->StyleXUL();
mAlignSelf = ConvertLegacyStyleToAlignItems(containerStyleXUL);
mAlignSelfFlags = 0;
mAlignSelf = {ConvertLegacyStyleToAlignItems(containerStyleXUL)};
mAlignSelfFlags = {0};
} else {
mAlignSelf = aFlexItemReflowInput.mStylePosition->UsedAlignSelf(
containerRS->mFrame->Style());
if (MOZ_LIKELY(mAlignSelf == NS_STYLE_ALIGN_NORMAL)) {
mAlignSelf = NS_STYLE_ALIGN_STRETCH;
if (MOZ_LIKELY(mAlignSelf._0 == StyleAlignFlags::NORMAL)) {
mAlignSelf = {StyleAlignFlags::STRETCH};
}
// Store and strip off the <overflow-position> bits
mAlignSelfFlags = mAlignSelf & NS_STYLE_ALIGN_FLAG_BITS;
mAlignSelf &= ~NS_STYLE_ALIGN_FLAG_BITS;
mAlignSelfFlags = mAlignSelf._0 & StyleAlignFlags::FLAG_BITS;
mAlignSelf._0 &= ~StyleAlignFlags::FLAG_BITS;
}
// Our main-size is considered definite if any of these are true:
@ -1996,10 +1992,10 @@ FlexItem::FlexItem(ReflowInput& aFlexItemReflowInput, float aFlexGrow,
// We are treating this case as one where it is appropriate to use the
// fallback values defined at https://www.w3.org/TR/css-align/#baseline-values
if (!IsBlockAxisCrossAxis()) {
if (mAlignSelf == NS_STYLE_ALIGN_BASELINE) {
mAlignSelf = NS_STYLE_ALIGN_FLEX_START;
} else if (mAlignSelf == NS_STYLE_ALIGN_LAST_BASELINE) {
mAlignSelf = NS_STYLE_ALIGN_FLEX_END;
if (mAlignSelf._0 == StyleAlignFlags::BASELINE) {
mAlignSelf = {StyleAlignFlags::FLEX_START};
} else if (mAlignSelf._0 == StyleAlignFlags::LAST_BASELINE) {
mAlignSelf = {StyleAlignFlags::FLEX_END};
}
}
}
@ -2019,7 +2015,7 @@ FlexItem::FlexItem(nsIFrame* aChildFrame, nscoord aCrossSize,
// just share container's WM for simplicity:
mIsFrozen(true),
mIsStrut(true), // (this is the constructor for making struts, after all)
mAlignSelf(NS_STYLE_ALIGN_FLEX_START) {
mAlignSelf({StyleAlignFlags::FLEX_START}) {
MOZ_ASSERT(mFrame, "expecting a non-null child frame");
MOZ_ASSERT(StyleVisibility::Collapse == mFrame->StyleVisibility()->mVisible,
"Should only make struts for children with 'visibility:collapse'");
@ -2236,7 +2232,8 @@ class MOZ_STACK_CLASS PositionTracker {
class MOZ_STACK_CLASS MainAxisPositionTracker : public PositionTracker {
public:
MainAxisPositionTracker(const FlexboxAxisTracker& aAxisTracker,
const FlexLine* aLine, uint8_t aJustifyContent,
const FlexLine* aLine,
const StyleContentDistribution& aJustifyContent,
nscoord aContentBoxMainSize);
~MainAxisPositionTracker() {
@ -2260,8 +2257,7 @@ class MOZ_STACK_CLASS MainAxisPositionTracker : public PositionTracker {
nscoord mPackingSpaceRemaining = 0;
uint32_t mNumAutoMarginsInMainAxis = 0;
uint32_t mNumPackingSpacesRemaining = 0;
// XXX this should be uint16_t when we add explicit fallback handling
uint8_t mJustifyContent = NS_STYLE_JUSTIFY_AUTO;
StyleContentDistribution mJustifyContent = {StyleAlignFlags::AUTO};
};
// Utility class for managing our position along the cross axis along
@ -2300,8 +2296,7 @@ class MOZ_STACK_CLASS CrossAxisPositionTracker : public PositionTracker {
private:
nscoord mPackingSpaceRemaining = 0;
uint32_t mNumPackingSpacesRemaining = 0;
// XXX this should be uint16_t when we add explicit fallback handling
uint8_t mAlignContent = NS_STYLE_ALIGN_AUTO;
StyleContentDistribution mAlignContent = {StyleAlignFlags::AUTO};
nscoord mCrossGapSize = 0;
};
@ -2903,7 +2898,8 @@ void FlexLine::ResolveFlexibleLengths(nscoord aFlexContainerMainSize,
MainAxisPositionTracker::MainAxisPositionTracker(
const FlexboxAxisTracker& aAxisTracker, const FlexLine* aLine,
uint8_t aJustifyContent, nscoord aContentBoxMainSize)
const StyleContentDistribution& aJustifyContent,
nscoord aContentBoxMainSize)
: PositionTracker(aAxisTracker.GetWritingMode(), aAxisTracker.MainAxis(),
aAxisTracker.IsMainAxisReversed()),
// we chip away at this below
@ -2912,15 +2908,16 @@ MainAxisPositionTracker::MainAxisPositionTracker(
// Extract the flag portion of mJustifyContent and strip off the flag bits
// NOTE: This must happen before any assignment to mJustifyContent to
// avoid overwriting the flag bits.
uint8_t justifyContentFlags = mJustifyContent & NS_STYLE_JUSTIFY_FLAG_BITS;
mJustifyContent &= ~NS_STYLE_JUSTIFY_FLAG_BITS;
StyleAlignFlags justifyContentFlags =
mJustifyContent.primary & StyleAlignFlags::FLAG_BITS;
mJustifyContent.primary &= ~StyleAlignFlags::FLAG_BITS;
// 'normal' behaves as 'stretch', and 'stretch' behaves as 'flex-start',
// in the main axis
// https://drafts.csswg.org/css-align-3/#propdef-justify-content
if (mJustifyContent == NS_STYLE_JUSTIFY_NORMAL ||
mJustifyContent == NS_STYLE_JUSTIFY_STRETCH) {
mJustifyContent = NS_STYLE_JUSTIFY_FLEX_START;
if (mJustifyContent.primary == StyleAlignFlags::NORMAL ||
mJustifyContent.primary == StyleAlignFlags::STRETCH) {
mJustifyContent.primary = StyleAlignFlags::FLEX_START;
}
// mPackingSpaceRemaining is initialized to the container's main size. Now
@ -2940,8 +2937,8 @@ MainAxisPositionTracker::MainAxisPositionTracker(
mNumAutoMarginsInMainAxis = 0;
// If packing space is negative and <overflow-position> is set to 'safe'
// all justify options fall back to 'start'
if (justifyContentFlags & NS_STYLE_JUSTIFY_SAFE) {
mJustifyContent = NS_STYLE_JUSTIFY_START;
if (justifyContentFlags & StyleAlignFlags::SAFE) {
mJustifyContent.primary = StyleAlignFlags::START;
}
}
@ -2950,11 +2947,11 @@ MainAxisPositionTracker::MainAxisPositionTracker(
// to 'center'. In those cases, it's simplest to just pretend we have a
// different 'justify-content' value and share code.
if (mPackingSpaceRemaining < 0 || aLine->NumItems() == 1) {
if (mJustifyContent == NS_STYLE_JUSTIFY_SPACE_BETWEEN) {
mJustifyContent = NS_STYLE_JUSTIFY_FLEX_START;
} else if (mJustifyContent == NS_STYLE_JUSTIFY_SPACE_AROUND ||
mJustifyContent == NS_STYLE_JUSTIFY_SPACE_EVENLY) {
mJustifyContent = NS_STYLE_JUSTIFY_CENTER;
if (mJustifyContent.primary == StyleAlignFlags::SPACE_BETWEEN) {
mJustifyContent.primary = StyleAlignFlags::FLEX_START;
} else if (mJustifyContent.primary == StyleAlignFlags::SPACE_AROUND ||
mJustifyContent.primary == StyleAlignFlags::SPACE_EVENLY) {
mJustifyContent.primary = StyleAlignFlags::CENTER;
}
}
@ -2969,66 +2966,63 @@ MainAxisPositionTracker::MainAxisPositionTracker(
// flex-relative axis direction; e.g. for "start" which purely depends on
// writing-mode and isn't affected by reversedness of flex axes.
if (aAxisTracker.AreAxesInternallyReversed()) {
if (mJustifyContent == NS_STYLE_JUSTIFY_FLEX_START) {
mJustifyContent = NS_STYLE_JUSTIFY_FLEX_END;
} else if (mJustifyContent == NS_STYLE_JUSTIFY_FLEX_END) {
mJustifyContent = NS_STYLE_JUSTIFY_FLEX_START;
if (mJustifyContent.primary == StyleAlignFlags::FLEX_START) {
mJustifyContent.primary = StyleAlignFlags::FLEX_END;
} else if (mJustifyContent.primary == StyleAlignFlags::FLEX_END) {
mJustifyContent.primary = StyleAlignFlags::FLEX_START;
}
}
// Map 'left'/'right' to 'start'/'end'
if (mJustifyContent == NS_STYLE_JUSTIFY_LEFT ||
mJustifyContent == NS_STYLE_JUSTIFY_RIGHT) {
if (mJustifyContent.primary == StyleAlignFlags::LEFT ||
mJustifyContent.primary == StyleAlignFlags::RIGHT) {
if (aAxisTracker.IsColumnOriented()) {
// Container's alignment axis is not parallel to the inline axis,
// so we map both 'left' and 'right' to 'start'.
mJustifyContent = NS_STYLE_JUSTIFY_START;
mJustifyContent.primary = StyleAlignFlags::START;
} else {
// Row-oriented, so we map 'left' and 'right' to 'start' or 'end',
// depending on left-to-right writing mode.
const bool isLTR = aAxisTracker.GetWritingMode().IsBidiLTR();
const bool isJustifyLeft = (mJustifyContent == NS_STYLE_JUSTIFY_LEFT);
mJustifyContent = (isJustifyLeft == isLTR) ? NS_STYLE_JUSTIFY_START
: NS_STYLE_JUSTIFY_END;
const bool isJustifyLeft =
(mJustifyContent.primary == StyleAlignFlags::LEFT);
mJustifyContent.primary = (isJustifyLeft == isLTR)
? StyleAlignFlags::START
: StyleAlignFlags::END;
}
}
// Map 'start'/'end' to 'flex-start'/'flex-end'.
if (mJustifyContent == NS_STYLE_JUSTIFY_START) {
mJustifyContent = aAxisTracker.IsMainAxisReversed()
? NS_STYLE_JUSTIFY_FLEX_END
: NS_STYLE_JUSTIFY_FLEX_START;
} else if (mJustifyContent == NS_STYLE_JUSTIFY_END) {
mJustifyContent = aAxisTracker.IsMainAxisReversed()
? NS_STYLE_JUSTIFY_FLEX_START
: NS_STYLE_JUSTIFY_FLEX_END;
if (mJustifyContent.primary == StyleAlignFlags::START) {
mJustifyContent.primary = aAxisTracker.IsMainAxisReversed()
? StyleAlignFlags::FLEX_END
: StyleAlignFlags::FLEX_START;
} else if (mJustifyContent.primary == StyleAlignFlags::END) {
mJustifyContent.primary = aAxisTracker.IsMainAxisReversed()
? StyleAlignFlags::FLEX_START
: StyleAlignFlags::FLEX_END;
}
// Figure out how much space we'll set aside for auto margins or
// packing spaces, and advance past any leading packing-space.
if (mNumAutoMarginsInMainAxis == 0 && mPackingSpaceRemaining != 0 &&
!aLine->IsEmpty()) {
switch (mJustifyContent) {
case NS_STYLE_JUSTIFY_FLEX_START:
// All packing space should go at the end --> nothing to do here.
break;
case NS_STYLE_JUSTIFY_FLEX_END:
// All packing space goes at the beginning
mPosition += mPackingSpaceRemaining;
break;
case NS_STYLE_JUSTIFY_CENTER:
// Half the packing space goes at the beginning
mPosition += mPackingSpaceRemaining / 2;
break;
case NS_STYLE_JUSTIFY_SPACE_BETWEEN:
case NS_STYLE_JUSTIFY_SPACE_AROUND:
case NS_STYLE_JUSTIFY_SPACE_EVENLY:
nsFlexContainerFrame::CalculatePackingSpace(
aLine->NumItems(), mJustifyContent, &mPosition,
&mNumPackingSpacesRemaining, &mPackingSpaceRemaining);
break;
default:
MOZ_ASSERT_UNREACHABLE("Unexpected justify-content value");
if (mJustifyContent.primary == StyleAlignFlags::FLEX_START) {
// All packing space should go at the end --> nothing to do here.
} else if (mJustifyContent.primary == StyleAlignFlags::FLEX_END) {
// All packing space goes at the beginning
mPosition += mPackingSpaceRemaining;
} else if (mJustifyContent.primary == StyleAlignFlags::CENTER) {
// Half the packing space goes at the beginning
mPosition += mPackingSpaceRemaining / 2;
} else if (mJustifyContent.primary == StyleAlignFlags::SPACE_BETWEEN ||
mJustifyContent.primary == StyleAlignFlags::SPACE_AROUND ||
mJustifyContent.primary == StyleAlignFlags::SPACE_EVENLY) {
nsFlexContainerFrame::CalculatePackingSpace(
aLine->NumItems(), mJustifyContent, &mPosition,
&mNumPackingSpacesRemaining, &mPackingSpaceRemaining);
} else {
MOZ_ASSERT_UNREACHABLE("Unexpected justify-content value");
}
}
@ -3061,9 +3055,9 @@ void MainAxisPositionTracker::ResolveAutoMarginsInMainAxis(FlexItem& aItem) {
void MainAxisPositionTracker::TraversePackingSpace() {
if (mNumPackingSpacesRemaining) {
MOZ_ASSERT(mJustifyContent == NS_STYLE_JUSTIFY_SPACE_BETWEEN ||
mJustifyContent == NS_STYLE_JUSTIFY_SPACE_AROUND ||
mJustifyContent == NS_STYLE_JUSTIFY_SPACE_EVENLY,
MOZ_ASSERT(mJustifyContent.primary == StyleAlignFlags::SPACE_BETWEEN ||
mJustifyContent.primary == StyleAlignFlags::SPACE_AROUND ||
mJustifyContent.primary == StyleAlignFlags::SPACE_EVENLY,
"mNumPackingSpacesRemaining only applies for "
"space-between/space-around/space-evenly");
@ -3092,12 +3086,13 @@ CrossAxisPositionTracker::CrossAxisPositionTracker(
MOZ_ASSERT(aFirstLine, "null first line pointer");
// Extract and strip the flag bits from alignContent
uint8_t alignContentFlags = mAlignContent & NS_STYLE_ALIGN_FLAG_BITS;
mAlignContent &= ~NS_STYLE_ALIGN_FLAG_BITS;
StyleAlignFlags alignContentFlags =
mAlignContent.primary & StyleAlignFlags::FLAG_BITS;
mAlignContent.primary &= ~StyleAlignFlags::FLAG_BITS;
// 'normal' behaves as 'stretch'
if (mAlignContent == NS_STYLE_ALIGN_NORMAL) {
mAlignContent = NS_STYLE_ALIGN_STRETCH;
if (mAlignContent.primary == StyleAlignFlags::NORMAL) {
mAlignContent.primary = StyleAlignFlags::STRETCH;
}
const bool isSingleLine =
@ -3148,8 +3143,9 @@ CrossAxisPositionTracker::CrossAxisPositionTracker(
// If <overflow-position> is 'safe' and packing space is negative
// all align options fall back to 'start'
if ((alignContentFlags & NS_STYLE_ALIGN_SAFE) && mPackingSpaceRemaining < 0) {
mAlignContent = NS_STYLE_ALIGN_START;
if ((alignContentFlags & StyleAlignFlags::SAFE) &&
mPackingSpaceRemaining < 0) {
mAlignContent.primary = StyleAlignFlags::START;
}
// If packing space is negative, 'space-between' and 'stretch' behave like
@ -3158,14 +3154,15 @@ CrossAxisPositionTracker::CrossAxisPositionTracker(
// 'align-content' value and share code. (If we only have one line, all of
// the 'space-*' keywords fall back as well, but 'stretch' doesn't because
// even a single line can still stretch.)
if (mPackingSpaceRemaining < 0 && mAlignContent == NS_STYLE_ALIGN_STRETCH) {
mAlignContent = NS_STYLE_ALIGN_FLEX_START;
if (mPackingSpaceRemaining < 0 &&
mAlignContent.primary == StyleAlignFlags::STRETCH) {
mAlignContent.primary = StyleAlignFlags::FLEX_START;
} else if (mPackingSpaceRemaining < 0 || numLines == 1) {
if (mAlignContent == NS_STYLE_ALIGN_SPACE_BETWEEN) {
mAlignContent = NS_STYLE_ALIGN_FLEX_START;
} else if (mAlignContent == NS_STYLE_ALIGN_SPACE_AROUND ||
mAlignContent == NS_STYLE_ALIGN_SPACE_EVENLY) {
mAlignContent = NS_STYLE_ALIGN_CENTER;
if (mAlignContent.primary == StyleAlignFlags::SPACE_BETWEEN) {
mAlignContent.primary = StyleAlignFlags::FLEX_START;
} else if (mAlignContent.primary == StyleAlignFlags::SPACE_AROUND ||
mAlignContent.primary == StyleAlignFlags::SPACE_EVENLY) {
mAlignContent.primary = StyleAlignFlags::CENTER;
}
}
@ -3174,86 +3171,78 @@ CrossAxisPositionTracker::CrossAxisPositionTracker(
// NOTE: It matters precisely when we do this; see comment alongside
// MainAxisPositionTracker's AreAxesInternallyReversed check.
if (aAxisTracker.AreAxesInternallyReversed()) {
if (mAlignContent == NS_STYLE_ALIGN_FLEX_START) {
mAlignContent = NS_STYLE_ALIGN_FLEX_END;
} else if (mAlignContent == NS_STYLE_ALIGN_FLEX_END) {
mAlignContent = NS_STYLE_ALIGN_FLEX_START;
if (mAlignContent.primary == StyleAlignFlags::FLEX_START) {
mAlignContent.primary = StyleAlignFlags::FLEX_END;
} else if (mAlignContent.primary == StyleAlignFlags::FLEX_END) {
mAlignContent.primary = StyleAlignFlags::FLEX_START;
}
}
// Map 'start'/'end' to 'flex-start'/'flex-end'.
if (mAlignContent == NS_STYLE_ALIGN_START) {
mAlignContent = aAxisTracker.IsCrossAxisReversed()
? NS_STYLE_ALIGN_FLEX_END
: NS_STYLE_ALIGN_FLEX_START;
} else if (mAlignContent == NS_STYLE_ALIGN_END) {
mAlignContent = aAxisTracker.IsCrossAxisReversed()
? NS_STYLE_ALIGN_FLEX_START
: NS_STYLE_ALIGN_FLEX_END;
if (mAlignContent.primary == StyleAlignFlags::START) {
mAlignContent.primary = aAxisTracker.IsCrossAxisReversed()
? StyleAlignFlags::FLEX_END
: StyleAlignFlags::FLEX_START;
} else if (mAlignContent.primary == StyleAlignFlags::END) {
mAlignContent.primary = aAxisTracker.IsCrossAxisReversed()
? StyleAlignFlags::FLEX_START
: StyleAlignFlags::FLEX_END;
}
// Figure out how much space we'll set aside for packing spaces, and advance
// past any leading packing-space.
if (mPackingSpaceRemaining != 0) {
switch (mAlignContent) {
case NS_STYLE_ALIGN_BASELINE:
case NS_STYLE_ALIGN_LAST_BASELINE:
NS_WARNING(
"NYI: "
"align-items/align-self:left/right/self-start/self-end/baseline/"
"last baseline");
[[fallthrough]];
case NS_STYLE_ALIGN_FLEX_START:
// All packing space should go at the end --> nothing to do here.
break;
case NS_STYLE_ALIGN_FLEX_END:
// All packing space goes at the beginning
mPosition += mPackingSpaceRemaining;
break;
case NS_STYLE_ALIGN_CENTER:
// Half the packing space goes at the beginning
mPosition += mPackingSpaceRemaining / 2;
break;
case NS_STYLE_ALIGN_SPACE_BETWEEN:
case NS_STYLE_ALIGN_SPACE_AROUND:
case NS_STYLE_ALIGN_SPACE_EVENLY:
nsFlexContainerFrame::CalculatePackingSpace(
numLines, mAlignContent, &mPosition, &mNumPackingSpacesRemaining,
&mPackingSpaceRemaining);
break;
case NS_STYLE_ALIGN_STRETCH: {
// Split space equally between the lines:
MOZ_ASSERT(mPackingSpaceRemaining > 0,
"negative packing space should make us use 'flex-start' "
"instead of 'stretch' (and we shouldn't bother with this "
"code if we have 0 packing space)");
if (mAlignContent.primary == StyleAlignFlags::BASELINE ||
mAlignContent.primary == StyleAlignFlags::LAST_BASELINE) {
NS_WARNING(
"NYI: "
"align-items/align-self:left/right/self-start/self-end/baseline/"
"last baseline");
} else if (mAlignContent.primary == StyleAlignFlags::FLEX_START) {
// All packing space should go at the end --> nothing to do here.
} else if (mAlignContent.primary == StyleAlignFlags::FLEX_END) {
// All packing space goes at the beginning
mPosition += mPackingSpaceRemaining;
} else if (mAlignContent.primary == StyleAlignFlags::CENTER) {
// Half the packing space goes at the beginning
mPosition += mPackingSpaceRemaining / 2;
} else if (mAlignContent.primary == StyleAlignFlags::SPACE_BETWEEN ||
mAlignContent.primary == StyleAlignFlags::SPACE_AROUND ||
mAlignContent.primary == StyleAlignFlags::SPACE_EVENLY) {
nsFlexContainerFrame::CalculatePackingSpace(
numLines, mAlignContent, &mPosition, &mNumPackingSpacesRemaining,
&mPackingSpaceRemaining);
} else if (mAlignContent.primary == StyleAlignFlags::STRETCH) {
// Split space equally between the lines:
MOZ_ASSERT(mPackingSpaceRemaining > 0,
"negative packing space should make us use 'flex-start' "
"instead of 'stretch' (and we shouldn't bother with this "
"code if we have 0 packing space)");
uint32_t numLinesLeft = numLines;
for (FlexLine* line = aFirstLine; line; line = line->getNext()) {
// Our share is the amount of space remaining, divided by the number
// of lines remainig.
MOZ_ASSERT(numLinesLeft > 0, "miscalculated num lines");
nscoord shareOfExtraSpace = mPackingSpaceRemaining / numLinesLeft;
nscoord newSize = line->LineCrossSize() + shareOfExtraSpace;
line->SetLineCrossSize(newSize);
uint32_t numLinesLeft = numLines;
for (FlexLine* line = aFirstLine; line; line = line->getNext()) {
// Our share is the amount of space remaining, divided by the number
// of lines remainig.
MOZ_ASSERT(numLinesLeft > 0, "miscalculated num lines");
nscoord shareOfExtraSpace = mPackingSpaceRemaining / numLinesLeft;
nscoord newSize = line->LineCrossSize() + shareOfExtraSpace;
line->SetLineCrossSize(newSize);
mPackingSpaceRemaining -= shareOfExtraSpace;
numLinesLeft--;
}
MOZ_ASSERT(numLinesLeft == 0, "miscalculated num lines");
break;
mPackingSpaceRemaining -= shareOfExtraSpace;
numLinesLeft--;
}
default:
MOZ_ASSERT_UNREACHABLE("Unexpected align-content value");
MOZ_ASSERT(numLinesLeft == 0, "miscalculated num lines");
} else {
MOZ_ASSERT_UNREACHABLE("Unexpected align-content value");
}
}
}
void CrossAxisPositionTracker::TraversePackingSpace() {
if (mNumPackingSpacesRemaining) {
MOZ_ASSERT(mAlignContent == NS_STYLE_ALIGN_SPACE_BETWEEN ||
mAlignContent == NS_STYLE_ALIGN_SPACE_AROUND ||
mAlignContent == NS_STYLE_ALIGN_SPACE_EVENLY,
MOZ_ASSERT(mAlignContent.primary == StyleAlignFlags::SPACE_BETWEEN ||
mAlignContent.primary == StyleAlignFlags::SPACE_AROUND ||
mAlignContent.primary == StyleAlignFlags::SPACE_EVENLY,
"mNumPackingSpacesRemaining only applies for "
"space-between/space-around/space-evenly");
@ -3286,10 +3275,10 @@ void FlexLine::ComputeCrossSizeAndBaseline(
for (const FlexItem* item = mItems.getFirst(); item; item = item->getNext()) {
nscoord curOuterCrossSize = item->OuterCrossSize();
if ((item->AlignSelf() == NS_STYLE_ALIGN_BASELINE ||
item->AlignSelf() == NS_STYLE_ALIGN_LAST_BASELINE) &&
if ((item->AlignSelf()._0 == StyleAlignFlags::BASELINE ||
item->AlignSelf()._0 == StyleAlignFlags::LAST_BASELINE) &&
item->NumAutoMarginsInCrossAxis() == 0) {
const bool useFirst = (item->AlignSelf() == NS_STYLE_ALIGN_BASELINE);
const bool useFirst = (item->AlignSelf()._0 == StyleAlignFlags::BASELINE);
// FIXME: Once we support "writing-mode", we'll have to do baseline
// alignment in vertical flex containers here (w/ horizontal cross-axes).
@ -3374,7 +3363,7 @@ void FlexItem::ResolveStretchedCrossSize(nscoord aLineCrossSize) {
// We stretch IFF we are align-self:stretch, have no auto margins in
// cross axis, and have cross-axis size property == "auto". If any of those
// conditions don't hold up, we won't stretch.
if (mAlignSelf != NS_STYLE_ALIGN_STRETCH ||
if (mAlignSelf._0 != StyleAlignFlags::STRETCH ||
NumAutoMarginsInCrossAxis() != 0 || !IsCrossSizeAuto()) {
return;
}
@ -3456,106 +3445,100 @@ void SingleLineCrossAxisPositionTracker::EnterAlignPackingSpace(
return;
}
uint8_t alignSelf = aItem.AlignSelf();
StyleAlignFlags alignSelf = aItem.AlignSelf()._0;
// NOTE: 'stretch' behaves like 'flex-start' once we've stretched any
// auto-sized items (which we've already done).
if (alignSelf == NS_STYLE_ALIGN_STRETCH) {
alignSelf = NS_STYLE_ALIGN_FLEX_START;
if (alignSelf == StyleAlignFlags::STRETCH) {
alignSelf = StyleAlignFlags::FLEX_START;
}
// If our cross axis is (internally) reversed, swap the align-self
// "flex-start" and "flex-end" behaviors:
if (aAxisTracker.AreAxesInternallyReversed()) {
if (alignSelf == NS_STYLE_ALIGN_FLEX_START) {
alignSelf = NS_STYLE_ALIGN_FLEX_END;
} else if (alignSelf == NS_STYLE_ALIGN_FLEX_END) {
alignSelf = NS_STYLE_ALIGN_FLEX_START;
if (alignSelf == StyleAlignFlags::FLEX_START) {
alignSelf = StyleAlignFlags::FLEX_END;
} else if (alignSelf == StyleAlignFlags::FLEX_END) {
alignSelf = StyleAlignFlags::FLEX_START;
}
}
// Map 'self-start'/'self-end' to 'start'/'end'
if (alignSelf == NS_STYLE_ALIGN_SELF_START ||
alignSelf == NS_STYLE_ALIGN_SELF_END) {
if (alignSelf == StyleAlignFlags::SELF_START ||
alignSelf == StyleAlignFlags::SELF_END) {
const LogicalAxis logCrossAxis =
aAxisTracker.IsRowOriented() ? eLogicalAxisBlock : eLogicalAxisInline;
const WritingMode cWM = aAxisTracker.GetWritingMode();
const bool sameStart =
cWM.ParallelAxisStartsOnSameSide(logCrossAxis, aItem.GetWritingMode());
alignSelf = sameStart == (alignSelf == NS_STYLE_ALIGN_SELF_START)
? NS_STYLE_ALIGN_START
: NS_STYLE_ALIGN_END;
alignSelf = sameStart == (alignSelf == StyleAlignFlags::SELF_START)
? StyleAlignFlags::START
: StyleAlignFlags::END;
}
// Map 'start'/'end' to 'flex-start'/'flex-end'.
if (alignSelf == NS_STYLE_ALIGN_START) {
alignSelf = aAxisTracker.IsCrossAxisReversed() ? NS_STYLE_ALIGN_FLEX_END
: NS_STYLE_ALIGN_FLEX_START;
} else if (alignSelf == NS_STYLE_ALIGN_END) {
alignSelf = aAxisTracker.IsCrossAxisReversed() ? NS_STYLE_ALIGN_FLEX_START
: NS_STYLE_ALIGN_FLEX_END;
if (alignSelf == StyleAlignFlags::START) {
alignSelf = aAxisTracker.IsCrossAxisReversed()
? StyleAlignFlags::FLEX_END
: StyleAlignFlags::FLEX_START;
} else if (alignSelf == StyleAlignFlags::END) {
alignSelf = aAxisTracker.IsCrossAxisReversed() ? StyleAlignFlags::FLEX_START
: StyleAlignFlags::FLEX_END;
}
// 'align-self' falls back to 'flex-start' if it is 'center'/'flex-end' and we
// have cross axis overflow
// XXX we should really be falling back to 'start' as of bug 1472843
if (aLine.LineCrossSize() < aItem.OuterCrossSize() &&
(aItem.AlignSelfFlags() & NS_STYLE_ALIGN_SAFE)) {
alignSelf = NS_STYLE_ALIGN_FLEX_START;
(aItem.AlignSelfFlags() & StyleAlignFlags::SAFE)) {
alignSelf = StyleAlignFlags::FLEX_START;
}
switch (alignSelf) {
case NS_STYLE_ALIGN_FLEX_START:
// No space to skip over -- we're done.
break;
case NS_STYLE_ALIGN_FLEX_END:
if (alignSelf == StyleAlignFlags::FLEX_START) {
// No space to skip over -- we're done.
} else if (alignSelf == StyleAlignFlags::FLEX_END) {
mPosition += aLine.LineCrossSize() - aItem.OuterCrossSize();
} else if (alignSelf == StyleAlignFlags::CENTER) {
// Note: If cross-size is odd, the "after" space will get the extra unit.
mPosition += (aLine.LineCrossSize() - aItem.OuterCrossSize()) / 2;
} else if (alignSelf == StyleAlignFlags::BASELINE ||
alignSelf == StyleAlignFlags::LAST_BASELINE) {
const bool useFirst = (alignSelf == StyleAlignFlags::BASELINE);
// Normally, baseline-aligned items are collectively aligned with the
// line's physical cross-start side; however, if our cross axis is
// (internally) reversed, we instead align them with the physical
// cross-end side. A similar logic holds for last baseline-aligned items,
// but in reverse.
const mozilla::Side baselineAlignStartSide =
aAxisTracker.AreAxesInternallyReversed() == useFirst
? aAxisTracker.CrossAxisPhysicalEndSide()
: aAxisTracker.CrossAxisPhysicalStartSide();
nscoord itemBaselineOffset = aItem.BaselineOffsetFromOuterCrossEdge(
baselineAlignStartSide, aAxisTracker, useFirst);
nscoord lineBaselineOffset =
useFirst ? aLine.FirstBaselineOffset() : aLine.LastBaselineOffset();
NS_ASSERTION(lineBaselineOffset >= itemBaselineOffset,
"failed at finding largest baseline offset");
// How much do we need to adjust our position (from the line edge),
// to get the item's baseline to hit the line's baseline offset:
nscoord baselineDiff = lineBaselineOffset - itemBaselineOffset;
if (aAxisTracker.AreAxesInternallyReversed() == useFirst) {
// Advance to align item w/ line's flex-end edge (as in FLEX_END case):
mPosition += aLine.LineCrossSize() - aItem.OuterCrossSize();
break;
case NS_STYLE_ALIGN_CENTER:
// Note: If cross-size is odd, the "after" space will get the extra unit.
mPosition += (aLine.LineCrossSize() - aItem.OuterCrossSize()) / 2;
break;
case NS_STYLE_ALIGN_BASELINE:
case NS_STYLE_ALIGN_LAST_BASELINE: {
const bool useFirst = (alignSelf == NS_STYLE_ALIGN_BASELINE);
// Normally, baseline-aligned items are collectively aligned with the
// line's physical cross-start side; however, if our cross axis is
// (internally) reversed, we instead align them with the physical
// cross-end side. A similar logic holds for last baseline-aligned items,
// but in reverse.
const mozilla::Side baselineAlignStartSide =
aAxisTracker.AreAxesInternallyReversed() == useFirst
? aAxisTracker.CrossAxisPhysicalEndSide()
: aAxisTracker.CrossAxisPhysicalStartSide();
nscoord itemBaselineOffset = aItem.BaselineOffsetFromOuterCrossEdge(
baselineAlignStartSide, aAxisTracker, useFirst);
nscoord lineBaselineOffset =
useFirst ? aLine.FirstBaselineOffset() : aLine.LastBaselineOffset();
NS_ASSERTION(lineBaselineOffset >= itemBaselineOffset,
"failed at finding largest baseline offset");
// How much do we need to adjust our position (from the line edge),
// to get the item's baseline to hit the line's baseline offset:
nscoord baselineDiff = lineBaselineOffset - itemBaselineOffset;
if (aAxisTracker.AreAxesInternallyReversed() == useFirst) {
// Advance to align item w/ line's flex-end edge (as in FLEX_END case):
mPosition += aLine.LineCrossSize() - aItem.OuterCrossSize();
// ...and step *back* by the baseline adjustment:
mPosition -= baselineDiff;
} else {
// mPosition is already at line's flex-start edge.
// From there, we step *forward* by the baseline adjustment:
mPosition += baselineDiff;
}
break;
// ...and step *back* by the baseline adjustment:
mPosition -= baselineDiff;
} else {
// mPosition is already at line's flex-start edge.
// From there, we step *forward* by the baseline adjustment:
mPosition += baselineDiff;
}
default:
MOZ_ASSERT_UNREACHABLE("Unexpected align-self value");
break;
} else {
MOZ_ASSERT_UNREACHABLE("Unexpected align-self value");
}
}
@ -4040,9 +4023,9 @@ nscoord nsFlexContainerFrame::ComputeCrossSize(
aReflowInput.ComputedMaxBSize());
}
void FlexLine::PositionItemsInMainAxis(uint8_t aJustifyContent,
nscoord aContentBoxMainSize,
const FlexboxAxisTracker& aAxisTracker) {
void FlexLine::PositionItemsInMainAxis(
const StyleContentDistribution& aJustifyContent,
nscoord aContentBoxMainSize, const FlexboxAxisTracker& aAxisTracker) {
MainAxisPositionTracker mainAxisPosnTracker(
aAxisTracker, this, aJustifyContent, aContentBoxMainSize);
for (FlexItem* item = mItems.getFirst(); item; item = item->getNext()) {
@ -4096,7 +4079,7 @@ void nsFlexContainerFrame::SizeItemInCrossAxis(nsPresContext* aPresContext,
MOZ_ASSERT(!aItem.HadMeasuringReflow(),
"We shouldn't need more than one measuring reflow");
if (aItem.AlignSelf() == NS_STYLE_ALIGN_STRETCH) {
if (aItem.AlignSelf()._0 == StyleAlignFlags::STRETCH) {
// This item's got "align-self: stretch", so we probably imposed a
// stretched computed cross-size on it during its previous
// reflow. We're not imposing that BSize for *this* "measuring" reflow, so
@ -4297,17 +4280,13 @@ class MOZ_RAII AutoFlexItemMainSizeOverride final {
};
void nsFlexContainerFrame::CalculatePackingSpace(
uint32_t aNumThingsToPack, uint8_t aAlignVal, nscoord* aFirstSubjectOffset,
uint32_t* aNumPackingSpacesRemaining, nscoord* aPackingSpaceRemaining) {
MOZ_ASSERT(NS_STYLE_ALIGN_SPACE_BETWEEN == NS_STYLE_JUSTIFY_SPACE_BETWEEN &&
NS_STYLE_ALIGN_SPACE_AROUND == NS_STYLE_JUSTIFY_SPACE_AROUND &&
NS_STYLE_ALIGN_SPACE_EVENLY == NS_STYLE_JUSTIFY_SPACE_EVENLY,
"CalculatePackingSpace assumes that NS_STYLE_ALIGN_SPACE and "
"NS_STYLE_JUSTIFY_SPACE constants are interchangeable");
MOZ_ASSERT(aAlignVal == NS_STYLE_ALIGN_SPACE_BETWEEN ||
aAlignVal == NS_STYLE_ALIGN_SPACE_AROUND ||
aAlignVal == NS_STYLE_ALIGN_SPACE_EVENLY,
uint32_t aNumThingsToPack, const StyleContentDistribution& aAlignVal,
nscoord* aFirstSubjectOffset, uint32_t* aNumPackingSpacesRemaining,
nscoord* aPackingSpaceRemaining) {
StyleAlignFlags val = aAlignVal.primary;
MOZ_ASSERT(val == StyleAlignFlags::SPACE_BETWEEN ||
val == StyleAlignFlags::SPACE_AROUND ||
val == StyleAlignFlags::SPACE_EVENLY,
"Unexpected alignment value");
MOZ_ASSERT(*aPackingSpaceRemaining >= 0,
@ -4324,7 +4303,7 @@ void nsFlexContainerFrame::CalculatePackingSpace(
// Packing spaces between items:
*aNumPackingSpacesRemaining = aNumThingsToPack - 1;
if (aAlignVal == NS_STYLE_ALIGN_SPACE_BETWEEN) {
if (val == StyleAlignFlags::SPACE_BETWEEN) {
// No need to reserve space at beginning/end, so we're done.
return;
}
@ -4332,7 +4311,7 @@ void nsFlexContainerFrame::CalculatePackingSpace(
// We need to add 1 or 2 packing spaces, split between beginning/end, for
// space-around / space-evenly:
size_t numPackingSpacesForEdges =
aAlignVal == NS_STYLE_JUSTIFY_SPACE_AROUND ? 1 : 2;
val == StyleAlignFlags::SPACE_AROUND ? 1 : 2;
// How big will each "full" packing space be:
nscoord packingSpaceSize =

Просмотреть файл

@ -156,7 +156,7 @@ class nsFlexContainerFrame final : public nsContainerFrame {
uint32_t GetLineClampValue() const;
// nsContainerFrame overrides
uint16_t CSSAlignmentForAbsPosChild(
mozilla::StyleAlignFlags CSSAlignmentForAbsPosChild(
const ReflowInput& aChildRI,
mozilla::LogicalAxis aLogicalAxis) const override;
@ -165,7 +165,8 @@ class nsFlexContainerFrame final : public nsContainerFrame {
* subjects in MainAxisPositionTracker() and CrossAxisPositionTracker() for
* space-between, space-around, and space-evenly.
* * @param aNumThingsToPack Number of alignment subjects.
* @param aAlignVal Value for align-self or justify-self.
* @param aAlignVal Value for align-content or
* justify-content.
* @param aFirstSubjectOffset Outparam for first subject offset.
* @param aNumPackingSpacesRemaining Outparam for number of equal-sized
* packing spaces to apply between each
@ -173,11 +174,11 @@ class nsFlexContainerFrame final : public nsContainerFrame {
* @param aPackingSpaceRemaining Outparam for total amount of packing
* space to be divided up.
*/
static void CalculatePackingSpace(uint32_t aNumThingsToPack,
uint8_t aAlignVal,
nscoord* aFirstSubjectOffset,
uint32_t* aNumPackingSpacesRemaining,
nscoord* aPackingSpaceRemaining);
static void CalculatePackingSpace(
uint32_t aNumThingsToPack,
const mozilla::StyleContentDistribution& aAlignVal,
nscoord* aFirstSubjectOffset, uint32_t* aNumPackingSpacesRemaining,
nscoord* aPackingSpaceRemaining);
/**
* This property is created by a call to

Просмотреть файл

@ -5960,10 +5960,10 @@ LogicalSize nsFrame::ComputeSize(gfxContext* aRenderingContext, WritingMode aWM,
!StyleMargin()->HasInlineAxisAuto(aWM)) {
auto inlineAxisAlignment =
aWM.IsOrthogonalTo(alignCB->GetWritingMode())
? StylePosition()->UsedAlignSelf(alignCB->Style())
: StylePosition()->UsedJustifySelf(alignCB->Style());
stretch = inlineAxisAlignment == NS_STYLE_ALIGN_NORMAL ||
inlineAxisAlignment == NS_STYLE_ALIGN_STRETCH;
? StylePosition()->UsedAlignSelf(alignCB->Style())._0
: StylePosition()->UsedJustifySelf(alignCB->Style())._0;
stretch = inlineAxisAlignment == StyleAlignFlags::NORMAL ||
inlineAxisAlignment == StyleAlignFlags::STRETCH;
}
if (stretch || (aFlags & ComputeSizeFlags::eIClampMarginBoxMinSize)) {
auto iSizeToFillCB =
@ -6041,10 +6041,10 @@ LogicalSize nsFrame::ComputeSize(gfxContext* aRenderingContext, WritingMode aWM,
if (!StyleMargin()->HasBlockAxisAuto(aWM)) {
auto blockAxisAlignment =
!aWM.IsOrthogonalTo(alignCB->GetWritingMode())
? StylePosition()->UsedAlignSelf(alignCB->Style())
: StylePosition()->UsedJustifySelf(alignCB->Style());
stretch = blockAxisAlignment == NS_STYLE_ALIGN_NORMAL ||
blockAxisAlignment == NS_STYLE_ALIGN_STRETCH;
? StylePosition()->UsedAlignSelf(alignCB->Style())._0
: StylePosition()->UsedJustifySelf(alignCB->Style())._0;
stretch = blockAxisAlignment == StyleAlignFlags::NORMAL ||
blockAxisAlignment == StyleAlignFlags::STRETCH;
}
if (stretch || (aFlags & ComputeSizeFlags::eBClampMarginBoxMinSize)) {
auto bSizeToFillCB =
@ -6260,14 +6260,14 @@ LogicalSize nsFrame::ComputeSizeWithIntrinsicDimensions(
if (!StyleMargin()->HasInlineAxisAuto(aWM)) {
auto inlineAxisAlignment =
aWM.IsOrthogonalTo(GetParent()->GetWritingMode())
? stylePos->UsedAlignSelf(GetParent()->Style())
: stylePos->UsedJustifySelf(GetParent()->Style());
? stylePos->UsedAlignSelf(GetParent()->Style())._0
: stylePos->UsedJustifySelf(GetParent()->Style())._0;
// Note: 'normal' means 'start' for elements with an intrinsic size
// or ratio in the relevant dimension, otherwise 'stretch'.
// https://drafts.csswg.org/css-grid/#grid-item-sizing
if ((inlineAxisAlignment == NS_STYLE_ALIGN_NORMAL &&
if ((inlineAxisAlignment == StyleAlignFlags::NORMAL &&
!hasIntrinsicISize && !logicalRatio) ||
inlineAxisAlignment == NS_STYLE_ALIGN_STRETCH) {
inlineAxisAlignment == StyleAlignFlags::STRETCH) {
stretchI = eStretch;
}
}
@ -6327,14 +6327,14 @@ LogicalSize nsFrame::ComputeSizeWithIntrinsicDimensions(
if (!StyleMargin()->HasBlockAxisAuto(aWM)) {
auto blockAxisAlignment =
!aWM.IsOrthogonalTo(GetParent()->GetWritingMode())
? stylePos->UsedAlignSelf(GetParent()->Style())
: stylePos->UsedJustifySelf(GetParent()->Style());
? stylePos->UsedAlignSelf(GetParent()->Style())._0
: stylePos->UsedJustifySelf(GetParent()->Style())._0;
// Note: 'normal' means 'start' for elements with an intrinsic size
// or ratio in the relevant dimension, otherwise 'stretch'.
// https://drafts.csswg.org/css-grid/#grid-item-sizing
if ((blockAxisAlignment == NS_STYLE_ALIGN_NORMAL &&
if ((blockAxisAlignment == StyleAlignFlags::NORMAL &&
!hasIntrinsicBSize && !logicalRatio) ||
blockAxisAlignment == NS_STYLE_ALIGN_STRETCH) {
blockAxisAlignment == StyleAlignFlags::STRETCH) {
stretchB = eStretch;
}
}

Просмотреть файл

@ -730,13 +730,13 @@ struct nsGridContainerFrame::GridItemInfo {
* axis then set aBaselineOffset to the baseline offset and return aAlign.
* Otherwise, return a fallback alignment.
*/
uint8_t GetSelfBaseline(uint8_t aAlign, LogicalAxis aAxis,
nscoord* aBaselineOffset) const {
MOZ_ASSERT(aAlign == NS_STYLE_ALIGN_BASELINE ||
aAlign == NS_STYLE_ALIGN_LAST_BASELINE);
StyleAlignFlags GetSelfBaseline(StyleAlignFlags aAlign, LogicalAxis aAxis,
nscoord* aBaselineOffset) const {
MOZ_ASSERT(aAlign == StyleAlignFlags::BASELINE ||
aAlign == StyleAlignFlags::LAST_BASELINE);
if (!(mState[aAxis] & eSelfBaseline)) {
return aAlign == NS_STYLE_ALIGN_BASELINE ? NS_STYLE_ALIGN_SELF_START
: NS_STYLE_ALIGN_SELF_END;
return aAlign == StyleAlignFlags::BASELINE ? StyleAlignFlags::SELF_START
: StyleAlignFlags::SELF_END;
}
*aBaselineOffset = mBaselineOffset[aAxis];
return aAlign;
@ -1846,8 +1846,8 @@ struct nsGridContainerFrame::Tracks {
mStateUnion(TrackSize::StateBits(0)),
mAxis(aAxis),
mCanResolveLineRangeSize(false) {
mBaselineSubtreeAlign[BaselineSharingGroup::First] = NS_STYLE_ALIGN_AUTO;
mBaselineSubtreeAlign[BaselineSharingGroup::Last] = NS_STYLE_ALIGN_AUTO;
mBaselineSubtreeAlign[BaselineSharingGroup::First] = StyleAlignFlags::AUTO;
mBaselineSubtreeAlign[BaselineSharingGroup::Last] = StyleAlignFlags::AUTO;
mBaseline[BaselineSharingGroup::First] = NS_INTRINSIC_ISIZE_UNKNOWN;
mBaseline[BaselineSharingGroup::Last] = NS_INTRINSIC_ISIZE_UNKNOWN;
}
@ -2454,10 +2454,10 @@ struct nsGridContainerFrame::Tracks {
TrackSize::StateBits mStateUnion;
LogicalAxis mAxis;
// Used for aligning a baseline-aligned subtree of items. The only possible
// values are NS_STYLE_ALIGN_{START,END,CENTER,AUTO}. AUTO means there are
// values are StyleAlignFlags::{START,END,CENTER,AUTO}. AUTO means there are
// no baseline-aligned items in any track in that axis.
// There is one alignment value for each BaselineSharingGroup.
PerBaseline<uint8_t> mBaselineSubtreeAlign;
PerBaseline<StyleAlignFlags> mBaselineSubtreeAlign;
// True if track positions and sizes are final in this axis.
bool mCanResolveLineRangeSize;
};
@ -3454,12 +3454,12 @@ static uint32_t GetDisplayFlagsForGridItem(nsIFrame* aFrame) {
}
// Align an item's margin box in its aAxis inside aCBSize.
static void AlignJustifySelf(uint8_t aAlignment, LogicalAxis aAxis,
static void AlignJustifySelf(StyleAlignFlags aAlignment, LogicalAxis aAxis,
AlignJustifyFlags aFlags, nscoord aBaselineAdjust,
nscoord aCBSize, const ReflowInput& aRI,
const LogicalSize& aChildSize,
LogicalPoint* aPos) {
MOZ_ASSERT(aAlignment != NS_STYLE_ALIGN_AUTO,
MOZ_ASSERT(aAlignment != StyleAlignFlags::AUTO,
"unexpected 'auto' "
"computed value for normal flow grid item");
@ -3476,16 +3476,16 @@ static void AlignJustifySelf(uint8_t aAlignment, LogicalAxis aAxis,
}
static void AlignSelf(const nsGridContainerFrame::GridItemInfo& aGridItem,
uint8_t aAlignSelf, nscoord aCBSize,
StyleAlignSelf aAlignSelf, nscoord aCBSize,
const WritingMode aCBWM, const ReflowInput& aRI,
const LogicalSize& aSize, LogicalPoint* aPos) {
auto alignSelf = aAlignSelf;
auto alignSelf = aAlignSelf._0;
AlignJustifyFlags flags = AlignJustifyFlags::NoFlags;
if (alignSelf & NS_STYLE_ALIGN_SAFE) {
if (alignSelf & StyleAlignFlags::SAFE) {
flags |= AlignJustifyFlags::OverflowSafe;
}
alignSelf &= ~NS_STYLE_ALIGN_FLAG_BITS;
alignSelf &= ~StyleAlignFlags::FLAG_BITS;
WritingMode childWM = aRI.GetWritingMode();
if (aCBWM.ParallelAxisStartsOnSameSide(eLogicalAxisBlock, childWM)) {
@ -3493,16 +3493,17 @@ static void AlignSelf(const nsGridContainerFrame::GridItemInfo& aGridItem,
}
// Grid's 'align-self' axis is never parallel to the container's inline axis.
if (alignSelf == NS_STYLE_ALIGN_LEFT || alignSelf == NS_STYLE_ALIGN_RIGHT) {
alignSelf = NS_STYLE_ALIGN_START;
if (alignSelf == StyleAlignFlags::LEFT ||
alignSelf == StyleAlignFlags::RIGHT) {
alignSelf = StyleAlignFlags::START;
}
if (MOZ_LIKELY(alignSelf == NS_STYLE_ALIGN_NORMAL)) {
alignSelf = NS_STYLE_ALIGN_STRETCH;
if (MOZ_LIKELY(alignSelf == StyleAlignFlags::NORMAL)) {
alignSelf = StyleAlignFlags::STRETCH;
}
nscoord baselineAdjust = 0;
if (alignSelf == NS_STYLE_ALIGN_BASELINE ||
alignSelf == NS_STYLE_ALIGN_LAST_BASELINE) {
if (alignSelf == StyleAlignFlags::BASELINE ||
alignSelf == StyleAlignFlags::LAST_BASELINE) {
alignSelf = aGridItem.GetSelfBaseline(alignSelf, eLogicalAxisBlock,
&baselineAdjust);
}
@ -3514,43 +3515,39 @@ static void AlignSelf(const nsGridContainerFrame::GridItemInfo& aGridItem,
}
static void JustifySelf(const nsGridContainerFrame::GridItemInfo& aGridItem,
uint8_t aJustifySelf, nscoord aCBSize,
StyleJustifySelf aJustifySelf, nscoord aCBSize,
const WritingMode aCBWM, const ReflowInput& aRI,
const LogicalSize& aSize, LogicalPoint* aPos) {
auto justifySelf = aJustifySelf;
auto justifySelf = aJustifySelf._0;
AlignJustifyFlags flags = AlignJustifyFlags::NoFlags;
if (justifySelf & NS_STYLE_JUSTIFY_SAFE) {
if (justifySelf & StyleAlignFlags::SAFE) {
flags |= AlignJustifyFlags::OverflowSafe;
}
justifySelf &= ~NS_STYLE_JUSTIFY_FLAG_BITS;
justifySelf &= ~StyleAlignFlags::FLAG_BITS;
WritingMode childWM = aRI.GetWritingMode();
if (aCBWM.ParallelAxisStartsOnSameSide(eLogicalAxisInline, childWM)) {
flags |= AlignJustifyFlags::SameSide;
}
if (MOZ_LIKELY(justifySelf == NS_STYLE_ALIGN_NORMAL)) {
justifySelf = NS_STYLE_ALIGN_STRETCH;
if (MOZ_LIKELY(justifySelf == StyleAlignFlags::NORMAL)) {
justifySelf = StyleAlignFlags::STRETCH;
}
nscoord baselineAdjust = 0;
// Grid's 'justify-self' axis is always parallel to the container's inline
// axis, so justify-self:left|right always applies.
switch (justifySelf) {
case NS_STYLE_JUSTIFY_LEFT:
justifySelf =
aCBWM.IsBidiLTR() ? NS_STYLE_JUSTIFY_START : NS_STYLE_JUSTIFY_END;
break;
case NS_STYLE_JUSTIFY_RIGHT:
justifySelf =
aCBWM.IsBidiLTR() ? NS_STYLE_JUSTIFY_END : NS_STYLE_JUSTIFY_START;
break;
case NS_STYLE_JUSTIFY_BASELINE:
case NS_STYLE_JUSTIFY_LAST_BASELINE:
justifySelf = aGridItem.GetSelfBaseline(justifySelf, eLogicalAxisInline,
&baselineAdjust);
break;
if (justifySelf == StyleAlignFlags::LEFT) {
justifySelf =
aCBWM.IsBidiLTR() ? StyleAlignFlags::START : StyleAlignFlags::END;
} else if (justifySelf == StyleAlignFlags::RIGHT) {
justifySelf =
aCBWM.IsBidiLTR() ? StyleAlignFlags::END : StyleAlignFlags::START;
} else if (justifySelf == StyleAlignFlags::BASELINE ||
justifySelf == StyleAlignFlags::LAST_BASELINE) {
justifySelf = aGridItem.GetSelfBaseline(justifySelf, eLogicalAxisInline,
&baselineAdjust);
}
bool isOrthogonal = aCBWM.IsOrthogonalTo(childWM);
@ -3559,48 +3556,46 @@ static void JustifySelf(const nsGridContainerFrame::GridItemInfo& aGridItem,
aSize, aPos);
}
static uint16_t GetAlignJustifyValue(uint16_t aAlignment, const WritingMode aWM,
const bool aIsAlign, bool* aOverflowSafe) {
*aOverflowSafe = aAlignment & NS_STYLE_ALIGN_SAFE;
aAlignment &= (NS_STYLE_ALIGN_ALL_BITS & ~NS_STYLE_ALIGN_FLAG_BITS);
static StyleAlignFlags GetAlignJustifyValue(StyleAlignFlags aAlignment,
const WritingMode aWM,
const bool aIsAlign,
bool* aOverflowSafe) {
*aOverflowSafe = bool(aAlignment & StyleAlignFlags::SAFE);
aAlignment &= ~StyleAlignFlags::FLAG_BITS;
// Map some alignment values to 'start' / 'end'.
switch (aAlignment) {
case NS_STYLE_ALIGN_LEFT:
case NS_STYLE_ALIGN_RIGHT: {
if (aIsAlign) {
// Grid's 'align-content' axis is never parallel to the inline axis.
return NS_STYLE_ALIGN_START;
}
bool isStart = aWM.IsBidiLTR() == (aAlignment == NS_STYLE_ALIGN_LEFT);
return isStart ? NS_STYLE_ALIGN_START : NS_STYLE_ALIGN_END;
if (aAlignment == StyleAlignFlags::LEFT ||
aAlignment == StyleAlignFlags::RIGHT) {
if (aIsAlign) {
// Grid's 'align-content' axis is never parallel to the inline axis.
return StyleAlignFlags::START;
}
case NS_STYLE_ALIGN_FLEX_START: // same as 'start' for Grid
return NS_STYLE_ALIGN_START;
case NS_STYLE_ALIGN_FLEX_END: // same as 'end' for Grid
return NS_STYLE_ALIGN_END;
bool isStart = aWM.IsBidiLTR() == (aAlignment == StyleAlignFlags::LEFT);
return isStart ? StyleAlignFlags::START : StyleAlignFlags::END;
}
if (aAlignment == StyleAlignFlags::FLEX_START) {
return StyleAlignFlags::START; // same as 'start' for Grid
}
if (aAlignment == StyleAlignFlags::FLEX_END) {
return StyleAlignFlags::END; // same as 'end' for Grid
}
return aAlignment;
}
static uint16_t GetAlignJustifyFallbackIfAny(uint16_t aAlignment,
const WritingMode aWM,
const bool aIsAlign,
bool* aOverflowSafe) {
uint16_t fallback = aAlignment >> NS_STYLE_ALIGN_ALL_SHIFT;
if (fallback) {
return GetAlignJustifyValue(fallback, aWM, aIsAlign, aOverflowSafe);
static Maybe<StyleAlignFlags> GetAlignJustifyFallbackIfAny(
const StyleContentDistribution& aDistribution, const WritingMode aWM,
const bool aIsAlign, bool* aOverflowSafe) {
// TODO: Eventually this should look at aDistribution's fallback alignment,
// see https://github.com/w3c/csswg-drafts/issues/1002.
if (aDistribution.primary == StyleAlignFlags::STRETCH ||
aDistribution.primary == StyleAlignFlags::SPACE_BETWEEN) {
return Some(StyleAlignFlags::START);
}
// https://drafts.csswg.org/css-align-3/#fallback-alignment
switch (aAlignment) {
case NS_STYLE_ALIGN_STRETCH:
case NS_STYLE_ALIGN_SPACE_BETWEEN:
return NS_STYLE_ALIGN_START;
case NS_STYLE_ALIGN_SPACE_AROUND:
case NS_STYLE_ALIGN_SPACE_EVENLY:
return NS_STYLE_ALIGN_CENTER;
if (aDistribution.primary == StyleAlignFlags::SPACE_AROUND ||
aDistribution.primary == StyleAlignFlags::SPACE_EVENLY) {
return Some(StyleAlignFlags::CENTER);
}
return 0;
return Nothing();
}
//----------------------------------------------------------------------
@ -5260,14 +5255,14 @@ void nsGridContainerFrame::Tracks::InitializeItemBaselines(
if (itemHasBaselineParallelToTrack) {
// [align|justify]-self:[last ]baseline.
auto selfAlignment =
isOrthogonal ? child->StylePosition()->UsedJustifySelf(containerSC)
: child->StylePosition()->UsedAlignSelf(containerSC);
selfAlignment &= ~NS_STYLE_ALIGN_FLAG_BITS;
if (selfAlignment == NS_STYLE_ALIGN_BASELINE) {
isOrthogonal ? child->StylePosition()->UsedJustifySelf(containerSC)._0
: child->StylePosition()->UsedAlignSelf(containerSC)._0;
selfAlignment &= ~StyleAlignFlags::FLAG_BITS;
if (selfAlignment == StyleAlignFlags::BASELINE) {
state |= ItemState::eFirstBaseline | ItemState::eSelfBaseline;
const GridArea& area = gridItem.mArea;
baselineTrack = isInlineAxis ? area.mCols.mStart : area.mRows.mStart;
} else if (selfAlignment == NS_STYLE_ALIGN_LAST_BASELINE) {
} else if (selfAlignment == StyleAlignFlags::LAST_BASELINE) {
state |= ItemState::eLastBaseline | ItemState::eSelfBaseline;
const GridArea& area = gridItem.mArea;
baselineTrack = (isInlineAxis ? area.mCols.mEnd : area.mRows.mEnd) - 1;
@ -5280,15 +5275,15 @@ void nsGridContainerFrame::Tracks::InitializeItemBaselines(
// For this purpose, the 'start', 'end', 'flex-start', and 'flex-end'
// values of 'align-self' are treated as either 'self-start' or
// 'self-end', whichever they end up equivalent to.
auto alignContent = child->StylePosition()->mAlignContent;
alignContent &= ~NS_STYLE_ALIGN_FLAG_BITS;
if (alignContent == NS_STYLE_ALIGN_BASELINE ||
alignContent == NS_STYLE_ALIGN_LAST_BASELINE) {
const auto selfAlignEdge = alignContent == NS_STYLE_ALIGN_BASELINE
? NS_STYLE_ALIGN_SELF_START
: NS_STYLE_ALIGN_SELF_END;
bool validCombo = selfAlignment == NS_STYLE_ALIGN_NORMAL ||
selfAlignment == NS_STYLE_ALIGN_STRETCH ||
auto alignContent = child->StylePosition()->mAlignContent.primary;
alignContent &= ~StyleAlignFlags::FLAG_BITS;
if (alignContent == StyleAlignFlags::BASELINE ||
alignContent == StyleAlignFlags::LAST_BASELINE) {
const auto selfAlignEdge = alignContent == StyleAlignFlags::BASELINE
? StyleAlignFlags::SELF_START
: StyleAlignFlags::SELF_END;
bool validCombo = selfAlignment == StyleAlignFlags::NORMAL ||
selfAlignment == StyleAlignFlags::STRETCH ||
selfAlignment == selfAlignEdge;
if (!validCombo) {
// We're doing alignment in the axis that's orthogonal to mAxis here.
@ -5296,38 +5291,33 @@ void nsGridContainerFrame::Tracks::InitializeItemBaselines(
// |sameSide| is true if the container's start side in this axis is
// the same as the child's start side, in the child's parallel axis.
bool sameSide = wm.ParallelAxisStartsOnSameSide(alignAxis, childWM);
switch (selfAlignment) {
case NS_STYLE_ALIGN_LEFT:
selfAlignment = !isInlineAxis || wm.IsBidiLTR()
? NS_STYLE_ALIGN_START
: NS_STYLE_ALIGN_END;
break;
case NS_STYLE_ALIGN_RIGHT:
selfAlignment = isInlineAxis && wm.IsBidiLTR()
? NS_STYLE_ALIGN_END
: NS_STYLE_ALIGN_START;
break;
if (selfAlignment == StyleAlignFlags::LEFT) {
selfAlignment = !isInlineAxis || wm.IsBidiLTR()
? StyleAlignFlags::START
: StyleAlignFlags::END;
} else if (selfAlignment == StyleAlignFlags::RIGHT) {
selfAlignment = isInlineAxis && wm.IsBidiLTR()
? StyleAlignFlags::END
: StyleAlignFlags::START;
}
switch (selfAlignment) {
case NS_STYLE_ALIGN_START:
case NS_STYLE_ALIGN_FLEX_START:
validCombo =
sameSide == (alignContent == NS_STYLE_ALIGN_BASELINE);
break;
case NS_STYLE_ALIGN_END:
case NS_STYLE_ALIGN_FLEX_END:
validCombo =
sameSide == (alignContent == NS_STYLE_ALIGN_LAST_BASELINE);
break;
if (selfAlignment == StyleAlignFlags::START ||
selfAlignment == StyleAlignFlags::FLEX_START) {
validCombo =
sameSide == (alignContent == StyleAlignFlags::BASELINE);
} else if (selfAlignment == StyleAlignFlags::END ||
selfAlignment == StyleAlignFlags::FLEX_END) {
validCombo =
sameSide == (alignContent == StyleAlignFlags::LAST_BASELINE);
}
}
if (validCombo) {
const GridArea& area = gridItem.mArea;
if (alignContent == NS_STYLE_ALIGN_BASELINE) {
if (alignContent == StyleAlignFlags::BASELINE) {
state |= ItemState::eFirstBaseline | ItemState::eContentBaseline;
baselineTrack =
isInlineAxis ? area.mCols.mStart : area.mRows.mStart;
} else if (alignContent == NS_STYLE_ALIGN_LAST_BASELINE) {
} else if (alignContent == StyleAlignFlags::LAST_BASELINE) {
state |= ItemState::eLastBaseline | ItemState::eContentBaseline;
baselineTrack =
(isInlineAxis ? area.mCols.mEnd : area.mRows.mEnd) - 1;
@ -5426,8 +5416,8 @@ void nsGridContainerFrame::Tracks::InitializeItemBaselines(
// TODO: CSS Align spec issue - how to align a baseline subtree in a track?
// https://lists.w3.org/Archives/Public/www-style/2016May/0141.html
mBaselineSubtreeAlign[BaselineSharingGroup::First] = NS_STYLE_ALIGN_START;
mBaselineSubtreeAlign[BaselineSharingGroup::Last] = NS_STYLE_ALIGN_END;
mBaselineSubtreeAlign[BaselineSharingGroup::First] = StyleAlignFlags::START;
mBaselineSubtreeAlign[BaselineSharingGroup::Last] = StyleAlignFlags::END;
CalculateItemBaselines(firstBaselineItems, BaselineSharingGroup::First);
CalculateItemBaselines(lastBaselineItems, BaselineSharingGroup::Last);
@ -5454,22 +5444,18 @@ void nsGridContainerFrame::Tracks::AlignBaselineSubtree(
: BaselineSharingGroup::Last;
nscoord delta = sz.mBase - sz.mBaselineSubtreeSize[baselineGroup];
const auto subtreeAlign = mBaselineSubtreeAlign[baselineGroup];
switch (subtreeAlign) {
case NS_STYLE_ALIGN_START:
if (state & ItemState::eLastBaseline) {
aGridItem.mBaselineOffset[mAxis] += delta;
}
break;
case NS_STYLE_ALIGN_END:
if (isFirstBaseline) {
aGridItem.mBaselineOffset[mAxis] += delta;
}
break;
case NS_STYLE_ALIGN_CENTER:
aGridItem.mBaselineOffset[mAxis] += delta / 2;
break;
default:
MOZ_ASSERT_UNREACHABLE("unexpected baseline subtree alignment");
if (subtreeAlign == StyleAlignFlags::START) {
if (state & ItemState::eLastBaseline) {
aGridItem.mBaselineOffset[mAxis] += delta;
}
} else if (subtreeAlign == StyleAlignFlags::END) {
if (isFirstBaseline) {
aGridItem.mBaselineOffset[mAxis] += delta;
}
} else if (subtreeAlign == StyleAlignFlags::CENTER) {
aGridItem.mBaselineOffset[mAxis] += delta / 2;
} else {
MOZ_ASSERT_UNREACHABLE("unexpected baseline subtree alignment");
}
}
@ -5991,19 +5977,18 @@ void nsGridContainerFrame::Tracks::AlignJustifyContent(
auto valueAndFallback =
isAlign ? aStyle->mAlignContent : aStyle->mJustifyContent;
bool overflowSafe;
auto alignment =
::GetAlignJustifyValue(valueAndFallback, aWM, isAlign, &overflowSafe);
if (alignment == NS_STYLE_ALIGN_NORMAL) {
MOZ_ASSERT(valueAndFallback == NS_STYLE_ALIGN_NORMAL,
"*-content:normal cannot be specified with explicit fallback");
alignment = NS_STYLE_ALIGN_STRETCH;
valueAndFallback = alignment; // we may need a fallback for 'stretch' below
auto alignment = ::GetAlignJustifyValue(valueAndFallback.primary, aWM,
isAlign, &overflowSafe);
if (alignment == StyleAlignFlags::NORMAL) {
alignment = StyleAlignFlags::STRETCH;
// we may need a fallback for 'stretch' below
valueAndFallback = {alignment};
}
// Compute the free space and count auto-sized tracks.
size_t numAutoTracks = 0;
nscoord space;
if (alignment != NS_STYLE_ALIGN_START) {
if (alignment != StyleAlignFlags::START) {
nscoord trackSizeSum = 0;
if (aIsSubgriddedAxis) {
numAutoTracks = mSizes.Length();
@ -6018,41 +6003,37 @@ void nsGridContainerFrame::Tracks::AlignJustifyContent(
space = aContentBoxSize - trackSizeSum - SumOfGridGaps();
// Use the fallback value instead when applicable.
if (space < 0 ||
(alignment == NS_STYLE_ALIGN_SPACE_BETWEEN && mSizes.Length() == 1)) {
(alignment == StyleAlignFlags::SPACE_BETWEEN && mSizes.Length() == 1)) {
auto fallback = ::GetAlignJustifyFallbackIfAny(valueAndFallback, aWM,
isAlign, &overflowSafe);
if (fallback) {
alignment = fallback;
alignment = *fallback;
}
}
if (space == 0 || (space < 0 && overflowSafe)) {
// XXX check that this makes sense also for [last ]baseline (bug 1151204).
alignment = NS_STYLE_ALIGN_START;
alignment = StyleAlignFlags::START;
}
}
// Optimize the cases where we just need to set each track's position.
nscoord pos = 0;
bool distribute = true;
switch (alignment) {
case NS_STYLE_ALIGN_BASELINE:
case NS_STYLE_ALIGN_LAST_BASELINE:
NS_WARNING("NYI: 'first/last baseline' (bug 1151204)"); // XXX
[[fallthrough]];
case NS_STYLE_ALIGN_START:
distribute = false;
break;
case NS_STYLE_ALIGN_END:
pos = space;
distribute = false;
break;
case NS_STYLE_ALIGN_CENTER:
pos = space / 2;
distribute = false;
break;
case NS_STYLE_ALIGN_STRETCH:
distribute = numAutoTracks != 0;
break;
if (alignment == StyleAlignFlags::BASELINE ||
alignment == StyleAlignFlags::LAST_BASELINE) {
NS_WARNING("NYI: 'first/last baseline' (bug 1151204)"); // XXX
alignment = StyleAlignFlags::START;
}
if (alignment == StyleAlignFlags::START) {
distribute = false;
} else if (alignment == StyleAlignFlags::END) {
pos = space;
distribute = false;
} else if (alignment == StyleAlignFlags::CENTER) {
pos = space / 2;
distribute = false;
} else if (alignment == StyleAlignFlags::STRETCH) {
distribute = numAutoTracks != 0;
}
if (!distribute) {
for (TrackSize& sz : mSizes) {
@ -6065,45 +6046,41 @@ void nsGridContainerFrame::Tracks::AlignJustifyContent(
// Distribute free space to/between tracks and set their position.
MOZ_ASSERT(space > 0, "should've handled that on the fallback path above");
nscoord between, roundingError;
switch (alignment) {
case NS_STYLE_ALIGN_STRETCH: {
MOZ_ASSERT(numAutoTracks > 0, "we handled numAutoTracks == 0 above");
nscoord spacePerTrack;
roundingError = NSCoordDivRem(space, numAutoTracks, &spacePerTrack);
for (TrackSize& sz : mSizes) {
sz.mPosition = pos;
if (!(sz.mState & TrackSize::eAutoMaxSizing)) {
pos += sz.mBase + mGridGap;
continue;
}
nscoord stretch = spacePerTrack;
if (roundingError) {
roundingError -= 1;
stretch += 1;
}
nscoord newBase = sz.mBase + stretch;
sz.mBase = newBase;
pos += newBase + mGridGap;
if (alignment == StyleAlignFlags::STRETCH) {
MOZ_ASSERT(numAutoTracks > 0, "we handled numAutoTracks == 0 above");
nscoord spacePerTrack;
roundingError = NSCoordDivRem(space, numAutoTracks, &spacePerTrack);
for (TrackSize& sz : mSizes) {
sz.mPosition = pos;
if (!(sz.mState & TrackSize::eAutoMaxSizing)) {
pos += sz.mBase + mGridGap;
continue;
}
MOZ_ASSERT(!roundingError, "we didn't distribute all rounding error?");
return;
nscoord stretch = spacePerTrack;
if (roundingError) {
roundingError -= 1;
stretch += 1;
}
nscoord newBase = sz.mBase + stretch;
sz.mBase = newBase;
pos += newBase + mGridGap;
}
case NS_STYLE_ALIGN_SPACE_BETWEEN:
MOZ_ASSERT(mSizes.Length() > 1, "should've used a fallback above");
roundingError = NSCoordDivRem(space, mSizes.Length() - 1, &between);
break;
case NS_STYLE_ALIGN_SPACE_AROUND:
roundingError = NSCoordDivRem(space, mSizes.Length(), &between);
pos = between / 2;
break;
case NS_STYLE_ALIGN_SPACE_EVENLY:
roundingError = NSCoordDivRem(space, mSizes.Length() + 1, &between);
pos = between;
break;
default:
MOZ_ASSERT_UNREACHABLE("unknown align-/justify-content value");
between = 0; // just to avoid a compiler warning
roundingError = 0; // just to avoid a compiler warning
MOZ_ASSERT(!roundingError, "we didn't distribute all rounding error?");
return;
}
if (alignment == StyleAlignFlags::SPACE_BETWEEN) {
MOZ_ASSERT(mSizes.Length() > 1, "should've used a fallback above");
roundingError = NSCoordDivRem(space, mSizes.Length() - 1, &between);
} else if (alignment == StyleAlignFlags::SPACE_AROUND) {
roundingError = NSCoordDivRem(space, mSizes.Length(), &between);
pos = between / 2;
} else if (alignment == StyleAlignFlags::SPACE_EVENLY) {
roundingError = NSCoordDivRem(space, mSizes.Length() + 1, &between);
pos = between;
} else {
MOZ_ASSERT_UNREACHABLE("unknown align-/justify-content value");
between = 0; // just to avoid a compiler warning
roundingError = 0; // just to avoid a compiler warning
}
between += mGridGap;
for (TrackSize& sz : mSizes) {
@ -6396,13 +6373,13 @@ void nsGridContainerFrame::ReflowInFlowChild(
if (aGridItemInfo) {
// Clamp during reflow if we're stretching in that axis.
auto* pos = aChild->StylePosition();
auto j = pos->UsedJustifySelf(Style());
auto a = pos->UsedAlignSelf(Style());
auto j = pos->UsedJustifySelf(Style())._0;
auto a = pos->UsedAlignSelf(Style())._0;
bool stretch[2];
stretch[eLogicalAxisInline] =
j == NS_STYLE_JUSTIFY_NORMAL || j == NS_STYLE_JUSTIFY_STRETCH;
j == StyleAlignFlags::NORMAL || j == StyleAlignFlags::STRETCH;
stretch[eLogicalAxisBlock] =
a == NS_STYLE_ALIGN_NORMAL || a == NS_STYLE_ALIGN_STRETCH;
a == StyleAlignFlags::NORMAL || a == StyleAlignFlags::STRETCH;
auto childIAxis = isOrthogonal ? eLogicalAxisBlock : eLogicalAxisInline;
if (stretch[childIAxis] &&
aGridItemInfo->mState[childIAxis] & ItemState::eClampMarginBoxMinSize) {
@ -6463,8 +6440,8 @@ void nsGridContainerFrame::ReflowInFlowChild(
if (!childRI.mStyleMargin->HasBlockAxisAuto(childWM) &&
childRI.mStylePosition->BSize(childWM).IsAuto()) {
auto blockAxisAlignment = childRI.mStylePosition->UsedAlignSelf(Style());
if (blockAxisAlignment == NS_STYLE_ALIGN_NORMAL ||
blockAxisAlignment == NS_STYLE_ALIGN_STRETCH) {
if (blockAxisAlignment._0 == StyleAlignFlags::NORMAL ||
blockAxisAlignment._0 == StyleAlignFlags::STRETCH) {
stretch = true;
}
}
@ -6515,8 +6492,9 @@ void nsGridContainerFrame::ReflowInFlowChild(
auto align = childRI.mStylePosition->UsedAlignSelf(containerSC);
auto state = aGridItemInfo->mState[eLogicalAxisBlock];
if (state & ItemState::eContentBaseline) {
align = (state & ItemState::eFirstBaseline) ? NS_STYLE_ALIGN_SELF_START
: NS_STYLE_ALIGN_SELF_END;
align = {(state & ItemState::eFirstBaseline)
? StyleAlignFlags::SELF_START
: StyleAlignFlags::SELF_END};
}
nscoord cbsz = cb.BSize(wm) - consumedGridAreaBSize;
AlignSelf(*aGridItemInfo, align, cbsz, wm, childRI, size, &childPos);
@ -6524,9 +6502,9 @@ void nsGridContainerFrame::ReflowInFlowChild(
auto justify = childRI.mStylePosition->UsedJustifySelf(containerSC);
auto state = aGridItemInfo->mState[eLogicalAxisInline];
if (state & ItemState::eContentBaseline) {
justify = (state & ItemState::eFirstBaseline)
? NS_STYLE_JUSTIFY_SELF_START
: NS_STYLE_JUSTIFY_SELF_END;
justify = {(state & ItemState::eFirstBaseline)
? StyleAlignFlags::SELF_START
: StyleAlignFlags::SELF_END};
}
nscoord cbsz = cb.ISize(wm);
JustifySelf(*aGridItemInfo, justify, cbsz, wm, childRI, size, &childPos);
@ -8135,46 +8113,47 @@ void nsGridContainerFrame::RemoveFrame(ChildListID aListID,
nsContainerFrame::RemoveFrame(aListID, aOldFrame);
}
uint16_t nsGridContainerFrame::CSSAlignmentForAbsPosChild(
StyleAlignFlags nsGridContainerFrame::CSSAlignmentForAbsPosChild(
const ReflowInput& aChildRI, LogicalAxis aLogicalAxis) const {
MOZ_ASSERT(aChildRI.mFrame->IsAbsolutelyPositioned(),
"This method should only be called for abspos children");
uint16_t alignment = (aLogicalAxis == eLogicalAxisInline)
? aChildRI.mStylePosition->UsedJustifySelf(Style())
: aChildRI.mStylePosition->UsedAlignSelf(Style());
StyleAlignFlags alignment =
(aLogicalAxis == eLogicalAxisInline)
? aChildRI.mStylePosition->UsedJustifySelf(Style())._0
: aChildRI.mStylePosition->UsedAlignSelf(Style())._0;
// Extract and strip the flag bits
uint16_t alignmentFlags = alignment & NS_STYLE_ALIGN_FLAG_BITS;
alignment &= ~NS_STYLE_ALIGN_FLAG_BITS;
StyleAlignFlags alignmentFlags = alignment & StyleAlignFlags::FLAG_BITS;
alignment &= ~StyleAlignFlags::FLAG_BITS;
if (alignment == NS_STYLE_ALIGN_NORMAL) {
if (alignment == StyleAlignFlags::NORMAL) {
// "the 'normal' keyword behaves as 'start' on replaced
// absolutely-positioned boxes, and behaves as 'stretch' on all other
// absolutely-positioned boxes."
// https://drafts.csswg.org/css-align/#align-abspos
// https://drafts.csswg.org/css-align/#justify-abspos
alignment = aChildRI.mFrame->IsFrameOfType(nsIFrame::eReplaced)
? NS_STYLE_ALIGN_START
: NS_STYLE_ALIGN_STRETCH;
} else if (alignment == NS_STYLE_ALIGN_FLEX_START) {
alignment = NS_STYLE_ALIGN_START;
} else if (alignment == NS_STYLE_ALIGN_FLEX_END) {
alignment = NS_STYLE_ALIGN_END;
} else if (alignment == NS_STYLE_ALIGN_LEFT ||
alignment == NS_STYLE_ALIGN_RIGHT) {
? StyleAlignFlags::START
: StyleAlignFlags::STRETCH;
} else if (alignment == StyleAlignFlags::FLEX_START) {
alignment = StyleAlignFlags::START;
} else if (alignment == StyleAlignFlags::FLEX_END) {
alignment = StyleAlignFlags::END;
} else if (alignment == StyleAlignFlags::LEFT ||
alignment == StyleAlignFlags::RIGHT) {
if (aLogicalAxis == eLogicalAxisInline) {
const bool isLeft = (alignment == NS_STYLE_ALIGN_LEFT);
const bool isLeft = (alignment == StyleAlignFlags::LEFT);
WritingMode wm = GetWritingMode();
alignment = (isLeft == wm.IsBidiLTR()) ? NS_STYLE_ALIGN_START
: NS_STYLE_ALIGN_END;
alignment = (isLeft == wm.IsBidiLTR()) ? StyleAlignFlags::START
: StyleAlignFlags::END;
} else {
alignment = NS_STYLE_ALIGN_START;
alignment = StyleAlignFlags::START;
}
} else if (alignment == NS_STYLE_ALIGN_BASELINE) {
alignment = NS_STYLE_ALIGN_START;
} else if (alignment == NS_STYLE_ALIGN_LAST_BASELINE) {
alignment = NS_STYLE_ALIGN_END;
} else if (alignment == StyleAlignFlags::BASELINE) {
alignment = StyleAlignFlags::START;
} else if (alignment == StyleAlignFlags::LAST_BASELINE) {
alignment = StyleAlignFlags::END;
}
return (alignment | alignmentFlags);

Просмотреть файл

@ -165,8 +165,8 @@ class nsGridContainerFrame final : public nsContainerFrame {
const nsLineList::iterator* aPrevFrameLine,
nsFrameList& aFrameList) override;
void RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) override;
uint16_t CSSAlignmentForAbsPosChild(const ReflowInput& aChildRI,
LogicalAxis aLogicalAxis) const override;
mozilla::StyleAlignFlags CSSAlignmentForAbsPosChild(
const ReflowInput& aChildRI, LogicalAxis aLogicalAxis) const override;
#ifdef DEBUG
void SetInitialChildList(ChildListID aListID,

Просмотреть файл

@ -553,6 +553,12 @@ cbindgen-types = [
{ gecko = "StyleContent", servo = "values::computed::counters::Content" },
{ gecko = "StyleSymbolsType", servo = "values::generics::SymbolsType" },
{ gecko = "StyleCounterStyle", servo = "values::generics::CounterStyle" },
{ gecko = "StyleComputedJustifyItems", servo = "values::computed::align::ComputedJustifyItems" },
{ gecko = "StyleAlignItems", servo = "values::computed::AlignItems" },
{ gecko = "StyleJustifySelf", servo = "values::computed::JustifySelf" },
{ gecko = "StyleAlignSelf", servo = "values::computed::AlignSelf" },
{ gecko = "StyleAlignContent", servo = "values::computed::align::AlignContent" },
{ gecko = "StyleJustifyContent", servo = "values::computed::align::JustifyContent" },
]
mapped-generic-types = [

Просмотреть файл

@ -354,55 +354,6 @@ enum class StyleDirection : uint8_t { Ltr, Rtl };
#define NS_STYLE_WRITING_MODE_SIDEWAYS_LR \
(NS_STYLE_WRITING_MODE_VERTICAL_LR | NS_STYLE_WRITING_MODE_SIDEWAYS_MASK)
// Shared constants for all align/justify properties (nsStylePosition):
#define NS_STYLE_ALIGN_AUTO 0
#define NS_STYLE_ALIGN_NORMAL 1
#define NS_STYLE_ALIGN_START 2
#define NS_STYLE_ALIGN_END 3
#define NS_STYLE_ALIGN_FLEX_START 4
#define NS_STYLE_ALIGN_FLEX_END 5
#define NS_STYLE_ALIGN_CENTER 6
#define NS_STYLE_ALIGN_LEFT 7
#define NS_STYLE_ALIGN_RIGHT 8
#define NS_STYLE_ALIGN_BASELINE 9
#define NS_STYLE_ALIGN_LAST_BASELINE 10
#define NS_STYLE_ALIGN_STRETCH 11
#define NS_STYLE_ALIGN_SELF_START 12
#define NS_STYLE_ALIGN_SELF_END 13
#define NS_STYLE_ALIGN_SPACE_BETWEEN 14
#define NS_STYLE_ALIGN_SPACE_AROUND 15
#define NS_STYLE_ALIGN_SPACE_EVENLY 16
#define NS_STYLE_ALIGN_LEGACY 0x20 // mutually exclusive w. SAFE & UNSAFE
#define NS_STYLE_ALIGN_SAFE 0x40
#define NS_STYLE_ALIGN_UNSAFE 0x80 // mutually exclusive w. SAFE
#define NS_STYLE_ALIGN_FLAG_BITS 0xE0
#define NS_STYLE_ALIGN_ALL_BITS 0xFF
#define NS_STYLE_ALIGN_ALL_SHIFT 8
#define NS_STYLE_JUSTIFY_AUTO NS_STYLE_ALIGN_AUTO
#define NS_STYLE_JUSTIFY_NORMAL NS_STYLE_ALIGN_NORMAL
#define NS_STYLE_JUSTIFY_START NS_STYLE_ALIGN_START
#define NS_STYLE_JUSTIFY_END NS_STYLE_ALIGN_END
#define NS_STYLE_JUSTIFY_FLEX_START NS_STYLE_ALIGN_FLEX_START
#define NS_STYLE_JUSTIFY_FLEX_END NS_STYLE_ALIGN_FLEX_END
#define NS_STYLE_JUSTIFY_CENTER NS_STYLE_ALIGN_CENTER
#define NS_STYLE_JUSTIFY_LEFT NS_STYLE_ALIGN_LEFT
#define NS_STYLE_JUSTIFY_RIGHT NS_STYLE_ALIGN_RIGHT
#define NS_STYLE_JUSTIFY_BASELINE NS_STYLE_ALIGN_BASELINE
#define NS_STYLE_JUSTIFY_LAST_BASELINE NS_STYLE_ALIGN_LAST_BASELINE
#define NS_STYLE_JUSTIFY_STRETCH NS_STYLE_ALIGN_STRETCH
#define NS_STYLE_JUSTIFY_SELF_START NS_STYLE_ALIGN_SELF_START
#define NS_STYLE_JUSTIFY_SELF_END NS_STYLE_ALIGN_SELF_END
#define NS_STYLE_JUSTIFY_SPACE_BETWEEN NS_STYLE_ALIGN_SPACE_BETWEEN
#define NS_STYLE_JUSTIFY_SPACE_AROUND NS_STYLE_ALIGN_SPACE_AROUND
#define NS_STYLE_JUSTIFY_SPACE_EVENLY NS_STYLE_ALIGN_SPACE_EVENLY
#define NS_STYLE_JUSTIFY_LEGACY NS_STYLE_ALIGN_LEGACY
#define NS_STYLE_JUSTIFY_SAFE NS_STYLE_ALIGN_SAFE
#define NS_STYLE_JUSTIFY_UNSAFE NS_STYLE_ALIGN_UNSAFE
#define NS_STYLE_JUSTIFY_FLAG_BITS NS_STYLE_ALIGN_FLAG_BITS
#define NS_STYLE_JUSTIFY_ALL_BITS NS_STYLE_ALIGN_ALL_BITS
#define NS_STYLE_JUSTIFY_ALL_SHIFT NS_STYLE_ALIGN_ALL_SHIFT
// See nsStylePosition
enum class StyleFlexDirection : uint8_t {
Row,

Просмотреть файл

@ -1183,13 +1183,12 @@ nsStylePosition::nsStylePosition(const Document& aDocument)
mAspectRatio(0.0f),
mGridAutoFlow(NS_STYLE_GRID_AUTO_FLOW_ROW),
mBoxSizing(StyleBoxSizing::Content),
mAlignContent(NS_STYLE_ALIGN_NORMAL),
mAlignItems(NS_STYLE_ALIGN_NORMAL),
mAlignSelf(NS_STYLE_ALIGN_AUTO),
mJustifyContent(NS_STYLE_JUSTIFY_NORMAL),
mSpecifiedJustifyItems(NS_STYLE_JUSTIFY_LEGACY),
mJustifyItems(NS_STYLE_JUSTIFY_NORMAL),
mJustifySelf(NS_STYLE_JUSTIFY_AUTO),
mAlignContent({StyleAlignFlags::NORMAL}),
mAlignItems({StyleAlignFlags::NORMAL}),
mAlignSelf({StyleAlignFlags::AUTO}),
mJustifyContent({StyleAlignFlags::NORMAL}),
mJustifyItems({{StyleAlignFlags::LEGACY}, {StyleAlignFlags::NORMAL}}),
mJustifySelf({StyleAlignFlags::AUTO}),
mFlexDirection(StyleFlexDirection::Row),
mFlexWrap(StyleFlexWrap::Nowrap),
mObjectFit(StyleObjectFit::Fill),
@ -1234,7 +1233,6 @@ nsStylePosition::nsStylePosition(const nsStylePosition& aSource)
mAlignItems(aSource.mAlignItems),
mAlignSelf(aSource.mAlignSelf),
mJustifyContent(aSource.mJustifyContent),
mSpecifiedJustifyItems(aSource.mSpecifiedJustifyItems),
mJustifyItems(aSource.mJustifyItems),
mJustifySelf(aSource.mJustifySelf),
mFlexDirection(aSource.mFlexDirection),
@ -1344,14 +1342,14 @@ nsChangeHint nsStylePosition::CalcDifference(
// Changing 'justify-content/items/self' might affect the positioning,
// but it won't affect any sizing.
if (mJustifyContent != aNewData.mJustifyContent ||
mJustifyItems != aNewData.mJustifyItems ||
mJustifyItems.computed != aNewData.mJustifyItems.computed ||
mJustifySelf != aNewData.mJustifySelf) {
hint |= nsChangeHint_NeedReflow;
}
// No need to do anything if mSpecifiedJustifyItems changes, as long as
// mJustifyItems (tested above) is unchanged.
if (mSpecifiedJustifyItems != aNewData.mSpecifiedJustifyItems) {
// No need to do anything if specified justify-items changes, as long as the
// computed one (tested above) is unchanged.
if (mJustifyItems.specified != aNewData.mJustifyItems.specified) {
hint |= nsChangeHint_NeutralChange;
}
@ -1405,28 +1403,31 @@ nsChangeHint nsStylePosition::CalcDifference(
return hint;
}
uint8_t nsStylePosition::UsedAlignSelf(ComputedStyle* aParent) const {
if (mAlignSelf != NS_STYLE_ALIGN_AUTO) {
StyleAlignSelf nsStylePosition::UsedAlignSelf(
const ComputedStyle* aParent) const {
if (mAlignSelf._0 != StyleAlignFlags::AUTO) {
return mAlignSelf;
}
if (MOZ_LIKELY(aParent)) {
auto parentAlignItems = aParent->StylePosition()->mAlignItems;
MOZ_ASSERT(!(parentAlignItems & NS_STYLE_ALIGN_LEGACY),
MOZ_ASSERT(!(parentAlignItems._0 & StyleAlignFlags::LEGACY),
"align-items can't have 'legacy'");
return parentAlignItems;
return {parentAlignItems._0};
}
return NS_STYLE_ALIGN_NORMAL;
return {StyleAlignFlags::NORMAL};
}
uint8_t nsStylePosition::UsedJustifySelf(ComputedStyle* aParent) const {
if (mJustifySelf != NS_STYLE_JUSTIFY_AUTO) {
StyleJustifySelf nsStylePosition::UsedJustifySelf(
const ComputedStyle* aParent) const {
if (mJustifySelf._0 != StyleAlignFlags::AUTO) {
return mJustifySelf;
}
if (MOZ_LIKELY(aParent)) {
auto inheritedJustifyItems = aParent->StylePosition()->mJustifyItems;
return inheritedJustifyItems & ~NS_STYLE_JUSTIFY_LEGACY;
const auto& inheritedJustifyItems =
aParent->StylePosition()->mJustifyItems.computed;
return {inheritedJustifyItems._0 & ~StyleAlignFlags::LEGACY};
}
return NS_STYLE_JUSTIFY_NORMAL;
return {StyleAlignFlags::NORMAL};
}
// --------------------

Просмотреть файл

@ -964,6 +964,9 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition {
using StyleFlexBasis = mozilla::StyleFlexBasis;
using WritingMode = mozilla::WritingMode;
using StyleImplicitGridTracks = mozilla::StyleImplicitGridTracks;
using ComputedStyle = mozilla::ComputedStyle;
using StyleAlignSelf = mozilla::StyleAlignSelf;
using StyleJustifySelf = mozilla::StyleJustifySelf;
explicit nsStylePosition(const mozilla::dom::Document&);
nsStylePosition(const nsStylePosition& aOther);
@ -985,15 +988,15 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition {
/**
* Return the used value for 'align-self' given our parent ComputedStyle
* aParent (or null for the root).
* (or null for the root).
*/
uint8_t UsedAlignSelf(mozilla::ComputedStyle* aParent) const;
StyleAlignSelf UsedAlignSelf(const ComputedStyle*) const;
/**
* Return the used value for 'justify-self' given our parent ComputedStyle
* aParent (or null for the root).
*/
uint8_t UsedJustifySelf(mozilla::ComputedStyle* aParent) const;
StyleJustifySelf UsedJustifySelf(const ComputedStyle*) const;
Position mObjectPosition;
StyleRect<LengthPercentageOrAuto> mOffset;
@ -1010,23 +1013,12 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition {
uint8_t mGridAutoFlow; // NS_STYLE_GRID_AUTO_FLOW_*
mozilla::StyleBoxSizing mBoxSizing;
// All align/justify properties here take NS_STYLE_ALIGN_* values.
uint16_t mAlignContent; // fallback value in the high byte
uint8_t mAlignItems;
uint8_t mAlignSelf;
uint16_t mJustifyContent; // fallback value in the high byte
// We cascade mSpecifiedJustifyItems, to handle the auto value, but store the
// computed value in mJustifyItems.
//
// They're effectively only different in this regard: mJustifyItems is set to
// mSpecifiedJustifyItems, except when the latter is AUTO -- in that case,
// mJustifyItems is set to NORMAL, or to the parent ComputedStyle's
// mJustifyItems if it has the legacy flag.
//
// This last part happens in ComputedStyle::ApplyStyleFixups.
uint8_t mSpecifiedJustifyItems;
uint8_t mJustifyItems;
uint8_t mJustifySelf;
mozilla::StyleAlignContent mAlignContent;
mozilla::StyleAlignItems mAlignItems;
mozilla::StyleAlignSelf mAlignSelf;
mozilla::StyleJustifyContent mJustifyContent;
mozilla::StyleComputedJustifyItems mJustifyItems;
mozilla::StyleJustifySelf mJustifySelf;
mozilla::StyleFlexDirection mFlexDirection;
mozilla::StyleFlexWrap mFlexWrap;
mozilla::StyleObjectFit mObjectFit;

Просмотреть файл

@ -386,10 +386,10 @@ nscoord nsTableWrapperFrame::ChildShrinkWrapISize(
if (MOZ_UNLIKELY(isGridItem) && !StyleMargin()->HasInlineAxisAuto(aWM)) {
auto inlineAxisAlignment =
aWM.IsOrthogonalTo(parent->GetWritingMode())
? StylePosition()->UsedAlignSelf(parent->Style())
: StylePosition()->UsedJustifySelf(parent->Style());
if (inlineAxisAlignment == NS_STYLE_ALIGN_NORMAL ||
inlineAxisAlignment == NS_STYLE_ALIGN_STRETCH) {
? StylePosition()->UsedAlignSelf(parent->Style())._0
: StylePosition()->UsedJustifySelf(parent->Style())._0;
if (inlineAxisAlignment == StyleAlignFlags::NORMAL ||
inlineAxisAlignment == StyleAlignFlags::STRETCH) {
flags = nsIFrame::ComputeSizeFlags::eDefault;
}
}

Просмотреть файл

@ -957,48 +957,16 @@ fn static_assert() {
<% skip_position_longhands = " ".join(x.ident for x in SIDES) %>
<%self:impl_trait style_struct_name="Position"
skip_longhands="${skip_position_longhands}
align-content justify-content align-self
justify-self align-items justify-items
grid-auto-flow">
skip_longhands="${skip_position_longhands} grid-auto-flow">
% for side in SIDES:
<% impl_split_style_coord(side.ident, "mOffset", side.index) %>
% endfor
% for kind in ["align", "justify"]:
${impl_simple_type_with_conversion(kind + "_content")}
${impl_simple_type_with_conversion(kind + "_self")}
% endfor
${impl_simple_type_with_conversion("align_items")}
pub fn set_justify_items(&mut self, v: longhands::justify_items::computed_value::T) {
self.gecko.mSpecifiedJustifyItems = v.specified.into();
self.set_computed_justify_items(v.computed);
}
${impl_simple_type_with_conversion("grid_auto_flow")}
pub fn set_computed_justify_items(&mut self, v: values::specified::JustifyItems) {
debug_assert_ne!(v.0, crate::values::specified::align::AlignFlags::LEGACY);
self.gecko.mJustifyItems = v.into();
self.gecko.mJustifyItems.computed = v;
}
pub fn reset_justify_items(&mut self, reset_style: &Self) {
self.gecko.mJustifyItems = reset_style.gecko.mJustifyItems;
self.gecko.mSpecifiedJustifyItems = reset_style.gecko.mSpecifiedJustifyItems;
}
pub fn copy_justify_items_from(&mut self, other: &Self) {
self.gecko.mJustifyItems = other.gecko.mJustifyItems;
self.gecko.mSpecifiedJustifyItems = other.gecko.mJustifyItems;
}
pub fn clone_justify_items(&self) -> longhands::justify_items::computed_value::T {
longhands::justify_items::computed_value::T {
computed: self.gecko.mJustifyItems.into(),
specified: self.gecko.mSpecifiedJustifyItems.into(),
}
}
${impl_simple_type_with_conversion("grid_auto_flow")}
</%self:impl_trait>
<% skip_outline_longhands = " ".join("outline-style outline-width".split() +

Просмотреть файл

@ -9,7 +9,7 @@
use crate::values::computed::{Context, ToComputedValue};
use crate::values::specified;
pub use super::specified::{AlignContent, AlignItems, JustifyContent, SelfAlignment};
pub use super::specified::{AlignContent, AlignItems, ContentDistribution, JustifyContent, SelfAlignment};
pub use super::specified::{AlignSelf, JustifySelf};
/// The computed value for the `justify-items` property.
@ -34,7 +34,8 @@ pub use super::specified::{AlignSelf, JustifySelf};
///
/// See the discussion in https://bugzil.la/1384542.
#[derive(Clone, Copy, Debug, Eq, PartialEq, ToCss, ToResolvedValue)]
pub struct JustifyItems {
#[repr(C)]
pub struct ComputedJustifyItems {
/// The specified value for the property. Can contain the bare `legacy`
/// keyword.
#[css(skip)]
@ -45,6 +46,8 @@ pub struct JustifyItems {
pub computed: specified::JustifyItems,
}
pub use self::ComputedJustifyItems as JustifyItems;
impl JustifyItems {
/// Returns the `legacy` value.
pub fn legacy() -> Self {

Просмотреть файл

@ -6,7 +6,6 @@
//!
//! https://drafts.csswg.org/css-align/
use crate::gecko_bindings::structs;
use crate::parser::{Parse, ParserContext};
use cssparser::Parser;
use std::fmt::{self, Write};
@ -14,56 +13,55 @@ use style_traits::{CssWriter, KeywordsCollectFn, ParseError, SpecifiedValueInfo,
bitflags! {
/// Constants shared by multiple CSS Box Alignment properties
///
/// These constants match Gecko's `NS_STYLE_ALIGN_*` constants.
#[derive(MallocSizeOf, ToComputedValue, ToResolvedValue, ToShmem)]
#[repr(C)]
pub struct AlignFlags: u8 {
// Enumeration stored in the lower 5 bits:
/// 'auto'
const AUTO = structs::NS_STYLE_ALIGN_AUTO as u8;
/// {align,justify}-{content,items,self}: 'auto'
const AUTO = 0;
/// 'normal'
const NORMAL = structs::NS_STYLE_ALIGN_NORMAL as u8;
const NORMAL = 1;
/// 'start'
const START = structs::NS_STYLE_ALIGN_START as u8;
const START = 2;
/// 'end'
const END = structs::NS_STYLE_ALIGN_END as u8;
const END = 3;
/// 'flex-start'
const FLEX_START = structs::NS_STYLE_ALIGN_FLEX_START as u8;
const FLEX_START = 4;
/// 'flex-end'
const FLEX_END = structs::NS_STYLE_ALIGN_FLEX_END as u8;
const FLEX_END = 5;
/// 'center'
const CENTER = structs::NS_STYLE_ALIGN_CENTER as u8;
const CENTER = 6;
/// 'left'
const LEFT = structs::NS_STYLE_ALIGN_LEFT as u8;
const LEFT = 7;
/// 'right'
const RIGHT = structs::NS_STYLE_ALIGN_RIGHT as u8;
const RIGHT = 8;
/// 'baseline'
const BASELINE = structs::NS_STYLE_ALIGN_BASELINE as u8;
const BASELINE = 9;
/// 'last-baseline'
const LAST_BASELINE = structs::NS_STYLE_ALIGN_LAST_BASELINE as u8;
const LAST_BASELINE = 10;
/// 'stretch'
const STRETCH = structs::NS_STYLE_ALIGN_STRETCH as u8;
const STRETCH = 11;
/// 'self-start'
const SELF_START = structs::NS_STYLE_ALIGN_SELF_START as u8;
const SELF_START = 12;
/// 'self-end'
const SELF_END = structs::NS_STYLE_ALIGN_SELF_END as u8;
const SELF_END = 13;
/// 'space-between'
const SPACE_BETWEEN = structs::NS_STYLE_ALIGN_SPACE_BETWEEN as u8;
const SPACE_BETWEEN = 14;
/// 'space-around'
const SPACE_AROUND = structs::NS_STYLE_ALIGN_SPACE_AROUND as u8;
const SPACE_AROUND = 15;
/// 'space-evenly'
const SPACE_EVENLY = structs::NS_STYLE_ALIGN_SPACE_EVENLY as u8;
const SPACE_EVENLY = 16;
// Additional flags stored in the upper bits:
/// 'legacy' (mutually exclusive w. SAFE & UNSAFE)
const LEGACY = structs::NS_STYLE_ALIGN_LEGACY as u8;
const LEGACY = 1 << 5;
/// 'safe'
const SAFE = structs::NS_STYLE_ALIGN_SAFE as u8;
const SAFE = 1 << 6;
/// 'unsafe' (mutually exclusive w. SAFE)
const UNSAFE = structs::NS_STYLE_ALIGN_UNSAFE as u8;
const UNSAFE = 1 << 7;
/// Mask for the additional flags above.
const FLAG_BITS = structs::NS_STYLE_ALIGN_FLAG_BITS as u8;
const FLAG_BITS = 0b11100000;
}
}
@ -146,6 +144,7 @@ pub enum AxisDirection {
ToResolvedValue,
ToShmem,
)]
#[repr(C)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
pub struct ContentDistribution {
primary: AlignFlags,
@ -270,6 +269,7 @@ impl ContentDistribution {
ToResolvedValue,
ToShmem,
)]
#[repr(transparent)]
pub struct AlignContent(pub ContentDistribution);
impl Parse for AlignContent {
@ -292,20 +292,6 @@ impl SpecifiedValueInfo for AlignContent {
}
}
#[cfg(feature = "gecko")]
impl From<u16> for AlignContent {
fn from(bits: u16) -> Self {
AlignContent(ContentDistribution::from_bits(bits))
}
}
#[cfg(feature = "gecko")]
impl From<AlignContent> for u16 {
fn from(v: AlignContent) -> u16 {
v.0.as_bits()
}
}
/// Value for the `justify-content` property.
///
/// <https://drafts.csswg.org/css-align/#propdef-justify-content>
@ -321,6 +307,7 @@ impl From<AlignContent> for u16 {
ToResolvedValue,
ToShmem,
)]
#[repr(transparent)]
pub struct JustifyContent(pub ContentDistribution);
impl Parse for JustifyContent {
@ -370,6 +357,7 @@ impl From<JustifyContent> for u16 {
ToResolvedValue,
ToShmem,
)]
#[repr(transparent)]
pub struct SelfAlignment(pub AlignFlags);
impl SelfAlignment {
@ -441,6 +429,7 @@ impl SelfAlignment {
ToResolvedValue,
ToShmem,
)]
#[repr(C)]
pub struct AlignSelf(pub SelfAlignment);
impl Parse for AlignSelf {
@ -463,18 +452,6 @@ impl SpecifiedValueInfo for AlignSelf {
}
}
impl From<u8> for AlignSelf {
fn from(bits: u8) -> Self {
AlignSelf(SelfAlignment(AlignFlags::from_bits_truncate(bits)))
}
}
impl From<AlignSelf> for u8 {
fn from(align: AlignSelf) -> u8 {
(align.0).0.bits()
}
}
/// The specified value of the justify-self property.
///
/// <https://drafts.csswg.org/css-align/#propdef-justify-self>
@ -490,6 +467,7 @@ impl From<AlignSelf> for u8 {
ToResolvedValue,
ToShmem,
)]
#[repr(C)]
pub struct JustifySelf(pub SelfAlignment);
impl Parse for JustifySelf {
@ -512,18 +490,6 @@ impl SpecifiedValueInfo for JustifySelf {
}
}
impl From<u8> for JustifySelf {
fn from(bits: u8) -> Self {
JustifySelf(SelfAlignment(AlignFlags::from_bits_truncate(bits)))
}
}
impl From<JustifySelf> for u8 {
fn from(justify: JustifySelf) -> u8 {
(justify.0).0.bits()
}
}
/// Value of the `align-items` property
///
/// <https://drafts.csswg.org/css-align/#propdef-align-items>
@ -539,6 +505,7 @@ impl From<JustifySelf> for u8 {
ToResolvedValue,
ToShmem,
)]
#[repr(C)]
pub struct AlignItems(pub AlignFlags);
impl AlignItems {
@ -590,6 +557,7 @@ impl SpecifiedValueInfo for AlignItems {
///
/// <https://drafts.csswg.org/css-align/#justify-items-property>
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToShmem)]
#[repr(C)]
pub struct JustifyItems(pub AlignFlags);
impl JustifyItems {

Просмотреть файл

@ -187,9 +187,14 @@ include = [
"CounterSetOrReset",
"CounterIncrement",
"WritingMode",
"VecU8",
"Content",
"ContentItem",
"AlignSelf",
"JustifySelf",
"AlignItems",
"ComputedJustifyItems",
"AlignContent",
"JustifyContent",
]
item_types = ["enums", "structs", "unions", "typedefs", "functions", "constants"]
renaming_overrides_prefixing = true