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_margin_strut.h" | 8 #include "core/layout/ng/ng_margin_strut.h" |
9 #include "core/style/ComputedStyle.h" | 9 #include "core/style/ComputedStyle.h" |
10 #include "platform/LayoutUnit.h" | 10 #include "platform/LayoutUnit.h" |
11 #include "platform/Length.h" | 11 #include "platform/Length.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 // TODO(layout-ng): | 14 // TODO(layout-ng): |
15 // - Handle border-box correctly | 15 // - Handle border-box correctly |
16 // - positioned and/or replaced calculations | 16 // - positioned and/or replaced calculations |
17 // - Handle margins for fill-available and width: auto | 17 // - Handle margins for fill-available and width: auto |
18 | 18 |
19 LayoutUnit resolveInlineLength(const NGConstraintSpace& constraintSpace, | 19 LayoutUnit resolveInlineLength(const NGConstraintSpace& constraintSpace, |
20 const Length& length, | 20 const Length& length, |
21 LengthResolveType type) { | 21 LengthResolveType type) { |
22 // TODO(layout-ng): Handle min/max/fit-content | 22 // TODO(layout-ng): Handle min/max/fit-content |
23 DCHECK(!length.isMaxSizeNone()); | 23 DCHECK(!length.isMaxSizeNone()); |
| 24 DCHECK_GE(constraintSpace.ContainerSize().inlineSize, LayoutUnit()); |
24 | 25 |
25 if (type == LengthResolveType::MinSize && length.isAuto()) | 26 if (type == LengthResolveType::MinSize && length.isAuto()) |
26 return LayoutUnit(); | 27 return LayoutUnit(); |
27 | 28 |
28 if (type == LengthResolveType::MarginSize && length.isAuto()) | 29 if (type == LengthResolveType::MarginSize && length.isAuto()) |
29 return LayoutUnit(); | 30 return LayoutUnit(); |
30 | 31 |
31 return valueForLength(length, constraintSpace.ContainerSize().inlineSize); | 32 return valueForLength(length, constraintSpace.ContainerSize().inlineSize); |
32 } | 33 } |
33 | 34 |
34 LayoutUnit resolveBlockLength(const NGConstraintSpace& constraintSpace, | 35 LayoutUnit resolveBlockLength(const NGConstraintSpace& constraintSpace, |
35 const Length& length, | 36 const Length& length, |
36 LayoutUnit contentSize, | 37 LayoutUnit contentSize, |
37 LengthResolveType type) { | 38 LengthResolveType type) { |
38 DCHECK(!length.isMaxSizeNone()); | 39 DCHECK(!length.isMaxSizeNone()); |
39 DCHECK(type != LengthResolveType::MarginSize); | 40 DCHECK(type != LengthResolveType::MarginSize); |
40 | 41 |
41 if (type == LengthResolveType::MinSize && length.isAuto()) | 42 if (type == LengthResolveType::MinSize && length.isAuto()) |
42 return LayoutUnit(); | 43 return LayoutUnit(); |
43 | 44 |
44 if (length.isAuto()) | 45 if (length.isAuto()) |
45 return contentSize; | 46 return contentSize; |
46 | 47 |
47 if (length.isMinContent() || length.isMaxContent() || length.isFitContent()) | 48 if (length.isMinContent() || length.isMaxContent() || length.isFitContent()) |
48 return contentSize; | 49 return contentSize; |
49 | 50 |
| 51 // Make sure that indefinite percentages resolve to NGSizeIndefinite, not to |
| 52 // a random negative number. |
| 53 if (length.hasPercent() && |
| 54 constraintSpace.ContainerSize().blockSize == NGSizeIndefinite) |
| 55 return contentSize; |
| 56 |
50 return valueForLength(length, constraintSpace.ContainerSize().blockSize); | 57 return valueForLength(length, constraintSpace.ContainerSize().blockSize); |
51 } | 58 } |
52 | 59 |
53 LayoutUnit computeInlineSizeForFragment( | 60 LayoutUnit computeInlineSizeForFragment( |
54 const NGConstraintSpace& constraintSpace, | 61 const NGConstraintSpace& constraintSpace, |
55 const ComputedStyle& style) { | 62 const ComputedStyle& style) { |
56 if (constraintSpace.fixedInlineSize()) | 63 if (constraintSpace.fixedInlineSize()) |
57 return constraintSpace.ContainerSize().inlineSize; | 64 return constraintSpace.ContainerSize().inlineSize; |
58 | 65 |
59 LayoutUnit extent = resolveInlineLength(constraintSpace, style.logicalWidth(), | 66 LayoutUnit extent = resolveInlineLength(constraintSpace, style.logicalWidth(), |
(...skipping 19 matching lines...) Expand all Loading... |
79 | 86 |
80 LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace, | 87 LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace, |
81 const ComputedStyle& style, | 88 const ComputedStyle& style, |
82 LayoutUnit contentSize) { | 89 LayoutUnit contentSize) { |
83 if (constraintSpace.fixedBlockSize()) | 90 if (constraintSpace.fixedBlockSize()) |
84 return constraintSpace.ContainerSize().blockSize; | 91 return constraintSpace.ContainerSize().blockSize; |
85 | 92 |
86 LayoutUnit extent = | 93 LayoutUnit extent = |
87 resolveBlockLength(constraintSpace, style.logicalHeight(), contentSize, | 94 resolveBlockLength(constraintSpace, style.logicalHeight(), contentSize, |
88 LengthResolveType::ContentSize); | 95 LengthResolveType::ContentSize); |
| 96 if (extent == NGSizeIndefinite) { |
| 97 DCHECK_EQ(contentSize, NGSizeIndefinite); |
| 98 return extent; |
| 99 } |
| 100 |
89 Length maxLength = style.logicalMaxHeight(); | 101 Length maxLength = style.logicalMaxHeight(); |
90 | |
91 if (!maxLength.isMaxSizeNone()) { | 102 if (!maxLength.isMaxSizeNone()) { |
92 LayoutUnit max = resolveBlockLength(constraintSpace, maxLength, contentSize, | 103 LayoutUnit max = resolveBlockLength(constraintSpace, maxLength, contentSize, |
93 LengthResolveType::MaxSize); | 104 LengthResolveType::MaxSize); |
94 extent = std::min(extent, max); | 105 extent = std::min(extent, max); |
95 } | 106 } |
96 | 107 |
97 LayoutUnit min = resolveBlockLength(constraintSpace, style.logicalMinHeight(), | 108 LayoutUnit min = resolveBlockLength(constraintSpace, style.logicalMinHeight(), |
98 contentSize, LengthResolveType::MinSize); | 109 contentSize, LengthResolveType::MinSize); |
99 extent = std::max(extent, min); | 110 extent = std::max(extent, min); |
100 | 111 |
(...skipping 14 matching lines...) Expand all Loading... |
115 margins.inlineEnd = resolveInlineLength(constraintSpace, style.marginEnd(), | 126 margins.inlineEnd = resolveInlineLength(constraintSpace, style.marginEnd(), |
116 LengthResolveType::MarginSize); | 127 LengthResolveType::MarginSize); |
117 margins.blockStart = resolveInlineLength( | 128 margins.blockStart = resolveInlineLength( |
118 constraintSpace, style.marginBefore(), LengthResolveType::MarginSize); | 129 constraintSpace, style.marginBefore(), LengthResolveType::MarginSize); |
119 margins.blockEnd = resolveInlineLength(constraintSpace, style.marginAfter(), | 130 margins.blockEnd = resolveInlineLength(constraintSpace, style.marginAfter(), |
120 LengthResolveType::MarginSize); | 131 LengthResolveType::MarginSize); |
121 return margins; | 132 return margins; |
122 } | 133 } |
123 | 134 |
124 } // namespace blink | 135 } // namespace blink |
OLD | NEW |