| 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; } | 56 bool isExplicit() const { return m_type == ExplicitPosition; } |
| 55 bool isSpan() const { return m_type == SpanPosition; } | 57 bool isSpan() const { return m_type == SpanPosition; } |
| 56 | 58 |
| 57 void setIntegerPosition(int position) | 59 void setExplicitPosition(int position, const String& namedGridLine) |
| 58 { | 60 { |
| 59 m_type = IntegerPosition; | 61 m_type = ExplicitPosition; |
| 60 m_integerPosition = position; | 62 m_integerPosition = position; |
| 63 m_namedGridLine = namedGridLine; |
| 61 } | 64 } |
| 62 | 65 |
| 63 // 'span' values cannot be negative, yet we reuse the <integer> position whi
ch can | 66 // '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 | 67 // 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. | 68 // some precision here. It shouldn't be an issue in practice though. |
| 66 void setSpanPosition(int position) | 69 void setSpanPosition(int position) |
| 67 { | 70 { |
| 68 m_type = SpanPosition; | 71 m_type = SpanPosition; |
| 69 m_integerPosition = position; | 72 m_integerPosition = position; |
| 70 } | 73 } |
| 71 | 74 |
| 72 int integerPosition() const | 75 int integerPosition() const |
| 73 { | 76 { |
| 74 ASSERT(type() == IntegerPosition); | 77 ASSERT(type() == ExplicitPosition); |
| 75 return m_integerPosition; | 78 return m_integerPosition; |
| 76 } | 79 } |
| 77 | 80 |
| 81 String namedGridLine() const |
| 82 { |
| 83 ASSERT(type() == ExplicitPosition); |
| 84 return m_namedGridLine; |
| 85 } |
| 86 |
| 78 int spanPosition() const | 87 int spanPosition() const |
| 79 { | 88 { |
| 80 ASSERT(type() == SpanPosition); | 89 ASSERT(type() == SpanPosition); |
| 81 return m_integerPosition; | 90 return m_integerPosition; |
| 82 } | 91 } |
| 83 | 92 |
| 84 bool operator==(const GridPosition& other) const | 93 bool operator==(const GridPosition& other) const |
| 85 { | 94 { |
| 86 return m_type == other.m_type && m_integerPosition == other.m_integerPos
ition; | 95 return m_type == other.m_type && m_integerPosition == other.m_integerPos
ition; |
| 87 } | 96 } |
| 88 | 97 |
| 89 bool shouldBeResolvedAgainstOppositePosition() const | 98 bool shouldBeResolvedAgainstOppositePosition() const |
| 90 { | 99 { |
| 91 return isAuto() || isSpan(); | 100 return isAuto() || isSpan(); |
| 92 } | 101 } |
| 93 private: | 102 private: |
| 94 GridPositionType m_type; | 103 GridPositionType m_type; |
| 95 int m_integerPosition; | 104 int m_integerPosition; |
| 105 String m_namedGridLine; |
| 96 }; | 106 }; |
| 97 | 107 |
| 98 } // namespace WebCore | 108 } // namespace WebCore |
| 99 | 109 |
| 100 #endif // GridPosition_h | 110 #endif // GridPosition_h |
| OLD | NEW |