2016-07-06 21:45:18 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "GridLines.h"
|
|
|
|
|
|
|
|
#include "GridDimension.h"
|
|
|
|
#include "GridLine.h"
|
|
|
|
#include "mozilla/dom/GridBinding.h"
|
2019-06-19 01:29:58 +03:00
|
|
|
#include "mozilla/dom/GridArea.h"
|
2016-07-06 21:45:18 +03:00
|
|
|
#include "nsGridContainerFrame.h"
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom {
|
2016-07-06 21:45:18 +03:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GridLines, mParent, mLines)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(GridLines)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(GridLines)
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GridLines)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
GridLines::GridLines(GridDimension* aParent) : mParent(aParent) {
|
|
|
|
MOZ_ASSERT(aParent, "Should never be instantiated with a null GridDimension");
|
|
|
|
}
|
|
|
|
|
2020-02-20 19:10:39 +03:00
|
|
|
GridLines::~GridLines() = default;
|
2016-07-06 21:45:18 +03:00
|
|
|
|
|
|
|
JSObject* GridLines::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return GridLines_Binding::Wrap(aCx, this, aGivenProto);
|
2016-07-06 21:45:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t GridLines::Length() const { return mLines.Length(); }
|
|
|
|
|
|
|
|
GridLine* GridLines::Item(uint32_t aIndex) {
|
|
|
|
return mLines.SafeElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
GridLine* GridLines::IndexedGetter(uint32_t aIndex, bool& aFound) {
|
|
|
|
aFound = aIndex < mLines.Length();
|
|
|
|
if (!aFound) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mLines[aIndex];
|
|
|
|
}
|
|
|
|
|
2019-06-19 08:58:11 +03:00
|
|
|
static void AddLineNameIfNotPresent(nsTArray<RefPtr<nsAtom>>& aLineNames,
|
|
|
|
nsAtom* aName) {
|
2017-12-19 02:42:21 +03:00
|
|
|
if (!aLineNames.Contains(aName)) {
|
|
|
|
aLineNames.AppendElement(aName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-19 08:58:11 +03:00
|
|
|
static void AddLineNamesIfNotPresent(nsTArray<RefPtr<nsAtom>>& aLineNames,
|
|
|
|
const nsTArray<RefPtr<nsAtom>>& aNames) {
|
2017-12-19 02:42:21 +03:00
|
|
|
for (const auto& name : aNames) {
|
|
|
|
AddLineNameIfNotPresent(aLineNames, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-07 21:38:12 +03:00
|
|
|
void GridLines::SetLineInfo(const ComputedGridTrackInfo* aTrackInfo,
|
2016-09-03 02:28:27 +03:00
|
|
|
const ComputedGridLineInfo* aLineInfo,
|
|
|
|
const nsTArray<RefPtr<GridArea>>& aAreas,
|
|
|
|
bool aIsRow) {
|
2016-10-06 19:05:46 +03:00
|
|
|
MOZ_ASSERT(aLineInfo);
|
2016-07-06 21:45:18 +03:00
|
|
|
mLines.Clear();
|
|
|
|
|
|
|
|
if (!aTrackInfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-09 01:06:51 +03:00
|
|
|
uint32_t lineCount =
|
|
|
|
aTrackInfo->mEndFragmentTrack - aTrackInfo->mStartFragmentTrack + 1;
|
2016-07-06 21:45:18 +03:00
|
|
|
|
|
|
|
// If there is at least one track, line count is one more
|
|
|
|
// than the number of tracks.
|
2017-11-09 01:06:51 +03:00
|
|
|
if (lineCount > 0) {
|
2016-09-21 21:49:29 +03:00
|
|
|
nscoord lastTrackEdge = 0;
|
|
|
|
nscoord startOfNextTrack;
|
|
|
|
uint32_t repeatIndex = 0;
|
|
|
|
uint32_t numRepeatTracks = aTrackInfo->mRemovedRepeatTracks.Length();
|
|
|
|
uint32_t numAddedLines = 0;
|
2016-07-06 21:45:18 +03:00
|
|
|
|
2017-11-09 01:06:51 +03:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-06 21:45:18 +03:00
|
|
|
for (uint32_t i = aTrackInfo->mStartFragmentTrack;
|
|
|
|
i < aTrackInfo->mEndFragmentTrack + 1; i++) {
|
2017-06-16 21:19:36 +03:00
|
|
|
// Since line indexes are 1-based, calculate a 1-based value
|
|
|
|
// for this track to simplify some calculations.
|
|
|
|
const uint32_t line1Index = i + 1;
|
2016-09-03 02:28:27 +03:00
|
|
|
|
2016-07-06 21:45:18 +03:00
|
|
|
startOfNextTrack = (i < aTrackInfo->mEndFragmentTrack)
|
|
|
|
? aTrackInfo->mPositions[i]
|
2016-09-21 21:49:29 +03:00
|
|
|
: lastTrackEdge;
|
2016-07-07 21:38:12 +03:00
|
|
|
|
2017-12-19 02:42:21 +03:00
|
|
|
// Get the line names for the current line. aLineInfo->mNames
|
|
|
|
// may contain duplicate names. This is intentional, since grid
|
|
|
|
// layout works fine with duplicate names, and we don't want to
|
|
|
|
// detect and remove duplicates in layout since it is an O(n^2)
|
|
|
|
// problem. We do the work here since this is only run when
|
|
|
|
// requested by devtools, and slowness here will not affect
|
|
|
|
// normal browsing.
|
2019-06-19 08:58:11 +03:00
|
|
|
const nsTArray<RefPtr<nsAtom>>& possiblyDuplicateLineNames(
|
|
|
|
aLineInfo->mNames.SafeElementAt(i, nsTArray<RefPtr<nsAtom>>()));
|
2017-12-19 02:42:21 +03:00
|
|
|
|
2019-06-19 08:58:11 +03:00
|
|
|
nsTArray<RefPtr<nsAtom>> lineNames;
|
2017-12-06 01:51:06 +03:00
|
|
|
AddLineNamesIfNotPresent(lineNames, possiblyDuplicateLineNames);
|
2016-07-07 21:38:12 +03:00
|
|
|
|
2016-09-03 02:28:27 +03:00
|
|
|
// Add in names from grid areas where this line is used as a boundary.
|
|
|
|
for (auto area : aAreas) {
|
2018-05-03 02:24:20 +03:00
|
|
|
// We specifically ignore line names from implicitly named areas,
|
|
|
|
// because it can be confusing for designers who might naturally use
|
|
|
|
// a named line of "-start" or "-end" and create an implicit named
|
|
|
|
// area without meaning to.
|
|
|
|
if (area->Type() == GridDeclaration::Implicit) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-03 02:28:27 +03:00
|
|
|
bool haveNameToAdd = false;
|
2019-06-19 08:58:11 +03:00
|
|
|
nsAutoString nameToAdd;
|
2016-09-03 02:28:27 +03:00
|
|
|
area->GetName(nameToAdd);
|
|
|
|
if (aIsRow) {
|
|
|
|
if (area->RowStart() == line1Index) {
|
|
|
|
haveNameToAdd = true;
|
|
|
|
nameToAdd.AppendLiteral("-start");
|
|
|
|
} else if (area->RowEnd() == line1Index) {
|
|
|
|
haveNameToAdd = true;
|
|
|
|
nameToAdd.AppendLiteral("-end");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (area->ColumnStart() == line1Index) {
|
|
|
|
haveNameToAdd = true;
|
|
|
|
nameToAdd.AppendLiteral("-start");
|
|
|
|
} else if (area->ColumnEnd() == line1Index) {
|
|
|
|
haveNameToAdd = true;
|
|
|
|
nameToAdd.AppendLiteral("-end");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 02:42:21 +03:00
|
|
|
if (haveNameToAdd) {
|
2019-06-19 08:58:11 +03:00
|
|
|
RefPtr<nsAtom> name = NS_Atomize(nameToAdd);
|
|
|
|
AddLineNameIfNotPresent(lineNames, name);
|
2016-09-03 02:28:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-10 20:46:22 +03:00
|
|
|
if (i >= (aTrackInfo->mRepeatFirstTrack +
|
|
|
|
aTrackInfo->mNumLeadingImplicitTracks) &&
|
2016-09-21 21:49:29 +03:00
|
|
|
repeatIndex < numRepeatTracks) {
|
|
|
|
numAddedLines += AppendRemovedAutoFits(
|
|
|
|
aTrackInfo, aLineInfo, lastTrackEdge, repeatIndex, numRepeatTracks,
|
2017-11-09 01:06:51 +03:00
|
|
|
leadingTrackCount, lineNames);
|
2016-09-21 21:49:29 +03:00
|
|
|
}
|
|
|
|
|
2017-12-06 01:51:06 +03:00
|
|
|
// If this line is the one that ends a repeat, then add
|
|
|
|
// in the mNamesFollowingRepeat names from aLineInfo.
|
|
|
|
if (numRepeatTracks > 0 && i == (aTrackInfo->mRepeatFirstTrack +
|
|
|
|
aTrackInfo->mNumLeadingImplicitTracks +
|
|
|
|
numRepeatTracks - numAddedLines)) {
|
|
|
|
AddLineNamesIfNotPresent(lineNames, aLineInfo->mNamesFollowingRepeat);
|
|
|
|
}
|
|
|
|
|
2016-09-21 21:49:29 +03:00
|
|
|
RefPtr<GridLine> line = new GridLine(this);
|
|
|
|
mLines.AppendElement(line);
|
2017-06-16 21:19:36 +03:00
|
|
|
MOZ_ASSERT(line1Index > 0, "line1Index must be positive.");
|
|
|
|
bool isBeforeFirstExplicit =
|
|
|
|
(line1Index <= aTrackInfo->mNumLeadingImplicitTracks);
|
2017-11-09 01:06:51 +03:00
|
|
|
bool isAfterLastExplicit = line1Index > (leadingTrackCount + 1);
|
2017-06-16 21:19:36 +03:00
|
|
|
// 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
|
2017-11-09 01:06:51 +03:00
|
|
|
: (line1Index + numAddedLines -
|
|
|
|
aTrackInfo->mNumLeadingImplicitTracks);
|
|
|
|
|
|
|
|
// The negativeNumber is counted back from the leadingTrackCount.
|
|
|
|
int32_t lineNegativeNumber =
|
|
|
|
isAfterLastExplicit
|
|
|
|
? 0
|
|
|
|
: (line1Index + numAddedLines - (leadingTrackCount + 2));
|
|
|
|
GridDeclaration lineType = (isBeforeFirstExplicit || isAfterLastExplicit)
|
2017-06-16 21:19:36 +03:00
|
|
|
? GridDeclaration::Implicit
|
|
|
|
: GridDeclaration::Explicit;
|
2016-07-06 21:45:18 +03:00
|
|
|
line->SetLineValues(
|
2016-09-21 21:49:29 +03:00
|
|
|
lineNames, nsPresContext::AppUnitsToDoubleCSSPixels(lastTrackEdge),
|
2016-07-06 21:45:18 +03:00
|
|
|
nsPresContext::AppUnitsToDoubleCSSPixels(startOfNextTrack -
|
2016-09-21 21:49:29 +03:00
|
|
|
lastTrackEdge),
|
2017-11-09 01:06:51 +03:00
|
|
|
lineNumber, lineNegativeNumber, lineType);
|
2016-07-06 21:45:18 +03:00
|
|
|
|
|
|
|
if (i < aTrackInfo->mEndFragmentTrack) {
|
2016-09-21 21:49:29 +03:00
|
|
|
lastTrackEdge = aTrackInfo->mPositions[i] + aTrackInfo->mSizes[i];
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 20:19:01 +03:00
|
|
|
|
|
|
|
// Define a function that gets the mLines index for a given line number.
|
|
|
|
// This is necessary since it's possible for a line number to not be
|
|
|
|
// represented in mLines. If this is the case, then return -1.
|
|
|
|
const int32_t lineCount = mLines.Length();
|
|
|
|
const uint32_t lastLineNumber = mLines[lineCount - 1]->Number();
|
|
|
|
auto IndexForLineNumber =
|
|
|
|
[lineCount, lastLineNumber](uint32_t aLineNumber) -> int32_t {
|
|
|
|
if (lastLineNumber == 0) {
|
|
|
|
// None of the lines have addressable numbers, so none of them can have
|
|
|
|
// aLineNumber
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t possibleIndex = (int32_t)aLineNumber - 1;
|
|
|
|
if (possibleIndex < 0 || possibleIndex > lineCount - 1) {
|
|
|
|
// aLineNumber is not represented in mLines.
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return possibleIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Post-processing loop for implicit grid areas.
|
|
|
|
for (const auto& area : aAreas) {
|
|
|
|
if (area->Type() == GridDeclaration::Implicit) {
|
|
|
|
// Get the appropriate indexes for the area's start and end lines as
|
|
|
|
// they are represented in mLines.
|
|
|
|
int32_t startIndex =
|
|
|
|
IndexForLineNumber(aIsRow ? area->RowStart() : area->ColumnStart());
|
|
|
|
int32_t endIndex =
|
|
|
|
IndexForLineNumber(aIsRow ? area->RowEnd() : area->ColumnEnd());
|
|
|
|
|
|
|
|
// If both start and end indexes are -1, then stop here since we cannot
|
|
|
|
// reason about the naming for either lines.
|
|
|
|
if (startIndex < 0 && endIndex < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the "-start" and "-end" line names of the grid area.
|
2019-06-19 08:58:11 +03:00
|
|
|
nsAutoString startLineName;
|
2019-04-17 20:19:01 +03:00
|
|
|
area->GetName(startLineName);
|
|
|
|
startLineName.AppendLiteral("-start");
|
2019-06-19 08:58:11 +03:00
|
|
|
nsAutoString endLineName;
|
2019-04-17 20:19:01 +03:00
|
|
|
area->GetName(endLineName);
|
|
|
|
endLineName.AppendLiteral("-end");
|
|
|
|
|
|
|
|
// Get the list of existing line names for the start and end of the grid
|
|
|
|
// area. In the case where one of the start or end indexes are -1, use a
|
|
|
|
// dummy line as a substitute for the start/end line.
|
|
|
|
RefPtr<GridLine> dummyLine = new GridLine(this);
|
|
|
|
RefPtr<GridLine> areaStartLine =
|
|
|
|
startIndex > -1 ? mLines[startIndex] : dummyLine;
|
2020-05-05 17:13:15 +03:00
|
|
|
nsTArray<RefPtr<nsAtom>> startLineNames(areaStartLine->Names().Clone());
|
2019-04-17 20:19:01 +03:00
|
|
|
|
|
|
|
RefPtr<GridLine> areaEndLine =
|
|
|
|
endIndex > -1 ? mLines[endIndex] : dummyLine;
|
2020-05-05 17:13:15 +03:00
|
|
|
nsTArray<RefPtr<nsAtom>> endLineNames(areaEndLine->Names().Clone());
|
2019-04-17 20:19:01 +03:00
|
|
|
|
2019-06-19 08:58:11 +03:00
|
|
|
RefPtr<nsAtom> start = NS_Atomize(startLineName);
|
|
|
|
RefPtr<nsAtom> end = NS_Atomize(endLineName);
|
|
|
|
if (startLineNames.Contains(end) || endLineNames.Contains(start)) {
|
2019-04-17 20:19:01 +03:00
|
|
|
// Add the reversed line names.
|
2019-06-19 08:58:11 +03:00
|
|
|
AddLineNameIfNotPresent(startLineNames, end);
|
|
|
|
AddLineNameIfNotPresent(endLineNames, start);
|
2019-04-17 20:19:01 +03:00
|
|
|
} else {
|
|
|
|
// Add the normal line names.
|
2019-06-19 08:58:11 +03:00
|
|
|
AddLineNameIfNotPresent(startLineNames, start);
|
|
|
|
AddLineNameIfNotPresent(endLineNames, end);
|
2019-04-17 20:19:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
areaStartLine->SetLineNames(startLineNames);
|
|
|
|
areaEndLine->SetLineNames(endLineNames);
|
|
|
|
}
|
|
|
|
}
|
2016-09-21 21:49:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t GridLines::AppendRemovedAutoFits(
|
|
|
|
const ComputedGridTrackInfo* aTrackInfo,
|
|
|
|
const ComputedGridLineInfo* aLineInfo, nscoord aLastTrackEdge,
|
|
|
|
uint32_t& aRepeatIndex, uint32_t aNumRepeatTracks,
|
2019-06-19 08:58:11 +03:00
|
|
|
uint32_t aNumLeadingTracks, nsTArray<RefPtr<nsAtom>>& aLineNames) {
|
2016-09-21 21:49:29 +03:00
|
|
|
bool extractedExplicitLineNames = false;
|
2019-06-19 08:58:11 +03:00
|
|
|
nsTArray<RefPtr<nsAtom>> explicitLineNames;
|
2016-09-21 21:49:29 +03:00
|
|
|
uint32_t linesAdded = 0;
|
|
|
|
while (aRepeatIndex < aNumRepeatTracks &&
|
|
|
|
aTrackInfo->mRemovedRepeatTracks[aRepeatIndex]) {
|
|
|
|
// If this is not the very first call to this function, and if we
|
|
|
|
// haven't already added a line this call, pull all the explicit
|
|
|
|
// names to pass along to the next line that will be added after
|
|
|
|
// this function completes.
|
|
|
|
if (aRepeatIndex > 0 && linesAdded == 0) {
|
|
|
|
// Find the names that didn't match the before or after names,
|
|
|
|
// and extract them.
|
|
|
|
for (const auto& name : aLineNames) {
|
|
|
|
if (!aLineInfo->mNamesBefore.Contains(name) &&
|
|
|
|
!aLineInfo->mNamesAfter.Contains(name)) {
|
|
|
|
explicitLineNames.AppendElement(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const auto& extractedName : explicitLineNames) {
|
|
|
|
aLineNames.RemoveElement(extractedName);
|
2016-07-06 21:45:18 +03:00
|
|
|
}
|
2016-09-21 21:49:29 +03:00
|
|
|
extractedExplicitLineNames = true;
|
|
|
|
}
|
|
|
|
|
Bug 1519958 - Refactor grid types to preserve repeat() at computed value time and use cbindgen. r=mats,boris
I'm _really_ sorry for the size of the patch. I tried to do this in two steps
but it was a lot of work and pretty ugly.
This patch makes us use cbindgen for grid-template-{rows,columns}, in order to:
* Make us preserve repeat() at computed-value time. This is per spec since
interpolation needs to know about repeat(). Except for subgrid, which did the
repeat expansion at parse-time and was a bit more annoying (plus it doesn't
really animate yet so we don't need it to comply with the spec).
* Tweaks the WPT tests for interpolation to adopt the resolution at:
https://github.com/w3c/csswg-drafts/issues/3503.
Trade-off here, as this patch stands, is that this change makes us use less
long-living memory, since we expand repeat() during layout, but at the cost of a
bit of CPU time during layout (conditional on the property applying though,
which wasn't the case before). It should be very easy to store a cached version
of the template, should this be too hot (I expect it isn't), or to change the
representation in other ways to optimize grid layout code if it's worth it.
Another trade-off: I've used SmallPointerArray to handle line-name merging,
pointing to the individual arrays in the style data, rather than actually
heap-allocating the merged lists. This would also be pretty easy to change
should we measure and see that it's not worth it.
This patch also opens the gate to potentially improving memory usage in some
other ways, by reference-counting line-name lists for example, though I don't
have data that suggests it is worth it.
In general, this patch makes much easier to tweak the internal representation of
the grid style data structures. Overall, I think it's a win, the amount of magic
going on in that mako code was a bit huge; it took a bit to wrap my head around
it.
This patch comments out the style struct size assertions. They will be
uncommented in a follow-up patch which contains some improvements for this type,
which are worth getting reviewed separately.
Also, this patch doesn't remove as much code as I would've hoped for because of
I tried not to change most of the dom/grid code for inspector, but I think a
fair bit of the nsGridContainerFrame.cpp code that collects information for it
can be simplified / de-copy-pasted to some extent. But that was a pre-existing
problem and this patch is already quite massive.
Differential Revision: https://phabricator.services.mozilla.com/D36598
2019-06-28 14:27:19 +03:00
|
|
|
AddLineNamesIfNotPresent(aLineNames, aLineInfo->mNamesBefore);
|
2016-09-21 21:49:29 +03:00
|
|
|
|
|
|
|
RefPtr<GridLine> line = new GridLine(this);
|
|
|
|
mLines.AppendElement(line);
|
2017-11-09 01:06:51 +03:00
|
|
|
|
|
|
|
// 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.
|
2017-11-10 20:46:22 +03:00
|
|
|
uint32_t lineNumber = aTrackInfo->mRepeatFirstTrack + aRepeatIndex + 1;
|
2017-11-09 01:06:51 +03:00
|
|
|
|
|
|
|
// 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);
|
2016-09-21 21:49:29 +03:00
|
|
|
line->SetLineValues(
|
|
|
|
aLineNames, nsPresContext::AppUnitsToDoubleCSSPixels(aLastTrackEdge),
|
|
|
|
nsPresContext::AppUnitsToDoubleCSSPixels(0), lineNumber,
|
|
|
|
lineNegativeNumber, GridDeclaration::Explicit);
|
|
|
|
|
|
|
|
// No matter what, the next line should have the after names associated
|
|
|
|
// with it. If we go through the loop again, the before names will also
|
|
|
|
// be added.
|
2020-05-05 17:13:15 +03:00
|
|
|
aLineNames = aLineInfo->mNamesAfter.Clone();
|
2016-09-21 21:49:29 +03:00
|
|
|
aRepeatIndex++;
|
|
|
|
|
|
|
|
linesAdded++;
|
|
|
|
}
|
Bug 1519958 - Refactor grid types to preserve repeat() at computed value time and use cbindgen. r=mats,boris
I'm _really_ sorry for the size of the patch. I tried to do this in two steps
but it was a lot of work and pretty ugly.
This patch makes us use cbindgen for grid-template-{rows,columns}, in order to:
* Make us preserve repeat() at computed-value time. This is per spec since
interpolation needs to know about repeat(). Except for subgrid, which did the
repeat expansion at parse-time and was a bit more annoying (plus it doesn't
really animate yet so we don't need it to comply with the spec).
* Tweaks the WPT tests for interpolation to adopt the resolution at:
https://github.com/w3c/csswg-drafts/issues/3503.
Trade-off here, as this patch stands, is that this change makes us use less
long-living memory, since we expand repeat() during layout, but at the cost of a
bit of CPU time during layout (conditional on the property applying though,
which wasn't the case before). It should be very easy to store a cached version
of the template, should this be too hot (I expect it isn't), or to change the
representation in other ways to optimize grid layout code if it's worth it.
Another trade-off: I've used SmallPointerArray to handle line-name merging,
pointing to the individual arrays in the style data, rather than actually
heap-allocating the merged lists. This would also be pretty easy to change
should we measure and see that it's not worth it.
This patch also opens the gate to potentially improving memory usage in some
other ways, by reference-counting line-name lists for example, though I don't
have data that suggests it is worth it.
In general, this patch makes much easier to tweak the internal representation of
the grid style data structures. Overall, I think it's a win, the amount of magic
going on in that mako code was a bit huge; it took a bit to wrap my head around
it.
This patch comments out the style struct size assertions. They will be
uncommented in a follow-up patch which contains some improvements for this type,
which are worth getting reviewed separately.
Also, this patch doesn't remove as much code as I would've hoped for because of
I tried not to change most of the dom/grid code for inspector, but I think a
fair bit of the nsGridContainerFrame.cpp code that collects information for it
can be simplified / de-copy-pasted to some extent. But that was a pre-existing
problem and this patch is already quite massive.
Differential Revision: https://phabricator.services.mozilla.com/D36598
2019-06-28 14:27:19 +03:00
|
|
|
|
2016-09-21 21:49:29 +03:00
|
|
|
aRepeatIndex++;
|
|
|
|
|
|
|
|
if (extractedExplicitLineNames) {
|
|
|
|
// Pass on the explicit names we saved to the next explicit line.
|
2017-12-19 02:42:21 +03:00
|
|
|
AddLineNamesIfNotPresent(aLineNames, explicitLineNames);
|
2016-09-21 21:49:29 +03:00
|
|
|
}
|
|
|
|
|
Bug 1519958 - Refactor grid types to preserve repeat() at computed value time and use cbindgen. r=mats,boris
I'm _really_ sorry for the size of the patch. I tried to do this in two steps
but it was a lot of work and pretty ugly.
This patch makes us use cbindgen for grid-template-{rows,columns}, in order to:
* Make us preserve repeat() at computed-value time. This is per spec since
interpolation needs to know about repeat(). Except for subgrid, which did the
repeat expansion at parse-time and was a bit more annoying (plus it doesn't
really animate yet so we don't need it to comply with the spec).
* Tweaks the WPT tests for interpolation to adopt the resolution at:
https://github.com/w3c/csswg-drafts/issues/3503.
Trade-off here, as this patch stands, is that this change makes us use less
long-living memory, since we expand repeat() during layout, but at the cost of a
bit of CPU time during layout (conditional on the property applying though,
which wasn't the case before). It should be very easy to store a cached version
of the template, should this be too hot (I expect it isn't), or to change the
representation in other ways to optimize grid layout code if it's worth it.
Another trade-off: I've used SmallPointerArray to handle line-name merging,
pointing to the individual arrays in the style data, rather than actually
heap-allocating the merged lists. This would also be pretty easy to change
should we measure and see that it's not worth it.
This patch also opens the gate to potentially improving memory usage in some
other ways, by reference-counting line-name lists for example, though I don't
have data that suggests it is worth it.
In general, this patch makes much easier to tweak the internal representation of
the grid style data structures. Overall, I think it's a win, the amount of magic
going on in that mako code was a bit huge; it took a bit to wrap my head around
it.
This patch comments out the style struct size assertions. They will be
uncommented in a follow-up patch which contains some improvements for this type,
which are worth getting reviewed separately.
Also, this patch doesn't remove as much code as I would've hoped for because of
I tried not to change most of the dom/grid code for inspector, but I think a
fair bit of the nsGridContainerFrame.cpp code that collects information for it
can be simplified / de-copy-pasted to some extent. But that was a pre-existing
problem and this patch is already quite massive.
Differential Revision: https://phabricator.services.mozilla.com/D36598
2019-06-28 14:27:19 +03:00
|
|
|
// If we haven't finished adding auto-repeated tracks, then we need to put
|
|
|
|
// back the before names, in case we cleared them above.
|
|
|
|
if (aRepeatIndex < aNumRepeatTracks) {
|
2017-12-19 02:42:21 +03:00
|
|
|
AddLineNamesIfNotPresent(aLineNames, aLineInfo->mNamesBefore);
|
2016-07-06 21:45:18 +03:00
|
|
|
}
|
Bug 1519958 - Refactor grid types to preserve repeat() at computed value time and use cbindgen. r=mats,boris
I'm _really_ sorry for the size of the patch. I tried to do this in two steps
but it was a lot of work and pretty ugly.
This patch makes us use cbindgen for grid-template-{rows,columns}, in order to:
* Make us preserve repeat() at computed-value time. This is per spec since
interpolation needs to know about repeat(). Except for subgrid, which did the
repeat expansion at parse-time and was a bit more annoying (plus it doesn't
really animate yet so we don't need it to comply with the spec).
* Tweaks the WPT tests for interpolation to adopt the resolution at:
https://github.com/w3c/csswg-drafts/issues/3503.
Trade-off here, as this patch stands, is that this change makes us use less
long-living memory, since we expand repeat() during layout, but at the cost of a
bit of CPU time during layout (conditional on the property applying though,
which wasn't the case before). It should be very easy to store a cached version
of the template, should this be too hot (I expect it isn't), or to change the
representation in other ways to optimize grid layout code if it's worth it.
Another trade-off: I've used SmallPointerArray to handle line-name merging,
pointing to the individual arrays in the style data, rather than actually
heap-allocating the merged lists. This would also be pretty easy to change
should we measure and see that it's not worth it.
This patch also opens the gate to potentially improving memory usage in some
other ways, by reference-counting line-name lists for example, though I don't
have data that suggests it is worth it.
In general, this patch makes much easier to tweak the internal representation of
the grid style data structures. Overall, I think it's a win, the amount of magic
going on in that mako code was a bit huge; it took a bit to wrap my head around
it.
This patch comments out the style struct size assertions. They will be
uncommented in a follow-up patch which contains some improvements for this type,
which are worth getting reviewed separately.
Also, this patch doesn't remove as much code as I would've hoped for because of
I tried not to change most of the dom/grid code for inspector, but I think a
fair bit of the nsGridContainerFrame.cpp code that collects information for it
can be simplified / de-copy-pasted to some extent. But that was a pre-existing
problem and this patch is already quite massive.
Differential Revision: https://phabricator.services.mozilla.com/D36598
2019-06-28 14:27:19 +03:00
|
|
|
|
2016-09-21 21:49:29 +03:00
|
|
|
return linesAdded;
|
2016-07-06 21:45:18 +03:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom
|