зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1176792 part 2 - [css-grid] Implement layout for the 'grid-column-gap' and 'grid-row-gap' properties. r=dholbert
This commit is contained in:
Родитель
4aaaee94eb
Коммит
4e5cfec08a
|
@ -231,6 +231,7 @@ struct MOZ_STACK_CLASS nsGridContainerFrame::Tracks
|
|||
explicit Tracks(LogicalAxis aAxis) : mAxis(aAxis) {}
|
||||
|
||||
void Initialize(const TrackSizingFunctions& aFunctions,
|
||||
const nsStyleCoord& aGridGap,
|
||||
uint32_t aNumTracks,
|
||||
nscoord aContentBoxSize);
|
||||
|
||||
|
@ -595,6 +596,11 @@ struct MOZ_STACK_CLASS nsGridContainerFrame::Tracks
|
|||
const LogicalSize& aContainerSize);
|
||||
|
||||
|
||||
nscoord SumOfGridGaps() const {
|
||||
auto len = mSizes.Length();
|
||||
return MOZ_LIKELY(len > 1) ? (len - 1) * mGridGap : 0;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
void Dump() const
|
||||
{
|
||||
|
@ -607,6 +613,7 @@ struct MOZ_STACK_CLASS nsGridContainerFrame::Tracks
|
|||
#endif
|
||||
|
||||
nsAutoTArray<TrackSize, 32> mSizes;
|
||||
nscoord mGridGap;
|
||||
LogicalAxis mAxis;
|
||||
};
|
||||
|
||||
|
@ -1903,6 +1910,7 @@ nsGridContainerFrame::TrackSize::Initialize(nscoord aPercentageBasis,
|
|||
void
|
||||
nsGridContainerFrame::Tracks::Initialize(
|
||||
const TrackSizingFunctions& aFunctions,
|
||||
const nsStyleCoord& aGridGap,
|
||||
uint32_t aNumTracks,
|
||||
nscoord aContentBoxSize)
|
||||
{
|
||||
|
@ -1936,6 +1944,11 @@ nsGridContainerFrame::Tracks::Initialize(
|
|||
aFunctions.mAutoMinSizing,
|
||||
aFunctions.mAutoMaxSizing);
|
||||
}
|
||||
|
||||
mGridGap = nsRuleNode::ComputeCoordPercentCalc(aGridGap, percentageBasis);
|
||||
if (mGridGap < 0) {
|
||||
mGridGap = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2066,8 +2079,12 @@ nsGridContainerFrame::Tracks::CalculateSizes(
|
|||
ResolveIntrinsicSize(aState, aGridItems, aFunctions, aRange, percentageBasis,
|
||||
aConstraint);
|
||||
if (aConstraint != nsLayoutUtils::MIN_ISIZE) {
|
||||
DistributeFreeSpace(aContentBoxSize);
|
||||
StretchFlexibleTracks(aState, aGridItems, aFunctions, aContentBoxSize);
|
||||
nscoord freeSpace = aContentBoxSize;
|
||||
if (freeSpace != NS_UNCONSTRAINEDSIZE) {
|
||||
freeSpace -= SumOfGridGaps();
|
||||
}
|
||||
DistributeFreeSpace(freeSpace);
|
||||
StretchFlexibleTracks(aState, aGridItems, aFunctions, freeSpace);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2077,10 +2094,11 @@ nsGridContainerFrame::CalculateTrackSizes(GridReflowState& aState,
|
|||
IntrinsicISizeType aConstraint)
|
||||
{
|
||||
const WritingMode& wm = aState.mWM;
|
||||
aState.mCols.Initialize(aState.mColFunctions, mGridColEnd,
|
||||
aContentBox.ISize(wm));
|
||||
aState.mRows.Initialize(aState.mRowFunctions, mGridRowEnd,
|
||||
aContentBox.BSize(wm));
|
||||
const nsStylePosition* stylePos = aState.mGridStyle;
|
||||
aState.mCols.Initialize(aState.mColFunctions, stylePos->mGridColumnGap,
|
||||
mGridColEnd, aContentBox.ISize(wm));
|
||||
aState.mRows.Initialize(aState.mRowFunctions, stylePos->mGridRowGap,
|
||||
mGridRowEnd, aContentBox.BSize(wm));
|
||||
|
||||
aState.mCols.CalculateSizes(aState, mGridItems, aState.mColFunctions,
|
||||
aContentBox.ISize(wm), &GridArea::mCols,
|
||||
|
@ -2605,7 +2623,7 @@ nsGridContainerFrame::Tracks::AlignJustifyContent(
|
|||
}
|
||||
nscoord cbSize = isAlign ? aContainerSize.BSize(wm)
|
||||
: aContainerSize.ISize(wm);
|
||||
space = cbSize - trackSizeSum;
|
||||
space = cbSize - trackSizeSum - SumOfGridGaps();
|
||||
// Use the fallback value instead when applicable.
|
||||
if (space < 0 ||
|
||||
(alignment == NS_STYLE_ALIGN_SPACE_BETWEEN && mSizes.Length() == 1)) {
|
||||
|
@ -2646,7 +2664,7 @@ nsGridContainerFrame::Tracks::AlignJustifyContent(
|
|||
if (!distribute) {
|
||||
for (TrackSize& sz : mSizes) {
|
||||
sz.mPosition = pos;
|
||||
pos += sz.mBase;
|
||||
pos += sz.mBase + mGridGap;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -2660,12 +2678,9 @@ nsGridContainerFrame::Tracks::AlignJustifyContent(
|
|||
nscoord spacePerTrack;
|
||||
roundingError = NSCoordDivRem(space, numAutoTracks, &spacePerTrack);
|
||||
for (TrackSize& sz : mSizes) {
|
||||
#ifdef DEBUG
|
||||
space += sz.mBase; // for the assert below: space + all mBase == pos
|
||||
#endif
|
||||
sz.mPosition = pos;
|
||||
if (!(sz.mState & TrackSize::eAutoMaxSizing)) {
|
||||
pos += sz.mBase;
|
||||
pos += sz.mBase + mGridGap;
|
||||
continue;
|
||||
}
|
||||
nscoord stretch = spacePerTrack;
|
||||
|
@ -2675,10 +2690,9 @@ nsGridContainerFrame::Tracks::AlignJustifyContent(
|
|||
}
|
||||
nscoord newBase = sz.mBase + stretch;
|
||||
sz.mBase = newBase;
|
||||
pos += newBase;
|
||||
pos += newBase + mGridGap;
|
||||
}
|
||||
MOZ_ASSERT(pos == space && !roundingError,
|
||||
"we didn't distribute all space?");
|
||||
MOZ_ASSERT(!roundingError, "we didn't distribute all rounding error?");
|
||||
return;
|
||||
}
|
||||
case NS_STYLE_ALIGN_SPACE_BETWEEN:
|
||||
|
@ -2695,7 +2709,9 @@ nsGridContainerFrame::Tracks::AlignJustifyContent(
|
|||
break;
|
||||
default:
|
||||
MOZ_ASSERT_UNREACHABLE("unknown align-/justify-content value");
|
||||
between = 0; // just to avoid a compiler warning
|
||||
}
|
||||
between += mGridGap;
|
||||
for (TrackSize& sz : mSizes) {
|
||||
sz.mPosition = pos;
|
||||
nscoord spacing = between;
|
||||
|
@ -2705,7 +2721,7 @@ nsGridContainerFrame::Tracks::AlignJustifyContent(
|
|||
}
|
||||
pos += sz.mBase + spacing;
|
||||
}
|
||||
MOZ_ASSERT(!roundingError, "we didn't distribute all space?");
|
||||
MOZ_ASSERT(!roundingError, "we didn't distribute all rounding error?");
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -3000,8 +3016,8 @@ nsGridContainerFrame::IntrinsicISize(nsRenderingContext* aRenderingContext,
|
|||
if (mGridColEnd == 0) {
|
||||
return 0;
|
||||
}
|
||||
state.mCols.Initialize(state.mColFunctions, mGridColEnd,
|
||||
NS_UNCONSTRAINEDSIZE);
|
||||
state.mCols.Initialize(state.mColFunctions, state.mGridStyle->mGridColumnGap,
|
||||
mGridColEnd, NS_UNCONSTRAINEDSIZE);
|
||||
state.mIter.Reset();
|
||||
state.mCols.CalculateSizes(state, mGridItems, state.mColFunctions,
|
||||
NS_UNCONSTRAINEDSIZE, &GridArea::mCols,
|
||||
|
@ -3010,7 +3026,7 @@ nsGridContainerFrame::IntrinsicISize(nsRenderingContext* aRenderingContext,
|
|||
for (const TrackSize& sz : state.mCols.mSizes) {
|
||||
length += sz.mBase;
|
||||
}
|
||||
return length;
|
||||
return length + state.mCols.SumOfGridGaps();
|
||||
}
|
||||
|
||||
nscoord
|
||||
|
|
Загрузка…
Ссылка в новой задаче