Commit e09a66db authored by rego's avatar rego Committed by Commit bot

[css-grid] Cache definite height detection

This is a refactoring patch which stores the definite/indefinite height
detection in a new attribute m_hasDefiniteLogicalHeight in LayoutGrid.
That way we just only call LayoutBlock::hasDefiniteLogicalHeight() once,
from LayoutGrid::layoutBlock(). Then in LayoutGrid::gridTrackSize()
we reuse the cached value.

No new tests, no change of behavior.

BUG=624301

Review-Url: https://codereview.chromium.org/2334133002
Cr-Commit-Position: refs/heads/master@{#418831}
parent 817f5d2c
...@@ -453,7 +453,7 @@ void LayoutGrid::layoutBlock(bool relayoutChildren) ...@@ -453,7 +453,7 @@ void LayoutGrid::layoutBlock(bool relayoutChildren)
LayoutSize previousSize = size(); LayoutSize previousSize = size();
updateLogicalWidth(); updateLogicalWidth();
bool logicalHeightWasIndefinite = !hasDefiniteLogicalHeight(); m_hasDefiniteLogicalHeight = hasDefiniteLogicalHeight();
TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope); TextAutosizer::LayoutScope textAutosizerLayoutScope(this, &layoutScope);
...@@ -475,10 +475,10 @@ void LayoutGrid::layoutBlock(bool relayoutChildren) ...@@ -475,10 +475,10 @@ void LayoutGrid::layoutBlock(bool relayoutChildren)
// 2- Next, the track sizing algorithm resolves the sizes of the grid rows, using the // 2- Next, the track sizing algorithm resolves the sizes of the grid rows, using the
// grid column sizes calculated in the previous step. // grid column sizes calculated in the previous step.
if (logicalHeightWasIndefinite) if (cachedHasDefiniteLogicalHeight())
computeIntrinsicLogicalHeight(sizingData);
else
computeTrackSizesForDirection(ForRows, sizingData, availableLogicalHeight(ExcludeMarginBorderPadding)); computeTrackSizesForDirection(ForRows, sizingData, availableLogicalHeight(ExcludeMarginBorderPadding));
else
computeIntrinsicLogicalHeight(sizingData);
setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndPaddingLogicalHeight() + scrollbarLogicalHeight()); setLogicalHeight(computeTrackBasedLogicalHeight(sizingData) + borderAndPaddingLogicalHeight() + scrollbarLogicalHeight());
LayoutUnit oldClientAfterEdge = clientLogicalBottom(); LayoutUnit oldClientAfterEdge = clientLogicalBottom();
...@@ -487,7 +487,7 @@ void LayoutGrid::layoutBlock(bool relayoutChildren) ...@@ -487,7 +487,7 @@ void LayoutGrid::layoutBlock(bool relayoutChildren)
// The above call might have changed the grid's logical height depending on min|max height restrictions. // The above call might have changed the grid's logical height depending on min|max height restrictions.
// Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes). // Update the sizes of the rows whose size depends on the logical height (also on definite|indefinite sizes).
LayoutUnit availableSpaceForRows = contentLogicalHeight(); LayoutUnit availableSpaceForRows = contentLogicalHeight();
if (logicalHeightWasIndefinite) if (!cachedHasDefiniteLogicalHeight())
computeTrackSizesForDirection(ForRows, sizingData, availableSpaceForRows); computeTrackSizesForDirection(ForRows, sizingData, availableSpaceForRows);
// 3- If the min-content contribution of any grid items have changed based on the row // 3- If the min-content contribution of any grid items have changed based on the row
...@@ -929,7 +929,7 @@ GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size ...@@ -929,7 +929,7 @@ GridTrackSize LayoutGrid::gridTrackSize(GridTrackSizingDirection direction, size
// If the logical width/height of the grid container is indefinite, percentage values are treated as <auto>. // If the logical width/height of the grid container is indefinite, percentage values are treated as <auto>.
if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) { if (minTrackBreadth.hasPercentage() || maxTrackBreadth.hasPercentage()) {
// For the inline axis this only happens when we're computing the intrinsic sizes (AvailableSpaceIndefinite). // For the inline axis this only happens when we're computing the intrinsic sizes (AvailableSpaceIndefinite).
if ((sizingOperation == IntrinsicSizeComputation) || (direction == ForRows && !hasDefiniteLogicalHeight())) { if ((sizingOperation == IntrinsicSizeComputation) || (direction == ForRows && !cachedHasDefiniteLogicalHeight())) {
if (minTrackBreadth.hasPercentage()) if (minTrackBreadth.hasPercentage())
minTrackBreadth = Length(Auto); minTrackBreadth = Length(Auto);
if (maxTrackBreadth.hasPercentage()) if (maxTrackBreadth.hasPercentage())
...@@ -2672,4 +2672,10 @@ void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa ...@@ -2672,4 +2672,10 @@ void LayoutGrid::paintChildren(const PaintInfo& paintInfo, const LayoutPoint& pa
GridPainter(*this).paintChildren(paintInfo, paintOffset); GridPainter(*this).paintChildren(paintInfo, paintOffset);
} }
bool LayoutGrid::cachedHasDefiniteLogicalHeight() const
{
SECURITY_DCHECK(m_hasDefiniteLogicalHeight);
return m_hasDefiniteLogicalHeight.value();
}
} // namespace blink } // namespace blink
...@@ -220,6 +220,8 @@ private: ...@@ -220,6 +220,8 @@ private:
bool isOrthogonalChild(const LayoutBox&) const; bool isOrthogonalChild(const LayoutBox&) const;
GridTrackSizingDirection flowAwareDirectionForChild(const LayoutBox&, GridTrackSizingDirection) const; GridTrackSizingDirection flowAwareDirectionForChild(const LayoutBox&, GridTrackSizingDirection) const;
bool cachedHasDefiniteLogicalHeight() const;
typedef Vector<Vector<GridCell>> GridRepresentation; typedef Vector<Vector<GridCell>> GridRepresentation;
GridRepresentation m_grid; GridRepresentation m_grid;
bool m_gridIsDirty; bool m_gridIsDirty;
...@@ -245,6 +247,8 @@ private: ...@@ -245,6 +247,8 @@ private:
std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyColumns { nullptr }; std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyColumns { nullptr };
std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyRows { nullptr }; std::unique_ptr<OrderedTrackIndexSet> m_autoRepeatEmptyRows { nullptr };
Optional<bool> m_hasDefiniteLogicalHeight;
}; };
DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutGrid, isLayoutGrid()); DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutGrid, isLayoutGrid());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment