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 20 matching lines...) Expand all Loading... |
31 #ifndef GridPosition_h | 31 #ifndef GridPosition_h |
32 #define GridPosition_h | 32 #define GridPosition_h |
33 | 33 |
34 #include "wtf/text/WTFString.h" | 34 #include "wtf/text/WTFString.h" |
35 | 35 |
36 namespace WebCore { | 36 namespace WebCore { |
37 | 37 |
38 enum GridPositionType { | 38 enum GridPositionType { |
39 AutoPosition, | 39 AutoPosition, |
40 ExplicitPosition, // [ <integer> || <string> ] | 40 ExplicitPosition, // [ <integer> || <string> ] |
41 SpanPosition | 41 SpanPosition, // span && [ <integer> || <string> ] |
| 42 NamedGridAreaPosition // <ident> |
42 }; | 43 }; |
43 | 44 |
44 class GridPosition { | 45 class GridPosition { |
45 public: | 46 public: |
46 GridPosition() | 47 GridPosition() |
47 : m_type(AutoPosition) | 48 : m_type(AutoPosition) |
48 , m_integerPosition(0) | 49 , m_integerPosition(0) |
49 { | 50 { |
50 } | 51 } |
51 | 52 |
52 bool isPositive() const { return integerPosition() > 0; } | 53 bool isPositive() const { return integerPosition() > 0; } |
53 | 54 |
54 GridPositionType type() const { return m_type; } | 55 GridPositionType type() const { return m_type; } |
55 bool isAuto() const { return m_type == AutoPosition; } | 56 bool isAuto() const { return m_type == AutoPosition; } |
56 bool isSpan() const { return m_type == SpanPosition; } | 57 bool isSpan() const { return m_type == SpanPosition; } |
| 58 bool isNamedGridArea() const { return m_type == NamedGridAreaPosition; } |
57 | 59 |
58 void setExplicitPosition(int position, const String& namedGridLine) | 60 void setExplicitPosition(int position, const String& namedGridLine) |
59 { | 61 { |
60 m_type = ExplicitPosition; | 62 m_type = ExplicitPosition; |
61 m_integerPosition = position; | 63 m_integerPosition = position; |
62 m_namedGridLine = namedGridLine; | 64 m_namedGridLine = namedGridLine; |
63 } | 65 } |
64 | 66 |
65 // 'span' values cannot be negative, yet we reuse the <integer> position whi
ch can | 67 // 'span' values cannot be negative, yet we reuse the <integer> position whi
ch can |
66 // be. This means that we have to convert the span position to an integer, l
osing | 68 // be. This means that we have to convert the span position to an integer, l
osing |
67 // some precision here. It shouldn't be an issue in practice though. | 69 // some precision here. It shouldn't be an issue in practice though. |
68 void setSpanPosition(int position, const String& namedGridLine) | 70 void setSpanPosition(int position, const String& namedGridLine) |
69 { | 71 { |
70 m_type = SpanPosition; | 72 m_type = SpanPosition; |
71 m_integerPosition = position; | 73 m_integerPosition = position; |
72 m_namedGridLine = namedGridLine; | 74 m_namedGridLine = namedGridLine; |
73 } | 75 } |
74 | 76 |
| 77 void setNamedGridArea(const String& namedGridArea) |
| 78 { |
| 79 m_type = NamedGridAreaPosition; |
| 80 m_namedGridLine = namedGridArea; |
| 81 } |
| 82 |
75 int integerPosition() const | 83 int integerPosition() const |
76 { | 84 { |
77 ASSERT(type() == ExplicitPosition); | 85 ASSERT(type() == ExplicitPosition); |
78 return m_integerPosition; | 86 return m_integerPosition; |
79 } | 87 } |
80 | 88 |
81 String namedGridLine() const | 89 String namedGridLine() const |
82 { | 90 { |
83 ASSERT(type() == ExplicitPosition || type() == SpanPosition); | 91 ASSERT(type() == ExplicitPosition || type() == SpanPosition || type() ==
NamedGridAreaPosition); |
84 return m_namedGridLine; | 92 return m_namedGridLine; |
85 } | 93 } |
86 | 94 |
87 int spanPosition() const | 95 int spanPosition() const |
88 { | 96 { |
89 ASSERT(type() == SpanPosition); | 97 ASSERT(type() == SpanPosition); |
90 return m_integerPosition; | 98 return m_integerPosition; |
91 } | 99 } |
92 | 100 |
93 bool operator==(const GridPosition& other) const | 101 bool operator==(const GridPosition& other) const |
94 { | 102 { |
95 return m_type == other.m_type && m_integerPosition == other.m_integerPos
ition && m_namedGridLine == other.m_namedGridLine; | 103 return m_type == other.m_type && m_integerPosition == other.m_integerPos
ition && m_namedGridLine == other.m_namedGridLine; |
96 } | 104 } |
97 | 105 |
98 bool shouldBeResolvedAgainstOppositePosition() const | 106 bool shouldBeResolvedAgainstOppositePosition() const |
99 { | 107 { |
100 return isAuto() || isSpan(); | 108 return isAuto() || isSpan(); |
101 } | 109 } |
102 private: | 110 private: |
103 GridPositionType m_type; | 111 GridPositionType m_type; |
104 int m_integerPosition; | 112 int m_integerPosition; |
105 String m_namedGridLine; | 113 String m_namedGridLine; |
106 }; | 114 }; |
107 | 115 |
108 } // namespace WebCore | 116 } // namespace WebCore |
109 | 117 |
110 #endif // GridPosition_h | 118 #endif // GridPosition_h |
OLD | NEW |