| 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 17 matching lines...) Expand all Loading... |
| 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 namespace WebCore { | 34 namespace WebCore { |
| 35 | 35 |
| 36 enum GridPositionType { | 36 enum GridPositionType { |
| 37 AutoPosition, | 37 AutoPosition, |
| 38 IntegerPosition | 38 IntegerPosition, |
| 39 SpanPosition |
| 39 }; | 40 }; |
| 40 | 41 |
| 41 class GridPosition { | 42 class GridPosition { |
| 42 public: | 43 public: |
| 43 GridPosition() | 44 GridPosition() |
| 44 : m_type(AutoPosition) | 45 : m_type(AutoPosition) |
| 45 , m_integerPosition(0) | 46 , m_integerPosition(0) |
| 46 { | 47 { |
| 47 } | 48 } |
| 48 | 49 |
| 49 bool isPositive() const { return integerPosition() > 0; } | 50 bool isPositive() const { return integerPosition() > 0; } |
| 50 | 51 |
| 51 GridPositionType type() const { return m_type; } | 52 GridPositionType type() const { return m_type; } |
| 52 bool isAuto() const { return m_type == AutoPosition; } | 53 bool isAuto() const { return m_type == AutoPosition; } |
| 54 bool isInteger() const { return m_type == IntegerPosition; } |
| 53 | 55 |
| 54 void setIntegerPosition(int position) | 56 void setIntegerPosition(int position) |
| 55 { | 57 { |
| 56 m_type = IntegerPosition; | 58 m_type = IntegerPosition; |
| 57 m_integerPosition = position; | 59 m_integerPosition = position; |
| 58 } | 60 } |
| 59 | 61 |
| 62 // 'span' values cannot be negative, yet we reuse the <integer> position whi
ch can |
| 63 // be. This means that we have to convert the span position to an integer, l
osing |
| 64 // some precision here. It shouldn't be an issue in practice though. |
| 65 void setSpanPosition(int position) |
| 66 { |
| 67 m_type = SpanPosition; |
| 68 m_integerPosition = position; |
| 69 } |
| 70 |
| 60 int integerPosition() const | 71 int integerPosition() const |
| 61 { | 72 { |
| 62 ASSERT(type() == IntegerPosition); | 73 ASSERT(type() == IntegerPosition); |
| 63 return m_integerPosition; | 74 return m_integerPosition; |
| 64 } | 75 } |
| 65 | 76 |
| 77 int spanPosition() const |
| 78 { |
| 79 ASSERT(type() == SpanPosition); |
| 80 return m_integerPosition; |
| 81 } |
| 82 |
| 66 bool operator==(const GridPosition& other) const | 83 bool operator==(const GridPosition& other) const |
| 67 { | 84 { |
| 68 return m_type == other.m_type && m_integerPosition == other.m_integerPos
ition; | 85 return m_type == other.m_type && m_integerPosition == other.m_integerPos
ition; |
| 69 } | 86 } |
| 70 | 87 |
| 71 private: | 88 private: |
| 72 GridPositionType m_type; | 89 GridPositionType m_type; |
| 73 // FIXME: This should probably be a size_t but the spec currently allows any
<integer>. | 90 // FIXME: This should probably be a size_t but the spec currently allows any
<integer>. |
| 74 int m_integerPosition; | 91 int m_integerPosition; |
| 75 }; | 92 }; |
| 76 | 93 |
| 77 } // namespace WebCore | 94 } // namespace WebCore |
| 78 | 95 |
| 79 #endif // GridPosition_h | 96 #endif // GridPosition_h |
| OLD | NEW |