Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
| diff --git a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
| index cfde1c770390d00cb5a418ebb7f1d54fd22443fa..be9deea740a363e94ec04bb7ab69755bc3624fdc 100644 |
| --- a/third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
| +++ b/third_party/WebKit/Source/core/layout/LayoutGrid.cpp |
| @@ -301,7 +301,8 @@ void LayoutGrid::styleDidChange(StyleDifference diff, const ComputedStyle* oldSt |
| if (explicitGridDidResize(*oldStyle) |
| || namedGridLinesDefinitionDidChange(*oldStyle) |
| - || oldStyle->getGridAutoFlow() != styleRef().getGridAutoFlow()) |
| + || oldStyle->getGridAutoFlow() != styleRef().getGridAutoFlow() |
| + || (diff.needsLayout() && (styleRef().gridAutoRepeatColumns().size() || styleRef().gridAutoRepeatRows().size()))) |
|
Manuel Rego
2016/04/18 21:31:42
We don't have a test for this.
BTW, why you need
svillar
2016/04/19 08:09:36
ACK
|
| dirtyGrid(); |
| } |
| @@ -310,7 +311,9 @@ bool LayoutGrid::explicitGridDidResize(const ComputedStyle& oldStyle) const |
| return oldStyle.gridTemplateColumns().size() != styleRef().gridTemplateColumns().size() |
| || oldStyle.gridTemplateRows().size() != styleRef().gridTemplateRows().size() |
| || oldStyle.namedGridAreaColumnCount() != styleRef().namedGridAreaColumnCount() |
| - || oldStyle.namedGridAreaRowCount() != styleRef().namedGridAreaRowCount(); |
| + || oldStyle.namedGridAreaRowCount() != styleRef().namedGridAreaRowCount() |
| + || oldStyle.gridAutoRepeatColumns().size() != styleRef().gridAutoRepeatColumns().size() |
| + || oldStyle.gridAutoRepeatRows().size() != styleRef().gridAutoRepeatRows().size(); |
|
Manuel Rego
2016/04/18 21:31:41
We don't have a test for this either.
svillar
2016/04/19 08:09:36
Acknowledged.
|
| } |
| bool LayoutGrid::namedGridLinesDefinitionDidChange(const ComputedStyle& oldStyle) const |
| @@ -694,13 +697,36 @@ static bool shouldClearOverrideContainingBlockContentSizeForChild(const LayoutBo |
| return child.hasRelativeLogicalHeight() || child.styleRef().logicalHeight().isIntrinsicOrAuto(); |
| } |
| -GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size_t i) const |
| +const GridTrackSize& LayoutGrid::unresolvedGridTrackSize(GridTrackSizingDirection direction, int i) const |
|
Manuel Rego
2016/04/18 21:31:42
We could find a better name than "i" for the varia
svillar
2016/04/19 08:09:36
Acknowledged.
|
| { |
| bool isForColumns = direction == ForColumns; |
|
Manuel Rego
2016/04/18 21:31:42
Probably better use "isRowAxis" as in most of the
svillar
2016/04/19 08:09:35
Acknowledged.
|
| - const Vector<GridTrackSize>& trackStyles = isForColumns ? style()->gridTemplateColumns() : style()->gridTemplateRows(); |
| - const GridTrackSize& autoTrackSize = isForColumns ? style()->gridAutoColumns() : style()->gridAutoRows(); |
| - int translatedIndex = i + (isForColumns ? m_smallestColumnStart : m_smallestRowStart); |
| - const GridTrackSize& trackSize = (translatedIndex < 0 || translatedIndex >= static_cast<int>(trackStyles.size())) ? autoTrackSize : trackStyles[translatedIndex]; |
| + const Vector<GridTrackSize>& trackStyles = isForColumns ? styleRef().gridTemplateColumns() : styleRef().gridTemplateRows(); |
| + const Vector<GridTrackSize>& autoRepeatTrackStyles = isForColumns ? styleRef().gridAutoRepeatColumns() : styleRef().gridAutoRepeatRows(); |
| + const GridTrackSize& autoTrackSize = isForColumns ? styleRef().gridAutoColumns() : styleRef().gridAutoRows(); |
| + size_t insertionPoint = isForColumns ? styleRef().gridAutoRepeatColumnsInsertionPoint() : styleRef().gridAutoRepeatRowsInsertionPoint(); |
| + size_t repetitions = autoRepeatCountForDirection(direction); |
| + |
| + // We should not use GridPositionsResolver::explicitGridXXXCount() for this because the |
| + // explicit grid might be larger than the number of tracks in grid-template-rows|columns (if |
| + // grid-template-areas is specified for example). |
|
Manuel Rego
2016/04/18 21:31:42
But explicitGridXXXCount() now already manages
the
svillar
2016/04/19 08:09:35
It's perfectly up to date :). So the thing is that
Manuel Rego
2016/04/19 11:37:30
Yeah I read the comment wrong, I got it now. Thank
|
| + size_t explicitTracksCount = trackStyles.size() + repetitions; |
| + |
| + if (i < 0 || i >= explicitTracksCount) |
| + return autoTrackSize; |
| + |
| + if (LIKELY(!repetitions) || i < insertionPoint) |
|
Manuel Rego
2016/04/18 21:31:42
Wow, first time I see LIKELY in a patch. :-)
svillar
2016/04/19 08:09:36
Not sure if this is a complain or what :). There a
Manuel Rego
2016/04/19 11:37:30
Just a funny comment, sorry. :-)
|
| + return trackStyles[i]; |
| + |
| + if (i < (insertionPoint + repetitions)) |
| + return autoRepeatTrackStyles[0]; |
| + |
| + return trackStyles[i - repetitions]; |
| +} |
| + |
| +GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size_t i) const |
| +{ |
| + int translatedIndex = i + (direction == ForColumns ? m_smallestColumnStart : m_smallestRowStart); |
|
Manuel Rego
2016/04/18 21:31:42
You could do this inside unresolvedGridTrackSize()
svillar
2016/04/19 08:09:36
Acknowledged.
|
| + const GridTrackSize& trackSize = unresolvedGridTrackSize(direction, translatedIndex); |
| GridLength minTrackBreadth = trackSize.minTrackBreadth(); |
| GridLength maxTrackBreadth = trackSize.maxTrackBreadth(); |
| @@ -1182,8 +1208,79 @@ void LayoutGrid::insertItemIntoGrid(LayoutBox& child, const GridArea& area) |
| size_t LayoutGrid::computeAutoRepeatTracksCount(GridTrackSizingDirection direction) const |
| { |
| - // TODO(svillar): implement the algorithm to compute the number of auto repeat tracks. |
| - return 0; |
| + bool isRowAxis = direction == ForColumns; |
| + const auto& autoRepeatTracks = isRowAxis ? styleRef().gridAutoRepeatColumns() : styleRef().gridAutoRepeatRows(); |
| + |
| + if (!autoRepeatTracks.size()) |
| + return 0; |
| + |
| + DCHECK_EQ(autoRepeatTracks.size(), 1); |
| + auto autoTrackSize = autoRepeatTracks.at(0); |
| + DCHECK(autoTrackSize.minTrackBreadth().isLength() && !autoTrackSize.minTrackBreadth().isContentSized()); |
|
Manuel Rego
2016/04/18 21:31:42
Usually it's preferred to split this in 2 lines,
t
svillar
2016/04/19 08:09:35
Acknowledged.
|
| + |
| + const Length& minSize = isRowAxis ? styleRef().logicalMinWidth() : styleRef().logicalMinHeight(); |
|
Manuel Rego
2016/04/18 21:31:42
This should be moved below where it's first used.
svillar
2016/04/19 08:09:36
Acknowledged.
|
| + LayoutUnit availableSize = isRowAxis ? availableLogicalWidth() : computeContentLogicalHeight(MainOrPreferredSize, styleRef().logicalHeight(), LayoutUnit(-1)); |
| + |
| + bool needsToFulfillMinimumSize = false; |
|
Manuel Rego
2016/04/18 21:31:42
Ditto.
svillar
2016/04/19 08:09:36
Acknowledged.
|
| + if (availableSize == -1) { |
| + const Length& maxLength = isRowAxis ? styleRef().logicalMaxWidth() : styleRef().logicalMaxHeight(); |
| + if (!maxLength.isMaxSizeNone()) { |
| + LayoutUnit maxSize = isRowAxis |
| + ? computeLogicalWidthUsing(MaxSize, maxLength, containingBlockLogicalWidthForContent(), containingBlock()) |
| + : computeContentLogicalHeight(MaxSize, maxLength, LayoutUnit(-1)); |
| + if (maxSize != -1) |
| + availableSize = availableSize != -1 ? std::min(availableSize, maxSize) : maxSize; |
|
Manuel Rego
2016/04/18 21:31:42
"availableSize" should be -1 if we are in this par
svillar
2016/04/19 08:09:36
Acknowledged.
|
| + } |
| + } else { |
| + availableSize = isRowAxis |
| + ? constrainLogicalWidthByMinMax(availableSize, containingBlockLogicalWidthForContent(), containingBlock()) |
| + : constrainLogicalHeightByMinMax(availableSize, LayoutUnit(-1)); |
| + } |
| + |
| + bool indefiniteMainAndMaxSizes = availableSize == LayoutUnit(-1); |
| + if (indefiniteMainAndMaxSizes) { |
| + if (!minSize.isSpecified()) |
| + return 1; |
| + |
| + LayoutUnit containingBlockAvailableSize = isRowAxis ? containingBlockLogicalWidthForContent() : containingBlockLogicalHeightForContent(ExcludeMarginBorderPadding); |
| + availableSize = valueForLength(minSize, containingBlockAvailableSize); |
| + needsToFulfillMinimumSize = true; |
| + } |
| + |
| + bool hasDefiniteMaxTrackSizingFunction = autoTrackSize.maxTrackBreadth().isLength() && !autoTrackSize.maxTrackBreadth().isContentSized(); |
| + const Length trackLength = hasDefiniteMaxTrackSizingFunction ? autoTrackSize.maxTrackBreadth().length() : autoTrackSize.minTrackBreadth().length(); |
| + // For the purpose of finding the number of auto-repeated tracks, the UA must floor the track size to a UA-specified |
| + // value to avoid division by zero. It is suggested that this floor be 1px. |
| + LayoutUnit autoRepeatTrackSize = std::max<LayoutUnit>(LayoutUnit(1), valueForLength(trackLength, availableSize)); |
| + |
| + // There will be always at least 1 auto-repeat track, so take it already into account when computing the total track size |
| + LayoutUnit tracksSize = autoRepeatTrackSize; |
| + const Vector<GridTrackSize>& trackSizes = isRowAxis ? styleRef().gridTemplateColumns() : styleRef().gridTemplateRows(); |
| + |
| + for (const auto& track : trackSizes) { |
| + bool hasDefiniteMaxTrackBreadth = track.maxTrackBreadth().isLength() && !track.maxTrackBreadth().isContentSized(); |
| + DCHECK(hasDefiniteMaxTrackBreadth || (track.minTrackBreadth().isLength() && !track.minTrackBreadth().isContentSized())); |
| + tracksSize += valueForLength(hasDefiniteMaxTrackBreadth ? track.maxTrackBreadth().length() : track.minTrackBreadth().length(), availableSize); |
| + } |
| + |
| + // Add gutters as if there where only 1 auto repeat track. Gaps between auto repeat tracks will be added later when |
| + // computing the repetitions. |
| + LayoutUnit gapSize = guttersSize(direction, 2); |
| + tracksSize += gapSize * trackSizes.size(); |
| + |
| + LayoutUnit freeSpace = availableSize - tracksSize; |
| + if (freeSpace <= 0) |
| + return 1; |
| + |
| + size_t repetitions = 1 + (freeSpace / (autoRepeatTrackSize + gapSize)).toInt(); |
|
Manuel Rego
2016/04/18 21:31:42
I'm not sure if I get this, if you've for example
svillar
2016/04/19 08:09:36
You're missing the freeSpace computation just a co
Manuel Rego
2016/04/19 11:37:30
Thanks again.
|
| + |
| + // Otherwise, if the grid container has a definite min size in the relevant axis, the |
| + // number of repetitions is the largest possible positive integer that fulfills that |
| + // minimum requirement. |
| + if (needsToFulfillMinimumSize) |
| + ++repetitions; |
|
Manuel Rego
2016/04/18 21:31:42
Again, I don't get why in this case we've to incre
svillar
2016/04/19 08:09:36
Because in the above code we compute the maximum n
Manuel Rego
2016/04/19 11:37:30
And thanks again, I was not getting it.
|
| + |
| + return std::min<size_t>(repetitions, kGridMaxTracks); |
|
Manuel Rego
2016/04/18 21:31:42
I guess the limit for kGridMaxTracks should be
rep
svillar
2016/04/19 08:09:36
Yeah good catch.
|
| } |
| void LayoutGrid::placeItemsOnGrid() |