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

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_units.h

Issue 2721613003: [LayoutNG] Move remaining ng_units structs to their own files (Closed)
Patch Set: Don't export NGBoxStrut for now Created 3 years, 9 months 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NGUnits_h
6 #define NGUnits_h
7
8 #include "core/CoreExport.h"
9 #include "core/layout/ng/geometry/ng_logical_offset.h"
10 #include "core/layout/ng/geometry/ng_logical_size.h"
11 #include "core/layout/ng/geometry/ng_physical_location.h"
12 #include "core/layout/ng/geometry/ng_physical_offset.h"
13 #include "core/layout/ng/geometry/ng_physical_rect.h"
14 #include "core/layout/ng/geometry/ng_physical_size.h"
15 #include "core/layout/ng/ng_writing_mode.h"
16 #include "platform/LayoutUnit.h"
17 #include "platform/text/TextDirection.h"
18 #include "wtf/text/WTFString.h"
19
20 namespace blink {
21
22 struct NGBoxStrut;
23
24 #define NGSizeIndefinite LayoutUnit(-1)
25
26 struct CORE_EXPORT MinAndMaxContentSizes {
27 LayoutUnit min_content;
28 LayoutUnit max_content;
29 LayoutUnit ShrinkToFit(LayoutUnit available_size) const;
30 bool operator==(const MinAndMaxContentSizes& other) const;
31 };
32
33 inline std::ostream& operator<<(std::ostream& stream,
34 const MinAndMaxContentSizes& value) {
35 return stream << "(" << value.min_content << ", " << value.max_content << ")";
36 }
37
38 // TODO(glebl): move to a separate file in layout/ng/units.
39 struct CORE_EXPORT NGLogicalRect {
40 NGLogicalRect() {}
41 NGLogicalRect(const NGLogicalOffset& offset, const NGLogicalSize& size)
42 : offset(offset), size(size) {}
43 NGLogicalRect(LayoutUnit inline_offset,
44 LayoutUnit block_offset,
45 LayoutUnit inline_size,
46 LayoutUnit block_size)
47 : offset(inline_offset, block_offset), size(inline_size, block_size) {}
48
49 bool IsEmpty() const;
50
51 // Whether this rectangle is contained by the provided rectangle.
52 bool IsContained(const NGLogicalRect& other) const;
53
54 String ToString() const;
55 bool operator==(const NGLogicalRect& other) const;
56
57 // Getters
58 LayoutUnit InlineStartOffset() const { return offset.inline_offset; }
59
60 LayoutUnit InlineEndOffset() const {
61 return offset.inline_offset + size.inline_size;
62 }
63
64 LayoutUnit BlockStartOffset() const { return offset.block_offset; }
65
66 LayoutUnit BlockEndOffset() const {
67 return offset.block_offset + size.block_size;
68 }
69
70 LayoutUnit BlockSize() const { return size.block_size; }
71
72 LayoutUnit InlineSize() const { return size.inline_size; }
73
74 NGLogicalOffset offset;
75 NGLogicalSize size;
76 };
77
78 inline std::ostream& operator<<(std::ostream& stream,
79 const NGLogicalRect& value) {
80 return stream << value.ToString();
81 }
82
83 // Struct that represents NG exclusion.
84 struct CORE_EXPORT NGExclusion {
85 // Type of NG exclusion.
86 enum Type {
87 // Undefined exclusion type.
88 // At this moment it's also used to represent CSS3 exclusion.
89 kExclusionTypeUndefined = 0,
90 // Exclusion that is created by LEFT float.
91 kFloatLeft = 1,
92 // Exclusion that is created by RIGHT float.
93 kFloatRight = 2
94 };
95
96 // Rectangle in logical coordinates the represents this exclusion.
97 NGLogicalRect rect;
98
99 // Type of this exclusion.
100 Type type;
101
102 bool operator==(const NGExclusion& other) const;
103 String ToString() const;
104 };
105
106 inline std::ostream& operator<<(std::ostream& stream,
107 const NGExclusion& value) {
108 return stream << value.ToString();
109 }
110
111 struct CORE_EXPORT NGExclusions {
112 // Default constructor.
113 NGExclusions();
114
115 // Copy constructor.
116 NGExclusions(const NGExclusions& other);
117
118 Vector<std::unique_ptr<const NGExclusion>> storage;
119
120 // Last left/right float exclusions are used to enforce the top edge alignment
121 // rule for floats and for the support of CSS "clear" property.
122 const NGExclusion* last_left_float; // Owned by storage.
123 const NGExclusion* last_right_float; // Owned by storage.
124
125 NGExclusions& operator=(const NGExclusions& other);
126
127 void Add(const NGExclusion& exclusion);
128 };
129
130
131 // Struct to store physical dimensions, independent of writing mode and
132 // direction.
133 // See https://drafts.csswg.org/css-writing-modes-3/#abstract-box
134 struct CORE_EXPORT NGPhysicalBoxStrut {
135 LayoutUnit left;
136 LayoutUnit right;
137 LayoutUnit top;
138 LayoutUnit bottom;
139 NGBoxStrut ConvertToLogical(NGWritingMode, TextDirection) const;
140 };
141
142 // This struct is used for storing margins, borders or padding of a box on all
143 // four edges.
144 struct CORE_EXPORT NGBoxStrut {
145 LayoutUnit inline_start;
146 LayoutUnit inline_end;
147 LayoutUnit block_start;
148 LayoutUnit block_end;
149
150 LayoutUnit InlineSum() const { return inline_start + inline_end; }
151 LayoutUnit BlockSum() const { return block_start + block_end; }
152
153 bool IsEmpty() const;
154
155 // The following two operators exist primarily to have an easy way to access
156 // the sum of border and padding.
157 NGBoxStrut& operator+=(const NGBoxStrut& other) {
158 inline_start += other.inline_start;
159 inline_end += other.inline_end;
160 block_start += other.block_start;
161 block_end += other.block_end;
162 return *this;
163 }
164
165 NGBoxStrut operator+(const NGBoxStrut& other) {
166 NGBoxStrut result(*this);
167 result += other;
168 return result;
169 }
170
171 bool operator==(const NGBoxStrut& other) const;
172
173 String ToString() const {
174 return String::format("Inline: (%d %d) Block: (%d %d)",
175 inline_start.toInt(), inline_end.toInt(),
176 block_start.toInt(), block_end.toInt());
177 }
178 };
179
180 inline std::ostream& operator<<(std::ostream& stream, const NGBoxStrut& value) {
181 return stream << value.ToString();
182 }
183
184 // This struct is used for the margin collapsing calculation.
185 struct CORE_EXPORT NGMarginStrut {
186 LayoutUnit margin;
187 LayoutUnit negative_margin;
188
189 // Appends negative or positive value to the current margin strut.
190 void Append(const LayoutUnit& value);
191
192 // Sum up negative and positive margins of this strut.
193 LayoutUnit Sum() const;
194
195 bool operator==(const NGMarginStrut& other) const;
196
197 String ToString() const;
198 };
199
200 inline std::ostream& operator<<(std::ostream& stream,
201 const NGMarginStrut& value) {
202 return stream << value.ToString();
203 }
204
205 // Struct to represent a simple edge that has start and end.
206 struct NGEdge {
207 LayoutUnit start;
208 LayoutUnit end;
209 };
210
211 // Represents static position of an out of flow descendant.
212 struct CORE_EXPORT NGStaticPosition {
213 enum Type { kTopLeft, kTopRight, kBottomLeft, kBottomRight };
214
215 Type type; // Logical corner that corresponds to physical top left.
216 NGPhysicalOffset offset;
217
218 // Creates a position with proper type wrt writing mode and direction.
219 static NGStaticPosition Create(NGWritingMode,
220 TextDirection,
221 NGPhysicalOffset);
222 // Left/Right/TopPosition functions map static position to
223 // left/right/top edge wrt container space.
224 // The function arguments are required to solve the equation:
225 // contaner_size = left + margin_left + width + margin_right + right
226 LayoutUnit LeftPosition(LayoutUnit container_size,
227 LayoutUnit width,
228 LayoutUnit margin_left,
229 LayoutUnit margin_right) const {
230 return GenericPosition(HasLeft(), offset.left, container_size, width,
231 margin_left, margin_right);
232 }
233 LayoutUnit RightPosition(LayoutUnit container_size,
234 LayoutUnit width,
235 LayoutUnit margin_left,
236 LayoutUnit margin_right) const {
237 return GenericPosition(!HasLeft(), offset.left, container_size, width,
238 margin_left, margin_right);
239 }
240 LayoutUnit TopPosition(LayoutUnit container_size,
241 LayoutUnit height,
242 LayoutUnit margin_top,
243 LayoutUnit margin_bottom) const {
244 return GenericPosition(HasTop(), offset.top, container_size, height,
245 margin_top, margin_bottom);
246 }
247
248 private:
249 bool HasTop() const { return type == kTopLeft || type == kTopRight; }
250 bool HasLeft() const { return type == kTopLeft || type == kBottomLeft; }
251 LayoutUnit GenericPosition(bool position_matches,
252 LayoutUnit position,
253 LayoutUnit container_size,
254 LayoutUnit length,
255 LayoutUnit margin_start,
256 LayoutUnit margin_end) const {
257 DCHECK_GE(container_size, LayoutUnit());
258 DCHECK_GE(length, LayoutUnit());
259 if (position_matches)
260 return position;
261 else
262 return container_size - position - length - margin_start - margin_end;
263 }
264 };
265
266 } // namespace blink
267
268 #endif // NGUnits_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698