Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/WebKit/Source/core/style/GridCoordinate.h

Issue 1500433003: [css-grid] Get rid of GridResolvedPosition (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change operators overloaded in GridSpanIterator Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // Recommended maximum size for both explicit and implicit grids. 43 // Recommended maximum size for both explicit and implicit grids.
44 const size_t kGridMaxTracks = 1000000; 44 const size_t 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 |resolvedIni tialPosition|
47 // and |resolvedFinalPosition| are grid lines' indexes. 47 // and |resolvedFinalPosition| are grid lines' indexes.
48 // Iterating over the span shouldn't include |resolvedFinalPosition| to be corre ct. 48 // Iterating over the span shouldn't include |resolvedFinalPosition| to be corre ct.
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 definiteGridSpan(const GridResolvedPosition& resolvedInitial Position, const GridResolvedPosition& resolvedFinalPosition) 53 static GridSpan definiteGridSpan(size_t resolvedInitialPosition, size_t reso lvedFinalPosition)
54 { 54 {
55 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Definite ); 55 return GridSpan(resolvedInitialPosition, resolvedFinalPosition, Definite );
56 } 56 }
57 57
58 static GridSpan indefiniteGridSpan() 58 static GridSpan indefiniteGridSpan()
59 { 59 {
60 return GridSpan(0, 1, Indefinite); 60 return GridSpan(0, 1, Indefinite);
61 } 61 }
62 62
63 bool operator==(const GridSpan& o) const 63 bool operator==(const GridSpan& o) const
64 { 64 {
65 return m_type == o.m_type && m_resolvedInitialPosition == o.m_resolvedIn itialPosition && m_resolvedFinalPosition == o.m_resolvedFinalPosition; 65 return m_type == o.m_type && m_resolvedInitialPosition == o.m_resolvedIn itialPosition && m_resolvedFinalPosition == o.m_resolvedFinalPosition;
66 } 66 }
67 67
68 size_t integerSpan() const 68 size_t integerSpan() const
69 { 69 {
70 ASSERT(isDefinite()); 70 ASSERT(isDefinite());
71 return m_resolvedFinalPosition.toInt() - m_resolvedInitialPosition.toInt (); 71 ASSERT(m_resolvedFinalPosition > m_resolvedInitialPosition);
72 return m_resolvedFinalPosition - m_resolvedInitialPosition;
72 } 73 }
73 74
74 const GridResolvedPosition& resolvedInitialPosition() const 75 size_t resolvedInitialPosition() const
75 { 76 {
76 ASSERT(isDefinite()); 77 ASSERT(isDefinite());
77 return m_resolvedInitialPosition; 78 return m_resolvedInitialPosition;
78 } 79 }
79 80
80 const GridResolvedPosition& resolvedFinalPosition() const 81 size_t resolvedFinalPosition() const
81 { 82 {
82 ASSERT(isDefinite()); 83 ASSERT(isDefinite());
84 ASSERT(m_resolvedFinalPosition);
83 return m_resolvedFinalPosition; 85 return m_resolvedFinalPosition;
84 } 86 }
85 87
86 typedef GridResolvedPosition iterator; 88 struct GridSpanIterator {
89 GridSpanIterator(size_t v) : value(v) {}
87 90
88 iterator begin() const 91 size_t operator*() const { return value; }
92 size_t operator++() { return value++; }
93 bool operator!=(GridSpanIterator other) const { return value != other.va lue; }
94
95 size_t value;
96 };
97
98 GridSpanIterator begin() const
89 { 99 {
90 ASSERT(isDefinite()); 100 ASSERT(isDefinite());
91 return m_resolvedInitialPosition; 101 return m_resolvedInitialPosition;
92 } 102 }
93 103
94 iterator end() const 104 GridSpanIterator end() const
95 { 105 {
96 ASSERT(isDefinite()); 106 ASSERT(isDefinite());
97 return m_resolvedFinalPosition; 107 return m_resolvedFinalPosition;
98 } 108 }
99 109
100 bool isDefinite() const 110 bool isDefinite() const
101 { 111 {
102 return m_type == Definite; 112 return m_type == Definite;
103 } 113 }
104 114
105 private: 115 private:
106 116
107 enum GridSpanType {Definite, Indefinite}; 117 enum GridSpanType {Definite, Indefinite};
108 118
109 GridSpan(const GridResolvedPosition& resolvedInitialPosition, const GridReso lvedPosition& resolvedFinalPosition, GridSpanType type) 119 GridSpan(size_t resolvedInitialPosition, size_t resolvedFinalPosition, GridS panType type)
110 : m_resolvedInitialPosition(std::min(resolvedInitialPosition.toInt(), kG ridMaxTracks - 1)) 120 : m_resolvedInitialPosition(std::min(resolvedInitialPosition, kGridMaxTr acks - 1))
111 , m_resolvedFinalPosition(std::min(resolvedFinalPosition.toInt(), kGridM axTracks)) 121 , m_resolvedFinalPosition(std::min(resolvedFinalPosition, kGridMaxTracks ))
112 , m_type(type) 122 , m_type(type)
113 { 123 {
114 ASSERT(resolvedInitialPosition < resolvedFinalPosition); 124 ASSERT(resolvedInitialPosition < resolvedFinalPosition);
115 } 125 }
116 126
117 GridResolvedPosition m_resolvedInitialPosition; 127 size_t m_resolvedInitialPosition;
118 GridResolvedPosition m_resolvedFinalPosition; 128 size_t m_resolvedFinalPosition;
119 GridSpanType m_type; 129 GridSpanType m_type;
120 }; 130 };
121 131
122 // This represents a grid area that spans in both rows' and columns' direction. 132 // This represents a grid area that spans in both rows' and columns' direction.
123 struct GridCoordinate { 133 struct GridCoordinate {
124 USING_FAST_MALLOC(GridCoordinate); 134 USING_FAST_MALLOC(GridCoordinate);
125 public: 135 public:
126 // HashMap requires a default constuctor. 136 // HashMap requires a default constuctor.
127 GridCoordinate() 137 GridCoordinate()
128 : columns(GridSpan::indefiniteGridSpan()) 138 : columns(GridSpan::indefiniteGridSpan())
(...skipping 19 matching lines...) Expand all
148 158
149 GridSpan columns; 159 GridSpan columns;
150 GridSpan rows; 160 GridSpan rows;
151 }; 161 };
152 162
153 typedef HashMap<String, GridCoordinate> NamedGridAreaMap; 163 typedef HashMap<String, GridCoordinate> NamedGridAreaMap;
154 164
155 } // namespace blink 165 } // namespace blink
156 166
157 #endif // GridCoordinate_h 167 #endif // GridCoordinate_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/GridPainter.cpp ('k') | third_party/WebKit/Source/core/style/GridResolvedPosition.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698