Changeset 155181 in webkit for trunk/Source/WebCore/rendering/RenderGrid.cpp
- Timestamp:
- Sep 6, 2013, 1:04:33 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/rendering/RenderGrid.cpp
r154996 r155181 338 338 } 339 339 340 size_t RenderGrid::explicitGridSizeForSide(GridPositionSide side) const 341 { 342 return (side == ColumnStartSide || side == ColumnEndSide) ? explicitGridColumnCount() : explicitGridRowCount(); 343 } 344 340 345 size_t RenderGrid::maximumIndexInDirection(TrackSizingDirection direction) const 341 346 { … … 754 759 } 755 760 761 inline static size_t adjustGridPositionForRowEndColumnEndSide(size_t resolvedPosition) 762 { 763 return resolvedPosition ? resolvedPosition - 1 : 0; 764 } 765 756 766 static size_t adjustGridPositionForSide(size_t resolvedPosition, RenderGrid::GridPositionSide side) 757 767 { 758 768 // An item finishing on the N-th line belongs to the N-1-th cell. 759 769 if (side == RenderGrid::ColumnEndSide || side == RenderGrid::RowEndSide) 760 return resolvedPosition ? resolvedPosition - 1 : 0;770 return adjustGridPositionForRowEndColumnEndSide(resolvedPosition); 761 771 762 772 return resolvedPosition; 773 } 774 775 size_t RenderGrid::resolveNamedGridLinePositionFromStyle(const GridPosition& position, GridPositionSide side) const 776 { 777 ASSERT(!position.namedGridLine().isNull()); 778 779 const NamedGridLinesMap& gridLinesNames = (side == ColumnStartSide || side == ColumnEndSide) ? style()->namedGridColumnLines() : style()->namedGridRowLines(); 780 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGridLine()); 781 if (it == gridLinesNames.end()) { 782 if (position.isPositive()) 783 return 0; 784 const size_t lastLine = explicitGridSizeForSide(side); 785 return adjustGridPositionForSide(lastLine, side); 786 } 787 788 size_t namedGridLineIndex; 789 if (position.isPositive()) 790 namedGridLineIndex = std::min<size_t>(position.integerPosition(), it->value.size()) - 1; 791 else 792 namedGridLineIndex = std::max<int>(it->value.size() - abs(position.integerPosition()), 0); 793 return adjustGridPositionForSide(it->value[namedGridLineIndex], side); 763 794 } 764 795 … … 769 800 case ExplicitPosition: { 770 801 ASSERT(position.integerPosition()); 802 803 if (!position.namedGridLine().isNull()) 804 return resolveNamedGridLinePositionFromStyle(position, side); 805 806 // Handle <integer> explicit position. 771 807 if (position.isPositive()) 772 808 return adjustGridPositionForSide(position.integerPosition() - 1, side); 773 809 774 810 size_t resolvedPosition = abs(position.integerPosition()) - 1; 775 const size_t endOfTrack = (side == ColumnStartSide || side == ColumnEndSide) ? explicitGridColumnCount() : explicitGridRowCount();811 const size_t endOfTrack = explicitGridSizeForSide(side); 776 812 777 813 // Per http://lists.w3.org/Archives/Public/www-style/2013Mar/0589.html, we clamp negative value to the first line. … … 802 838 ASSERT(position.spanPosition() > 0); 803 839 840 if (!position.namedGridLine().isNull()) { 841 // span 2 'c' -> we need to find the appropriate grid line before / after our opposite position. 842 return resolveNamedGridLinePositionAgainstOppositePosition(resolvedOppositePosition, position, side); 843 } 844 804 845 // 'span 1' is contained inside a single grid track regardless of the direction. 805 846 // That's why the CSS span value is one more than the offset we apply. … … 811 852 812 853 return GridSpan::create(resolvedOppositePosition, resolvedOppositePosition + positionOffset); 854 } 855 856 PassOwnPtr<RenderGrid::GridSpan> RenderGrid::resolveNamedGridLinePositionAgainstOppositePosition(size_t resolvedOppositePosition, const GridPosition& position, GridPositionSide side) const 857 { 858 ASSERT(position.isSpan()); 859 ASSERT(!position.namedGridLine().isNull()); 860 // Negative positions are not allowed per the specification and should have been handled during parsing. 861 ASSERT(position.spanPosition() > 0); 862 863 const NamedGridLinesMap& gridLinesNames = (side == ColumnStartSide || side == ColumnEndSide) ? style()->namedGridColumnLines() : style()->namedGridRowLines(); 864 NamedGridLinesMap::const_iterator it = gridLinesNames.find(position.namedGridLine()); 865 866 // 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). 867 // See http://lists.w3.org/Archives/Public/www-style/2013Jun/0394.html. 868 if (it == gridLinesNames.end()) 869 return GridSpan::create(resolvedOppositePosition, resolvedOppositePosition); 870 871 if (side == RowStartSide || side == ColumnStartSide) 872 return resolveRowStartColumnStartNamedGridLinePositionAgainstOppositePosition(resolvedOppositePosition, position, it->value); 873 874 return resolveRowEndColumnEndNamedGridLinePositionAgainstOppositePosition(resolvedOppositePosition, position, it->value); 875 } 876 877 PassOwnPtr<RenderGrid::GridSpan> RenderGrid::resolveRowStartColumnStartNamedGridLinePositionAgainstOppositePosition(size_t resolvedOppositePosition, const GridPosition& position, const Vector<size_t>& gridLines) const 878 { 879 // The grid line inequality needs to be strict (which doesn't match the after / end case) because |resolvedOppositePosition| 880 // is already converted to an index in our grid representation (ie one was removed from the grid line to account for the side). 881 // FIXME: This could be a binary search as |gridLines| is ordered. 882 int firstLineBeforeOppositePositionIndex = gridLines.size() - 1; 883 for (; firstLineBeforeOppositePositionIndex >= 0 && gridLines[firstLineBeforeOppositePositionIndex] > resolvedOppositePosition; --firstLineBeforeOppositePositionIndex) { } 884 885 size_t gridLineIndex = std::max<int>(0, firstLineBeforeOppositePositionIndex - position.spanPosition() + 1); 886 size_t resolvedGridLinePosition = gridLines[gridLineIndex]; 887 if (resolvedGridLinePosition > resolvedOppositePosition) 888 resolvedGridLinePosition = resolvedOppositePosition; 889 return GridSpan::create(resolvedGridLinePosition, resolvedOppositePosition); 890 } 891 892 PassOwnPtr<RenderGrid::GridSpan> RenderGrid::resolveRowEndColumnEndNamedGridLinePositionAgainstOppositePosition(size_t resolvedOppositePosition, const GridPosition& position, const Vector<size_t>& gridLines) const 893 { 894 // FIXME: This could be a binary search as |gridLines| is ordered. 895 size_t firstLineAfterOppositePositionIndex = 0; 896 for (; firstLineAfterOppositePositionIndex < gridLines.size() && gridLines[firstLineAfterOppositePositionIndex] <= resolvedOppositePosition; ++firstLineAfterOppositePositionIndex) { } 897 898 size_t gridLineIndex = std::min(gridLines.size() - 1, firstLineAfterOppositePositionIndex + position.spanPosition() - 1); 899 size_t resolvedGridLinePosition = adjustGridPositionForRowEndColumnEndSide(gridLines[gridLineIndex]); 900 if (resolvedGridLinePosition < resolvedOppositePosition) 901 resolvedGridLinePosition = resolvedOppositePosition; 902 return GridSpan::create(resolvedOppositePosition, resolvedGridLinePosition); 813 903 } 814 904
Note:
See TracChangeset
for help on using the changeset viewer.