OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef GridResolvedPosition_h |
| 6 #define GridResolvedPosition_h |
| 7 |
| 8 #include "core/rendering/style/GridPosition.h" |
| 9 |
| 10 namespace WebCore { |
| 11 |
| 12 struct GridSpan; |
| 13 class RenderBox; |
| 14 class RenderStyle; |
| 15 |
| 16 enum GridPositionSide { |
| 17 ColumnStartSide, |
| 18 ColumnEndSide, |
| 19 RowStartSide, |
| 20 RowEndSide |
| 21 }; |
| 22 |
| 23 enum GridTrackSizingDirection { |
| 24 ForColumns, |
| 25 ForRows |
| 26 }; |
| 27 |
| 28 // This class represents an index into one of the dimensions of the grid array. |
| 29 // Wraps a size_t integer just for the purpose of knowing what we manipulate in
the grid code. |
| 30 class GridResolvedPosition { |
| 31 public: |
| 32 static size_t adjustGridPositionForAfterEndSide(size_t resolvedPosition) |
| 33 { |
| 34 return resolvedPosition ? resolvedPosition - 1 : 0; |
| 35 } |
| 36 |
| 37 static size_t adjustGridPositionForSide(size_t resolvedPosition, GridPositio
nSide side) |
| 38 { |
| 39 // An item finishing on the N-th line belongs to the N-1-th cell. |
| 40 if (side == ColumnEndSide || side == RowEndSide) |
| 41 return adjustGridPositionForAfterEndSide(resolvedPosition); |
| 42 |
| 43 return resolvedPosition; |
| 44 } |
| 45 |
| 46 static GridSpan resolveGridPositionsFromAutoPlacementPosition(const RenderBo
x&, GridTrackSizingDirection, const GridResolvedPosition&); |
| 47 static PassOwnPtr<GridSpan> resolveGridPositionsFromStyle(const RenderStyle&
, const RenderBox&, GridTrackSizingDirection); |
| 48 static GridResolvedPosition resolveNamedGridLinePositionFromStyle(const Rend
erStyle&, const GridPosition&, GridPositionSide); |
| 49 static GridResolvedPosition resolveGridPositionFromStyle(const RenderStyle&,
const GridPosition&, GridPositionSide); |
| 50 static PassOwnPtr<GridSpan> resolveGridPositionAgainstOppositePosition(const
RenderStyle&, const GridResolvedPosition& resolvedOppositePosition, const GridP
osition&, GridPositionSide); |
| 51 static PassOwnPtr<GridSpan> resolveNamedGridLinePositionAgainstOppositePosit
ion(const RenderStyle&, const GridResolvedPosition& resolvedOppositePosition, co
nst GridPosition&, GridPositionSide); |
| 52 |
| 53 GridResolvedPosition(size_t position) |
| 54 : m_integerPosition(position) |
| 55 { |
| 56 } |
| 57 |
| 58 GridResolvedPosition(const GridPosition& position, GridPositionSide side) |
| 59 { |
| 60 ASSERT(position.integerPosition()); |
| 61 size_t integerPosition = position.integerPosition() - 1; |
| 62 |
| 63 m_integerPosition = adjustGridPositionForSide(integerPosition, side); |
| 64 } |
| 65 |
| 66 GridResolvedPosition& operator++() |
| 67 { |
| 68 m_integerPosition++; |
| 69 return *this; |
| 70 } |
| 71 |
| 72 bool operator==(const GridResolvedPosition& other) const |
| 73 { |
| 74 return m_integerPosition == other.m_integerPosition; |
| 75 } |
| 76 |
| 77 bool operator<(const GridResolvedPosition& other) const |
| 78 { |
| 79 return m_integerPosition < other.m_integerPosition; |
| 80 } |
| 81 |
| 82 bool operator>(const GridResolvedPosition& other) const |
| 83 { |
| 84 return m_integerPosition > other.m_integerPosition; |
| 85 } |
| 86 |
| 87 bool operator<=(const GridResolvedPosition& other) const |
| 88 { |
| 89 return m_integerPosition <= other.m_integerPosition; |
| 90 } |
| 91 |
| 92 bool operator>=(const GridResolvedPosition& other) const |
| 93 { |
| 94 return m_integerPosition >= other.m_integerPosition; |
| 95 } |
| 96 |
| 97 size_t toInt() const |
| 98 { |
| 99 return m_integerPosition; |
| 100 } |
| 101 |
| 102 static size_t explicitGridColumnCount(const RenderStyle&); |
| 103 static size_t explicitGridRowCount(const RenderStyle&); |
| 104 |
| 105 private: |
| 106 |
| 107 static size_t explicitGridSizeForSide(const RenderStyle&, GridPositionSide); |
| 108 |
| 109 size_t m_integerPosition; |
| 110 }; |
| 111 |
| 112 } // namespace WebCore |
| 113 |
| 114 #endif // GridResolvedPosition_h |
OLD | NEW |