Bug 1238294 part 1 - [css-grid] Make GridLineEdge() a method on the Tracks class rather than a static function (idempotent change). r=dholbert

This commit is contained in:
Mats Palmgren 2016-01-14 23:11:44 +01:00
Родитель 3f054f833d
Коммит eef633de78
2 изменённых файлов: 36 добавлений и 41 удалений

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

@ -35,6 +35,12 @@ const uint32_t nsGridContainerFrame::kAutoLine = kTranslatedMaxLine + 3457U;
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(TrackSize::StateBits)
enum class GridLineSide
{
eBeforeGridGap,
eAfterGridGap,
};
class nsGridContainerFrame::GridItemCSSOrderIterator
{
public:
@ -914,6 +920,28 @@ struct MOZ_STACK_CLASS nsGridContainerFrame::Tracks
void AlignJustifyContent(const nsHTMLReflowState& aReflowState,
const LogicalSize& aContainerSize);
nscoord GridLineEdge(uint32_t aLine, GridLineSide aSide) const
{
if (MOZ_UNLIKELY(mSizes.IsEmpty())) {
// https://drafts.csswg.org/css-grid/#grid-definition
// "... the explicit grid still contains one grid line in each axis."
MOZ_ASSERT(aLine == 0, "We should only resolve line 1 in an empty grid");
return nscoord(0);
}
MOZ_ASSERT(aLine <= mSizes.Length(), "mSizes is too small");
if (aSide == GridLineSide::eBeforeGridGap) {
if (aLine == 0) {
return mSizes[0].mPosition;
}
const TrackSize& sz = mSizes[aLine - 1];
return sz.mPosition + sz.mBase;
}
if (aLine == mSizes.Length()) {
const TrackSize& sz = mSizes[aLine - 1];
return sz.mPosition + sz.mBase;
}
return mSizes[aLine].mPosition;
}
nscoord SumOfGridGaps() const {
auto len = mSizes.Length();
@ -1041,36 +1069,6 @@ IsNameWithStartSuffix(const nsString& aString, uint32_t* aIndex)
return IsNameWithSuffix(aString, NS_LITERAL_STRING("-start"), aIndex);
}
enum class GridLineSide {
eBeforeGridGap,
eAfterGridGap,
};
static nscoord
GridLineEdge(uint32_t aLine, const nsTArray<TrackSize>& aTrackSizes,
GridLineSide aSide)
{
if (MOZ_UNLIKELY(aTrackSizes.IsEmpty())) {
// https://drafts.csswg.org/css-grid/#grid-definition
// "... the explicit grid still contains one grid line in each axis."
MOZ_ASSERT(aLine == 0, "We should only resolve line 1 in an empty grid");
return nscoord(0);
}
MOZ_ASSERT(aLine <= aTrackSizes.Length(), "aTrackSizes is too small");
if (aSide == GridLineSide::eBeforeGridGap) {
if (aLine == 0) {
return aTrackSizes[0].mPosition;
}
const TrackSize& sz = aTrackSizes[aLine - 1];
return sz.mPosition + sz.mBase;
}
if (aLine == aTrackSizes.Length()) {
const TrackSize& sz = aTrackSizes[aLine - 1];
return sz.mPosition + sz.mBase;
}
return aTrackSizes[aLine].mPosition;
}
/**
* (XXX share this utility function with nsFlexContainerFrame at some point)
*
@ -3090,7 +3088,7 @@ nsGridContainerFrame::LineRange::ToLength(
void
nsGridContainerFrame::LineRange::ToPositionAndLengthForAbsPos(
const nsTArray<TrackSize>& aTrackSizes, nscoord aGridOrigin,
const Tracks& aTracks, nscoord aGridOrigin,
nscoord* aPos, nscoord* aLength) const
{
// kAutoLine for abspos children contributes the corresponding edge
@ -3101,18 +3099,17 @@ nsGridContainerFrame::LineRange::ToPositionAndLengthForAbsPos(
} else {
const nscoord endPos = *aPos + *aLength;
nscoord startPos =
::GridLineEdge(mStart, aTrackSizes, GridLineSide::eAfterGridGap);
aTracks.GridLineEdge(mStart, GridLineSide::eAfterGridGap);
*aPos = aGridOrigin + startPos;
*aLength = std::max(endPos - *aPos, 0);
}
} else {
if (mStart == kAutoLine) {
nscoord endPos =
::GridLineEdge(mEnd, aTrackSizes, GridLineSide::eBeforeGridGap);
nscoord endPos = aTracks.GridLineEdge(mEnd, GridLineSide::eBeforeGridGap);
*aLength = std::max(aGridOrigin + endPos, 0);
} else {
nscoord pos;
ToPositionAndLength(aTrackSizes, &pos, aLength);
ToPositionAndLength(aTracks.mSizes, &pos, aLength);
*aPos = aGridOrigin + pos;
}
}
@ -3141,11 +3138,9 @@ nsGridContainerFrame::ContainingBlockForAbsPos(const GridReflowState& aState,
nscoord b = aGridCB.BStart(wm);
nscoord iSize = aGridCB.ISize(wm);
nscoord bSize = aGridCB.BSize(wm);
aArea.mCols.ToPositionAndLengthForAbsPos(aState.mCols.mSizes,
aGridOrigin.I(wm),
aArea.mCols.ToPositionAndLengthForAbsPos(aState.mCols, aGridOrigin.I(wm),
&i, &iSize);
aArea.mRows.ToPositionAndLengthForAbsPos(aState.mRows.mSizes,
aGridOrigin.B(wm),
aArea.mRows.ToPositionAndLengthForAbsPos(aState.mRows, aGridOrigin.B(wm),
&b, &bSize);
return LogicalRect(wm, i, b, iSize, bSize);
}

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

@ -254,12 +254,12 @@ protected:
*/
nscoord ToLength(const nsTArray<TrackSize>& aTrackSizes) const;
/**
* Given an array of track sizes and a grid origin coordinate, adjust the
* Given a set of tracks and a grid origin coordinate, adjust the
* abs.pos. containing block along an axis given by aPos and aLength.
* aPos and aLength should already be initialized to the grid container
* containing block for this axis before calling this method.
*/
void ToPositionAndLengthForAbsPos(const nsTArray<TrackSize>& aTrackSizes,
void ToPositionAndLengthForAbsPos(const Tracks& aTracks,
nscoord aGridOrigin,
nscoord* aPos, nscoord* aLength) const;