Diff
Modified: trunk/Source/WebCore/ChangeLog (238113 => 238114)
--- trunk/Source/WebCore/ChangeLog 2018-11-12 23:42:49 UTC (rev 238113)
+++ trunk/Source/WebCore/ChangeLog 2018-11-13 00:31:51 UTC (rev 238114)
@@ -1,3 +1,46 @@
+2018-11-12 Javier Fernandez <[email protected]>
+
+ [css-grid] Refactoring to make more explicit the orthogonal items' pre-layout logic
+ https://bugs.webkit.org/show_bug.cgi?id=191358
+
+ Reviewed by Manuel Rego Casasnovas.
+
+ These changes are just a refactoring to ease the integration of the new Baseline Alignment
+ logic in a follow up patch.
+
+ We need to properly estimate the grid area size of orthogonal items so that we can perform
+ an accurate pre-layout. This is important because orthogonal items will synthesize their baseline
+ if they participate in any baseline alignment context.
+
+ No new tests, since no behavior change has been introduced in this patch.
+
+ * rendering/Grid.cpp:
+ (WebCore::Grid::setNeedsItemsPlacement):
+ * rendering/Grid.h:
+ * rendering/GridTrackSizingAlgorithm.cpp:
+ (WebCore::GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChild const):
+ (WebCore::GridTrackSizingAlgorithm::gridAreaBreadthForChild const):
+ (WebCore::GridTrackSizingAlgorithm::isRelativeGridLengthAsAuto const):
+ (WebCore::GridTrackSizingAlgorithm::isRelativeSizedTrackAsAuto const):
+ (WebCore::GridTrackSizingAlgorithm::gridTrackSize const):
+ (WebCore::IndefiniteSizeStrategy::findUsedFlexFraction const):
+ (WebCore::GridTrackSizingAlgorithm::run):
+ (WebCore::GridTrackSizingAlgorithm::reset):
+ * rendering/GridTrackSizingAlgorithm.h:
+ (WebCore::GridTrackSizingAlgorithmStrategy::gridTrackSize const):
+ * rendering/RenderGrid.cpp:
+ (WebCore::RenderGrid::repeatTracksSizingIfNeeded):
+ (WebCore::RenderGrid::layoutBlock):
+ (WebCore::RenderGrid::computeIntrinsicLogicalWidths const):
+ (WebCore::RenderGrid::computeTrackSizesForIndefiniteSize const):
+ (WebCore::RenderGrid::placeItemsOnGrid const):
+ (WebCore::RenderGrid::performGridItemsPreLayout const):
+ (WebCore::overrideSizeChanged):
+ (WebCore::hasRelativeBlockAxisSize):
+ (WebCore::RenderGrid::updateGridAreaLogicalSize const):
+ (WebCore::RenderGrid::layoutGridItems):
+ * rendering/RenderGrid.h:
+
2018-11-12 Sihui Liu <[email protected]>
imported/w3c/web-platform-tests/IndexedDB/keygenerator-explicit.html crashing on iOS device
Modified: trunk/Source/WebCore/rendering/Grid.cpp (238113 => 238114)
--- trunk/Source/WebCore/rendering/Grid.cpp 2018-11-12 23:42:49 UTC (rev 238113)
+++ trunk/Source/WebCore/rendering/Grid.cpp 2018-11-13 00:31:51 UTC (rev 238114)
@@ -157,7 +157,6 @@
m_grid.shrink(0);
m_gridItemArea.clear();
- m_hasAnyOrthogonalGridItem = false;
m_smallestRowStart = 0;
m_smallestColumnStart = 0;
m_autoRepeatEmptyColumns = nullptr;
Modified: trunk/Source/WebCore/rendering/Grid.h (238113 => 238114)
--- trunk/Source/WebCore/rendering/Grid.h 2018-11-12 23:42:49 UTC (rev 238113)
+++ trunk/Source/WebCore/rendering/Grid.h 2018-11-13 00:31:51 UTC (rev 238114)
@@ -53,10 +53,6 @@
// this method will return false for a grid container with only out of flow children.
bool hasGridItems() const { return !m_gridItemArea.isEmpty(); }
- // FIXME: move this to SizingData once placeItemsOnGrid() takes it as argument.
- bool hasAnyOrthogonalGridItem() const { return m_hasAnyOrthogonalGridItem; }
- void setHasAnyOrthogonalGridItem(bool hasAnyOrthogonalGridItem) { m_hasAnyOrthogonalGridItem = hasAnyOrthogonalGridItem; }
-
GridArea gridItemArea(const RenderBox& item) const;
void setGridItemArea(const RenderBox& item, GridArea);
@@ -95,7 +91,6 @@
unsigned m_autoRepeatColumns { 0 };
unsigned m_autoRepeatRows { 0 };
- bool m_hasAnyOrthogonalGridItem { false };
bool m_needsItemsPlacement { true };
GridAsMatrix m_grid;
Modified: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp (238113 => 238114)
--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp 2018-11-12 23:42:49 UTC (rev 238113)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp 2018-11-13 00:31:51 UTC (rev 238114)
@@ -533,24 +533,35 @@
track->setPlannedSize(track->plannedSize() == infinity ? track->tempSize() : std::max(track->plannedSize(), track->tempSize()));
}
-LayoutUnit GridTrackSizingAlgorithm::assumedRowsSizeForOrthogonalChild(const RenderBox& child) const
+LayoutSize GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChild(const RenderBox& child) const
{
- ASSERT(GridLayoutFunctions::isOrthogonalChild(*m_renderGrid, child));
- const GridSpan& span = m_grid.gridItemSpan(child, ForRows);
+ return {estimatedGridAreaBreadthForChild(child, ForColumns), estimatedGridAreaBreadthForChild(child, ForRows)};
+}
+
+LayoutUnit GridTrackSizingAlgorithm::estimatedGridAreaBreadthForChild(const RenderBox& child, GridTrackSizingDirection direction) const
+{
+ const GridSpan& span = m_grid.gridItemSpan(child, direction);
LayoutUnit gridAreaSize;
bool gridAreaIsIndefinite = false;
- LayoutUnit containingBlockAvailableSize = m_renderGrid->containingBlockLogicalHeightForContent(ExcludeMarginBorderPadding);
+ std::optional<LayoutUnit> availableSize = availableSpace(direction);
for (auto trackPosition : span) {
- GridLength maxTrackSize = gridTrackSize(ForRows, trackPosition).maxTrackBreadth();
- if (maxTrackSize.isContentSized() || maxTrackSize.isFlex())
+ // We may need to estimate the grid area size before running the track
+ // sizing algorithm in order to perform the pre-layout of orthogonal
+ // items.
+ GridTrackSize trackSize = wasSetup() ? gridTrackSize(direction, trackPosition) : rawGridTrackSize(direction, trackPosition);
+ GridLength maxTrackSize = trackSize.maxTrackBreadth();
+ if (maxTrackSize.isContentSized() || maxTrackSize.isFlex() || isRelativeGridLengthAsAuto(maxTrackSize, direction))
gridAreaIsIndefinite = true;
else
- gridAreaSize += valueForLength(maxTrackSize.length(), containingBlockAvailableSize);
+ gridAreaSize += valueForLength(maxTrackSize.length(), availableSize.value_or(LayoutUnit()));
}
- gridAreaSize += m_renderGrid->guttersSize(m_grid, ForRows, span.startLine(), span.integerSpan(), availableSpace(ForRows));
+ gridAreaSize += m_renderGrid->guttersSize(m_grid, direction, span.startLine(), span.integerSpan(), availableSize);
- return gridAreaIsIndefinite ? std::max(child.maxPreferredLogicalWidth(), gridAreaSize) : gridAreaSize;
+ GridTrackSizingDirection childInlineDirection = GridLayoutFunctions::flowAwareDirectionForChild(*m_renderGrid, child, ForColumns);
+ if (gridAreaIsIndefinite)
+ return direction == childInlineDirection ? std::max(child.maxPreferredLogicalWidth(), gridAreaSize) : LayoutUnit(-1);
+ return gridAreaSize;
}
LayoutUnit GridTrackSizingAlgorithm::gridAreaBreadthForChild(const RenderBox& child, GridTrackSizingDirection direction) const
@@ -565,7 +576,7 @@
// FIXME (jfernandez) Content Alignment should account for this heuristic.
// https://github.com/w3c/csswg-drafts/issues/2697
if (m_sizingState == ColumnSizingFirstIteration)
- return assumedRowsSizeForOrthogonalChild(child);
+ return estimatedGridAreaBreadthForChild(child, ForRows);
addContentAlignmentOffset = true;
}
@@ -583,8 +594,14 @@
return gridAreaBreadth;
}
+bool GridTrackSizingAlgorithm::isRelativeGridLengthAsAuto(const GridLength& length, GridTrackSizingDirection direction) const
+{
+ return length.isPercentage() && !availableSpace(direction);
+}
+
GridTrackSize GridTrackSizingAlgorithm::gridTrackSize(GridTrackSizingDirection direction, unsigned translatedIndex) const
{
+ ASSERT(wasSetup());
// Collapse empty auto repeat tracks if auto-fit.
if (m_grid.hasAutoRepeatEmptyTracks(direction) && m_grid.isEmptyAutoRepeatTrack(direction, translatedIndex))
return { Length(Fixed), LengthTrackSizing };
@@ -595,16 +612,13 @@
GridLength minTrackBreadth = trackSize.minTrackBreadth();
GridLength maxTrackBreadth = trackSize.maxTrackBreadth();
+ // If the logical width/height of the grid container is indefinite, percentage
+ // values are treated as <auto>.
+ if (isRelativeGridLengthAsAuto(trackSize.minTrackBreadth(), direction))
+ minTrackBreadth = Length(Auto);
+ if (isRelativeGridLengthAsAuto(trackSize.maxTrackBreadth(), direction))
+ maxTrackBreadth = Length(Auto);
- // FIXME: Ensure this condition for determining whether a size is indefinite or not is working
- // correctly for orthogonal flows.
- if (!availableSpace(direction) && (minTrackBreadth.isPercentage() || maxTrackBreadth.isPercentage())) {
- if (minTrackBreadth.isPercentage())
- minTrackBreadth = Length(Auto);
- if (maxTrackBreadth.isPercentage())
- maxTrackBreadth = Length(Auto);
- }
-
// Flex sizes are invalid as a min sizing function. However we still can have a flexible |minTrackBreadth|
// if the track size is just a flex size (e.g. "1fr"), the spec says that in this case it implies an automatic minimum.
if (minTrackBreadth.isFlex())
@@ -841,7 +855,7 @@
for (const auto& trackIndex : flexibleSizedTracksIndex) {
// FIXME: we pass TrackSizing to gridTrackSize() because it does not really matter
// as we know the track is a flex sized track. It'd be nice not to have to do that.
- flexFraction = std::max(flexFraction, normalizedFlexFraction(allTracks[trackIndex], m_algorithm.gridTrackSize(direction, trackIndex).maxTrackBreadth().flex()));
+ flexFraction = std::max(flexFraction, normalizedFlexFraction(allTracks[trackIndex], gridTrackSize(direction, trackIndex).maxTrackBreadth().flex()));
}
const Grid& grid = m_algorithm.grid();
@@ -1164,6 +1178,7 @@
void GridTrackSizingAlgorithm::run()
{
+ ASSERT(wasSetup());
StateMachine stateMachine(*this);
// Step 1.
@@ -1197,6 +1212,7 @@
void GridTrackSizingAlgorithm::reset()
{
+ ASSERT(wasSetup());
m_sizingState = ColumnSizingFirstIteration;
m_columns.shrink(0);
m_rows.shrink(0);
Modified: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h (238113 => 238114)
--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h 2018-11-12 23:42:49 UTC (rev 238113)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h 2018-11-13 00:31:51 UTC (rev 238114)
@@ -102,11 +102,15 @@
// Required by RenderGrid. Try to minimize the exposed surface.
const Grid& grid() const { return m_grid; }
- GridTrackSize gridTrackSize(GridTrackSizingDirection, unsigned translatedIndex) const;
+ // FIXME (jfernandez): We should remove any public getter for this attribute
+ // and encapsulate any access in the algorithm class.
+ Grid& mutableGrid() const { return m_grid; }
LayoutUnit minContentSize() const { return m_minContentSize; };
LayoutUnit maxContentSize() const { return m_maxContentSize; };
+ LayoutSize estimatedGridAreaBreadthForChild(const RenderBox&) const;
+
Vector<GridTrack>& tracks(GridTrackSizingDirection direction) { return direction == ForColumns ? m_columns : m_rows; }
const Vector<GridTrack>& tracks(GridTrackSizingDirection direction) const { return direction == ForColumns ? m_columns : m_rows; }
@@ -126,8 +130,9 @@
private:
std::optional<LayoutUnit> availableSpace() const { return availableSpace(m_direction); }
+ bool isRelativeGridLengthAsAuto(const GridLength&, GridTrackSizingDirection) const;
+ GridTrackSize gridTrackSize(GridTrackSizingDirection, unsigned translatedIndex) const;
const GridTrackSize& rawGridTrackSize(GridTrackSizingDirection, unsigned translatedIndex) const;
- LayoutUnit assumedRowsSizeForOrthogonalChild(const RenderBox&) const;
// Helper methods for step 1. initializeTrackSizes().
LayoutUnit initialBaseSize(const GridTrackSize&) const;
@@ -140,6 +145,7 @@
template <TrackSizeComputationPhase phase> void increaseSizesToAccommodateSpanningItems(const GridItemsSpanGroupRange& gridItemsWithSpan);
LayoutUnit itemSizeForTrackSizeComputationPhase(TrackSizeComputationPhase, RenderBox&) const;
template <TrackSizeComputationPhase phase> void distributeSpaceToTracks(Vector<GridTrack*>& tracks, Vector<GridTrack*>* growBeyondGrowthLimitsTracks, LayoutUnit& availableLogicalSpace) const;
+ LayoutUnit estimatedGridAreaBreadthForChild(const RenderBox&, GridTrackSizingDirection) const;
LayoutUnit gridAreaBreadthForChild(const RenderBox&, GridTrackSizingDirection) const;
void computeGridContainerIntrinsicSizes();
@@ -162,6 +168,8 @@
void advanceNextState();
bool isValidTransition() const;
+ // Data.
+ bool wasSetup() const { return !!m_strategy; }
bool m_needsSetup { true };
bool m_hasPercentSizedRowsIndefiniteHeight { false };
std::optional<LayoutUnit> m_availableSpaceRows;
@@ -239,6 +247,8 @@
LayoutUnit logicalHeightForChild(RenderBox&) const;
bool updateOverrideContainingBlockContentSizeForChild(RenderBox&, GridTrackSizingDirection, std::optional<LayoutUnit> = std::nullopt) const;
+ GridTrackSize gridTrackSize(GridTrackSizingDirection direction, size_t translatedIndex) const { return m_algorithm.gridTrackSize(direction, translatedIndex); }
+
// GridTrackSizingAlgorithm accessors for subclasses.
LayoutUnit computeTrackBasedSize() const { return m_algorithm.computeTrackBasedSize(); }
GridTrackSizingDirection direction() const { return m_algorithm.m_direction; }
Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (238113 => 238114)
--- trunk/Source/WebCore/rendering/RenderGrid.cpp 2018-11-12 23:42:49 UTC (rev 238113)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp 2018-11-13 00:31:51 UTC (rev 238114)
@@ -158,7 +158,7 @@
// a new cycle of the sizing algorithm; there may be more. In addition, not all the
// cases with orthogonal flows require this extra cycle; we need a more specific
// condition to detect whether child's min-content contribution has changed or not.
- if (m_grid.hasAnyOrthogonalGridItem() || m_trackSizingAlgorithm.hasAnyPercentSizedRowsIndefiniteHeight()) {
+ if (m_hasAnyOrthogonalItem || m_trackSizingAlgorithm.hasAnyPercentSizedRowsIndefiniteHeight()) {
computeTrackSizesForDefiniteSize(ForColumns, availableSpaceForColumns);
computeContentPositionAndDistributionOffset(ForColumns, m_trackSizingAlgorithm.freeSpace(ForColumns).value(), nonCollapsedTracks(ForColumns));
computeTrackSizesForDefiniteSize(ForRows, availableSpaceForRows);
@@ -194,17 +194,18 @@
// FIXME: Consider caching the hasDefiniteLogicalHeight value throughout the layout.
bool hasDefiniteLogicalHeight = hasOverrideContentLogicalHeight() || computeContentLogicalHeight(MainOrPreferredSize, style().logicalHeight(), std::nullopt);
- // We need to clear both own and containingBlock override sizes of orthogonal items to ensure we get the
- // same result when grid's intrinsic size is computed again in the updateLogicalWidth call bellow.
- if (sizesLogicalWidthToFitContent(MaxSize) || style().logicalWidth().isIntrinsicOrAuto()) {
- for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
- if (child->isOutOfFlowPositioned() || !GridLayoutFunctions::isOrthogonalChild(*this, *child))
- continue;
- child->clearOverrideContentSize();
- child->clearOverrideContainingBlockContentSize();
- child->setNeedsLayout();
- child->layoutIfNeeded();
- }
+ m_hasAnyOrthogonalItem = false;
+ for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
+ if (child->isOutOfFlowPositioned())
+ continue;
+ // Grid's layout logic controls the grid item's override height, hence we need to
+ // clear any override height set previously, so it doesn't interfere in current layout
+ // execution. Grid never uses the override width, that's why we don't need to clear it.
+ child->clearOverrideContentLogicalHeight();
+
+ // We may need to repeat the track sizing in case of any grid item was orthogonal.
+ if (GridLayoutFunctions::isOrthogonalChild(*this, *child))
+ m_hasAnyOrthogonalItem = true;
}
setLogicalHeight(0);
@@ -216,8 +217,10 @@
layoutExcludedChildren(relayoutChildren);
LayoutUnit availableSpaceForColumns = availableLogicalWidth();
- placeItemsOnGrid(m_grid, availableSpaceForColumns);
+ placeItemsOnGrid(m_trackSizingAlgorithm, availableSpaceForColumns);
+ performGridItemsPreLayout(m_trackSizingAlgorithm);
+
// 1- First, the track sizing algorithm is used to resolve the sizes of the
// grid columns.
// At this point the logical width is always definite as the above call to
@@ -235,7 +238,7 @@
if (!hasDefiniteLogicalHeight) {
m_minContentHeight = LayoutUnit();
m_maxContentHeight = LayoutUnit();
- computeTrackSizesForIndefiniteSize(m_trackSizingAlgorithm, ForRows, m_grid, *m_minContentHeight, *m_maxContentHeight);
+ computeTrackSizesForIndefiniteSize(m_trackSizingAlgorithm, ForRows, *m_minContentHeight, *m_maxContentHeight);
// FIXME: This should be really added to the intrinsic height in RenderBox::computeContentAndScrollbarLogicalHeightUsing().
// Remove this when that is fixed.
ASSERT(m_minContentHeight);
@@ -384,11 +387,13 @@
bool hadExcludedChildren = computePreferredWidthsForExcludedChildren(childMinWidth, childMaxWidth);
Grid grid(const_cast<RenderGrid&>(*this));
- placeItemsOnGrid(grid, std::nullopt);
-
GridTrackSizingAlgorithm algorithm(this, grid);
- computeTrackSizesForIndefiniteSize(algorithm, ForColumns, grid, minLogicalWidth, maxLogicalWidth);
+ placeItemsOnGrid(algorithm, std::nullopt);
+ performGridItemsPreLayout(algorithm);
+
+ computeTrackSizesForIndefiniteSize(algorithm, ForColumns, minLogicalWidth, maxLogicalWidth);
+
if (hadExcludedChildren) {
minLogicalWidth = std::max(minLogicalWidth, childMinWidth);
maxLogicalWidth = std::max(maxLogicalWidth, childMaxWidth);
@@ -399,8 +404,9 @@
maxLogicalWidth += scrollbarWidth;
}
-void RenderGrid::computeTrackSizesForIndefiniteSize(GridTrackSizingAlgorithm& algorithm, GridTrackSizingDirection direction, Grid& grid, LayoutUnit& minIntrinsicSize, LayoutUnit& maxIntrinsicSize) const
+void RenderGrid::computeTrackSizesForIndefiniteSize(GridTrackSizingAlgorithm& algorithm, GridTrackSizingDirection direction, LayoutUnit& minIntrinsicSize, LayoutUnit& maxIntrinsicSize) const
{
+ const Grid& grid = algorithm.grid();
algorithm.setup(direction, numTracks(direction, grid), IntrinsicSizeComputation, std::nullopt, std::nullopt);
algorithm.run();
@@ -557,13 +563,14 @@
return std::min(autoRepeatTracks, maxTracks - insertionPoint);
}
-// FIXME): We shouldn't have to pass the available logical width as argument. The problem is that
+// FIXME: We shouldn't have to pass the available logical width as argument. The problem is that
// availableLogicalWidth() does always return a value even if we cannot resolve it like when
// computing the intrinsic size (preferred widths). That's why we pass the responsibility to the
// caller who does know whether the available logical width is indefinite or not.
-void RenderGrid::placeItemsOnGrid(Grid& grid, std::optional<LayoutUnit> availableSpace) const
+void RenderGrid::placeItemsOnGrid(GridTrackSizingAlgorithm& algorithm, std::optional<LayoutUnit> availableLogicalWidth) const
{
- unsigned autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns, availableSpace);
+ Grid& grid = algorithm.mutableGrid();
+ unsigned autoRepeatColumns = computeAutoRepeatTracksCount(ForColumns, availableLogicalWidth);
unsigned autoRepeatRows = computeAutoRepeatTracksCount(ForRows, availableLogicalHeightForPercentageComputation());
autoRepeatRows = clampAutoRepeatTracks(ForRows, autoRepeatRows);
@@ -582,13 +589,10 @@
Vector<RenderBox*> autoMajorAxisAutoGridItems;
Vector<RenderBox*> specifiedMajorAxisAutoGridItems;
- bool hasAnyOrthogonalGridItem = false;
for (auto* child = grid.orderIterator().first(); child; child = grid.orderIterator().next()) {
if (grid.orderIterator().shouldSkipChild(*child))
continue;
- hasAnyOrthogonalGridItem = hasAnyOrthogonalGridItem || GridLayoutFunctions::isOrthogonalChild(*this, *child);
-
GridArea area = grid.gridItemArea(*child);
if (!area.rows.isIndefinite())
area.rows.translate(std::abs(grid.smallestTrackStart(ForRows)));
@@ -607,7 +611,6 @@
}
grid.insert(*child, { area.rows, area.columns });
}
- grid.setHasAnyOrthogonalGridItem(hasAnyOrthogonalGridItem);
#if !ASSERT_DISABLED
if (grid.hasGridItems()) {
@@ -636,6 +639,23 @@
#endif
}
+void RenderGrid::performGridItemsPreLayout(const GridTrackSizingAlgorithm& algorithm) const
+{
+ ASSERT(!algorithm.grid().needsItemsPlacement());
+ // FIXME: We need a way when we are calling this during intrinsic size compuation before performing
+ // the layout. Maybe using the PreLayout phase ?
+ for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
+ if (child->isOutOfFlowPositioned())
+ continue;
+ // Orthogonal items should be laid out in order to properly compute content-sized tracks that may depend on item's intrinsic size.
+ // We also need to properly estimate its grid area size, since it may affect to the baseline shims if such item particiaptes in baseline alignment.
+ if (GridLayoutFunctions::isOrthogonalChild(*this, *child)) {
+ updateGridAreaLogicalSize(*child, algorithm.estimatedGridAreaBreadthForChild(*child));
+ child->layoutIfNeeded();
+ }
+ }
+}
+
void RenderGrid::populateExplicitGridAndOrderIterator(Grid& grid) const
{
OrderIteratorPopulator populator(grid.orderIterator());
@@ -849,6 +869,31 @@
return normalBehavior;
}
+static bool overrideSizeChanged(const RenderBox& child, GridTrackSizingDirection direction, LayoutSize size)
+{
+ if (direction == ForColumns)
+ return !child.hasOverrideContainingBlockContentLogicalWidth() || child.overrideContainingBlockContentLogicalWidth() != size.width();
+ return !child.hasOverrideContainingBlockContentLogicalHeight() || child.overrideContainingBlockContentLogicalHeight() != size.height();
+}
+
+static bool hasRelativeBlockAxisSize(const RenderGrid& grid, const RenderBox& child)
+{
+ return GridLayoutFunctions::isOrthogonalChild(grid, child) ? child.hasRelativeLogicalWidth() || child.style().logicalWidth().isAuto() : child.hasRelativeLogicalHeight();
+}
+
+void RenderGrid::updateGridAreaLogicalSize(RenderBox& child, LayoutSize gridAreaLogicalSize) const
+{
+ // Because the grid area cannot be styled, we don't need to adjust
+ // the grid breadth to account for 'box-sizing'.
+ bool gridAreaWidthChanged = overrideSizeChanged(child, ForColumns, gridAreaLogicalSize);
+ bool gridAreaHeightChanged = overrideSizeChanged(child, ForRows, gridAreaLogicalSize);
+ if (gridAreaWidthChanged || (gridAreaHeightChanged && hasRelativeBlockAxisSize(*this, child)))
+ child.setNeedsLayout(MarkOnlyThis);
+
+ child.setOverrideContainingBlockContentLogicalWidth(gridAreaLogicalSize.width());
+ child.setOverrideContainingBlockContentLogicalHeight(gridAreaLogicalSize.height());
+}
+
void RenderGrid::layoutGridItems()
{
populateGridPositionsForDirection(ForColumns);
@@ -862,21 +907,11 @@
continue;
}
- // Because the grid area cannot be styled, we don't need to adjust
- // the grid breadth to account for 'box-sizing'.
- std::optional<LayoutUnit> oldOverrideContainingBlockContentLogicalWidth = child->hasOverrideContainingBlockContentLogicalWidth() ? child->overrideContainingBlockContentLogicalWidth() : LayoutUnit();
- std::optional<LayoutUnit> oldOverrideContainingBlockContentLogicalHeight = child->hasOverrideContainingBlockContentLogicalHeight() ? child->overrideContainingBlockContentLogicalHeight() : LayoutUnit();
+ // Setting the definite grid area's sizes. It may imply that the
+ // item must perform a layout if its area differs from the one
+ // used during the track sizing algorithm.
+ updateGridAreaLogicalSize(*child, LayoutSize(gridAreaBreadthForChildIncludingAlignmentOffsets(*child, ForColumns), gridAreaBreadthForChildIncludingAlignmentOffsets(*child, ForRows)));
- LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForChildIncludingAlignmentOffsets(*child, ForColumns);
- LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadthForChildIncludingAlignmentOffsets(*child, ForRows);
- if (!oldOverrideContainingBlockContentLogicalWidth || oldOverrideContainingBlockContentLogicalWidth.value() != overrideContainingBlockContentLogicalWidth
- || ((!oldOverrideContainingBlockContentLogicalHeight || oldOverrideContainingBlockContentLogicalHeight.value() != overrideContainingBlockContentLogicalHeight)
- && child->hasRelativeLogicalHeight()))
- child->setNeedsLayout(MarkOnlyThis);
-
- child->setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockContentLogicalWidth);
- child->setOverrideContainingBlockContentLogicalHeight(overrideContainingBlockContentLogicalHeight);
-
LayoutRect oldChildRect = child->frameRect();
// Stretching logic might force a child layout, so we need to run it before the layoutIfNeeded
Modified: trunk/Source/WebCore/rendering/RenderGrid.h (238113 => 238114)
--- trunk/Source/WebCore/rendering/RenderGrid.h 2018-11-12 23:42:49 UTC (rev 238113)
+++ trunk/Source/WebCore/rendering/RenderGrid.h 2018-11-13 00:31:51 UTC (rev 238114)
@@ -74,6 +74,8 @@
LayoutUnit guttersSize(const Grid&, GridTrackSizingDirection, unsigned startLine, unsigned span, std::optional<LayoutUnit> availableSize) const;
LayoutUnit gridItemOffset(GridTrackSizingDirection) const;
+ void updateGridAreaLogicalSize(RenderBox&, LayoutSize) const;
+
StyleContentAlignmentData contentAlignment(GridTrackSizingDirection) const;
protected:
@@ -105,7 +107,9 @@
std::unique_ptr<OrderedTrackIndexSet> computeEmptyTracksForAutoRepeat(Grid&, GridTrackSizingDirection) const;
- void placeItemsOnGrid(Grid&, std::optional<LayoutUnit> availableSpaceForColumns) const;
+ void performGridItemsPreLayout(const GridTrackSizingAlgorithm&) const;
+
+ void placeItemsOnGrid(GridTrackSizingAlgorithm&, std::optional<LayoutUnit> availableLogicalWidth) const;
void populateExplicitGridAndOrderIterator(Grid&) const;
std::unique_ptr<GridArea> createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(Grid&, const RenderBox&, GridTrackSizingDirection, const GridSpan&) const;
void placeSpecifiedMajorAxisItemsOnGrid(Grid&, const Vector<RenderBox*>&) const;
@@ -121,7 +125,7 @@
void layoutPositionedObject(RenderBox&, bool relayoutChildren, bool fixedPositionObjectsOnly) override;
void computeTrackSizesForDefiniteSize(GridTrackSizingDirection, LayoutUnit availableSpace);
- void computeTrackSizesForIndefiniteSize(GridTrackSizingAlgorithm&, GridTrackSizingDirection, Grid&, LayoutUnit& minIntrinsicSize, LayoutUnit& maxIntrinsicSize) const;
+ void computeTrackSizesForIndefiniteSize(GridTrackSizingAlgorithm&, GridTrackSizingDirection, LayoutUnit& minIntrinsicSize, LayoutUnit& maxIntrinsicSize) const;
LayoutUnit computeTrackBasedLogicalHeight() const;
void repeatTracksSizingIfNeeded(LayoutUnit availableSpaceForColumns, LayoutUnit availableSpaceForRows);
@@ -193,6 +197,8 @@
std::optional<LayoutUnit> m_minContentHeight;
std::optional<LayoutUnit> m_maxContentHeight;
+
+ bool m_hasAnyOrthogonalItem {false};
};
} // namespace WebCore