Changeset 173427 in webkit for trunk/Source/WebCore/rendering/RenderGrid.cpp
- Timestamp:
- Sep 9, 2014, 4:39:41 AM (11 years ago)
- File:
-
- 1 edited
-
trunk/Source/WebCore/rendering/RenderGrid.cpp (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/rendering/RenderGrid.cpp
r171102 r173427 361 361 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i]); 362 362 while (RenderBox* gridItem = iterator.nextGridItem()) { 363 const GridCoordinate coordinate = cachedGridCoordinate( gridItem);363 const GridCoordinate coordinate = cachedGridCoordinate(*gridItem); 364 364 const GridSpan span = (direction == ForColumns) ? coordinate.columns : coordinate.rows; 365 365 … … 368 368 continue; 369 369 370 double itemNormalizedFlexBreadth = computeNormalizedFractionBreadth(tracks, span, direction, maxContentForChild( gridItem, direction, sizingData.columnTracks));370 double itemNormalizedFlexBreadth = computeNormalizedFractionBreadth(tracks, span, direction, maxContentForChild(*gridItem, direction, sizingData.columnTracks)); 371 371 normalizedFractionBreadth = std::max(normalizedFractionBreadth, itemNormalizedFlexBreadth); 372 372 } … … 485 485 } 486 486 487 LayoutUnit RenderGrid::logicalContentHeightForChild(RenderBox *child, Vector<GridTrack>& columnTracks)488 { 489 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child ->hasOverrideContainingBlockLogicalWidth() ? child->overrideContainingBlockContentLogicalWidth() : LayoutUnit();487 LayoutUnit RenderGrid::logicalContentHeightForChild(RenderBox& child, Vector<GridTrack>& columnTracks) 488 { 489 LayoutUnit oldOverrideContainingBlockContentLogicalWidth = child.hasOverrideContainingBlockLogicalWidth() ? child.overrideContainingBlockContentLogicalWidth() : LayoutUnit(); 490 490 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForChild(child, ForColumns, columnTracks); 491 if (child ->style().logicalHeight().isPercent() || oldOverrideContainingBlockContentLogicalWidth != overrideContainingBlockContentLogicalWidth)492 child ->setNeedsLayout(MarkOnlyThis);493 494 child ->setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockContentLogicalWidth);491 if (child.style().logicalHeight().isPercent() || oldOverrideContainingBlockContentLogicalWidth != overrideContainingBlockContentLogicalWidth) 492 child.setNeedsLayout(MarkOnlyThis); 493 494 child.setOverrideContainingBlockContentLogicalWidth(overrideContainingBlockContentLogicalWidth); 495 495 // If |child| has a percentage logical height, we shouldn't let it override its intrinsic height, which is 496 496 // what we are interested in here. Thus we need to set the override logical height to -1 (no possible resolution). 497 child ->setOverrideContainingBlockContentLogicalHeight(-1);498 child ->layoutIfNeeded();499 return child ->logicalHeight() + child->marginLogicalHeight();500 } 501 502 LayoutUnit RenderGrid::minContentForChild(RenderBox *child, GridTrackSizingDirection direction, Vector<GridTrack>& columnTracks)503 { 504 bool hasOrthogonalWritingMode = child ->isHorizontalWritingMode() != isHorizontalWritingMode();497 child.setOverrideContainingBlockContentLogicalHeight(-1); 498 child.layoutIfNeeded(); 499 return child.logicalHeight() + child.marginLogicalHeight(); 500 } 501 502 LayoutUnit RenderGrid::minContentForChild(RenderBox& child, GridTrackSizingDirection direction, Vector<GridTrack>& columnTracks) 503 { 504 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizontalWritingMode(); 505 505 // FIXME: Properly support orthogonal writing mode. 506 506 if (hasOrthogonalWritingMode) … … 510 510 // FIXME: It's unclear if we should return the intrinsic width or the preferred width. 511 511 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html 512 return child ->minPreferredLogicalWidth() + marginIntrinsicLogicalWidthForChild(*child);512 return child.minPreferredLogicalWidth() + marginIntrinsicLogicalWidthForChild(child); 513 513 } 514 514 … … 516 516 } 517 517 518 LayoutUnit RenderGrid::maxContentForChild(RenderBox *child, GridTrackSizingDirection direction, Vector<GridTrack>& columnTracks)519 { 520 bool hasOrthogonalWritingMode = child ->isHorizontalWritingMode() != isHorizontalWritingMode();518 LayoutUnit RenderGrid::maxContentForChild(RenderBox& child, GridTrackSizingDirection direction, Vector<GridTrack>& columnTracks) 519 { 520 bool hasOrthogonalWritingMode = child.isHorizontalWritingMode() != isHorizontalWritingMode(); 521 521 // FIXME: Properly support orthogonal writing mode. 522 522 if (hasOrthogonalWritingMode) … … 526 526 // FIXME: It's unclear if we should return the intrinsic width or the preferred width. 527 527 // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html 528 return child ->maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthForChild(*child);528 return child.maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthForChild(child); 529 529 } 530 530 … … 539 539 GridIterator iterator(m_grid, direction, sizingData.contentSizedTracksIndex[i]); 540 540 while (RenderBox* gridItem = iterator.nextGridItem()) { 541 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, gridItem, &GridTrackSize::hasMinOrMaxContentMinTrackBreadth, &RenderGrid::minContentForChild, &GridTrack::usedBreadth, &GridTrack::growUsedBreadth);542 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, gridItem, &GridTrackSize::hasMaxContentMinTrackBreadth, &RenderGrid::maxContentForChild, &GridTrack::usedBreadth, &GridTrack::growUsedBreadth);543 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, gridItem, &GridTrackSize::hasMinOrMaxContentMaxTrackBreadth, &RenderGrid::minContentForChild, &GridTrack::maxBreadthIfNotInfinite, &GridTrack::growMaxBreadth);544 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, gridItem, &GridTrackSize::hasMaxContentMaxTrackBreadth, &RenderGrid::maxContentForChild, &GridTrack::maxBreadthIfNotInfinite, &GridTrack::growMaxBreadth);541 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, *gridItem, &GridTrackSize::hasMinOrMaxContentMinTrackBreadth, &RenderGrid::minContentForChild, &GridTrack::usedBreadth, &GridTrack::growUsedBreadth); 542 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, *gridItem, &GridTrackSize::hasMaxContentMinTrackBreadth, &RenderGrid::maxContentForChild, &GridTrack::usedBreadth, &GridTrack::growUsedBreadth); 543 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, *gridItem, &GridTrackSize::hasMinOrMaxContentMaxTrackBreadth, &RenderGrid::minContentForChild, &GridTrack::maxBreadthIfNotInfinite, &GridTrack::growMaxBreadth); 544 resolveContentBasedTrackSizingFunctionsForItems(direction, sizingData, *gridItem, &GridTrackSize::hasMaxContentMaxTrackBreadth, &RenderGrid::maxContentForChild, &GridTrack::maxBreadthIfNotInfinite, &GridTrack::growMaxBreadth); 545 545 } 546 546 … … 551 551 } 552 552 553 void RenderGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizingDirection direction, GridSizingData& sizingData, RenderBox *gridItem, FilterFunction filterFunction, SizingFunction sizingFunction, AccumulatorGetter trackGetter, AccumulatorGrowFunction trackGrowthFunction)553 void RenderGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizingDirection direction, GridSizingData& sizingData, RenderBox& gridItem, FilterFunction filterFunction, SizingFunction sizingFunction, AccumulatorGetter trackGetter, AccumulatorGrowFunction trackGrowthFunction) 554 554 { 555 555 const GridCoordinate coordinate = cachedGridCoordinate(gridItem); … … 646 646 } 647 647 648 void RenderGrid::insertItemIntoGrid(RenderBox *child, const GridCoordinate& coordinate)648 void RenderGrid::insertItemIntoGrid(RenderBox& child, const GridCoordinate& coordinate) 649 649 { 650 650 ensureGridSize(coordinate.rows.resolvedFinalPosition.toInt(), coordinate.columns.resolvedFinalPosition.toInt()); … … 652 652 for (auto row : coordinate.rows) { 653 653 for (auto column : coordinate.columns) 654 m_grid[row.toInt()][column.toInt()].append( child);655 } 656 m_gridItemCoordinate.set( child, coordinate);654 m_grid[row.toInt()][column.toInt()].append(&child); 655 } 656 m_gridItemCoordinate.set(&child, coordinate); 657 657 } 658 658 … … 679 679 continue; 680 680 } 681 insertItemIntoGrid( child, GridCoordinate(*rowPositions, *columnPositions));681 insertItemIntoGrid(*child, GridCoordinate(*rowPositions, *columnPositions)); 682 682 } 683 683 … … 733 733 } 734 734 735 std::unique_ptr<GridCoordinate> RenderGrid::createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(const RenderBox *gridItem, GridTrackSizingDirection specifiedDirection, const GridSpan& specifiedPositions) const735 std::unique_ptr<GridCoordinate> RenderGrid::createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(const RenderBox& gridItem, GridTrackSizingDirection specifiedDirection, const GridSpan& specifiedPositions) const 736 736 { 737 737 GridTrackSizingDirection crossDirection = specifiedDirection == ForColumns ? ForRows : ForColumns; 738 738 const size_t endOfCrossDirection = crossDirection == ForColumns ? gridColumnCount() : gridRowCount(); 739 GridSpan crossDirectionPositions = GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(style(), *gridItem, crossDirection, GridResolvedPosition(endOfCrossDirection));739 GridSpan crossDirectionPositions = GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(style(), gridItem, crossDirection, GridResolvedPosition(endOfCrossDirection)); 740 740 return std::make_unique<GridCoordinate>(specifiedDirection == ForColumns ? crossDirectionPositions : specifiedPositions, specifiedDirection == ForColumns ? specifiedPositions : crossDirectionPositions); 741 741 } … … 750 750 std::unique_ptr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(majorAxisPositions->integerSpan(), minorAxisPositions.integerSpan()); 751 751 if (!emptyGridArea) 752 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid( autoGridItem, autoPlacementMajorAxisDirection(), *majorAxisPositions);753 insertItemIntoGrid( autoGridItem, *emptyGridArea);752 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(*autoGridItem, autoPlacementMajorAxisDirection(), *majorAxisPositions); 753 insertItemIntoGrid(*autoGridItem, *emptyGridArea); 754 754 } 755 755 } … … 761 761 762 762 for (auto& autoGridItem : autoGridItems) { 763 placeAutoMajorAxisItemOnGrid( autoGridItem, autoPlacementCursor);763 placeAutoMajorAxisItemOnGrid(*autoGridItem, autoPlacementCursor); 764 764 765 765 if (isGridAutoFlowDense) { … … 770 770 } 771 771 772 void RenderGrid::placeAutoMajorAxisItemOnGrid(RenderBox *gridItem, AutoPlacementCursor& autoPlacementCursor)773 { 774 std::unique_ptr<GridSpan> minorAxisPositions = GridResolvedPosition::resolveGridPositionsFromStyle(style(), *gridItem, autoPlacementMinorAxisDirection());775 ASSERT(!GridResolvedPosition::resolveGridPositionsFromStyle(style(), *gridItem, autoPlacementMajorAxisDirection()));776 GridSpan majorAxisPositions = GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(style(), *gridItem, autoPlacementMajorAxisDirection(), GridResolvedPosition(0));772 void RenderGrid::placeAutoMajorAxisItemOnGrid(RenderBox& gridItem, AutoPlacementCursor& autoPlacementCursor) 773 { 774 std::unique_ptr<GridSpan> minorAxisPositions = GridResolvedPosition::resolveGridPositionsFromStyle(style(), gridItem, autoPlacementMinorAxisDirection()); 775 ASSERT(!GridResolvedPosition::resolveGridPositionsFromStyle(style(), gridItem, autoPlacementMajorAxisDirection())); 776 GridSpan majorAxisPositions = GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(style(), gridItem, autoPlacementMajorAxisDirection(), GridResolvedPosition(0)); 777 777 778 778 const size_t endOfMajorAxis = (autoPlacementMajorAxisDirection() == ForColumns) ? gridColumnCount() : gridRowCount(); … … 794 794 emptyGridArea = createEmptyGridAreaAtSpecifiedPositionsOutsideGrid(gridItem, autoPlacementMinorAxisDirection(), *minorAxisPositions); 795 795 } else { 796 GridSpan minorAxisPositions = GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(style(), *gridItem, autoPlacementMinorAxisDirection(), GridResolvedPosition(0));796 GridSpan minorAxisPositions = GridResolvedPosition::resolveGridPositionsFromAutoPlacementPosition(style(), gridItem, autoPlacementMinorAxisDirection(), GridResolvedPosition(0)); 797 797 798 798 for (size_t majorAxisIndex = majorAxisAutoPlacementCursor; majorAxisIndex < endOfMajorAxis; ++majorAxisIndex) { … … 859 859 LayoutUnit oldOverrideContainingBlockContentLogicalHeight = child->hasOverrideContainingBlockLogicalHeight() ? child->overrideContainingBlockContentLogicalHeight() : LayoutUnit(); 860 860 861 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForChild( child, ForColumns, sizingData.columnTracks);862 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadthForChild( child, ForRows, sizingData.rowTracks);861 LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForChild(*child, ForColumns, sizingData.columnTracks); 862 LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadthForChild(*child, ForRows, sizingData.rowTracks); 863 863 if (oldOverrideContainingBlockContentLogicalWidth != overrideContainingBlockContentLogicalWidth || (oldOverrideContainingBlockContentLogicalHeight != overrideContainingBlockContentLogicalHeight && child->hasRelativeLogicalHeight())) 864 864 child->setNeedsLayout(MarkOnlyThis); … … 874 874 child->layoutIfNeeded(); 875 875 876 child->setLogicalLocation(findChildLogicalPosition( child, sizingData));876 child->setLogicalLocation(findChildLogicalPosition(*child, sizingData)); 877 877 878 878 // If the child moved, we have to repaint it as well as any floating/positioned … … 891 891 } 892 892 893 GridCoordinate RenderGrid::cachedGridCoordinate(const RenderBox *gridItem) const894 { 895 ASSERT(m_gridItemCoordinate.contains( gridItem));896 return m_gridItemCoordinate.get( gridItem);897 } 898 899 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox *child, GridTrackSizingDirection direction, const Vector<GridTrack>& tracks) const893 GridCoordinate RenderGrid::cachedGridCoordinate(const RenderBox& gridItem) const 894 { 895 ASSERT(m_gridItemCoordinate.contains(&gridItem)); 896 return m_gridItemCoordinate.get(&gridItem); 897 } 898 899 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox& child, GridTrackSizingDirection direction, const Vector<GridTrack>& tracks) const 900 900 { 901 901 const GridCoordinate& coordinate = cachedGridCoordinate(child); … … 920 920 } 921 921 922 LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox *child, const GridSizingData& sizingData)922 LayoutPoint RenderGrid::findChildLogicalPosition(RenderBox& child, const GridSizingData& sizingData) 923 923 { 924 924 const GridCoordinate& coordinate = cachedGridCoordinate(child); … … 927 927 928 928 // The grid items should be inside the grid container's border box, that's why they need to be shifted. 929 return LayoutPoint(m_columnPositions[coordinate.columns.resolvedInitialPosition.toInt()] + marginStartForChild( *child), m_rowPositions[coordinate.rows.resolvedInitialPosition.toInt()] + marginBeforeForChild(*child));929 return LayoutPoint(m_columnPositions[coordinate.columns.resolvedInitialPosition.toInt()] + marginStartForChild(child), m_rowPositions[coordinate.rows.resolvedInitialPosition.toInt()] + marginBeforeForChild(child)); 930 930 } 931 931
Note:
See TracChangeset
for help on using the changeset viewer.