Chromium Code Reviews| Index: third_party/WebKit/Source/core/style/GridCoordinate.h |
| diff --git a/third_party/WebKit/Source/core/style/GridCoordinate.h b/third_party/WebKit/Source/core/style/GridCoordinate.h |
| index ae3e89415a13fe5ad8492ca0a4025baef39257ef..d8e62ff01835659b4b3eb06545ec8d4501e228b0 100644 |
| --- a/third_party/WebKit/Source/core/style/GridCoordinate.h |
| +++ b/third_party/WebKit/Source/core/style/GridCoordinate.h |
| @@ -44,8 +44,8 @@ namespace blink { |
| const size_t kGridMaxTracks = 1000000; |
| // A span in a single direction (either rows or columns). Note that |resolvedInitialPosition| |
| -// and |resolvedFinalPosition| are grid areas' indexes, NOT grid lines'. Iterating over the |
| -// span should include both |resolvedInitialPosition| and |resolvedFinalPosition| to be correct. |
| +// and |resolvedFinalPosition| are grid lines' indexes. |
| +// Iterating over the span shouldn't include |resolvedFinalPosition| to be correct. |
| struct GridSpan { |
| USING_FAST_MALLOC(GridSpan); |
| public: |
| @@ -56,9 +56,7 @@ public: |
| static PassOwnPtr<GridSpan> createWithSpanAgainstOpposite(const GridResolvedPosition& resolvedOppositePosition, const GridPosition& position, GridPositionSide side) |
| { |
| - // 'span 1' is contained inside a single grid track regardless of the direction. |
| - // That's why the CSS span value is one more than the offset we apply. |
| - size_t positionOffset = position.spanPosition() - 1; |
| + size_t positionOffset = position.spanPosition(); |
| if (side == ColumnStartSide || side == RowStartSide) { |
| GridResolvedPosition initialResolvedPosition = GridResolvedPosition(std::max<int>(0, resolvedOppositePosition.toInt() - positionOffset)); |
| return GridSpan::create(initialResolvedPosition, resolvedOppositePosition); |
| @@ -69,29 +67,25 @@ public: |
| static PassOwnPtr<GridSpan> createWithNamedSpanAgainstOpposite(const GridResolvedPosition& resolvedOppositePosition, const GridPosition& position, GridPositionSide side, const Vector<size_t>& gridLines) |
| { |
| - if (side == RowStartSide || side == ColumnStartSide) |
| + if (side == RowStartSide || side == ColumnStartSide) { |
| + if (resolvedOppositePosition == 0) |
| + return GridSpan::create(resolvedOppositePosition, resolvedOppositePosition.next()); |
|
svillar
2015/11/17 11:37:05
I think it's better to move this check to createWi
Manuel Rego
2015/11/17 14:30:49
Done.
|
| return createWithInitialNamedSpanAgainstOpposite(resolvedOppositePosition, position, gridLines); |
| + } |
| return createWithFinalNamedSpanAgainstOpposite(resolvedOppositePosition, position, gridLines); |
| } |
| static PassOwnPtr<GridSpan> createWithInitialNamedSpanAgainstOpposite(const GridResolvedPosition& resolvedOppositePosition, const GridPosition& position, const Vector<size_t>& gridLines) |
| { |
| - // The grid line inequality needs to be strict (which doesn't match the after / end case) because |resolvedOppositePosition| |
| - // is already converted to an index in our grid representation (ie one was removed from the grid line to account for the side). |
| size_t firstLineBeforeOppositePositionIndex = 0; |
| const size_t* firstLineBeforeOppositePosition = std::lower_bound(gridLines.begin(), gridLines.end(), resolvedOppositePosition.toInt()); |
| - if (firstLineBeforeOppositePosition != gridLines.end()) { |
| - if (*firstLineBeforeOppositePosition > resolvedOppositePosition.toInt() && firstLineBeforeOppositePosition != gridLines.begin()) |
| - --firstLineBeforeOppositePosition; |
| - |
| + if (firstLineBeforeOppositePosition != gridLines.end()) |
| firstLineBeforeOppositePositionIndex = firstLineBeforeOppositePosition - gridLines.begin(); |
| - } |
| - |
| - size_t gridLineIndex = std::max<int>(0, firstLineBeforeOppositePositionIndex - position.spanPosition() + 1); |
| + size_t gridLineIndex = std::max<int>(0, firstLineBeforeOppositePositionIndex - position.spanPosition()); |
| GridResolvedPosition resolvedGridLinePosition = GridResolvedPosition(gridLines[gridLineIndex]); |
| - if (resolvedGridLinePosition > resolvedOppositePosition) |
| - resolvedGridLinePosition = resolvedOppositePosition; |
| + if (resolvedGridLinePosition >= resolvedOppositePosition) |
| + resolvedGridLinePosition = resolvedOppositePosition.prev(); |
| return GridSpan::create(resolvedGridLinePosition, resolvedOppositePosition); |
| } |
| @@ -101,11 +95,11 @@ public: |
| const size_t* firstLineAfterOppositePosition = std::upper_bound(gridLines.begin(), gridLines.end(), resolvedOppositePosition.toInt()); |
| if (firstLineAfterOppositePosition != gridLines.end()) |
| firstLineAfterOppositePositionIndex = firstLineAfterOppositePosition - gridLines.begin(); |
| - |
| size_t gridLineIndex = std::min(gridLines.size() - 1, firstLineAfterOppositePositionIndex + position.spanPosition() - 1); |
| - GridResolvedPosition resolvedGridLinePosition = GridResolvedPosition::adjustGridPositionForAfterEndSide(gridLines[gridLineIndex]); |
| - if (resolvedGridLinePosition < resolvedOppositePosition) |
| - resolvedGridLinePosition = resolvedOppositePosition; |
| + GridResolvedPosition resolvedGridLinePosition = gridLines[gridLineIndex]; |
| + if (resolvedGridLinePosition <= resolvedOppositePosition) |
| + resolvedGridLinePosition = resolvedOppositePosition.next(); |
| + |
| return GridSpan::create(resolvedOppositePosition, resolvedGridLinePosition); |
| } |
| @@ -113,7 +107,7 @@ public: |
| : resolvedInitialPosition(std::min(resolvedInitialPosition.toInt(), kGridMaxTracks - 1)) |
| , resolvedFinalPosition(std::min(resolvedFinalPosition.toInt(), kGridMaxTracks)) |
| { |
| - ASSERT(resolvedInitialPosition <= resolvedFinalPosition); |
| + ASSERT(resolvedInitialPosition < resolvedFinalPosition); |
| } |
| bool operator==(const GridSpan& o) const |
| @@ -123,7 +117,7 @@ public: |
| size_t integerSpan() const |
| { |
| - return resolvedFinalPosition.toInt() - resolvedInitialPosition.toInt() + 1; |
| + return resolvedFinalPosition.toInt() - resolvedInitialPosition.toInt(); |
| } |
| GridResolvedPosition resolvedInitialPosition; |
| @@ -138,7 +132,7 @@ public: |
| iterator end() const |
| { |
| - return resolvedFinalPosition.next(); |
| + return resolvedFinalPosition; |
| } |
| }; |
| @@ -148,8 +142,8 @@ struct GridCoordinate { |
| public: |
| // HashMap requires a default constuctor. |
| GridCoordinate() |
| - : columns(0, 0) |
| - , rows(0, 0) |
| + : columns(0, 1) |
| + , rows(0, 1) |
| { |
| } |