Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1415670 Part 2: Calculate negativeNumber for each GridLine. r=mats
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: D56jk7MbeIa
  • Loading branch information
bradwerth committed Nov 8, 2017
1 parent d105a8e commit 82e0f3f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
4 changes: 3 additions & 1 deletion dom/grid/GridLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,22 @@ GridLine::Number() const
int32_t
GridLine::NegativeNumber() const
{
return 0;
return mNegativeNumber;
}

void
GridLine::SetLineValues(const nsTArray<nsString>& aNames,
double aStart,
double aBreadth,
uint32_t aNumber,
int32_t aNegativeNumber,
GridDeclaration aType)
{
mNames = aNames;
mStart = aStart;
mBreadth = aBreadth;
mNumber = aNumber;
mNegativeNumber = aNegativeNumber;
mType = aType;
}

Expand Down
2 changes: 2 additions & 0 deletions dom/grid/GridLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class GridLine : public nsISupports
double aStart,
double aBreadth,
uint32_t aNumber,
int32_t aNegativeNumber,
GridDeclaration aType);

protected:
Expand All @@ -57,6 +58,7 @@ class GridLine : public nsISupports
double mBreadth;
GridDeclaration mType;
uint32_t mNumber;
int32_t mNegativeNumber;
};

} // namespace dom
Expand Down
52 changes: 45 additions & 7 deletions dom/grid/GridLines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,34 @@ GridLines::SetLineInfo(const ComputedGridTrackInfo* aTrackInfo,
return;
}

uint32_t trackCount = aTrackInfo->mEndFragmentTrack -
aTrackInfo->mStartFragmentTrack;
uint32_t lineCount = aTrackInfo->mEndFragmentTrack -
aTrackInfo->mStartFragmentTrack +
1;

// If there is at least one track, line count is one more
// than the number of tracks.
if (trackCount > 0) {
if (lineCount > 0) {
nscoord lastTrackEdge = 0;
nscoord startOfNextTrack;
uint32_t repeatIndex = 0;
uint32_t numRepeatTracks = aTrackInfo->mRemovedRepeatTracks.Length();
uint32_t numAddedLines = 0;

// For the calculation of negative line numbers, we need to know
// the total number of leading implicit and explicit tracks.
// This might be different from the number of tracks sizes in
// aTrackInfo, because some of those tracks may be auto-fits that
// have been removed.
uint32_t leadingTrackCount = aTrackInfo->mNumLeadingImplicitTracks +
aTrackInfo->mNumExplicitTracks;
if (numRepeatTracks > 0) {
for (auto& removedTrack : aTrackInfo->mRemovedRepeatTracks) {
if (removedTrack) {
++leadingTrackCount;
}
}
}

for (uint32_t i = aTrackInfo->mStartFragmentTrack;
i < aTrackInfo->mEndFragmentTrack + 1;
i++) {
Expand Down Expand Up @@ -137,6 +153,7 @@ GridLines::SetLineInfo(const ComputedGridTrackInfo* aTrackInfo,
lastTrackEdge,
repeatIndex,
numRepeatTracks,
leadingTrackCount,
lineNames);
}

Expand All @@ -145,18 +162,21 @@ GridLines::SetLineInfo(const ComputedGridTrackInfo* aTrackInfo,
MOZ_ASSERT(line1Index > 0, "line1Index must be positive.");
bool isBeforeFirstExplicit =
(line1Index <= aTrackInfo->mNumLeadingImplicitTracks);
bool isAfterLastExplicit = line1Index > (leadingTrackCount + 1);
// Calculate an actionable line number for this line, that could be used
// in a css grid property to align a grid item or area at that line.
// For implicit lines that appear before line 1, report a number of 0.
// We can't report negative indexes, because those have a different
// meaning in the css grid spec (negative indexes are negative-1-based
// from the end of the grid decreasing towards the front).
uint32_t lineNumber = isBeforeFirstExplicit ? 0 :
(line1Index - aTrackInfo->mNumLeadingImplicitTracks + numAddedLines);
(line1Index + numAddedLines - aTrackInfo->mNumLeadingImplicitTracks);

// The negativeNumber is counted back from the leadingTrackCount.
int32_t lineNegativeNumber = isAfterLastExplicit ? 0 :
(line1Index + numAddedLines - (leadingTrackCount + 2));
GridDeclaration lineType =
(isBeforeFirstExplicit ||
line1Index > (aTrackInfo->mNumLeadingImplicitTracks +
aTrackInfo->mNumExplicitTracks + 1))
(isBeforeFirstExplicit || isAfterLastExplicit)
? GridDeclaration::Implicit
: GridDeclaration::Explicit;
line->SetLineValues(
Expand All @@ -165,6 +185,7 @@ GridLines::SetLineInfo(const ComputedGridTrackInfo* aTrackInfo,
nsPresContext::AppUnitsToDoubleCSSPixels(startOfNextTrack -
lastTrackEdge),
lineNumber,
lineNegativeNumber,
lineType
);

Expand All @@ -181,6 +202,7 @@ GridLines::AppendRemovedAutoFits(const ComputedGridTrackInfo* aTrackInfo,
nscoord aLastTrackEdge,
uint32_t& aRepeatIndex,
uint32_t aNumRepeatTracks,
uint32_t aNumLeadingTracks,
nsTArray<nsString>& aLineNames)
{
// Check to see if lineNames contains ALL of the before line names.
Expand Down Expand Up @@ -225,13 +247,29 @@ GridLines::AppendRemovedAutoFits(const ComputedGridTrackInfo* aTrackInfo,

RefPtr<GridLine> line = new GridLine(this);
mLines.AppendElement(line);

// Time to calculate the line numbers. For the positive numbers
// we count with a 1-based index from mRepeatFirstTrack. Although
// this number is the index of the first repeat track AFTER all
// the leading implicit tracks, that's still what we want since
// all those leading implicit tracks have line number 0.
uint32_t lineNumber = aTrackInfo->mRepeatFirstTrack +
aRepeatIndex + 1;

// The negative number does have to account for the leading
// implicit tracks. We've been passed aNumLeadingTracks which is
// the total of the leading implicit tracks plus the explicit
// tracks. So all we have to do is subtract that number plus one
// from the 0-based index of this track.
int32_t lineNegativeNumber = (aTrackInfo->mNumLeadingImplicitTracks +
aTrackInfo->mRepeatFirstTrack +
aRepeatIndex) - (aNumLeadingTracks + 1);
line->SetLineValues(
aLineNames,
nsPresContext::AppUnitsToDoubleCSSPixels(aLastTrackEdge),
nsPresContext::AppUnitsToDoubleCSSPixels(0),
lineNumber,
lineNegativeNumber,
GridDeclaration::Explicit
);

Expand Down
1 change: 1 addition & 0 deletions dom/grid/GridLines.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class GridLines : public nsISupports
nscoord aLastTrackEdge,
uint32_t& aRepeatIndex,
uint32_t aNumRepeatTracks,
uint32_t aNumLeadingTracks,
nsTArray<nsString>& aLineNames);

RefPtr<GridDimension> mParent;
Expand Down

0 comments on commit 82e0f3f

Please sign in to comment.