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_exclusion.h" | 5 #include "core/layout/ng/ng_exclusion.h" |
6 | 6 |
7 #include "wtf/text/WTFString.h" | 7 #include "wtf/text/WTFString.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
11 bool NGExclusion::operator==(const NGExclusion& other) const { | 11 bool NGExclusion::operator==(const NGExclusion& other) const { |
12 return std::tie(other.rect, other.type) == std::tie(rect, type); | 12 return std::tie(other.rect, other.type) == std::tie(rect, type); |
13 } | 13 } |
14 | 14 |
15 String NGExclusion::ToString() const { | 15 String NGExclusion::ToString() const { |
16 return String::format("Rect: %s Type: %d", rect.ToString().ascii().data(), | 16 return String::format("Rect: %s Type: %d", rect.ToString().ascii().data(), |
17 type); | 17 type); |
18 } | 18 } |
19 | 19 |
| 20 bool NGExclusion::MaybeCombineWith(const NGExclusion& other) { |
| 21 if (other.rect.BlockEndOffset() < rect.BlockEndOffset()) |
| 22 return false; |
| 23 |
| 24 if (other.type != type) |
| 25 return false; |
| 26 |
| 27 switch (other.type) { |
| 28 case NGExclusion::kFloatLeft: { |
| 29 if (other.rect.offset == rect.InlineEndBlockStartOffset()) { |
| 30 rect.size = {other.rect.InlineSize() + rect.InlineSize(), |
| 31 other.rect.BlockSize()}; |
| 32 return true; |
| 33 } |
| 34 } |
| 35 case NGExclusion::kFloatRight: { |
| 36 if (rect.offset == other.rect.InlineEndBlockStartOffset()) { |
| 37 rect.offset = other.rect.offset; |
| 38 rect.size = {other.rect.InlineSize() + rect.InlineSize(), |
| 39 other.rect.BlockSize()}; |
| 40 return true; |
| 41 } |
| 42 } |
| 43 default: |
| 44 return false; |
| 45 } |
| 46 } |
| 47 |
20 std::ostream& operator<<(std::ostream& stream, const NGExclusion& value) { | 48 std::ostream& operator<<(std::ostream& stream, const NGExclusion& value) { |
21 return stream << value.ToString(); | 49 return stream << value.ToString(); |
22 } | 50 } |
23 | 51 |
24 NGExclusions::NGExclusions() | 52 NGExclusions::NGExclusions() |
25 : last_left_float(nullptr), last_right_float(nullptr) {} | 53 : last_left_float(nullptr), last_right_float(nullptr) {} |
26 | 54 |
27 NGExclusions::NGExclusions(const NGExclusions& other) { | 55 NGExclusions::NGExclusions(const NGExclusions& other) { |
28 for (const auto& exclusion : other.storage) | 56 for (const auto& exclusion : other.storage) |
29 Add(*exclusion); | 57 Add(*exclusion); |
(...skipping 11 matching lines...) Expand all Loading... |
41 inline NGExclusions& NGExclusions::operator=(const NGExclusions& other) { | 69 inline NGExclusions& NGExclusions::operator=(const NGExclusions& other) { |
42 storage.clear(); | 70 storage.clear(); |
43 last_left_float = nullptr; | 71 last_left_float = nullptr; |
44 last_right_float = nullptr; | 72 last_right_float = nullptr; |
45 for (const auto& exclusion : other.storage) | 73 for (const auto& exclusion : other.storage) |
46 Add(*exclusion); | 74 Add(*exclusion); |
47 return *this; | 75 return *this; |
48 } | 76 } |
49 | 77 |
50 } // namespace blink | 78 } // namespace blink |
OLD | NEW |