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

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: move NGLogicalSize,NGLogicalOffset "for tests" constructors to private 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
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);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 bool NGLogicalOffset::operator<(const NGLogicalOffset& other) const { 126 bool NGLogicalOffset::operator<(const NGLogicalOffset& other) const {
127 return inline_offset < other.inline_offset && 127 return inline_offset < other.inline_offset &&
128 block_offset < other.block_offset; 128 block_offset < other.block_offset;
129 } 129 }
130 130
131 bool NGLogicalOffset::operator<=(const NGLogicalOffset& other) const { 131 bool NGLogicalOffset::operator<=(const NGLogicalOffset& other) const {
132 return inline_offset <= other.inline_offset && 132 return inline_offset <= other.inline_offset &&
133 block_offset <= other.block_offset; 133 block_offset <= other.block_offset;
134 } 134 }
135 135
136 NGLogicalOffset NGLogicalOffset::operator-(const NGLogicalOffset& other) const {
137 return NGLogicalOffset{this->inline_offset - other.inline_offset,
138 this->block_offset - other.block_offset};
139 }
140
141 NGLogicalOffset& NGLogicalOffset::operator-=(const NGLogicalOffset& other) {
142 *this = *this - other;
143 return *this;
144 }
145
136 String NGLogicalOffset::ToString() const { 146 String NGLogicalOffset::ToString() const {
137 return String::format("%dx%d", inline_offset.toInt(), block_offset.toInt()); 147 return String::format("%dx%d", inline_offset.toInt(), block_offset.toInt());
138 } 148 }
139 149
140 NGPhysicalOffset NGPhysicalOffset::operator+( 150 NGPhysicalOffset NGPhysicalOffset::operator+(
141 const NGPhysicalOffset& other) const { 151 const NGPhysicalOffset& other) const {
142 return NGPhysicalOffset{this->left + other.left, this->top + other.top}; 152 return NGPhysicalOffset{this->left + other.left, this->top + other.top};
143 } 153 }
144 154
145 NGPhysicalOffset& NGPhysicalOffset::operator+=(const NGPhysicalOffset& other) { 155 NGPhysicalOffset& NGPhysicalOffset::operator+=(const NGPhysicalOffset& other) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 break; 195 break;
186 case kSidewaysLeftRight: 196 case kSidewaysLeftRight:
187 strut = {bottom, top, left, right}; 197 strut = {bottom, top, left, right};
188 break; 198 break;
189 } 199 }
190 if (direction == TextDirection::kRtl) 200 if (direction == TextDirection::kRtl)
191 std::swap(strut.inline_start, strut.inline_end); 201 std::swap(strut.inline_start, strut.inline_end);
192 return strut; 202 return strut;
193 } 203 }
194 204
195 LayoutUnit NGMarginStrut::BlockEndSum() const { 205 LayoutUnit NGDeprecatedMarginStrut::BlockEndSum() const {
196 return margin_block_end + negative_margin_block_end; 206 return margin_block_end + negative_margin_block_end;
197 } 207 }
198 208
199 void NGMarginStrut::AppendMarginBlockStart(const LayoutUnit& value) { 209 void NGDeprecatedMarginStrut::AppendMarginBlockStart(const LayoutUnit& value) {
200 if (value < 0) { 210 if (value < 0) {
201 negative_margin_block_start = 211 negative_margin_block_start =
202 -std::max(value.abs(), negative_margin_block_start.abs()); 212 -std::max(value.abs(), negative_margin_block_start.abs());
203 } else { 213 } else {
204 margin_block_start = std::max(value, margin_block_start); 214 margin_block_start = std::max(value, margin_block_start);
205 } 215 }
206 } 216 }
207 217
208 void NGMarginStrut::AppendMarginBlockEnd(const LayoutUnit& value) { 218 void NGDeprecatedMarginStrut::AppendMarginBlockEnd(const LayoutUnit& value) {
209 if (value < 0) { 219 if (value < 0) {
210 negative_margin_block_end = 220 negative_margin_block_end =
211 -std::max(value.abs(), negative_margin_block_end.abs()); 221 -std::max(value.abs(), negative_margin_block_end.abs());
212 } else { 222 } else {
213 margin_block_end = std::max(value, margin_block_end); 223 margin_block_end = std::max(value, margin_block_end);
214 } 224 }
215 } 225 }
216 226
217 void NGMarginStrut::SetMarginBlockStart(const LayoutUnit& value) { 227 void NGDeprecatedMarginStrut::SetMarginBlockStart(const LayoutUnit& value) {
218 if (value < 0) { 228 if (value < 0) {
219 negative_margin_block_start = value; 229 negative_margin_block_start = value;
220 } else { 230 } else {
221 margin_block_start = value; 231 margin_block_start = value;
222 } 232 }
223 } 233 }
224 234
225 void NGMarginStrut::SetMarginBlockEnd(const LayoutUnit& value) { 235 void NGDeprecatedMarginStrut::SetMarginBlockEnd(const LayoutUnit& value) {
226 if (value < 0) { 236 if (value < 0) {
227 negative_margin_block_end = value; 237 negative_margin_block_end = value;
228 } else { 238 } else {
229 margin_block_end = value; 239 margin_block_end = value;
230 } 240 }
231 } 241 }
232 242
233 String NGMarginStrut::ToString() const { 243 String NGDeprecatedMarginStrut::ToString() const {
234 return String::format("Start: (%d %d) End: (%d %d)", 244 return String::format("Start: (%d %d) End: (%d %d)",
235 margin_block_start.toInt(), margin_block_end.toInt(), 245 margin_block_start.toInt(), margin_block_end.toInt(),
236 negative_margin_block_start.toInt(), 246 negative_margin_block_start.toInt(),
237 negative_margin_block_end.toInt()); 247 negative_margin_block_end.toInt());
238 } 248 }
239 249
240 bool NGMarginStrut::IsEmpty() const { 250 bool NGDeprecatedMarginStrut::IsEmpty() const {
241 return *this == NGMarginStrut(); 251 return *this == NGDeprecatedMarginStrut();
242 } 252 }
243 253
244 bool NGMarginStrut::operator==(const NGMarginStrut& other) const { 254 bool NGDeprecatedMarginStrut::operator==(
255 const NGDeprecatedMarginStrut& other) const {
245 return std::tie(other.margin_block_start, other.margin_block_end, 256 return std::tie(other.margin_block_start, other.margin_block_end,
246 other.negative_margin_block_start, 257 other.negative_margin_block_start,
247 other.negative_margin_block_end) == 258 other.negative_margin_block_end) ==
248 std::tie(margin_block_start, margin_block_end, 259 std::tie(margin_block_start, margin_block_end,
249 negative_margin_block_start, negative_margin_block_end); 260 negative_margin_block_start, negative_margin_block_end);
250 } 261 }
251 262
263 void NGMarginStrut::Append(const LayoutUnit& value) {
264 if (value < 0) {
265 negative_margin = std::min(value, negative_margin);
266 } else {
267 margin = std::max(value, margin);
268 }
269 }
270
271 LayoutUnit NGMarginStrut::Collapse() const {
272 return margin + negative_margin;
273 }
274
275 LayoutUnit NGMarginStrut::CollapseWith(const NGMarginStrut& other) const {
ikilpatrick 2017/01/24 00:22:13 I don't think you'll need this, re: 0 block size c
Gleb Lanbin 2017/01/24 04:38:02 deleted for now.
276 return std::max(margin, other.margin) +
277 std::min(negative_margin, other.negative_margin);
278 }
279
280 String NGMarginStrut::ToString() const {
281 return String::format("%d %d", margin.toInt(), negative_margin.toInt());
282 }
283
284 bool NGMarginStrut::operator==(const NGMarginStrut& other) const {
285 return std::tie(other.margin, other.negative_margin) ==
286 std::tie(margin, negative_margin);
287 }
288
289 bool NGExclusion::operator==(const NGExclusion& other) const {
290 return std::tie(other.rect, other.type) == std::tie(rect, type);
291 }
292
293 String NGExclusion::ToString() const {
294 return String::format("Rect: %s Type: %d", rect.ToString().ascii().data(),
295 type);
296 }
297
252 NGExclusions::NGExclusions() 298 NGExclusions::NGExclusions()
253 : last_left_float(nullptr), last_right_float(nullptr) {} 299 : last_left_float(nullptr), last_right_float(nullptr) {}
254 300
255 NGExclusions::NGExclusions(const NGExclusions& other) { 301 NGExclusions::NGExclusions(const NGExclusions& other) {
256 for (const auto& exclusion : other.storage) 302 for (const auto& exclusion : other.storage)
257 Add(*exclusion); 303 Add(*exclusion);
258 } 304 }
259 305
260 void NGExclusions::Add(const NGExclusion& exclusion) { 306 void NGExclusions::Add(const NGExclusion& exclusion) {
261 storage.push_back(WTF::makeUnique<NGExclusion>(exclusion)); 307 storage.push_back(WTF::makeUnique<NGExclusion>(exclusion));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 break; 341 break;
296 case kSidewaysLeftRight: 342 case kSidewaysLeftRight:
297 position.type = 343 position.type =
298 (direction == TextDirection::kLtr) ? kBottomLeft : kTopLeft; 344 (direction == TextDirection::kLtr) ? kBottomLeft : kTopLeft;
299 break; 345 break;
300 } 346 }
301 return position; 347 return position;
302 } 348 }
303 349
304 } // namespace blink 350 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698