OLD | NEW |
| (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 #include "core/layout/ng/ng_units.h" | |
6 | |
7 namespace blink { | |
8 | |
9 LayoutUnit MinAndMaxContentSizes::ShrinkToFit(LayoutUnit available_size) const { | |
10 DCHECK_GE(max_content, min_content); | |
11 return std::min(max_content, std::max(min_content, available_size)); | |
12 } | |
13 | |
14 bool MinAndMaxContentSizes::operator==( | |
15 const MinAndMaxContentSizes& other) const { | |
16 return min_content == other.min_content && max_content == other.max_content; | |
17 } | |
18 | |
19 | |
20 bool NGLogicalRect::IsEmpty() const { | |
21 // TODO(layout-dev): equality check shouldn't allocate an object each time. | |
22 return *this == NGLogicalRect(); | |
23 } | |
24 | |
25 bool NGLogicalRect::IsContained(const NGLogicalRect& other) const { | |
26 return !(InlineEndOffset() <= other.InlineStartOffset() || | |
27 BlockEndOffset() <= other.BlockStartOffset() || | |
28 InlineStartOffset() >= other.InlineEndOffset() || | |
29 BlockStartOffset() >= other.BlockEndOffset()); | |
30 } | |
31 | |
32 bool NGLogicalRect::operator==(const NGLogicalRect& other) const { | |
33 return std::tie(other.offset, other.size) == std::tie(offset, size); | |
34 } | |
35 | |
36 String NGLogicalRect::ToString() const { | |
37 return String::format("%s,%s %sx%s", | |
38 offset.inline_offset.toString().ascii().data(), | |
39 offset.block_offset.toString().ascii().data(), | |
40 size.inline_size.toString().ascii().data(), | |
41 size.block_size.toString().ascii().data()); | |
42 } | |
43 | |
44 | |
45 bool NGBoxStrut::IsEmpty() const { | |
46 return *this == NGBoxStrut(); | |
47 } | |
48 | |
49 bool NGBoxStrut::operator==(const NGBoxStrut& other) const { | |
50 return std::tie(other.inline_start, other.inline_end, other.block_start, | |
51 other.block_end) == | |
52 std::tie(inline_start, inline_end, block_start, block_end); | |
53 } | |
54 | |
55 // Converts physical dimensions to logical ones per | |
56 // https://drafts.csswg.org/css-writing-modes-3/#logical-to-physical | |
57 NGBoxStrut NGPhysicalBoxStrut::ConvertToLogical(NGWritingMode writing_mode, | |
58 TextDirection direction) const { | |
59 NGBoxStrut strut; | |
60 switch (writing_mode) { | |
61 case kHorizontalTopBottom: | |
62 strut = {left, right, top, bottom}; | |
63 break; | |
64 case kVerticalRightLeft: | |
65 case kSidewaysRightLeft: | |
66 strut = {top, bottom, right, left}; | |
67 break; | |
68 case kVerticalLeftRight: | |
69 strut = {top, bottom, left, right}; | |
70 break; | |
71 case kSidewaysLeftRight: | |
72 strut = {bottom, top, left, right}; | |
73 break; | |
74 } | |
75 if (direction == TextDirection::kRtl) | |
76 std::swap(strut.inline_start, strut.inline_end); | |
77 return strut; | |
78 } | |
79 | |
80 LayoutUnit NGMarginStrut::Sum() const { | |
81 return margin + negative_margin; | |
82 } | |
83 | |
84 bool NGMarginStrut::operator==(const NGMarginStrut& other) const { | |
85 return margin == other.margin && negative_margin == other.negative_margin; | |
86 } | |
87 | |
88 void NGMarginStrut::Append(const LayoutUnit& value) { | |
89 if (value < 0) { | |
90 negative_margin = std::min(value, negative_margin); | |
91 } else { | |
92 margin = std::max(value, margin); | |
93 } | |
94 } | |
95 | |
96 String NGMarginStrut::ToString() const { | |
97 return String::format("%d %d", margin.toInt(), negative_margin.toInt()); | |
98 } | |
99 | |
100 bool NGExclusion::operator==(const NGExclusion& other) const { | |
101 return std::tie(other.rect, other.type) == std::tie(rect, type); | |
102 } | |
103 | |
104 String NGExclusion::ToString() const { | |
105 return String::format("Rect: %s Type: %d", rect.ToString().ascii().data(), | |
106 type); | |
107 } | |
108 | |
109 NGExclusions::NGExclusions() | |
110 : last_left_float(nullptr), last_right_float(nullptr) {} | |
111 | |
112 NGExclusions::NGExclusions(const NGExclusions& other) { | |
113 for (const auto& exclusion : other.storage) | |
114 Add(*exclusion); | |
115 } | |
116 | |
117 void NGExclusions::Add(const NGExclusion& exclusion) { | |
118 storage.push_back(WTF::makeUnique<NGExclusion>(exclusion)); | |
119 if (exclusion.type == NGExclusion::kFloatLeft) { | |
120 last_left_float = storage.rbegin()->get(); | |
121 } else if (exclusion.type == NGExclusion::kFloatRight) { | |
122 last_right_float = storage.rbegin()->get(); | |
123 } | |
124 } | |
125 | |
126 inline NGExclusions& NGExclusions::operator=(const NGExclusions& other) { | |
127 storage.clear(); | |
128 last_left_float = nullptr; | |
129 last_right_float = nullptr; | |
130 for (const auto& exclusion : other.storage) | |
131 Add(*exclusion); | |
132 return *this; | |
133 } | |
134 | |
135 NGStaticPosition NGStaticPosition::Create(NGWritingMode writing_mode, | |
136 TextDirection direction, | |
137 NGPhysicalOffset offset) { | |
138 NGStaticPosition position; | |
139 position.offset = offset; | |
140 switch (writing_mode) { | |
141 case kHorizontalTopBottom: | |
142 position.type = (direction == TextDirection::kLtr) ? kTopLeft : kTopRight; | |
143 break; | |
144 case kVerticalRightLeft: | |
145 case kSidewaysRightLeft: | |
146 position.type = | |
147 (direction == TextDirection::kLtr) ? kTopRight : kBottomRight; | |
148 break; | |
149 case kVerticalLeftRight: | |
150 position.type = | |
151 (direction == TextDirection::kLtr) ? kTopLeft : kBottomLeft; | |
152 break; | |
153 case kSidewaysLeftRight: | |
154 position.type = | |
155 (direction == TextDirection::kLtr) ? kBottomLeft : kTopLeft; | |
156 break; | |
157 } | |
158 return position; | |
159 } | |
160 | |
161 } // namespace blink | |
OLD | NEW |