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

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

Issue 2651853002: Deprecate the currently used NGMarginStrut in favor of the new one. (Closed)
Patch Set: git rebase-update Created 3 years, 10 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_units.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/layout/ng/ng_units.h" 5 #include "core/layout/ng/ng_units.h"
6 6
7 namespace blink { 7 namespace blink {
8 8
9 LayoutUnit MinAndMaxContentSizes::ShrinkToFit(LayoutUnit available_size) const { 9 LayoutUnit MinAndMaxContentSizes::ShrinkToFit(LayoutUnit available_size) const {
10 DCHECK_GE(max_content, min_content); 10 DCHECK_GE(max_content, min_content);
11 return std::min(max_content, std::max(min_content, available_size)); 11 return std::min(max_content, std::max(min_content, available_size));
12 } 12 }
13 13
14 bool MinAndMaxContentSizes::operator==( 14 bool MinAndMaxContentSizes::operator==(
15 const MinAndMaxContentSizes& other) const { 15 const MinAndMaxContentSizes& other) const {
16 return min_content == other.min_content && max_content == other.max_content; 16 return min_content == other.min_content && max_content == other.max_content;
17 } 17 }
18 18
19 NGPhysicalSize NGLogicalSize::ConvertToPhysical(NGWritingMode mode) const { 19 NGPhysicalSize NGLogicalSize::ConvertToPhysical(NGWritingMode mode) const {
20 return mode == kHorizontalTopBottom ? NGPhysicalSize(inline_size, block_size) 20 return mode == kHorizontalTopBottom ? NGPhysicalSize(inline_size, block_size)
21 : NGPhysicalSize(block_size, inline_size); 21 : NGPhysicalSize(block_size, inline_size);
22 } 22 }
23 23
24 bool NGLogicalSize::operator==(const NGLogicalSize& other) const { 24 bool NGLogicalSize::operator==(const NGLogicalSize& other) const {
25 return std::tie(other.inline_size, other.block_size) == 25 return std::tie(other.inline_size, other.block_size) ==
26 std::tie(inline_size, block_size); 26 std::tie(inline_size, block_size);
27 } 27 }
28 28
29 bool NGPhysicalSize::operator==(const NGPhysicalSize& other) const {
30 return std::tie(other.width, other.height) == std::tie(width, height);
31 }
32
29 NGLogicalSize NGPhysicalSize::ConvertToLogical(NGWritingMode mode) const { 33 NGLogicalSize NGPhysicalSize::ConvertToLogical(NGWritingMode mode) const {
30 return mode == kHorizontalTopBottom ? NGLogicalSize(width, height) 34 return mode == kHorizontalTopBottom ? NGLogicalSize(width, height)
31 : NGLogicalSize(height, width); 35 : NGLogicalSize(height, width);
32 } 36 }
33 37
34 bool NGLogicalRect::IsEmpty() const { 38 bool NGLogicalRect::IsEmpty() const {
35 // TODO(layout-dev): equality check shouldn't allocate an object each time. 39 // TODO(layout-dev): equality check shouldn't allocate an object each time.
36 return *this == NGLogicalRect(); 40 return *this == NGLogicalRect();
37 } 41 }
38 42
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 bool NGLogicalOffset::operator<(const NGLogicalOffset& other) const { 130 bool NGLogicalOffset::operator<(const NGLogicalOffset& other) const {
127 return inline_offset < other.inline_offset && 131 return inline_offset < other.inline_offset &&
128 block_offset < other.block_offset; 132 block_offset < other.block_offset;
129 } 133 }
130 134
131 bool NGLogicalOffset::operator<=(const NGLogicalOffset& other) const { 135 bool NGLogicalOffset::operator<=(const NGLogicalOffset& other) const {
132 return inline_offset <= other.inline_offset && 136 return inline_offset <= other.inline_offset &&
133 block_offset <= other.block_offset; 137 block_offset <= other.block_offset;
134 } 138 }
135 139
140 NGLogicalOffset NGLogicalOffset::operator-(const NGLogicalOffset& other) const {
141 return NGLogicalOffset{this->inline_offset - other.inline_offset,
142 this->block_offset - other.block_offset};
143 }
144
145 NGLogicalOffset& NGLogicalOffset::operator-=(const NGLogicalOffset& other) {
146 *this = *this - other;
147 return *this;
148 }
149
136 String NGLogicalOffset::ToString() const { 150 String NGLogicalOffset::ToString() const {
137 return String::format("%dx%d", inline_offset.toInt(), block_offset.toInt()); 151 return String::format("%dx%d", inline_offset.toInt(), block_offset.toInt());
138 } 152 }
139 153
140 NGPhysicalOffset NGPhysicalOffset::operator+( 154 NGPhysicalOffset NGPhysicalOffset::operator+(
141 const NGPhysicalOffset& other) const { 155 const NGPhysicalOffset& other) const {
142 return NGPhysicalOffset{this->left + other.left, this->top + other.top}; 156 return NGPhysicalOffset{this->left + other.left, this->top + other.top};
143 } 157 }
144 158
145 NGPhysicalOffset& NGPhysicalOffset::operator+=(const NGPhysicalOffset& other) { 159 NGPhysicalOffset& NGPhysicalOffset::operator+=(const NGPhysicalOffset& other) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 break; 199 break;
186 case kSidewaysLeftRight: 200 case kSidewaysLeftRight:
187 strut = {bottom, top, left, right}; 201 strut = {bottom, top, left, right};
188 break; 202 break;
189 } 203 }
190 if (direction == TextDirection::kRtl) 204 if (direction == TextDirection::kRtl)
191 std::swap(strut.inline_start, strut.inline_end); 205 std::swap(strut.inline_start, strut.inline_end);
192 return strut; 206 return strut;
193 } 207 }
194 208
195 LayoutUnit NGMarginStrut::BlockEndSum() const { 209 LayoutUnit NGDeprecatedMarginStrut::BlockEndSum() const {
196 return margin_block_end + negative_margin_block_end; 210 return margin_block_end + negative_margin_block_end;
197 } 211 }
198 212
199 void NGMarginStrut::AppendMarginBlockStart(const LayoutUnit& value) { 213 void NGDeprecatedMarginStrut::AppendMarginBlockStart(const LayoutUnit& value) {
200 if (value < 0) { 214 if (value < 0) {
201 negative_margin_block_start = 215 negative_margin_block_start =
202 -std::max(value.abs(), negative_margin_block_start.abs()); 216 -std::max(value.abs(), negative_margin_block_start.abs());
203 } else { 217 } else {
204 margin_block_start = std::max(value, margin_block_start); 218 margin_block_start = std::max(value, margin_block_start);
205 } 219 }
206 } 220 }
207 221
208 void NGMarginStrut::AppendMarginBlockEnd(const LayoutUnit& value) { 222 void NGDeprecatedMarginStrut::AppendMarginBlockEnd(const LayoutUnit& value) {
209 if (value < 0) { 223 if (value < 0) {
210 negative_margin_block_end = 224 negative_margin_block_end =
211 -std::max(value.abs(), negative_margin_block_end.abs()); 225 -std::max(value.abs(), negative_margin_block_end.abs());
212 } else { 226 } else {
213 margin_block_end = std::max(value, margin_block_end); 227 margin_block_end = std::max(value, margin_block_end);
214 } 228 }
215 } 229 }
216 230
217 void NGMarginStrut::SetMarginBlockStart(const LayoutUnit& value) { 231 void NGDeprecatedMarginStrut::SetMarginBlockStart(const LayoutUnit& value) {
218 if (value < 0) { 232 if (value < 0) {
219 negative_margin_block_start = value; 233 negative_margin_block_start = value;
220 } else { 234 } else {
221 margin_block_start = value; 235 margin_block_start = value;
222 } 236 }
223 } 237 }
224 238
225 void NGMarginStrut::SetMarginBlockEnd(const LayoutUnit& value) { 239 void NGDeprecatedMarginStrut::SetMarginBlockEnd(const LayoutUnit& value) {
226 if (value < 0) { 240 if (value < 0) {
227 negative_margin_block_end = value; 241 negative_margin_block_end = value;
228 } else { 242 } else {
229 margin_block_end = value; 243 margin_block_end = value;
230 } 244 }
231 } 245 }
232 246
233 String NGMarginStrut::ToString() const { 247 String NGDeprecatedMarginStrut::ToString() const {
234 return String::format("Start: (%d %d) End: (%d %d)", 248 return String::format("Start: (%d %d) End: (%d %d)",
235 margin_block_start.toInt(), margin_block_end.toInt(), 249 margin_block_start.toInt(), margin_block_end.toInt(),
236 negative_margin_block_start.toInt(), 250 negative_margin_block_start.toInt(),
237 negative_margin_block_end.toInt()); 251 negative_margin_block_end.toInt());
238 } 252 }
239 253
240 bool NGMarginStrut::IsEmpty() const { 254 bool NGDeprecatedMarginStrut::IsEmpty() const {
241 return *this == NGMarginStrut(); 255 return *this == NGDeprecatedMarginStrut();
242 } 256 }
243 257
244 bool NGMarginStrut::operator==(const NGMarginStrut& other) const { 258 bool NGDeprecatedMarginStrut::operator==(
259 const NGDeprecatedMarginStrut& other) const {
245 return std::tie(other.margin_block_start, other.margin_block_end, 260 return std::tie(other.margin_block_start, other.margin_block_end,
246 other.negative_margin_block_start, 261 other.negative_margin_block_start,
247 other.negative_margin_block_end) == 262 other.negative_margin_block_end) ==
248 std::tie(margin_block_start, margin_block_end, 263 std::tie(margin_block_start, margin_block_end,
249 negative_margin_block_start, negative_margin_block_end); 264 negative_margin_block_start, negative_margin_block_end);
250 } 265 }
251 266
267 void NGMarginStrut::Append(const LayoutUnit& value) {
268 if (value < 0) {
269 negative_margin = std::min(value, negative_margin);
270 } else {
271 margin = std::max(value, margin);
272 }
273 }
274
275 LayoutUnit NGMarginStrut::Collapse() const {
276 return margin + negative_margin;
277 }
278
279 String NGMarginStrut::ToString() const {
280 return String::format("%d %d", margin.toInt(), negative_margin.toInt());
281 }
282
283 bool NGMarginStrut::operator==(const NGMarginStrut& other) const {
284 return std::tie(other.margin, other.negative_margin) ==
285 std::tie(margin, negative_margin);
286 }
287
288 bool NGExclusion::operator==(const NGExclusion& other) const {
289 return std::tie(other.rect, other.type) == std::tie(rect, type);
290 }
291
292 String NGExclusion::ToString() const {
293 return String::format("Rect: %s Type: %d", rect.ToString().ascii().data(),
294 type);
295 }
296
252 NGExclusions::NGExclusions() 297 NGExclusions::NGExclusions()
253 : last_left_float(nullptr), last_right_float(nullptr) {} 298 : last_left_float(nullptr), last_right_float(nullptr) {}
254 299
255 NGExclusions::NGExclusions(const NGExclusions& other) { 300 NGExclusions::NGExclusions(const NGExclusions& other) {
256 for (const auto& exclusion : other.storage) 301 for (const auto& exclusion : other.storage)
257 Add(*exclusion); 302 Add(*exclusion);
258 } 303 }
259 304
260 void NGExclusions::Add(const NGExclusion& exclusion) { 305 void NGExclusions::Add(const NGExclusion& exclusion) {
261 storage.push_back(WTF::makeUnique<NGExclusion>(exclusion)); 306 storage.push_back(WTF::makeUnique<NGExclusion>(exclusion));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 break; 340 break;
296 case kSidewaysLeftRight: 341 case kSidewaysLeftRight:
297 position.type = 342 position.type =
298 (direction == TextDirection::kLtr) ? kBottomLeft : kTopLeft; 343 (direction == TextDirection::kLtr) ? kBottomLeft : kTopLeft;
299 break; 344 break;
300 } 345 }
301 return position; 346 return position;
302 } 347 }
303 348
304 } // namespace blink 349 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/ng/ng_units.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698