| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 25 matching lines...) Expand all Loading... |
| 36 #include "wtf/HashMap.h" | 36 #include "wtf/HashMap.h" |
| 37 #include "wtf/PassOwnPtr.h" | 37 #include "wtf/PassOwnPtr.h" |
| 38 #include "wtf/text/WTFString.h" | 38 #include "wtf/text/WTFString.h" |
| 39 #include <algorithm> | 39 #include <algorithm> |
| 40 | 40 |
| 41 namespace blink { | 41 namespace blink { |
| 42 | 42 |
| 43 // Recommended maximum size for both explicit and implicit grids. | 43 // Recommended maximum size for both explicit and implicit grids. |
| 44 const int kGridMaxTracks = 1000000; | 44 const int kGridMaxTracks = 1000000; |
| 45 | 45 |
| 46 // A span in a single direction (either rows or columns). Note that |resolvedIni
tialPosition| | 46 // A span in a single direction (either rows or columns). Note that |startLine| |
| 47 // and |resolvedFinalPosition| are grid lines' indexes. | 47 // and |endLine| are grid lines' indexes. |
| 48 // Iterating over the span shouldn't include |resolvedFinalPosition| to be corre
ct. | 48 // Despite line numbers in the spec start in "1", the indexes here start in "0". |
| 49 struct GridSpan { | 49 struct GridSpan { |
| 50 USING_FAST_MALLOC(GridSpan); | 50 USING_FAST_MALLOC(GridSpan); |
| 51 public: | 51 public: |
| 52 | 52 |
| 53 static GridSpan untranslatedDefiniteGridSpan(int resolvedInitialPosition, in
t resolvedFinalPosition) | 53 static GridSpan untranslatedDefiniteGridSpan(int startLine, int endLine) |
| 54 { | 54 { |
| 55 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Untransl
atedDefinite); | 55 return GridSpan(startLine, endLine, UntranslatedDefinite); |
| 56 } | 56 } |
| 57 | 57 |
| 58 static GridSpan translatedDefiniteGridSpan(size_t resolvedInitialPosition, s
ize_t resolvedFinalPosition) | 58 static GridSpan translatedDefiniteGridSpan(size_t startLine, size_t endLine) |
| 59 { | 59 { |
| 60 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Translat
edDefinite); | 60 return GridSpan(startLine, endLine, TranslatedDefinite); |
| 61 } | 61 } |
| 62 | 62 |
| 63 static GridSpan indefiniteGridSpan() | 63 static GridSpan indefiniteGridSpan() |
| 64 { | 64 { |
| 65 return GridSpan(0, 1, Indefinite); | 65 return GridSpan(0, 1, Indefinite); |
| 66 } | 66 } |
| 67 | 67 |
| 68 bool operator==(const GridSpan& o) const | 68 bool operator==(const GridSpan& o) const |
| 69 { | 69 { |
| 70 return m_type == o.m_type && m_resolvedInitialPosition == o.m_resolvedIn
itialPosition && m_resolvedFinalPosition == o.m_resolvedFinalPosition; | 70 return m_type == o.m_type && m_startLine == o.m_startLine && m_endLine =
= o.m_endLine; |
| 71 } | 71 } |
| 72 | 72 |
| 73 size_t integerSpan() const | 73 size_t integerSpan() const |
| 74 { | 74 { |
| 75 ASSERT(isTranslatedDefinite()); | 75 ASSERT(isTranslatedDefinite()); |
| 76 ASSERT(m_resolvedFinalPosition > m_resolvedInitialPosition); | 76 ASSERT(m_endLine > m_startLine); |
| 77 return m_resolvedFinalPosition - m_resolvedInitialPosition; | 77 return m_endLine - m_startLine; |
| 78 } | 78 } |
| 79 | 79 |
| 80 int untranslatedResolvedInitialPosition() const | 80 int untranslatedStartLine() const |
| 81 { | 81 { |
| 82 ASSERT(m_type == UntranslatedDefinite); | 82 ASSERT(m_type == UntranslatedDefinite); |
| 83 return m_resolvedInitialPosition; | 83 return m_startLine; |
| 84 } | 84 } |
| 85 | 85 |
| 86 int untranslatedResolvedFinalPosition() const | 86 int untranslatedEndLine() const |
| 87 { | 87 { |
| 88 ASSERT(m_type == UntranslatedDefinite); | 88 ASSERT(m_type == UntranslatedDefinite); |
| 89 return m_resolvedFinalPosition; | 89 return m_endLine; |
| 90 } | 90 } |
| 91 | 91 |
| 92 size_t resolvedInitialPosition() const | 92 size_t startLine() const |
| 93 { | 93 { |
| 94 ASSERT(isTranslatedDefinite()); | 94 ASSERT(isTranslatedDefinite()); |
| 95 ASSERT(m_resolvedInitialPosition >= 0); | 95 ASSERT(m_startLine >= 0); |
| 96 return m_resolvedInitialPosition; | 96 return m_startLine; |
| 97 } | 97 } |
| 98 | 98 |
| 99 size_t resolvedFinalPosition() const | 99 size_t endLine() const |
| 100 { | 100 { |
| 101 ASSERT(isTranslatedDefinite()); | 101 ASSERT(isTranslatedDefinite()); |
| 102 ASSERT(m_resolvedFinalPosition > 0); | 102 ASSERT(m_endLine > 0); |
| 103 return m_resolvedFinalPosition; | 103 return m_endLine; |
| 104 } | 104 } |
| 105 | 105 |
| 106 struct GridSpanIterator { | 106 struct GridSpanIterator { |
| 107 GridSpanIterator(size_t v) : value(v) {} | 107 GridSpanIterator(size_t v) : value(v) {} |
| 108 | 108 |
| 109 size_t operator*() const { return value; } | 109 size_t operator*() const { return value; } |
| 110 size_t operator++() { return value++; } | 110 size_t operator++() { return value++; } |
| 111 bool operator!=(GridSpanIterator other) const { return value != other.va
lue; } | 111 bool operator!=(GridSpanIterator other) const { return value != other.va
lue; } |
| 112 | 112 |
| 113 size_t value; | 113 size_t value; |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 GridSpanIterator begin() const | 116 GridSpanIterator begin() const |
| 117 { | 117 { |
| 118 ASSERT(isTranslatedDefinite()); | 118 ASSERT(isTranslatedDefinite()); |
| 119 return m_resolvedInitialPosition; | 119 return m_startLine; |
| 120 } | 120 } |
| 121 | 121 |
| 122 GridSpanIterator end() const | 122 GridSpanIterator end() const |
| 123 { | 123 { |
| 124 ASSERT(isTranslatedDefinite()); | 124 ASSERT(isTranslatedDefinite()); |
| 125 return m_resolvedFinalPosition; | 125 return m_endLine; |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool isTranslatedDefinite() const | 128 bool isTranslatedDefinite() const |
| 129 { | 129 { |
| 130 return m_type == TranslatedDefinite; | 130 return m_type == TranslatedDefinite; |
| 131 } | 131 } |
| 132 | 132 |
| 133 bool isIndefinite() const | 133 bool isIndefinite() const |
| 134 { | 134 { |
| 135 return m_type == Indefinite; | 135 return m_type == Indefinite; |
| 136 } | 136 } |
| 137 | 137 |
| 138 void translate(size_t offset) | 138 void translate(size_t offset) |
| 139 { | 139 { |
| 140 ASSERT(m_type == UntranslatedDefinite); | 140 ASSERT(m_type == UntranslatedDefinite); |
| 141 | 141 |
| 142 m_type = TranslatedDefinite; | 142 m_type = TranslatedDefinite; |
| 143 m_resolvedInitialPosition += offset; | 143 m_startLine += offset; |
| 144 m_resolvedFinalPosition += offset; | 144 m_endLine += offset; |
| 145 | 145 |
| 146 ASSERT(m_resolvedInitialPosition >= 0); | 146 ASSERT(m_startLine >= 0); |
| 147 ASSERT(m_resolvedFinalPosition > 0); | 147 ASSERT(m_endLine > 0); |
| 148 } | 148 } |
| 149 | 149 |
| 150 private: | 150 private: |
| 151 | 151 |
| 152 enum GridSpanType {UntranslatedDefinite, TranslatedDefinite, Indefinite}; | 152 enum GridSpanType {UntranslatedDefinite, TranslatedDefinite, Indefinite}; |
| 153 | 153 |
| 154 GridSpan(int resolvedInitialPosition, int resolvedFinalPosition, GridSpanTyp
e type) | 154 GridSpan(int startLine, int endLine, GridSpanType type) |
| 155 : m_type(type) | 155 : m_type(type) |
| 156 { | 156 { |
| 157 #if ENABLE(ASSERT) | 157 #if ENABLE(ASSERT) |
| 158 ASSERT(resolvedInitialPosition < resolvedFinalPosition); | 158 ASSERT(startLine < endLine); |
| 159 if (type == TranslatedDefinite) { | 159 if (type == TranslatedDefinite) { |
| 160 ASSERT(resolvedInitialPosition >= 0); | 160 ASSERT(startLine >= 0); |
| 161 ASSERT(resolvedFinalPosition > 0); | 161 ASSERT(endLine > 0); |
| 162 } | 162 } |
| 163 #endif | 163 #endif |
| 164 | 164 |
| 165 if (resolvedInitialPosition >= 0) | 165 if (startLine >= 0) |
| 166 m_resolvedInitialPosition = std::min(resolvedInitialPosition, kGridM
axTracks - 1); | 166 m_startLine = std::min(startLine, kGridMaxTracks - 1); |
| 167 else | 167 else |
| 168 m_resolvedInitialPosition = std::max(resolvedInitialPosition, -kGrid
MaxTracks); | 168 m_startLine = std::max(startLine, -kGridMaxTracks); |
| 169 | 169 |
| 170 if (resolvedFinalPosition >= 0) | 170 if (endLine >= 0) |
| 171 m_resolvedFinalPosition = std::min(resolvedFinalPosition, kGridMaxTr
acks); | 171 m_endLine = std::min(endLine, kGridMaxTracks); |
| 172 else | 172 else |
| 173 m_resolvedFinalPosition = std::max(resolvedFinalPosition, -kGridMaxT
racks + 1); | 173 m_endLine = std::max(endLine, -kGridMaxTracks + 1); |
| 174 } | 174 } |
| 175 | 175 |
| 176 int m_resolvedInitialPosition; | 176 int m_startLine; |
| 177 int m_resolvedFinalPosition; | 177 int m_endLine; |
| 178 GridSpanType m_type; | 178 GridSpanType m_type; |
| 179 }; | 179 }; |
| 180 | 180 |
| 181 // This represents a grid area that spans in both rows' and columns' direction. | 181 // This represents a grid area that spans in both rows' and columns' direction. |
| 182 struct GridArea { | 182 struct GridArea { |
| 183 USING_FAST_MALLOC(GridArea); | 183 USING_FAST_MALLOC(GridArea); |
| 184 public: | 184 public: |
| 185 // HashMap requires a default constuctor. | 185 // HashMap requires a default constuctor. |
| 186 GridArea() | 186 GridArea() |
| 187 : columns(GridSpan::indefiniteGridSpan()) | 187 : columns(GridSpan::indefiniteGridSpan()) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 207 | 207 |
| 208 GridSpan columns; | 208 GridSpan columns; |
| 209 GridSpan rows; | 209 GridSpan rows; |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 typedef HashMap<String, GridArea> NamedGridAreaMap; | 212 typedef HashMap<String, GridArea> NamedGridAreaMap; |
| 213 | 213 |
| 214 } // namespace blink | 214 } // namespace blink |
| 215 | 215 |
| 216 #endif // GridArea_h | 216 #endif // GridArea_h |
| OLD | NEW |