OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef GridPosition_h | 31 #ifndef GridPosition_h |
32 #define GridPosition_h | 32 #define GridPosition_h |
33 | 33 |
| 34 #include "wtf/text/WTFString.h" |
| 35 |
34 namespace WebCore { | 36 namespace WebCore { |
35 | 37 |
36 enum GridPositionType { | 38 enum GridPositionType { |
37 AutoPosition, | 39 AutoPosition, |
38 IntegerPosition, | 40 ExplicitPosition, // [ <integer> || <string> ] |
39 SpanPosition | 41 SpanPosition |
40 }; | 42 }; |
41 | 43 |
42 class GridPosition { | 44 class GridPosition { |
43 public: | 45 public: |
44 GridPosition() | 46 GridPosition() |
45 : m_type(AutoPosition) | 47 : m_type(AutoPosition) |
46 , m_integerPosition(0) | 48 , m_integerPosition(0) |
47 { | 49 { |
48 } | 50 } |
49 | 51 |
50 bool isPositive() const { return integerPosition() > 0; } | 52 bool isPositive() const { return integerPosition() > 0; } |
51 | 53 |
52 GridPositionType type() const { return m_type; } | 54 GridPositionType type() const { return m_type; } |
53 bool isAuto() const { return m_type == AutoPosition; } | 55 bool isAuto() const { return m_type == AutoPosition; } |
54 bool isInteger() const { return m_type == IntegerPosition; } | |
55 bool isSpan() const { return m_type == SpanPosition; } | 56 bool isSpan() const { return m_type == SpanPosition; } |
56 | 57 |
57 void setIntegerPosition(int position) | 58 void setExplicitPosition(int position, const String& namedGridLine) |
58 { | 59 { |
59 m_type = IntegerPosition; | 60 m_type = ExplicitPosition; |
60 m_integerPosition = position; | 61 m_integerPosition = position; |
| 62 m_namedGridLine = namedGridLine; |
61 } | 63 } |
62 | 64 |
63 // 'span' values cannot be negative, yet we reuse the <integer> position whi
ch can | 65 // 'span' values cannot be negative, yet we reuse the <integer> position whi
ch can |
64 // be. This means that we have to convert the span position to an integer, l
osing | 66 // be. This means that we have to convert the span position to an integer, l
osing |
65 // some precision here. It shouldn't be an issue in practice though. | 67 // some precision here. It shouldn't be an issue in practice though. |
66 void setSpanPosition(int position) | 68 void setSpanPosition(int position) |
67 { | 69 { |
68 m_type = SpanPosition; | 70 m_type = SpanPosition; |
69 m_integerPosition = position; | 71 m_integerPosition = position; |
70 } | 72 } |
71 | 73 |
72 int integerPosition() const | 74 int integerPosition() const |
73 { | 75 { |
74 ASSERT(type() == IntegerPosition); | 76 ASSERT(type() == ExplicitPosition); |
75 return m_integerPosition; | 77 return m_integerPosition; |
76 } | 78 } |
77 | 79 |
| 80 String namedGridLine() const |
| 81 { |
| 82 ASSERT(type() == ExplicitPosition); |
| 83 return m_namedGridLine; |
| 84 } |
| 85 |
78 int spanPosition() const | 86 int spanPosition() const |
79 { | 87 { |
80 ASSERT(type() == SpanPosition); | 88 ASSERT(type() == SpanPosition); |
81 return m_integerPosition; | 89 return m_integerPosition; |
82 } | 90 } |
83 | 91 |
84 bool operator==(const GridPosition& other) const | 92 bool operator==(const GridPosition& other) const |
85 { | 93 { |
86 return m_type == other.m_type && m_integerPosition == other.m_integerPos
ition; | 94 return m_type == other.m_type && m_integerPosition == other.m_integerPos
ition; |
87 } | 95 } |
88 | 96 |
89 bool shouldBeResolvedAgainstOppositePosition() const | 97 bool shouldBeResolvedAgainstOppositePosition() const |
90 { | 98 { |
91 return isAuto() || isSpan(); | 99 return isAuto() || isSpan(); |
92 } | 100 } |
93 private: | 101 private: |
94 GridPositionType m_type; | 102 GridPositionType m_type; |
95 int m_integerPosition; | 103 int m_integerPosition; |
| 104 String m_namedGridLine; |
96 }; | 105 }; |
97 | 106 |
98 } // namespace WebCore | 107 } // namespace WebCore |
99 | 108 |
100 #endif // GridPosition_h | 109 #endif // GridPosition_h |
OLD | NEW |