OLD | NEW |
---|---|
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); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 break; | 199 break; |
200 case kSidewaysLeftRight: | 200 case kSidewaysLeftRight: |
201 strut = {bottom, top, left, right}; | 201 strut = {bottom, top, left, right}; |
202 break; | 202 break; |
203 } | 203 } |
204 if (direction == TextDirection::kRtl) | 204 if (direction == TextDirection::kRtl) |
205 std::swap(strut.inline_start, strut.inline_end); | 205 std::swap(strut.inline_start, strut.inline_end); |
206 return strut; | 206 return strut; |
207 } | 207 } |
208 | 208 |
209 LayoutUnit NGDeprecatedMarginStrut::BlockEndSum() const { | 209 LayoutUnit NGMarginStrut::Collapse() const { |
210 return margin_block_end + negative_margin_block_end; | 210 return margin + negative_margin; |
211 } | 211 } |
212 | 212 |
213 void NGDeprecatedMarginStrut::AppendMarginBlockStart(const LayoutUnit& value) { | 213 bool NGMarginStrut::operator==(const NGMarginStrut& other) const { |
214 if (value < 0) { | 214 return std::tie(other.margin, other.negative_margin) == |
mstensho (USE GERRIT)
2017/01/26 09:19:08
What's the advantage with this over simply doing:
Gleb Lanbin
2017/01/31 00:25:01
done. thanks. you are right your variant is shorte
| |
215 negative_margin_block_start = | 215 std::tie(margin, negative_margin); |
216 -std::max(value.abs(), negative_margin_block_start.abs()); | |
217 } else { | |
218 margin_block_start = std::max(value, margin_block_start); | |
219 } | |
220 } | |
221 | |
222 void NGDeprecatedMarginStrut::AppendMarginBlockEnd(const LayoutUnit& value) { | |
223 if (value < 0) { | |
224 negative_margin_block_end = | |
225 -std::max(value.abs(), negative_margin_block_end.abs()); | |
226 } else { | |
227 margin_block_end = std::max(value, margin_block_end); | |
228 } | |
229 } | |
230 | |
231 void NGDeprecatedMarginStrut::SetMarginBlockStart(const LayoutUnit& value) { | |
232 if (value < 0) { | |
233 negative_margin_block_start = value; | |
234 } else { | |
235 margin_block_start = value; | |
236 } | |
237 } | |
238 | |
239 void NGDeprecatedMarginStrut::SetMarginBlockEnd(const LayoutUnit& value) { | |
240 if (value < 0) { | |
241 negative_margin_block_end = value; | |
242 } else { | |
243 margin_block_end = value; | |
244 } | |
245 } | |
246 | |
247 String NGDeprecatedMarginStrut::ToString() const { | |
248 return String::format("Start: (%d %d) End: (%d %d)", | |
249 margin_block_start.toInt(), margin_block_end.toInt(), | |
250 negative_margin_block_start.toInt(), | |
251 negative_margin_block_end.toInt()); | |
252 } | |
253 | |
254 bool NGDeprecatedMarginStrut::IsEmpty() const { | |
255 return *this == NGDeprecatedMarginStrut(); | |
256 } | |
257 | |
258 bool NGDeprecatedMarginStrut::operator==( | |
259 const NGDeprecatedMarginStrut& other) const { | |
260 return std::tie(other.margin_block_start, other.margin_block_end, | |
261 other.negative_margin_block_start, | |
262 other.negative_margin_block_end) == | |
263 std::tie(margin_block_start, margin_block_end, | |
264 negative_margin_block_start, negative_margin_block_end); | |
265 } | 216 } |
266 | 217 |
267 void NGMarginStrut::Append(const LayoutUnit& value) { | 218 void NGMarginStrut::Append(const LayoutUnit& value) { |
268 if (value < 0) { | 219 if (value < 0) { |
269 negative_margin = std::min(value, negative_margin); | 220 negative_margin = std::min(value, negative_margin); |
270 } else { | 221 } else { |
271 margin = std::max(value, margin); | 222 margin = std::max(value, margin); |
272 } | 223 } |
273 } | 224 } |
274 | 225 |
275 LayoutUnit NGMarginStrut::Collapse() const { | |
276 return margin + negative_margin; | |
277 } | |
278 | |
279 String NGMarginStrut::ToString() const { | 226 String NGMarginStrut::ToString() const { |
280 return String::format("%d %d", margin.toInt(), negative_margin.toInt()); | 227 return String::format("%d %d", margin.toInt(), negative_margin.toInt()); |
281 } | 228 } |
282 | 229 |
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 { | 230 bool NGExclusion::operator==(const NGExclusion& other) const { |
289 return std::tie(other.rect, other.type) == std::tie(rect, type); | 231 return std::tie(other.rect, other.type) == std::tie(rect, type); |
290 } | 232 } |
291 | 233 |
292 String NGExclusion::ToString() const { | 234 String NGExclusion::ToString() const { |
293 return String::format("Rect: %s Type: %d", rect.ToString().ascii().data(), | 235 return String::format("Rect: %s Type: %d", rect.ToString().ascii().data(), |
294 type); | 236 type); |
295 } | 237 } |
296 | 238 |
297 NGExclusions::NGExclusions() | 239 NGExclusions::NGExclusions() |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 break; | 282 break; |
341 case kSidewaysLeftRight: | 283 case kSidewaysLeftRight: |
342 position.type = | 284 position.type = |
343 (direction == TextDirection::kLtr) ? kBottomLeft : kTopLeft; | 285 (direction == TextDirection::kLtr) ? kBottomLeft : kTopLeft; |
344 break; | 286 break; |
345 } | 287 } |
346 return position; | 288 return position; |
347 } | 289 } |
348 | 290 |
349 } // namespace blink | 291 } // namespace blink |
OLD | NEW |