| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 return; | 191 return; |
| 192 } | 192 } |
| 193 | 193 |
| 194 RenderBox* newChildBox = toRenderBox(newChild); | 194 RenderBox* newChildBox = toRenderBox(newChild); |
| 195 OwnPtr<GridSpan> rowPositions = resolveGridPositionsFromStyle(newChildBox, F
orRows); | 195 OwnPtr<GridSpan> rowPositions = resolveGridPositionsFromStyle(newChildBox, F
orRows); |
| 196 OwnPtr<GridSpan> columnPositions = resolveGridPositionsFromStyle(newChildBox
, ForColumns); | 196 OwnPtr<GridSpan> columnPositions = resolveGridPositionsFromStyle(newChildBox
, ForColumns); |
| 197 if (!rowPositions || !columnPositions) { | 197 if (!rowPositions || !columnPositions) { |
| 198 // The new child requires the auto-placement algorithm to run so we need
to recompute the grid fully. | 198 // The new child requires the auto-placement algorithm to run so we need
to recompute the grid fully. |
| 199 dirtyGrid(); | 199 dirtyGrid(); |
| 200 } else { | 200 } else { |
| 201 if (gridRowCount() <= rowPositions->finalPositionIndex || gridColumnCoun
t() <= columnPositions->finalPositionIndex) { | 201 if (gridRowCount() <= rowPositions->finalPositionIndex.integerPosition()
|| gridColumnCount() <= columnPositions->finalPositionIndex.integerPosition())
{ |
| 202 // FIXME: We could just insert the new child provided we had a primi
tive to arbitrarily grow the grid. | 202 // FIXME: We could just insert the new child provided we had a primi
tive to arbitrarily grow the grid. |
| 203 dirtyGrid(); | 203 dirtyGrid(); |
| 204 } else { | 204 } else { |
| 205 insertItemIntoGrid(newChildBox, GridCoordinate(*rowPositions, *colum
nPositions)); | 205 insertItemIntoGrid(newChildBox, GridCoordinate(*rowPositions, *colum
nPositions)); |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 | 209 |
| 210 void RenderGrid::removeChild(RenderObject* child) | 210 void RenderGrid::removeChild(RenderObject* child) |
| 211 { | 211 { |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 normalizedFractionBreadth = std::max(normalizedFractionBreadth, trac
ks[trackIndex].m_usedBreadth / trackSize.maxTrackBreadth().flex()); | 415 normalizedFractionBreadth = std::max(normalizedFractionBreadth, trac
ks[trackIndex].m_usedBreadth / trackSize.maxTrackBreadth().flex()); |
| 416 } | 416 } |
| 417 | 417 |
| 418 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { | 418 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { |
| 419 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i]
); | 419 GridIterator iterator(m_grid, direction, flexibleSizedTracksIndex[i]
); |
| 420 while (RenderBox* gridItem = iterator.nextGridItem()) { | 420 while (RenderBox* gridItem = iterator.nextGridItem()) { |
| 421 const GridCoordinate coordinate = cachedGridCoordinate(gridItem)
; | 421 const GridCoordinate coordinate = cachedGridCoordinate(gridItem)
; |
| 422 const GridSpan span = (direction == ForColumns) ? coordinate.col
umns : coordinate.rows; | 422 const GridSpan span = (direction == ForColumns) ? coordinate.col
umns : coordinate.rows; |
| 423 | 423 |
| 424 // Do not include already processed items. | 424 // Do not include already processed items. |
| 425 if (i > 0 && span.initialPositionIndex <= flexibleSizedTracksInd
ex[i - 1]) | 425 if (i > 0 && span.initialPositionIndex.integerPosition() <= flex
ibleSizedTracksIndex[i - 1]) |
| 426 continue; | 426 continue; |
| 427 | 427 |
| 428 double itemNormalizedFlexBreadth = computeNormalizedFractionBrea
dth(tracks, span, direction, maxContentForChild(gridItem, direction, sizingData.
columnTracks)); | 428 double itemNormalizedFlexBreadth = computeNormalizedFractionBrea
dth(tracks, span, direction, maxContentForChild(gridItem, direction, sizingData.
columnTracks)); |
| 429 normalizedFractionBreadth = std::max(normalizedFractionBreadth,
itemNormalizedFlexBreadth); | 429 normalizedFractionBreadth = std::max(normalizedFractionBreadth,
itemNormalizedFlexBreadth); |
| 430 } | 430 } |
| 431 } | 431 } |
| 432 } | 432 } |
| 433 | 433 |
| 434 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { | 434 for (size_t i = 0; i < flexibleSizedTracksIndex.size(); ++i) { |
| 435 const size_t trackIndex = flexibleSizedTracksIndex[i]; | 435 const size_t trackIndex = flexibleSizedTracksIndex[i]; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 static bool sortByGridNormalizedFlexValue(const GridTrackForNormalization& track
1, const GridTrackForNormalization& track2) | 480 static bool sortByGridNormalizedFlexValue(const GridTrackForNormalization& track
1, const GridTrackForNormalization& track2) |
| 481 { | 481 { |
| 482 return track1.m_normalizedFlexValue < track2.m_normalizedFlexValue; | 482 return track1.m_normalizedFlexValue < track2.m_normalizedFlexValue; |
| 483 } | 483 } |
| 484 | 484 |
| 485 double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, c
onst GridSpan& tracksSpan, GridTrackSizingDirection direction, LayoutUnit availa
bleLogicalSpace) const | 485 double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, c
onst GridSpan& tracksSpan, GridTrackSizingDirection direction, LayoutUnit availa
bleLogicalSpace) const |
| 486 { | 486 { |
| 487 // |availableLogicalSpace| already accounts for the used breadths so no need
to remove it here. | 487 // |availableLogicalSpace| already accounts for the used breadths so no need
to remove it here. |
| 488 | 488 |
| 489 Vector<GridTrackForNormalization> tracksForNormalization; | 489 Vector<GridTrackForNormalization> tracksForNormalization; |
| 490 for (size_t i = tracksSpan.initialPositionIndex; i <= tracksSpan.finalPositi
onIndex; ++i) { | 490 for (size_t i = tracksSpan.initialPositionIndex.integerPosition(); i <= trac
ksSpan.finalPositionIndex.integerPosition(); ++i) { |
| 491 const GridTrackSize& trackSize = gridTrackSize(direction, i); | 491 const GridTrackSize& trackSize = gridTrackSize(direction, i); |
| 492 if (!trackSize.maxTrackBreadth().isFlex()) | 492 if (!trackSize.maxTrackBreadth().isFlex()) |
| 493 continue; | 493 continue; |
| 494 | 494 |
| 495 tracksForNormalization.append(GridTrackForNormalization(tracks[i], track
Size.maxTrackBreadth().flex())); | 495 tracksForNormalization.append(GridTrackForNormalization(tracks[i], track
Size.maxTrackBreadth().flex())); |
| 496 } | 496 } |
| 497 | 497 |
| 498 // The function is not called if we don't have <flex> grid tracks | 498 // The function is not called if we don't have <flex> grid tracks |
| 499 ASSERT(!tracksForNormalization.isEmpty()); | 499 ASSERT(!tracksForNormalization.isEmpty()); |
| 500 | 500 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 | 625 |
| 626 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[i
] : sizingData.rowTracks[i]; | 626 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[i
] : sizingData.rowTracks[i]; |
| 627 if (track.m_maxBreadth == infinity) | 627 if (track.m_maxBreadth == infinity) |
| 628 track.m_maxBreadth = track.m_usedBreadth; | 628 track.m_maxBreadth = track.m_usedBreadth; |
| 629 } | 629 } |
| 630 } | 630 } |
| 631 | 631 |
| 632 void RenderGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing
Direction direction, GridSizingData& sizingData, RenderBox* gridItem, FilterFunc
tion filterFunction, SizingFunction sizingFunction, AccumulatorGetter trackGette
r, AccumulatorGrowFunction trackGrowthFunction) | 632 void RenderGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing
Direction direction, GridSizingData& sizingData, RenderBox* gridItem, FilterFunc
tion filterFunction, SizingFunction sizingFunction, AccumulatorGetter trackGette
r, AccumulatorGrowFunction trackGrowthFunction) |
| 633 { | 633 { |
| 634 const GridCoordinate coordinate = cachedGridCoordinate(gridItem); | 634 const GridCoordinate coordinate = cachedGridCoordinate(gridItem); |
| 635 const size_t initialTrackIndex = (direction == ForColumns) ? coordinate.colu
mns.initialPositionIndex : coordinate.rows.initialPositionIndex; | 635 const size_t initialTrackIndex = (direction == ForColumns) ? coordinate.colu
mns.initialPositionIndex.integerPosition() : coordinate.rows.initialPositionInde
x.integerPosition(); |
| 636 const size_t finalTrackIndex = (direction == ForColumns) ? coordinate.column
s.finalPositionIndex : coordinate.rows.finalPositionIndex; | 636 const size_t finalTrackIndex = (direction == ForColumns) ? coordinate.column
s.finalPositionIndex.integerPosition() : coordinate.rows.finalPositionIndex.inte
gerPosition(); |
| 637 | 637 |
| 638 sizingData.filteredTracks.shrink(0); | 638 sizingData.filteredTracks.shrink(0); |
| 639 for (size_t trackIndex = initialTrackIndex; trackIndex <= finalTrackIndex; +
+trackIndex) { | 639 for (size_t trackIndex = initialTrackIndex; trackIndex <= finalTrackIndex; +
+trackIndex) { |
| 640 const GridTrackSize& trackSize = gridTrackSize(direction, trackIndex); | 640 const GridTrackSize& trackSize = gridTrackSize(direction, trackIndex); |
| 641 if (!(trackSize.*filterFunction)()) | 641 if (!(trackSize.*filterFunction)()) |
| 642 continue; | 642 continue; |
| 643 | 643 |
| 644 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t
rackIndex] : sizingData.rowTracks[trackIndex]; | 644 GridTrack& track = (direction == ForColumns) ? sizingData.columnTracks[t
rackIndex] : sizingData.rowTracks[trackIndex]; |
| 645 sizingData.filteredTracks.append(&track); | 645 sizingData.filteredTracks.append(&track); |
| 646 } | 646 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 m_grid[row].grow(oldColumnSize + 1); | 720 m_grid[row].grow(oldColumnSize + 1); |
| 721 } else { | 721 } else { |
| 722 const size_t oldRowSize = m_grid.size(); | 722 const size_t oldRowSize = m_grid.size(); |
| 723 m_grid.grow(oldRowSize + 1); | 723 m_grid.grow(oldRowSize + 1); |
| 724 m_grid[oldRowSize].grow(m_grid[0].size()); | 724 m_grid[oldRowSize].grow(m_grid[0].size()); |
| 725 } | 725 } |
| 726 } | 726 } |
| 727 | 727 |
| 728 void RenderGrid::insertItemIntoGrid(RenderBox* child, const GridCoordinate& coor
dinate) | 728 void RenderGrid::insertItemIntoGrid(RenderBox* child, const GridCoordinate& coor
dinate) |
| 729 { | 729 { |
| 730 for (size_t row = coordinate.rows.initialPositionIndex; row <= coordinate.ro
ws.finalPositionIndex; ++row) { | 730 for (size_t row = coordinate.rows.initialPositionIndex.integerPosition(); ro
w <= coordinate.rows.finalPositionIndex.integerPosition(); ++row) { |
| 731 for (size_t column = coordinate.columns.initialPositionIndex; column <=
coordinate.columns.finalPositionIndex; ++column) | 731 for (size_t column = coordinate.columns.initialPositionIndex.integerPosi
tion(); column <= coordinate.columns.finalPositionIndex.integerPosition(); ++col
umn) |
| 732 m_grid[row][column].append(child); | 732 m_grid[row][column].append(child); |
| 733 } | 733 } |
| 734 | 734 |
| 735 m_gridItemCoordinate.set(child, coordinate); | 735 m_gridItemCoordinate.set(child, coordinate); |
| 736 } | 736 } |
| 737 | 737 |
| 738 void RenderGrid::insertItemIntoGrid(RenderBox* child, size_t rowTrack, size_t co
lumnTrack) | 738 void RenderGrid::insertItemIntoGrid(RenderBox* child, size_t rowTrack, size_t co
lumnTrack) |
| 739 { | 739 { |
| 740 const GridSpan& rowSpan = resolveGridPositionsFromAutoPlacementPosition(chil
d, ForRows, rowTrack); | 740 const GridSpan& rowSpan = resolveGridPositionsFromAutoPlacementPosition(chil
d, ForRows, rowTrack); |
| 741 const GridSpan& columnSpan = resolveGridPositionsFromAutoPlacementPosition(c
hild, ForColumns, columnTrack); | 741 const GridSpan& columnSpan = resolveGridPositionsFromAutoPlacementPosition(c
hild, ForColumns, columnTrack); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { | 800 for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBo
x()) { |
| 801 populator.collectChild(child); | 801 populator.collectChild(child); |
| 802 | 802 |
| 803 // This function bypasses the cache (cachedGridCoordinate()) as it is us
ed to build it. | 803 // This function bypasses the cache (cachedGridCoordinate()) as it is us
ed to build it. |
| 804 OwnPtr<GridSpan> rowPositions = resolveGridPositionsFromStyle(child, For
Rows); | 804 OwnPtr<GridSpan> rowPositions = resolveGridPositionsFromStyle(child, For
Rows); |
| 805 OwnPtr<GridSpan> columnPositions = resolveGridPositionsFromStyle(child,
ForColumns); | 805 OwnPtr<GridSpan> columnPositions = resolveGridPositionsFromStyle(child,
ForColumns); |
| 806 | 806 |
| 807 // |positions| is 0 if we need to run the auto-placement algorithm. Our
estimation ignores | 807 // |positions| is 0 if we need to run the auto-placement algorithm. Our
estimation ignores |
| 808 // this case as the auto-placement algorithm will grow the grid as neede
d. | 808 // this case as the auto-placement algorithm will grow the grid as neede
d. |
| 809 if (rowPositions) | 809 if (rowPositions) |
| 810 maximumRowIndex = std::max(maximumRowIndex, rowPositions->finalPosit
ionIndex + 1); | 810 maximumRowIndex = std::max(maximumRowIndex, rowPositions->finalPosit
ionIndex.integerPosition() + 1); |
| 811 if (columnPositions) | 811 if (columnPositions) |
| 812 maximumColumnIndex = std::max(maximumColumnIndex, columnPositions->f
inalPositionIndex + 1); | 812 maximumColumnIndex = std::max(maximumColumnIndex, columnPositions->f
inalPositionIndex.integerPosition() + 1); |
| 813 } | 813 } |
| 814 | 814 |
| 815 m_grid.grow(maximumRowIndex); | 815 m_grid.grow(maximumRowIndex); |
| 816 for (size_t i = 0; i < m_grid.size(); ++i) | 816 for (size_t i = 0; i < m_grid.size(); ++i) |
| 817 m_grid[i].grow(maximumColumnIndex); | 817 m_grid[i].grow(maximumColumnIndex); |
| 818 } | 818 } |
| 819 | 819 |
| 820 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<RenderBox*>& au
toGridItems) | 820 void RenderGrid::placeSpecifiedMajorAxisItemsOnGrid(const Vector<RenderBox*>& au
toGridItems) |
| 821 { | 821 { |
| 822 for (size_t i = 0; i < autoGridItems.size(); ++i) { | 822 for (size_t i = 0; i < autoGridItems.size(); ++i) { |
| 823 OwnPtr<GridSpan> majorAxisPositions = resolveGridPositionsFromStyle(auto
GridItems[i], autoPlacementMajorAxisDirection()); | 823 OwnPtr<GridSpan> majorAxisPositions = resolveGridPositionsFromStyle(auto
GridItems[i], autoPlacementMajorAxisDirection()); |
| 824 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx
isPositions->initialPositionIndex); | 824 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), majorAx
isPositions->initialPositionIndex.integerPosition()); |
| 825 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea())
{ | 825 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea())
{ |
| 826 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosi
tionIndex, emptyGridArea->columns.initialPositionIndex); | 826 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosi
tionIndex.integerPosition(), emptyGridArea->columns.initialPositionIndex.integer
Position()); |
| 827 continue; | 827 continue; |
| 828 } | 828 } |
| 829 | 829 |
| 830 growGrid(autoPlacementMinorAxisDirection()); | 830 growGrid(autoPlacementMinorAxisDirection()); |
| 831 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(); | 831 OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea(); |
| 832 ASSERT(emptyGridArea); | 832 ASSERT(emptyGridArea); |
| 833 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosition
Index, emptyGridArea->columns.initialPositionIndex); | 833 insertItemIntoGrid(autoGridItems[i], emptyGridArea->rows.initialPosition
Index.integerPosition(), emptyGridArea->columns.initialPositionIndex.integerPosi
tion()); |
| 834 } | 834 } |
| 835 } | 835 } |
| 836 | 836 |
| 837 void RenderGrid::placeAutoMajorAxisItemsOnGrid(const Vector<RenderBox*>& autoGri
dItems) | 837 void RenderGrid::placeAutoMajorAxisItemsOnGrid(const Vector<RenderBox*>& autoGri
dItems) |
| 838 { | 838 { |
| 839 for (size_t i = 0; i < autoGridItems.size(); ++i) | 839 for (size_t i = 0; i < autoGridItems.size(); ++i) |
| 840 placeAutoMajorAxisItemOnGrid(autoGridItems[i]); | 840 placeAutoMajorAxisItemOnGrid(autoGridItems[i]); |
| 841 } | 841 } |
| 842 | 842 |
| 843 void RenderGrid::placeAutoMajorAxisItemOnGrid(RenderBox* gridItem) | 843 void RenderGrid::placeAutoMajorAxisItemOnGrid(RenderBox* gridItem) |
| 844 { | 844 { |
| 845 OwnPtr<GridSpan> minorAxisPositions = resolveGridPositionsFromStyle(gridItem
, autoPlacementMinorAxisDirection()); | 845 OwnPtr<GridSpan> minorAxisPositions = resolveGridPositionsFromStyle(gridItem
, autoPlacementMinorAxisDirection()); |
| 846 ASSERT(!resolveGridPositionsFromStyle(gridItem, autoPlacementMajorAxisDirect
ion())); | 846 ASSERT(!resolveGridPositionsFromStyle(gridItem, autoPlacementMajorAxisDirect
ion())); |
| 847 size_t minorAxisIndex = 0; | 847 size_t minorAxisIndex = 0; |
| 848 if (minorAxisPositions) { | 848 if (minorAxisPositions) { |
| 849 minorAxisIndex = minorAxisPositions->initialPositionIndex; | 849 minorAxisIndex = minorAxisPositions->initialPositionIndex.integerPositio
n(); |
| 850 GridIterator iterator(m_grid, autoPlacementMinorAxisDirection(), minorAx
isIndex); | 850 GridIterator iterator(m_grid, autoPlacementMinorAxisDirection(), minorAx
isIndex); |
| 851 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea())
{ | 851 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridArea())
{ |
| 852 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPositionInde
x, emptyGridArea->columns.initialPositionIndex); | 852 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPositionInde
x.integerPosition(), emptyGridArea->columns.initialPositionIndex.integerPosition
()); |
| 853 return; | 853 return; |
| 854 } | 854 } |
| 855 } else { | 855 } else { |
| 856 const size_t endOfMajorAxis = (autoPlacementMajorAxisDirection() == ForC
olumns) ? gridColumnCount() : gridRowCount(); | 856 const size_t endOfMajorAxis = (autoPlacementMajorAxisDirection() == ForC
olumns) ? gridColumnCount() : gridRowCount(); |
| 857 for (size_t majorAxisIndex = 0; majorAxisIndex < endOfMajorAxis; ++major
AxisIndex) { | 857 for (size_t majorAxisIndex = 0; majorAxisIndex < endOfMajorAxis; ++major
AxisIndex) { |
| 858 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), maj
orAxisIndex); | 858 GridIterator iterator(m_grid, autoPlacementMajorAxisDirection(), maj
orAxisIndex); |
| 859 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridAre
a()) { | 859 if (OwnPtr<GridCoordinate> emptyGridArea = iterator.nextEmptyGridAre
a()) { |
| 860 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPosition
Index, emptyGridArea->columns.initialPositionIndex); | 860 insertItemIntoGrid(gridItem, emptyGridArea->rows.initialPosition
Index.integerPosition(), emptyGridArea->columns.initialPositionIndex.integerPosi
tion()); |
| 861 return; | 861 return; |
| 862 } | 862 } |
| 863 } | 863 } |
| 864 } | 864 } |
| 865 | 865 |
| 866 // We didn't find an empty grid area so we need to create an extra major axi
s line and insert our gridItem in it. | 866 // We didn't find an empty grid area so we need to create an extra major axi
s line and insert our gridItem in it. |
| 867 const size_t columnIndex = (autoPlacementMajorAxisDirection() == ForColumns)
? m_grid[0].size() : minorAxisIndex; | 867 const size_t columnIndex = (autoPlacementMajorAxisDirection() == ForColumns)
? m_grid[0].size() : minorAxisIndex; |
| 868 const size_t rowIndex = (autoPlacementMajorAxisDirection() == ForColumns) ?
minorAxisIndex : m_grid.size(); | 868 const size_t rowIndex = (autoPlacementMajorAxisDirection() == ForColumns) ?
minorAxisIndex : m_grid.size(); |
| 869 growGrid(autoPlacementMajorAxisDirection()); | 869 growGrid(autoPlacementMajorAxisDirection()); |
| 870 insertItemIntoGrid(gridItem, rowIndex, columnIndex); | 870 insertItemIntoGrid(gridItem, rowIndex, columnIndex); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 | 925 |
| 926 LayoutRect oldChildRect = child->frameRect(); | 926 LayoutRect oldChildRect = child->frameRect(); |
| 927 | 927 |
| 928 // FIXME: Grid items should stretch to fill their cells. Once we | 928 // FIXME: Grid items should stretch to fill their cells. Once we |
| 929 // implement grid-{column,row}-align, we can also shrink to fit. For | 929 // implement grid-{column,row}-align, we can also shrink to fit. For |
| 930 // now, just size as if we were a regular child. | 930 // now, just size as if we were a regular child. |
| 931 child->layoutIfNeeded(); | 931 child->layoutIfNeeded(); |
| 932 | 932 |
| 933 #ifndef NDEBUG | 933 #ifndef NDEBUG |
| 934 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 934 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 935 ASSERT(coordinate.columns.initialPositionIndex < sizingData.columnTracks
.size()); | 935 ASSERT(coordinate.columns.initialPositionIndex.integerPosition() < sizin
gData.columnTracks.size()); |
| 936 ASSERT(coordinate.rows.initialPositionIndex < sizingData.rowTracks.size(
)); | 936 ASSERT(coordinate.rows.initialPositionIndex.integerPosition() < sizingDa
ta.rowTracks.size()); |
| 937 #endif | 937 #endif |
| 938 child->setLogicalLocation(findChildLogicalPosition(child)); | 938 child->setLogicalLocation(findChildLogicalPosition(child)); |
| 939 | 939 |
| 940 // Keep track of children overflowing their grid area as we might need t
o paint them even if the grid-area is | 940 // Keep track of children overflowing their grid area as we might need t
o paint them even if the grid-area is |
| 941 // not visible | 941 // not visible |
| 942 if (child->logicalHeight() > overrideContainingBlockContentLogicalHeight | 942 if (child->logicalHeight() > overrideContainingBlockContentLogicalHeight |
| 943 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt
h) | 943 || child->logicalWidth() > overrideContainingBlockContentLogicalWidt
h) |
| 944 m_gridItemsOverflowingGridArea.append(child); | 944 m_gridItemsOverflowingGridArea.append(child); |
| 945 | 945 |
| 946 // If the child moved, we have to repaint it as well as any floating/pos
itioned | 946 // If the child moved, we have to repaint it as well as any floating/pos
itioned |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi
on.shouldBeResolvedAgainstOppositePosition()) { | 984 if (initialPosition.shouldBeResolvedAgainstOppositePosition() && finalPositi
on.shouldBeResolvedAgainstOppositePosition()) { |
| 985 if (style()->gridAutoFlow() == AutoFlowNone) | 985 if (style()->gridAutoFlow() == AutoFlowNone) |
| 986 return adoptPtr(new GridSpan(0, 0)); | 986 return adoptPtr(new GridSpan(0, 0)); |
| 987 | 987 |
| 988 // We can't get our grid positions without running the auto placement al
gorithm. | 988 // We can't get our grid positions without running the auto placement al
gorithm. |
| 989 return nullptr; | 989 return nullptr; |
| 990 } | 990 } |
| 991 | 991 |
| 992 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { | 992 if (initialPosition.shouldBeResolvedAgainstOppositePosition()) { |
| 993 // Infer the position from the final position ('auto / 1' or 'span 2 / 3
' case). | 993 // Infer the position from the final position ('auto / 1' or 'span 2 / 3
' case). |
| 994 const size_t finalResolvedPosition = resolveGridPositionFromStyle(finalP
osition, finalPositionSide); | 994 GridResolvedPosition finalResolvedPosition = resolveGridPositionFromStyl
e(finalPosition, finalPositionSide); |
| 995 return resolveGridPositionAgainstOppositePosition(finalResolvedPosition,
initialPosition, initialPositionSide); | 995 return resolveGridPositionAgainstOppositePosition(finalResolvedPosition,
initialPosition, initialPositionSide); |
| 996 } | 996 } |
| 997 | 997 |
| 998 if (finalPosition.shouldBeResolvedAgainstOppositePosition()) { | 998 if (finalPosition.shouldBeResolvedAgainstOppositePosition()) { |
| 999 // Infer our position from the initial position ('1 / auto' or '3 / span
2' case). | 999 // Infer our position from the initial position ('1 / auto' or '3 / span
2' case). |
| 1000 const size_t initialResolvedPosition = resolveGridPositionFromStyle(init
ialPosition, initialPositionSide); | 1000 GridResolvedPosition initialResolvedPosition = resolveGridPositionFromSt
yle(initialPosition, initialPositionSide); |
| 1001 return resolveGridPositionAgainstOppositePosition(initialResolvedPositio
n, finalPosition, finalPositionSide); | 1001 return resolveGridPositionAgainstOppositePosition(initialResolvedPositio
n, finalPosition, finalPositionSide); |
| 1002 } | 1002 } |
| 1003 | 1003 |
| 1004 size_t resolvedInitialPosition = resolveGridPositionFromStyle(initialPositio
n, initialPositionSide); | 1004 GridResolvedPosition resolvedInitialPosition = resolveGridPositionFromStyle(
initialPosition, initialPositionSide); |
| 1005 size_t resolvedFinalPosition = resolveGridPositionFromStyle(finalPosition, f
inalPositionSide); | 1005 GridResolvedPosition resolvedFinalPosition = resolveGridPositionFromStyle(fi
nalPosition, finalPositionSide); |
| 1006 | 1006 |
| 1007 // If 'grid-after' specifies a line at or before that specified by 'grid-bef
ore', it computes to 'span 1'. | 1007 // If 'grid-after' specifies a line at or before that specified by 'grid-bef
ore', it computes to 'span 1'. |
| 1008 if (resolvedFinalPosition < resolvedInitialPosition) | 1008 if (resolvedFinalPosition.integerPosition() < resolvedInitialPosition.intege
rPosition()) |
| 1009 resolvedFinalPosition = resolvedInitialPosition; | 1009 resolvedFinalPosition.setIntegerPosition(resolvedInitialPosition.integer
Position()); |
| 1010 | 1010 |
| 1011 return adoptPtr(new GridSpan(resolvedInitialPosition, resolvedFinalPosition)
); | 1011 return adoptPtr(new GridSpan(resolvedInitialPosition.integerPosition(), reso
lvedFinalPosition.integerPosition())); |
| 1012 } | 1012 } |
| 1013 | 1013 |
| 1014 size_t RenderGrid::resolveNamedGridLinePositionFromStyle(const GridPosition& pos
ition, GridPositionSide side) const | 1014 GridResolvedPosition RenderGrid::resolveNamedGridLinePositionFromStyle(const Gri
dPosition& position, GridPositionSide side) const |
| 1015 { | 1015 { |
| 1016 ASSERT(!position.namedGridLine().isNull()); | 1016 ASSERT(!position.namedGridLine().isNull()); |
| 1017 | 1017 |
| 1018 const NamedGridLinesMap& gridLinesNames = (side == ColumnStartSide || side =
= ColumnEndSide) ? style()->namedGridColumnLines() : style()->namedGridRowLines(
); | 1018 const NamedGridLinesMap& gridLinesNames = (side == ColumnStartSide || side =
= ColumnEndSide) ? style()->namedGridColumnLines() : style()->namedGridRowLines(
); |
| 1019 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); | 1019 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); |
| 1020 if (it == gridLinesNames.end()) { | 1020 if (it == gridLinesNames.end()) { |
| 1021 if (position.isPositive()) | 1021 if (position.isPositive()) |
| 1022 return 0; | 1022 return GridResolvedPosition(); |
| 1023 const size_t lastLine = explicitGridSizeForSide(side); | 1023 const size_t lastLine = explicitGridSizeForSide(side); |
| 1024 return GridPosition::adjustGridPositionForSide(lastLine, side); | 1024 return GridResolvedPosition::adjustGridPositionForSide(lastLine, side); |
| 1025 } | 1025 } |
| 1026 | 1026 |
| 1027 size_t namedGridLineIndex; | 1027 size_t namedGridLineIndex; |
| 1028 if (position.isPositive()) | 1028 if (position.isPositive()) |
| 1029 namedGridLineIndex = std::min<size_t>(position.integerPosition(), it->va
lue.size()) - 1; | 1029 namedGridLineIndex = std::min<size_t>(position.integerPosition(), it->va
lue.size()) - 1; |
| 1030 else | 1030 else |
| 1031 namedGridLineIndex = std::max<int>(it->value.size() - abs(position.integ
erPosition()), 0); | 1031 namedGridLineIndex = std::max<int>(it->value.size() - abs(position.integ
erPosition()), 0); |
| 1032 return GridPosition::adjustGridPositionForSide(it->value[namedGridLineIndex]
, side); | 1032 return GridResolvedPosition::adjustGridPositionForSide(it->value[namedGridLi
neIndex], side); |
| 1033 } | 1033 } |
| 1034 | 1034 |
| 1035 size_t RenderGrid::resolveGridPositionFromStyle(const GridPosition& position, Gr
idPositionSide side) const | 1035 GridResolvedPosition RenderGrid::resolveGridPositionFromStyle(const GridPosition
& position, GridPositionSide side) const |
| 1036 { | 1036 { |
| 1037 switch (position.type()) { | 1037 switch (position.type()) { |
| 1038 case ExplicitPosition: { | 1038 case ExplicitPosition: { |
| 1039 ASSERT(position.integerPosition()); | 1039 ASSERT(position.integerPosition()); |
| 1040 | 1040 |
| 1041 if (!position.namedGridLine().isNull()) | 1041 if (!position.namedGridLine().isNull()) |
| 1042 return resolveNamedGridLinePositionFromStyle(position, side); | 1042 return resolveNamedGridLinePositionFromStyle(position, side); |
| 1043 | 1043 |
| 1044 // Handle <integer> explicit position. | 1044 // Handle <integer> explicit position. |
| 1045 if (position.isPositive()) | 1045 if (position.isPositive()) |
| 1046 return GridPosition::adjustGridPositionForSide(position.integerPosit
ion() - 1, side); | 1046 return GridResolvedPosition::adjustGridPositionForSide(position.inte
gerPosition() - 1, side); |
| 1047 | 1047 |
| 1048 size_t resolvedPosition = abs(position.integerPosition()) - 1; | 1048 size_t resolvedPosition = abs(position.integerPosition()) - 1; |
| 1049 const size_t endOfTrack = explicitGridSizeForSide(side); | 1049 const size_t endOfTrack = explicitGridSizeForSide(side); |
| 1050 | 1050 |
| 1051 // Per http://lists.w3.org/Archives/Public/www-style/2013Mar/0589.html,
we clamp negative value to the first line. | 1051 // Per http://lists.w3.org/Archives/Public/www-style/2013Mar/0589.html,
we clamp negative value to the first line. |
| 1052 if (endOfTrack < resolvedPosition) | 1052 if (endOfTrack < resolvedPosition) |
| 1053 return 0; | 1053 return GridResolvedPosition(); |
| 1054 | 1054 |
| 1055 return GridPosition::adjustGridPositionForSide(endOfTrack - resolvedPosi
tion, side); | 1055 return GridResolvedPosition::adjustGridPositionForSide(endOfTrack - reso
lvedPosition, side); |
| 1056 } | 1056 } |
| 1057 case NamedGridAreaPosition: | 1057 case NamedGridAreaPosition: |
| 1058 { | 1058 { |
| 1059 NamedGridAreaMap::const_iterator it = style()->namedGridArea().find(posi
tion.namedGridLine()); | 1059 NamedGridAreaMap::const_iterator it = style()->namedGridArea().find(posi
tion.namedGridLine()); |
| 1060 // Unknown grid area should have been computed to 'auto' by now. | 1060 // Unknown grid area should have been computed to 'auto' by now. |
| 1061 ASSERT_WITH_SECURITY_IMPLICATION(it != style()->namedGridArea().end()); | 1061 ASSERT_WITH_SECURITY_IMPLICATION(it != style()->namedGridArea().end()); |
| 1062 const GridCoordinate& gridAreaCoordinate = it->value; | 1062 const GridCoordinate& gridAreaCoordinate = it->value; |
| 1063 switch (side) { | 1063 switch (side) { |
| 1064 case ColumnStartSide: | 1064 case ColumnStartSide: |
| 1065 return gridAreaCoordinate.columns.initialPositionIndex; | 1065 return gridAreaCoordinate.columns.initialPositionIndex; |
| 1066 case ColumnEndSide: | 1066 case ColumnEndSide: |
| 1067 return gridAreaCoordinate.columns.finalPositionIndex; | 1067 return gridAreaCoordinate.columns.finalPositionIndex; |
| 1068 case RowStartSide: | 1068 case RowStartSide: |
| 1069 return gridAreaCoordinate.rows.initialPositionIndex; | 1069 return gridAreaCoordinate.rows.initialPositionIndex; |
| 1070 case RowEndSide: | 1070 case RowEndSide: |
| 1071 return gridAreaCoordinate.rows.finalPositionIndex; | 1071 return GridResolvedPosition(gridAreaCoordinate.rows.finalPositionInd
ex); |
| 1072 } | 1072 } |
| 1073 ASSERT_NOT_REACHED(); | 1073 ASSERT_NOT_REACHED(); |
| 1074 return 0; | 1074 return GridResolvedPosition(); |
| 1075 } | 1075 } |
| 1076 case AutoPosition: | 1076 case AutoPosition: |
| 1077 case SpanPosition: | 1077 case SpanPosition: |
| 1078 // 'auto' and span depend on the opposite position for resolution (e.g.
grid-row: auto / 1 or grid-column: span 3 / "myHeader"). | 1078 // 'auto' and span depend on the opposite position for resolution (e.g.
grid-row: auto / 1 or grid-column: span 3 / "myHeader"). |
| 1079 ASSERT_NOT_REACHED(); | 1079 ASSERT_NOT_REACHED(); |
| 1080 return 0; | 1080 return GridResolvedPosition(); |
| 1081 } | 1081 } |
| 1082 ASSERT_NOT_REACHED(); | 1082 ASSERT_NOT_REACHED(); |
| 1083 return 0; | 1083 return GridResolvedPosition(); |
| 1084 } | 1084 } |
| 1085 | 1085 |
| 1086 PassOwnPtr<GridSpan> RenderGrid::resolveGridPositionAgainstOppositePosition(size
_t resolvedOppositePosition, const GridPosition& position, GridPositionSide side
) const | 1086 PassOwnPtr<GridSpan> RenderGrid::resolveGridPositionAgainstOppositePosition(cons
t GridResolvedPosition& resolvedOppositePosition, const GridPosition& position,
GridPositionSide side) const |
| 1087 { | 1087 { |
| 1088 if (position.isAuto()) | 1088 if (position.isAuto()) |
| 1089 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); | 1089 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); |
| 1090 | 1090 |
| 1091 ASSERT(position.isSpan()); | 1091 ASSERT(position.isSpan()); |
| 1092 ASSERT(position.spanPosition() > 0); | 1092 ASSERT(position.spanPosition() > 0); |
| 1093 | 1093 |
| 1094 if (!position.namedGridLine().isNull()) { | 1094 if (!position.namedGridLine().isNull()) { |
| 1095 // span 2 'c' -> we need to find the appropriate grid line before / afte
r our opposite position. | 1095 // span 2 'c' -> we need to find the appropriate grid line before / afte
r our opposite position. |
| 1096 return resolveNamedGridLinePositionAgainstOppositePosition(resolvedOppos
itePosition, position, side); | 1096 return resolveNamedGridLinePositionAgainstOppositePosition(resolvedOppos
itePosition, position, side); |
| 1097 } | 1097 } |
| 1098 | 1098 |
| 1099 return GridSpan::createWithSpanAgainstOpposite(resolvedOppositePosition, pos
ition, side); | 1099 return GridSpan::createWithSpanAgainstOpposite(resolvedOppositePosition, pos
ition, side); |
| 1100 } | 1100 } |
| 1101 | 1101 |
| 1102 PassOwnPtr<GridSpan> RenderGrid::resolveNamedGridLinePositionAgainstOppositePosi
tion(size_t resolvedOppositePosition, const GridPosition& position, GridPosition
Side side) const | 1102 PassOwnPtr<GridSpan> RenderGrid::resolveNamedGridLinePositionAgainstOppositePosi
tion(const GridResolvedPosition& resolvedOppositePosition, const GridPosition& p
osition, GridPositionSide side) const |
| 1103 { | 1103 { |
| 1104 ASSERT(position.isSpan()); | 1104 ASSERT(position.isSpan()); |
| 1105 ASSERT(!position.namedGridLine().isNull()); | 1105 ASSERT(!position.namedGridLine().isNull()); |
| 1106 // Negative positions are not allowed per the specification and should have
been handled during parsing. | 1106 // Negative positions are not allowed per the specification and should have
been handled during parsing. |
| 1107 ASSERT(position.spanPosition() > 0); | 1107 ASSERT(position.spanPosition() > 0); |
| 1108 | 1108 |
| 1109 const NamedGridLinesMap& gridLinesNames = (side == ColumnStartSide || side =
= ColumnEndSide) ? style()->namedGridColumnLines() : style()->namedGridRowLines(
); | 1109 const NamedGridLinesMap& gridLinesNames = (side == ColumnStartSide || side =
= ColumnEndSide) ? style()->namedGridColumnLines() : style()->namedGridRowLines(
); |
| 1110 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); | 1110 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGri
dLine()); |
| 1111 | 1111 |
| 1112 // If there is no named grid line of that name, we resolve the position to '
auto' (which is equivalent to 'span 1' in this case). | 1112 // If there is no named grid line of that name, we resolve the position to '
auto' (which is equivalent to 'span 1' in this case). |
| 1113 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. | 1113 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. |
| 1114 if (it == gridLinesNames.end()) | 1114 if (it == gridLinesNames.end()) |
| 1115 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); | 1115 return GridSpan::create(resolvedOppositePosition, resolvedOppositePositi
on); |
| 1116 | 1116 |
| 1117 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); | 1117 return GridSpan::createWithNamedSpanAgainstOpposite(resolvedOppositePosition
, position, side, it->value); |
| 1118 } | 1118 } |
| 1119 | 1119 |
| 1120 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox* child, GridTrack
SizingDirection direction, const Vector<GridTrack>& tracks) const | 1120 LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox* child, GridTrack
SizingDirection direction, const Vector<GridTrack>& tracks) const |
| 1121 { | 1121 { |
| 1122 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1122 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1123 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor
dinate.rows; | 1123 const GridSpan& span = (direction == ForColumns) ? coordinate.columns : coor
dinate.rows; |
| 1124 LayoutUnit gridAreaBreadth = 0; | 1124 LayoutUnit gridAreaBreadth = 0; |
| 1125 for (size_t trackIndex = span.initialPositionIndex; trackIndex <= span.final
PositionIndex; ++trackIndex) | 1125 for (size_t trackIndex = span.initialPositionIndex.integerPosition(); trackI
ndex <= span.finalPositionIndex.integerPosition(); ++trackIndex) |
| 1126 gridAreaBreadth += tracks[trackIndex].m_usedBreadth; | 1126 gridAreaBreadth += tracks[trackIndex].m_usedBreadth; |
| 1127 return gridAreaBreadth; | 1127 return gridAreaBreadth; |
| 1128 } | 1128 } |
| 1129 | 1129 |
| 1130 void RenderGrid::populateGridPositions(const GridSizingData& sizingData) | 1130 void RenderGrid::populateGridPositions(const GridSizingData& sizingData) |
| 1131 { | 1131 { |
| 1132 m_columnPositions.resize(sizingData.columnTracks.size() + 1); | 1132 m_columnPositions.resize(sizingData.columnTracks.size() + 1); |
| 1133 m_columnPositions[0] = borderAndPaddingStart(); | 1133 m_columnPositions[0] = borderAndPaddingStart(); |
| 1134 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i) | 1134 for (size_t i = 0; i < m_columnPositions.size() - 1; ++i) |
| 1135 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack
s[i].m_usedBreadth; | 1135 m_columnPositions[i + 1] = m_columnPositions[i] + sizingData.columnTrack
s[i].m_usedBreadth; |
| 1136 | 1136 |
| 1137 m_rowPositions.resize(sizingData.rowTracks.size() + 1); | 1137 m_rowPositions.resize(sizingData.rowTracks.size() + 1); |
| 1138 m_rowPositions[0] = borderAndPaddingBefore(); | 1138 m_rowPositions[0] = borderAndPaddingBefore(); |
| 1139 for (size_t i = 0; i < m_rowPositions.size() - 1; ++i) | 1139 for (size_t i = 0; i < m_rowPositions.size() - 1; ++i) |
| 1140 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_us
edBreadth; | 1140 m_rowPositions[i + 1] = m_rowPositions[i] + sizingData.rowTracks[i].m_us
edBreadth; |
| 1141 } | 1141 } |
| 1142 | 1142 |
| 1143 LayoutUnit RenderGrid::startOfColumnForChild(const RenderBox* child) const | 1143 LayoutUnit RenderGrid::startOfColumnForChild(const RenderBox* child) const |
| 1144 { | 1144 { |
| 1145 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1145 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1146 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPosit
ionIndex]; | 1146 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPosit
ionIndex.integerPosition()]; |
| 1147 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. | 1147 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. |
| 1148 // FIXME: This should account for the grid item's <overflow-position>. | 1148 // FIXME: This should account for the grid item's <overflow-position>. |
| 1149 return startOfColumn + marginStartForChild(child); | 1149 return startOfColumn + marginStartForChild(child); |
| 1150 } | 1150 } |
| 1151 | 1151 |
| 1152 LayoutUnit RenderGrid::endOfColumnForChild(const RenderBox* child) const | 1152 LayoutUnit RenderGrid::endOfColumnForChild(const RenderBox* child) const |
| 1153 { | 1153 { |
| 1154 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1154 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1155 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPosit
ionIndex]; | 1155 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPosit
ionIndex.integerPosition()]; |
| 1156 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. | 1156 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. |
| 1157 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); | 1157 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); |
| 1158 | 1158 |
| 1159 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalPositionI
ndex + 1]; | 1159 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalPositionI
ndex.integerPosition() + 1]; |
| 1160 // FIXME: This should account for the grid item's <overflow-position>. | 1160 // FIXME: This should account for the grid item's <overflow-position>. |
| 1161 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - m_columnPositi
ons[coordinate.columns.initialPositionIndex] - child->logicalWidth()); | 1161 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - m_columnPositi
ons[coordinate.columns.initialPositionIndex.integerPosition()] - child->logicalW
idth()); |
| 1162 } | 1162 } |
| 1163 | 1163 |
| 1164 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerStart(const RenderB
ox* child) const | 1164 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerStart(const RenderB
ox* child) const |
| 1165 { | 1165 { |
| 1166 if (style()->isLeftToRightDirection()) | 1166 if (style()->isLeftToRightDirection()) |
| 1167 return startOfColumnForChild(child); | 1167 return startOfColumnForChild(child); |
| 1168 | 1168 |
| 1169 return endOfColumnForChild(child); | 1169 return endOfColumnForChild(child); |
| 1170 } | 1170 } |
| 1171 | 1171 |
| 1172 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerEnd(const RenderBox
* child) const | 1172 LayoutUnit RenderGrid::columnPositionAlignedWithGridContainerEnd(const RenderBox
* child) const |
| 1173 { | 1173 { |
| 1174 if (!style()->isLeftToRightDirection()) | 1174 if (!style()->isLeftToRightDirection()) |
| 1175 return startOfColumnForChild(child); | 1175 return startOfColumnForChild(child); |
| 1176 | 1176 |
| 1177 return endOfColumnForChild(child); | 1177 return endOfColumnForChild(child); |
| 1178 } | 1178 } |
| 1179 | 1179 |
| 1180 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox* child) co
nst | 1180 LayoutUnit RenderGrid::centeredColumnPositionForChild(const RenderBox* child) co
nst |
| 1181 { | 1181 { |
| 1182 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1182 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1183 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPosit
ionIndex]; | 1183 LayoutUnit startOfColumn = m_columnPositions[coordinate.columns.initialPosit
ionIndex.integerPosition()]; |
| 1184 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalPositionI
ndex + 1]; | 1184 LayoutUnit endOfColumn = m_columnPositions[coordinate.columns.finalPositionI
ndex.integerPosition() + 1]; |
| 1185 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); | 1185 LayoutUnit columnPosition = startOfColumn + marginStartForChild(child); |
| 1186 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn
- child->logicalWidth()) / 2; | 1186 return columnPosition + std::max<LayoutUnit>(0, endOfColumn - startOfColumn
- child->logicalWidth()) / 2; |
| 1187 } | 1187 } |
| 1188 | 1188 |
| 1189 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox* child) const | 1189 LayoutUnit RenderGrid::columnPositionForChild(const RenderBox* child) const |
| 1190 { | 1190 { |
| 1191 ItemPosition childJustifySelf = child->style()->justifySelf(); | 1191 ItemPosition childJustifySelf = child->style()->justifySelf(); |
| 1192 switch (childJustifySelf) { | 1192 switch (childJustifySelf) { |
| 1193 case ItemPositionSelfStart: | 1193 case ItemPositionSelfStart: |
| 1194 // self-start is based on the child's direction. That's why we need to c
heck against the grid container's direction. | 1194 // self-start is based on the child's direction. That's why we need to c
heck against the grid container's direction. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1243 | 1243 |
| 1244 ASSERT_NOT_REACHED(); | 1244 ASSERT_NOT_REACHED(); |
| 1245 return 0; | 1245 return 0; |
| 1246 } | 1246 } |
| 1247 | 1247 |
| 1248 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox* child) const | 1248 LayoutUnit RenderGrid::rowPositionForChild(const RenderBox* child) const |
| 1249 { | 1249 { |
| 1250 const GridCoordinate& coordinate = cachedGridCoordinate(child); | 1250 const GridCoordinate& coordinate = cachedGridCoordinate(child); |
| 1251 | 1251 |
| 1252 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. | 1252 // The grid items should be inside the grid container's border box, that's w
hy they need to be shifted. |
| 1253 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.initialPositionIndex]
; | 1253 LayoutUnit startOfRow = m_rowPositions[coordinate.rows.initialPositionIndex.
integerPosition()]; |
| 1254 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); | 1254 LayoutUnit rowPosition = startOfRow + marginBeforeForChild(child); |
| 1255 | 1255 |
| 1256 // FIXME: This function should account for 'align-self'. | 1256 // FIXME: This function should account for 'align-self'. |
| 1257 | 1257 |
| 1258 return rowPosition; | 1258 return rowPosition; |
| 1259 } | 1259 } |
| 1260 | 1260 |
| 1261 LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox* child) const | 1261 LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox* child) const |
| 1262 { | 1262 { |
| 1263 return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child)
); | 1263 return LayoutPoint(columnPositionForChild(child), rowPositionForChild(child)
); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1278 | 1278 |
| 1279 class GridCoordinateSorter { | 1279 class GridCoordinateSorter { |
| 1280 public: | 1280 public: |
| 1281 GridCoordinateSorter(RenderGrid* renderer) : m_renderer(renderer) { } | 1281 GridCoordinateSorter(RenderGrid* renderer) : m_renderer(renderer) { } |
| 1282 | 1282 |
| 1283 bool operator()(const RenderBox* firstItem, const RenderBox* secondItem) con
st | 1283 bool operator()(const RenderBox* firstItem, const RenderBox* secondItem) con
st |
| 1284 { | 1284 { |
| 1285 GridCoordinate first = m_renderer->cachedGridCoordinate(firstItem); | 1285 GridCoordinate first = m_renderer->cachedGridCoordinate(firstItem); |
| 1286 GridCoordinate second = m_renderer->cachedGridCoordinate(secondItem); | 1286 GridCoordinate second = m_renderer->cachedGridCoordinate(secondItem); |
| 1287 | 1287 |
| 1288 if (first.rows.initialPositionIndex < second.rows.initialPositionIndex) | 1288 if (first.rows.initialPositionIndex.integerPosition() < second.rows.init
ialPositionIndex.integerPosition()) |
| 1289 return true; | 1289 return true; |
| 1290 if (first.rows.initialPositionIndex > second.rows.initialPositionIndex) | 1290 if (first.rows.initialPositionIndex.integerPosition() > second.rows.init
ialPositionIndex.integerPosition()) |
| 1291 return false; | 1291 return false; |
| 1292 return first.columns.finalPositionIndex < second.columns.finalPositionIn
dex; | 1292 return first.columns.finalPositionIndex.integerPosition() < second.colum
ns.finalPositionIndex.integerPosition(); |
| 1293 } | 1293 } |
| 1294 private: | 1294 private: |
| 1295 RenderGrid* m_renderer; | 1295 RenderGrid* m_renderer; |
| 1296 }; | 1296 }; |
| 1297 | 1297 |
| 1298 static inline bool isInSameRowBeforeDirtyArea(const GridCoordinate& coordinate,
size_t row, const GridSpan& dirtiedColumns) | 1298 static inline bool isInSameRowBeforeDirtyArea(const GridCoordinate& coordinate,
size_t row, const GridSpan& dirtiedColumns) |
| 1299 { | 1299 { |
| 1300 return coordinate.rows.initialPositionIndex == row && coordinate.columns.ini
tialPositionIndex < dirtiedColumns.initialPositionIndex; | 1300 return coordinate.rows.initialPositionIndex.integerPosition() == row && coor
dinate.columns.initialPositionIndex.integerPosition() < dirtiedColumns.initialPo
sitionIndex.integerPosition(); |
| 1301 } | 1301 } |
| 1302 | 1302 |
| 1303 static inline bool isInSameRowAfterDirtyArea(const GridCoordinate& coordinate, s
ize_t row, const GridSpan& dirtiedColumns) | 1303 static inline bool isInSameRowAfterDirtyArea(const GridCoordinate& coordinate, s
ize_t row, const GridSpan& dirtiedColumns) |
| 1304 { | 1304 { |
| 1305 return coordinate.rows.initialPositionIndex == row && coordinate.columns.ini
tialPositionIndex >= dirtiedColumns.finalPositionIndex; | 1305 return coordinate.rows.initialPositionIndex.integerPosition() == row && coor
dinate.columns.initialPositionIndex.integerPosition() >= dirtiedColumns.finalPos
itionIndex.integerPosition(); |
| 1306 } | 1306 } |
| 1307 | 1307 |
| 1308 static inline bool rowIsBeforeDirtyArea(const GridCoordinate& coordinate, const
GridSpan& dirtiedRows) | 1308 static inline bool rowIsBeforeDirtyArea(const GridCoordinate& coordinate, const
GridSpan& dirtiedRows) |
| 1309 { | 1309 { |
| 1310 return coordinate.rows.initialPositionIndex < dirtiedRows.initialPositionInd
ex; | 1310 return coordinate.rows.initialPositionIndex.integerPosition() < dirtiedRows.
initialPositionIndex.integerPosition(); |
| 1311 } | 1311 } |
| 1312 | 1312 |
| 1313 void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOff
set) | 1313 void RenderGrid::paintChildren(PaintInfo& paintInfo, const LayoutPoint& paintOff
set) |
| 1314 { | 1314 { |
| 1315 ASSERT_WITH_SECURITY_IMPLICATION(!gridIsDirty()); | 1315 ASSERT_WITH_SECURITY_IMPLICATION(!gridIsDirty()); |
| 1316 | 1316 |
| 1317 LayoutRect localRepaintRect = paintInfo.rect; | 1317 LayoutRect localRepaintRect = paintInfo.rect; |
| 1318 localRepaintRect.moveBy(-paintOffset); | 1318 localRepaintRect.moveBy(-paintOffset); |
| 1319 | 1319 |
| 1320 GridSpan dirtiedColumns = dirtiedGridAreas(m_columnPositions, localRepaintRe
ct.x(), localRepaintRect.maxX()); | 1320 GridSpan dirtiedColumns = dirtiedGridAreas(m_columnPositions, localRepaintRe
ct.x(), localRepaintRect.maxX()); |
| 1321 GridSpan dirtiedRows = dirtiedGridAreas(m_rowPositions, localRepaintRect.y()
, localRepaintRect.maxY()); | 1321 GridSpan dirtiedRows = dirtiedGridAreas(m_rowPositions, localRepaintRect.y()
, localRepaintRect.maxY()); |
| 1322 | 1322 |
| 1323 // Sort the overflowing grid items according to their positions in the grid.
We collect items during the layout | 1323 // Sort the overflowing grid items according to their positions in the grid.
We collect items during the layout |
| 1324 // process following DOM's order but we have to paint following grid's. | 1324 // process following DOM's order but we have to paint following grid's. |
| 1325 std::stable_sort(m_gridItemsOverflowingGridArea.begin(), m_gridItemsOverflow
ingGridArea.end(), GridCoordinateSorter(this)); | 1325 std::stable_sort(m_gridItemsOverflowingGridArea.begin(), m_gridItemsOverflow
ingGridArea.end(), GridCoordinateSorter(this)); |
| 1326 | 1326 |
| 1327 OrderIterator paintIterator(this); | 1327 OrderIterator paintIterator(this); |
| 1328 { | 1328 { |
| 1329 OrderIteratorPopulator populator(paintIterator); | 1329 OrderIteratorPopulator populator(paintIterator); |
| 1330 Vector<RenderBox*>::const_iterator overflowIterator = m_gridItemsOverflo
wingGridArea.begin(); | 1330 Vector<RenderBox*>::const_iterator overflowIterator = m_gridItemsOverflo
wingGridArea.begin(); |
| 1331 Vector<RenderBox*>::const_iterator end = m_gridItemsOverflowingGridArea.
end(); | 1331 Vector<RenderBox*>::const_iterator end = m_gridItemsOverflowingGridArea.
end(); |
| 1332 | 1332 |
| 1333 for (; overflowIterator != end && rowIsBeforeDirtyArea(cachedGridCoordin
ate(*overflowIterator), dirtiedRows); ++overflowIterator) { | 1333 for (; overflowIterator != end && rowIsBeforeDirtyArea(cachedGridCoordin
ate(*overflowIterator), dirtiedRows); ++overflowIterator) { |
| 1334 if ((*overflowIterator)->frameRect().intersects(localRepaintRect)) | 1334 if ((*overflowIterator)->frameRect().intersects(localRepaintRect)) |
| 1335 populator.storeChild(*overflowIterator); | 1335 populator.storeChild(*overflowIterator); |
| 1336 } | 1336 } |
| 1337 | 1337 |
| 1338 for (size_t row = dirtiedRows.initialPositionIndex; row < dirtiedRows.fi
nalPositionIndex; ++row) { | 1338 for (size_t row = dirtiedRows.initialPositionIndex.integerPosition(); ro
w < dirtiedRows.finalPositionIndex.integerPosition(); ++row) { |
| 1339 | 1339 |
| 1340 for (; overflowIterator != end && isInSameRowBeforeDirtyArea(cachedG
ridCoordinate(*overflowIterator), row, dirtiedColumns); ++overflowIterator) { | 1340 for (; overflowIterator != end && isInSameRowBeforeDirtyArea(cachedG
ridCoordinate(*overflowIterator), row, dirtiedColumns); ++overflowIterator) { |
| 1341 if ((*overflowIterator)->frameRect().intersects(localRepaintRect
)) | 1341 if ((*overflowIterator)->frameRect().intersects(localRepaintRect
)) |
| 1342 populator.storeChild(*overflowIterator); | 1342 populator.storeChild(*overflowIterator); |
| 1343 } | 1343 } |
| 1344 | 1344 |
| 1345 for (size_t column = dirtiedColumns.initialPositionIndex; column < d
irtiedColumns.finalPositionIndex; ++column) { | 1345 for (size_t column = dirtiedColumns.initialPositionIndex.integerPosi
tion(); column < dirtiedColumns.finalPositionIndex.integerPosition(); ++column)
{ |
| 1346 const Vector<RenderBox*, 1>& children = m_grid[row][column]; | 1346 const Vector<RenderBox*, 1>& children = m_grid[row][column]; |
| 1347 // FIXME: If we start adding spanning children in all grid areas
they span, this | 1347 // FIXME: If we start adding spanning children in all grid areas
they span, this |
| 1348 // would make us paint them several times, which is wrong! | 1348 // would make us paint them several times, which is wrong! |
| 1349 for (size_t j = 0; j < children.size(); ++j) { | 1349 for (size_t j = 0; j < children.size(); ++j) { |
| 1350 populator.storeChild(children[j]); | 1350 populator.storeChild(children[j]); |
| 1351 // Do not paint overflowing grid items twice. | 1351 // Do not paint overflowing grid items twice. |
| 1352 if (overflowIterator != end && *overflowIterator == children
[j]) | 1352 if (overflowIterator != end && *overflowIterator == children
[j]) |
| 1353 ++overflowIterator; | 1353 ++overflowIterator; |
| 1354 } | 1354 } |
| 1355 } | 1355 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1377 if (isOutOfFlowPositioned()) | 1377 if (isOutOfFlowPositioned()) |
| 1378 return "RenderGrid (positioned)"; | 1378 return "RenderGrid (positioned)"; |
| 1379 if (isAnonymous()) | 1379 if (isAnonymous()) |
| 1380 return "RenderGrid (generated)"; | 1380 return "RenderGrid (generated)"; |
| 1381 if (isRelPositioned()) | 1381 if (isRelPositioned()) |
| 1382 return "RenderGrid (relative positioned)"; | 1382 return "RenderGrid (relative positioned)"; |
| 1383 return "RenderGrid"; | 1383 return "RenderGrid"; |
| 1384 } | 1384 } |
| 1385 | 1385 |
| 1386 } // namespace WebCore | 1386 } // namespace WebCore |
| OLD | NEW |