| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GridResolvedPosition_h | 5 #ifndef GridResolvedPosition_h |
| 6 #define GridResolvedPosition_h | 6 #define GridResolvedPosition_h |
| 7 | 7 |
| 8 #include "core/style/GridPosition.h" | 8 #include "core/style/GridPosition.h" |
| 9 #include "wtf/Allocator.h" | 9 #include "wtf/Allocator.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 struct GridSpan; | 13 struct GridSpan; |
| 14 class LayoutBox; | 14 class LayoutBox; |
| 15 class ComputedStyle; | 15 class ComputedStyle; |
| 16 | 16 |
| 17 enum GridPositionSide { | 17 enum GridPositionSide { |
| 18 ColumnStartSide, | 18 ColumnStartSide, |
| 19 ColumnEndSide, | 19 ColumnEndSide, |
| 20 RowStartSide, | 20 RowStartSide, |
| 21 RowEndSide | 21 RowEndSide |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 enum GridTrackSizingDirection { | 24 enum GridTrackSizingDirection { |
| 25 ForColumns, | 25 ForColumns, |
| 26 ForRows | 26 ForRows |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 // This class represents an index into one of the dimensions of the grid array. | 29 // This class represents a line index into one of the dimensions of the grid arr
ay. |
| 30 // Wraps a size_t integer just for the purpose of knowing what we manipulate in
the grid code. | 30 // Wraps a size_t integer just for the purpose of knowing what we manipulate in
the grid code. |
| 31 class GridResolvedPosition { | 31 class GridResolvedPosition { |
| 32 DISALLOW_NEW(); | 32 DISALLOW_NEW(); |
| 33 public: | 33 public: |
| 34 static GridResolvedPosition adjustGridPositionForAfterEndSide(size_t resolve
dPosition) | |
| 35 { | |
| 36 return resolvedPosition ? GridResolvedPosition(resolvedPosition - 1) : G
ridResolvedPosition(0); | |
| 37 } | |
| 38 | |
| 39 static GridResolvedPosition adjustGridPositionForSide(size_t resolvedPositio
n, GridPositionSide side) | |
| 40 { | |
| 41 // An item finishing on the N-th line belongs to the N-1-th cell. | |
| 42 if (side == ColumnEndSide || side == RowEndSide) | |
| 43 return adjustGridPositionForAfterEndSide(resolvedPosition); | |
| 44 | |
| 45 return GridResolvedPosition(resolvedPosition); | |
| 46 } | |
| 47 | 34 |
| 48 static bool isValidNamedLineOrArea(const String& lineName, const ComputedSty
le&, GridPositionSide); | 35 static bool isValidNamedLineOrArea(const String& lineName, const ComputedSty
le&, GridPositionSide); |
| 49 static GridPositionSide initialPositionSide(GridTrackSizingDirection); | 36 static GridPositionSide initialPositionSide(GridTrackSizingDirection); |
| 50 static GridPositionSide finalPositionSide(GridTrackSizingDirection); | 37 static GridPositionSide finalPositionSide(GridTrackSizingDirection); |
| 51 static void initialAndFinalPositionsFromStyle(const ComputedStyle&, const La
youtBox&, GridTrackSizingDirection, GridPosition &initialPosition, GridPosition
&finalPosition); | 38 static void initialAndFinalPositionsFromStyle(const ComputedStyle&, const La
youtBox&, GridTrackSizingDirection, GridPosition &initialPosition, GridPosition
&finalPosition); |
| 52 static GridSpan resolveGridPositionsFromAutoPlacementPosition(const Computed
Style&, const LayoutBox&, GridTrackSizingDirection, const GridResolvedPosition&)
; | 39 static GridSpan resolveGridPositionsFromAutoPlacementPosition(const Computed
Style&, const LayoutBox&, GridTrackSizingDirection, const GridResolvedPosition&)
; |
| 53 static PassOwnPtr<GridSpan> resolveGridPositionsFromStyle(const ComputedStyl
e&, const LayoutBox&, GridTrackSizingDirection); | 40 static PassOwnPtr<GridSpan> resolveGridPositionsFromStyle(const ComputedStyl
e&, const LayoutBox&, GridTrackSizingDirection); |
| 54 static GridResolvedPosition resolveNamedGridLinePositionFromStyle(const Comp
utedStyle&, const GridPosition&, GridPositionSide); | 41 static GridResolvedPosition resolveNamedGridLinePositionFromStyle(const Comp
utedStyle&, const GridPosition&, GridPositionSide); |
| 55 static GridResolvedPosition resolveGridPositionFromStyle(const ComputedStyle
&, const GridPosition&, GridPositionSide); | 42 static GridResolvedPosition resolveGridPositionFromStyle(const ComputedStyle
&, const GridPosition&, GridPositionSide); |
| 56 static PassOwnPtr<GridSpan> resolveGridPositionAgainstOppositePosition(const
ComputedStyle&, const GridResolvedPosition& resolvedOppositePosition, const Gri
dPosition&, GridPositionSide); | 43 static PassOwnPtr<GridSpan> resolveGridPositionAgainstOppositePosition(const
ComputedStyle&, const GridResolvedPosition& resolvedOppositePosition, const Gri
dPosition&, GridPositionSide); |
| 57 static PassOwnPtr<GridSpan> resolveNamedGridLinePositionAgainstOppositePosit
ion(const ComputedStyle&, const GridResolvedPosition& resolvedOppositePosition,
const GridPosition&, GridPositionSide); | 44 static PassOwnPtr<GridSpan> resolveNamedGridLinePositionAgainstOppositePosit
ion(const ComputedStyle&, const GridResolvedPosition& resolvedOppositePosition,
const GridPosition&, GridPositionSide); |
| 58 | 45 |
| 59 GridResolvedPosition(size_t position) | 46 GridResolvedPosition(size_t position) |
| 60 : m_integerPosition(position) | 47 : m_integerPosition(position) |
| 61 { | 48 { |
| 62 } | 49 } |
| 63 | 50 |
| 64 GridResolvedPosition(const GridPosition& position, GridPositionSide side) | |
| 65 { | |
| 66 ASSERT(position.integerPosition()); | |
| 67 size_t integerPosition = position.integerPosition() - 1; | |
| 68 | |
| 69 m_integerPosition = adjustGridPositionForSide(integerPosition, side).toI
nt(); | |
| 70 } | |
| 71 | |
| 72 GridResolvedPosition& operator*() | 51 GridResolvedPosition& operator*() |
| 73 { | 52 { |
| 74 return *this; | 53 return *this; |
| 75 } | 54 } |
| 76 | 55 |
| 77 GridResolvedPosition& operator++() | 56 GridResolvedPosition& operator++() |
| 78 { | 57 { |
| 79 m_integerPosition++; | 58 m_integerPosition++; |
| 80 return *this; | 59 return *this; |
| 81 } | 60 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 size_t toInt() const | 92 size_t toInt() const |
| 114 { | 93 { |
| 115 return m_integerPosition; | 94 return m_integerPosition; |
| 116 } | 95 } |
| 117 | 96 |
| 118 GridResolvedPosition next() const | 97 GridResolvedPosition next() const |
| 119 { | 98 { |
| 120 return GridResolvedPosition(m_integerPosition + 1); | 99 return GridResolvedPosition(m_integerPosition + 1); |
| 121 } | 100 } |
| 122 | 101 |
| 102 GridResolvedPosition prev() const |
| 103 { |
| 104 return GridResolvedPosition(m_integerPosition > 0 ? m_integerPosition -
1 : 0); |
| 105 } |
| 106 |
| 123 static size_t explicitGridColumnCount(const ComputedStyle&); | 107 static size_t explicitGridColumnCount(const ComputedStyle&); |
| 124 static size_t explicitGridRowCount(const ComputedStyle&); | 108 static size_t explicitGridRowCount(const ComputedStyle&); |
| 125 | 109 |
| 126 private: | 110 private: |
| 127 | 111 |
| 128 static size_t explicitGridSizeForSide(const ComputedStyle&, GridPositionSide
); | 112 static size_t explicitGridSizeForSide(const ComputedStyle&, GridPositionSide
); |
| 129 | 113 |
| 130 size_t m_integerPosition; | 114 size_t m_integerPosition; |
| 131 }; | 115 }; |
| 132 | 116 |
| 133 } // namespace blink | 117 } // namespace blink |
| 134 | 118 |
| 135 #endif // GridResolvedPosition_h | 119 #endif // GridResolvedPosition_h |
| OLD | NEW |