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

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

Issue 2655783006: Top down version of algorithm to position margins and floats in LayoutNG (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);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::Sum() 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 margin == other.margin && negative_margin == other.negative_margin;
215 negative_margin_block_start =
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 } 215 }
266 216
267 void NGMarginStrut::Append(const LayoutUnit& value) { 217 void NGMarginStrut::Append(const LayoutUnit& value) {
268 if (value < 0) { 218 if (value < 0) {
269 negative_margin = std::min(value, negative_margin); 219 negative_margin = std::min(value, negative_margin);
270 } else { 220 } else {
271 margin = std::max(value, margin); 221 margin = std::max(value, margin);
272 } 222 }
273 } 223 }
274 224
275 LayoutUnit NGMarginStrut::Collapse() const {
276 return margin + negative_margin;
277 }
278
279 String NGMarginStrut::ToString() const { 225 String NGMarginStrut::ToString() const {
280 return String::format("%d %d", margin.toInt(), negative_margin.toInt()); 226 return String::format("%d %d", margin.toInt(), negative_margin.toInt());
281 } 227 }
282 228
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 { 229 bool NGExclusion::operator==(const NGExclusion& other) const {
289 return std::tie(other.rect, other.type) == std::tie(rect, type); 230 return std::tie(other.rect, other.type) == std::tie(rect, type);
290 } 231 }
291 232
292 String NGExclusion::ToString() const { 233 String NGExclusion::ToString() const {
293 return String::format("Rect: %s Type: %d", rect.ToString().ascii().data(), 234 return String::format("Rect: %s Type: %d", rect.ToString().ascii().data(),
294 type); 235 type);
295 } 236 }
296 237
297 NGExclusions::NGExclusions() 238 NGExclusions::NGExclusions()
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 break; 281 break;
341 case kSidewaysLeftRight: 282 case kSidewaysLeftRight:
342 position.type = 283 position.type =
343 (direction == TextDirection::kLtr) ? kBottomLeft : kTopLeft; 284 (direction == TextDirection::kLtr) ? kBottomLeft : kTopLeft;
344 break; 285 break;
345 } 286 }
346 return position; 287 return position;
347 } 288 }
348 289
349 } // namespace blink 290 } // 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