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

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

Issue 2721613003: [LayoutNG] Move remaining ng_units structs to their own files (Closed)
Patch Set: Don't export NGBoxStrut for now Created 3 years, 9 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_absolute_utils.h" 5 #include "core/layout/ng/ng_absolute_utils.h"
6 6
7 #include "core/layout/ng/ng_constraint_space.h" 7 #include "core/layout/ng/ng_constraint_space.h"
8 #include "core/layout/ng/ng_length_utils.h" 8 #include "core/layout/ng/ng_length_utils.h"
9 #include "core/style/ComputedStyle.h" 9 #include "core/style/ComputedStyle.h"
10 #include "platform/LengthFunctions.h" 10 #include "platform/LengthFunctions.h"
(...skipping 10 matching lines...) Expand all
21 21
22 bool AbsoluteVerticalNeedsEstimate(const ComputedStyle& style) { 22 bool AbsoluteVerticalNeedsEstimate(const ComputedStyle& style) {
23 Length height = style.height(); 23 Length height = style.height();
24 return height.isIntrinsic() || 24 return height.isIntrinsic() ||
25 (height.isAuto() && (style.top().isAuto() || style.bottom().isAuto())); 25 (height.isAuto() && (style.top().isAuto() || style.bottom().isAuto()));
26 } 26 }
27 27
28 LayoutUnit ResolveWidth(const Length& width, 28 LayoutUnit ResolveWidth(const Length& width,
29 const NGConstraintSpace& space, 29 const NGConstraintSpace& space,
30 const ComputedStyle& style, 30 const ComputedStyle& style,
31 const Optional<MinAndMaxContentSizes>& child_minmax, 31 const Optional<MinMaxContentSize>& child_minmax,
32 LengthResolveType resolve_type) { 32 LengthResolveType resolve_type) {
33 if (space.WritingMode() == kHorizontalTopBottom) 33 if (space.WritingMode() == kHorizontalTopBottom)
34 return ResolveInlineLength(space, style, child_minmax, width, resolve_type); 34 return ResolveInlineLength(space, style, child_minmax, width, resolve_type);
35 LayoutUnit computed_width = 35 LayoutUnit computed_width =
36 child_minmax.has_value() ? child_minmax->max_content : LayoutUnit(); 36 child_minmax.has_value() ? child_minmax->max_content : LayoutUnit();
37 return ResolveBlockLength(space, style, style.width(), computed_width, 37 return ResolveBlockLength(space, style, style.width(), computed_width,
38 resolve_type); 38 resolve_type);
39 } 39 }
40 40
41 LayoutUnit ResolveHeight(const Length& height, 41 LayoutUnit ResolveHeight(const Length& height,
42 const NGConstraintSpace& space, 42 const NGConstraintSpace& space,
43 const ComputedStyle& style, 43 const ComputedStyle& style,
44 const Optional<MinAndMaxContentSizes>& child_minmax, 44 const Optional<MinMaxContentSize>& child_minmax,
45 LengthResolveType resolve_type) { 45 LengthResolveType resolve_type) {
46 if (space.WritingMode() != kHorizontalTopBottom) 46 if (space.WritingMode() != kHorizontalTopBottom)
47 return ResolveInlineLength(space, style, child_minmax, height, 47 return ResolveInlineLength(space, style, child_minmax, height,
48 resolve_type); 48 resolve_type);
49 LayoutUnit computed_height = 49 LayoutUnit computed_height =
50 child_minmax.has_value() ? child_minmax->max_content : LayoutUnit(); 50 child_minmax.has_value() ? child_minmax->max_content : LayoutUnit();
51 return ResolveBlockLength(space, style, height, computed_height, 51 return ResolveBlockLength(space, style, height, computed_height,
52 resolve_type); 52 resolve_type);
53 } 53 }
54 54
55 // Implement absolute horizontal size resolution algorithm. 55 // Implement absolute horizontal size resolution algorithm.
56 // https://www.w3.org/TR/css-position-3/#abs-non-replaced-width 56 // https://www.w3.org/TR/css-position-3/#abs-non-replaced-width
57 void ComputeAbsoluteHorizontal( 57 void ComputeAbsoluteHorizontal(const NGConstraintSpace& space,
58 const NGConstraintSpace& space, 58 const ComputedStyle& style,
59 const ComputedStyle& style, 59 const Optional<LayoutUnit>& incoming_width,
60 const Optional<LayoutUnit>& incoming_width, 60 const NGStaticPosition& static_position,
61 const NGStaticPosition& static_position, 61 const Optional<MinMaxContentSize>& child_minmax,
62 const Optional<MinAndMaxContentSizes>& child_minmax, 62 NGAbsolutePhysicalPosition* position) {
63 NGAbsolutePhysicalPosition* position) {
64 NGLogicalSize percentage_logical = space.PercentageResolutionSize(); 63 NGLogicalSize percentage_logical = space.PercentageResolutionSize();
65 NGPhysicalSize percentage_physical = 64 NGPhysicalSize percentage_physical =
66 percentage_logical.ConvertToPhysical(space.WritingMode()); 65 percentage_logical.ConvertToPhysical(space.WritingMode());
67 LayoutUnit border_left(style.borderLeftWidth()); 66 LayoutUnit border_left(style.borderLeftWidth());
68 LayoutUnit border_right(style.borderRightWidth()); 67 LayoutUnit border_right(style.borderRightWidth());
69 LayoutUnit padding_left = 68 LayoutUnit padding_left =
70 valueForLength(style.paddingLeft(), percentage_logical.inline_size); 69 valueForLength(style.paddingLeft(), percentage_logical.inline_size);
71 LayoutUnit padding_right = 70 LayoutUnit padding_right =
72 valueForLength(style.paddingRight(), percentage_logical.inline_size); 71 valueForLength(style.paddingRight(), percentage_logical.inline_size);
73 Optional<LayoutUnit> margin_left; 72 Optional<LayoutUnit> margin_left;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // Negative widths are not allowed. 207 // Negative widths are not allowed.
209 width = std::max(*width, border_padding); 208 width = std::max(*width, border_padding);
210 209
211 position->inset.left = *left + *margin_left; 210 position->inset.left = *left + *margin_left;
212 position->inset.right = *right + *margin_right; 211 position->inset.right = *right + *margin_right;
213 position->size.width = *width; 212 position->size.width = *width;
214 } 213 }
215 214
216 // Implements absolute vertical size resolution algorithm. 215 // Implements absolute vertical size resolution algorithm.
217 // https://www.w3.org/TR/css-position-3/#abs-non-replaced-height 216 // https://www.w3.org/TR/css-position-3/#abs-non-replaced-height
218 void ComputeAbsoluteVertical( 217 void ComputeAbsoluteVertical(const NGConstraintSpace& space,
219 const NGConstraintSpace& space, 218 const ComputedStyle& style,
220 const ComputedStyle& style, 219 const Optional<LayoutUnit>& incoming_height,
221 const Optional<LayoutUnit>& incoming_height, 220 const NGStaticPosition& static_position,
222 const NGStaticPosition& static_position, 221 const Optional<MinMaxContentSize>& child_minmax,
223 const Optional<MinAndMaxContentSizes>& child_minmax, 222 NGAbsolutePhysicalPosition* position) {
224 NGAbsolutePhysicalPosition* position) {
225 NGLogicalSize percentage_logical = space.PercentageResolutionSize(); 223 NGLogicalSize percentage_logical = space.PercentageResolutionSize();
226 NGPhysicalSize percentage_physical = 224 NGPhysicalSize percentage_physical =
227 percentage_logical.ConvertToPhysical(space.WritingMode()); 225 percentage_logical.ConvertToPhysical(space.WritingMode());
228 226
229 LayoutUnit border_top(style.borderTopWidth()); 227 LayoutUnit border_top(style.borderTopWidth());
230 LayoutUnit border_bottom(style.borderBottomWidth()); 228 LayoutUnit border_bottom(style.borderBottomWidth());
231 LayoutUnit padding_top = 229 LayoutUnit padding_top =
232 valueForLength(style.paddingTop(), percentage_logical.inline_size); 230 valueForLength(style.paddingTop(), percentage_logical.inline_size);
233 LayoutUnit padding_bottom = 231 LayoutUnit padding_bottom =
234 valueForLength(style.paddingBottom(), percentage_logical.inline_size); 232 valueForLength(style.paddingBottom(), percentage_logical.inline_size);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 if (style.isHorizontalWritingMode()) 374 if (style.isHorizontalWritingMode())
377 return AbsoluteHorizontalNeedsEstimate(style); 375 return AbsoluteHorizontalNeedsEstimate(style);
378 else 376 else
379 return AbsoluteVerticalNeedsEstimate(style); 377 return AbsoluteVerticalNeedsEstimate(style);
380 } 378 }
381 379
382 NGAbsolutePhysicalPosition ComputePartialAbsoluteWithChildInlineSize( 380 NGAbsolutePhysicalPosition ComputePartialAbsoluteWithChildInlineSize(
383 const NGConstraintSpace& space, 381 const NGConstraintSpace& space,
384 const ComputedStyle& style, 382 const ComputedStyle& style,
385 const NGStaticPosition& static_position, 383 const NGStaticPosition& static_position,
386 const Optional<MinAndMaxContentSizes>& child_minmax) { 384 const Optional<MinMaxContentSize>& child_minmax) {
387 NGAbsolutePhysicalPosition position; 385 NGAbsolutePhysicalPosition position;
388 if (style.isHorizontalWritingMode()) { 386 if (style.isHorizontalWritingMode()) {
389 Optional<LayoutUnit> width; 387 Optional<LayoutUnit> width;
390 if (!style.width().isAuto()) { 388 if (!style.width().isAuto()) {
391 width = ResolveWidth(style.width(), space, style, child_minmax, 389 width = ResolveWidth(style.width(), space, style, child_minmax,
392 LengthResolveType::kContentSize); 390 LengthResolveType::kContentSize);
393 } 391 }
394 ComputeAbsoluteHorizontal(space, style, width, static_position, 392 ComputeAbsoluteHorizontal(space, style, width, static_position,
395 child_minmax, &position); 393 child_minmax, &position);
396 } else { 394 } else {
(...skipping 11 matching lines...) Expand all
408 void ComputeFullAbsoluteWithChildBlockSize( 406 void ComputeFullAbsoluteWithChildBlockSize(
409 const NGConstraintSpace& space, 407 const NGConstraintSpace& space,
410 const ComputedStyle& style, 408 const ComputedStyle& style,
411 const NGStaticPosition& static_position, 409 const NGStaticPosition& static_position,
412 const Optional<LayoutUnit>& child_block_size, 410 const Optional<LayoutUnit>& child_block_size,
413 NGAbsolutePhysicalPosition* position) { 411 NGAbsolutePhysicalPosition* position) {
414 // After partial size has been computed, child block size is either 412 // After partial size has been computed, child block size is either
415 // unknown, or fully computed, there is no minmax. 413 // unknown, or fully computed, there is no minmax.
416 // To express this, a 'fixed' minmax is created where 414 // To express this, a 'fixed' minmax is created where
417 // min and max are the same. 415 // min and max are the same.
418 Optional<MinAndMaxContentSizes> child_minmax; 416 Optional<MinMaxContentSize> child_minmax;
419 if (child_block_size.has_value()) { 417 if (child_block_size.has_value()) {
420 child_minmax = MinAndMaxContentSizes{*child_block_size, *child_block_size}; 418 child_minmax = MinMaxContentSize{*child_block_size, *child_block_size};
421 } 419 }
422 if (style.isHorizontalWritingMode()) { 420 if (style.isHorizontalWritingMode()) {
423 Optional<LayoutUnit> height; 421 Optional<LayoutUnit> height;
424 if (!style.height().isAuto()) { 422 if (!style.height().isAuto()) {
425 height = ResolveHeight(style.height(), space, style, child_minmax, 423 height = ResolveHeight(style.height(), space, style, child_minmax,
426 LengthResolveType::kContentSize); 424 LengthResolveType::kContentSize);
427 } 425 }
428 ComputeAbsoluteVertical(space, style, height, static_position, child_minmax, 426 ComputeAbsoluteVertical(space, style, height, static_position, child_minmax,
429 position); 427 position);
430 } else { 428 } else {
431 Optional<LayoutUnit> width; 429 Optional<LayoutUnit> width;
432 if (!style.width().isAuto()) { 430 if (!style.width().isAuto()) {
433 width = ResolveWidth(style.width(), space, style, child_minmax, 431 width = ResolveWidth(style.width(), space, style, child_minmax,
434 LengthResolveType::kContentSize); 432 LengthResolveType::kContentSize);
435 } 433 }
436 ComputeAbsoluteHorizontal(space, style, width, static_position, 434 ComputeAbsoluteHorizontal(space, style, width, static_position,
437 child_minmax, position); 435 child_minmax, position);
438 } 436 }
439 } 437 }
440 438
441 } // namespace blink 439 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698