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_length_utils.h" | 5 #include "core/layout/ng/ng_length_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_constraint_space_builder.h" | 8 #include "core/layout/ng/ng_constraint_space_builder.h" |
9 #include "core/layout/ng/ng_fragment_base.h" | 9 #include "core/layout/ng/ng_fragment_base.h" |
10 #include "core/style/ComputedStyle.h" | 10 #include "core/style/ComputedStyle.h" |
11 #include "platform/LayoutUnit.h" | 11 #include "platform/LayoutUnit.h" |
12 #include "platform/Length.h" | 12 #include "platform/Length.h" |
13 #include "wtf/Optional.h" | 13 #include "wtf/Optional.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 // TODO(layout-ng): | 16 // TODO(layout-ng): |
17 // - positioned and/or replaced calculations | 17 // - positioned and/or replaced calculations |
18 // - Take scrollbars into account | 18 // - Take scrollbars into account |
19 | 19 |
20 bool NeedMinAndMaxContentSizes(const ComputedStyle& style) { | 20 bool NeedMinAndMaxContentSizes(const NGConstraintSpace& constraint_space, |
21 // TODO(layout-ng): In the future we may pass a shrink-to-fit flag through the | 21 const ComputedStyle& style) { |
22 // constraint space; if so, this function needs to take a constraint space | |
23 // as well to take that into account. | |
24 // This check is technically too broad (fill-available does not need intrinsic | 22 // This check is technically too broad (fill-available does not need intrinsic |
25 // size computation) but that's a rare case and only affects performance, not | 23 // size computation) but that's a rare case and only affects performance, not |
26 // correctness. | 24 // correctness. |
27 return style.logicalWidth().isIntrinsic() || | 25 return constraint_space.IsShrinkToFit() || |
| 26 style.logicalWidth().isIntrinsic() || |
28 style.logicalMinWidth().isIntrinsic() || | 27 style.logicalMinWidth().isIntrinsic() || |
29 style.logicalMaxWidth().isIntrinsic(); | 28 style.logicalMaxWidth().isIntrinsic(); |
30 } | 29 } |
31 | 30 |
32 bool NeedMinAndMaxContentSizesForContentContribution( | 31 bool NeedMinAndMaxContentSizesForContentContribution( |
33 const ComputedStyle& style) { | 32 const ComputedStyle& style) { |
34 return NeedMinAndMaxContentSizes(style) || style.logicalWidth().isAuto(); | 33 return style.logicalWidth().isIntrinsicOrAuto() || |
| 34 style.logicalMinWidth().isIntrinsic() || |
| 35 style.logicalMaxWidth().isIntrinsic(); |
35 } | 36 } |
36 | 37 |
37 LayoutUnit ResolveInlineLength( | 38 LayoutUnit ResolveInlineLength( |
38 const NGConstraintSpace& constraint_space, | 39 const NGConstraintSpace& constraint_space, |
39 const ComputedStyle& style, | 40 const ComputedStyle& style, |
40 const WTF::Optional<MinAndMaxContentSizes>& min_and_max, | 41 const WTF::Optional<MinAndMaxContentSizes>& min_and_max, |
41 const Length& length, | 42 const Length& length, |
42 LengthResolveType type) { | 43 LengthResolveType type) { |
43 // TODO(layout-ng): Handle min/max/fit-content | 44 // TODO(layout-ng): Handle min/max/fit-content |
44 DCHECK(!length.isMaxSizeNone()); | 45 DCHECK(!length.isMaxSizeNone()); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 return computed_sizes; | 228 return computed_sizes; |
228 } | 229 } |
229 | 230 |
230 LayoutUnit ComputeInlineSizeForFragment( | 231 LayoutUnit ComputeInlineSizeForFragment( |
231 const NGConstraintSpace& space, | 232 const NGConstraintSpace& space, |
232 const ComputedStyle& style, | 233 const ComputedStyle& style, |
233 const WTF::Optional<MinAndMaxContentSizes>& min_and_max) { | 234 const WTF::Optional<MinAndMaxContentSizes>& min_and_max) { |
234 if (space.IsFixedSizeInline()) | 235 if (space.IsFixedSizeInline()) |
235 return space.AvailableSize().inline_size; | 236 return space.AvailableSize().inline_size; |
236 | 237 |
237 LayoutUnit extent = | 238 Length logicalWidth = style.logicalWidth(); |
238 ResolveInlineLength(space, style, min_and_max, style.logicalWidth(), | 239 if (logicalWidth.isAuto() && space.IsShrinkToFit()) |
239 LengthResolveType::kContentSize); | 240 logicalWidth = Length(FitContent); |
| 241 |
| 242 LayoutUnit extent = ResolveInlineLength( |
| 243 space, style, min_and_max, logicalWidth, LengthResolveType::kContentSize); |
240 | 244 |
241 Length max_length = style.logicalMaxWidth(); | 245 Length max_length = style.logicalMaxWidth(); |
242 if (!max_length.isMaxSizeNone()) { | 246 if (!max_length.isMaxSizeNone()) { |
243 LayoutUnit max = ResolveInlineLength(space, style, min_and_max, max_length, | 247 LayoutUnit max = ResolveInlineLength(space, style, min_and_max, max_length, |
244 LengthResolveType::kMaxSize); | 248 LengthResolveType::kMaxSize); |
245 extent = std::min(extent, max); | 249 extent = std::min(extent, max); |
246 } | 250 } |
247 | 251 |
248 LayoutUnit min = | 252 LayoutUnit min = |
249 ResolveInlineLength(space, style, min_and_max, style.logicalMinWidth(), | 253 ResolveInlineLength(space, style, min_and_max, style.logicalMinWidth(), |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 margins->inline_start = available_space / 2; | 402 margins->inline_start = available_space / 2; |
399 margins->inline_end = available_space - margins->inline_start; | 403 margins->inline_end = available_space - margins->inline_start; |
400 } else if (style.marginStart().isAuto()) { | 404 } else if (style.marginStart().isAuto()) { |
401 margins->inline_start = available_space; | 405 margins->inline_start = available_space; |
402 } else if (style.marginEnd().isAuto()) { | 406 } else if (style.marginEnd().isAuto()) { |
403 margins->inline_end = available_space; | 407 margins->inline_end = available_space; |
404 } | 408 } |
405 } | 409 } |
406 | 410 |
407 } // namespace blink | 411 } // namespace blink |
OLD | NEW |