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/style/ComputedStyle.h" | 9 #include "core/style/ComputedStyle.h" |
9 #include "platform/LayoutUnit.h" | 10 #include "platform/LayoutUnit.h" |
10 #include "platform/Length.h" | 11 #include "platform/Length.h" |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 // TODO(layout-ng): | 14 // TODO(layout-ng): |
14 // - Handle border-box correctly | 15 // - Handle border-box correctly |
15 // - positioned and/or replaced calculations | 16 // - positioned and/or replaced calculations |
16 // - Handle margins for fill-available and width: auto | 17 // - Handle margins for fill-available and width: auto |
17 | 18 |
18 LayoutUnit resolveInlineLength(const NGConstraintSpace& constraintSpace, | 19 LayoutUnit resolveInlineLength(const NGConstraintSpace& constraintSpace, |
19 const Length& length, | 20 const Length& length, |
20 LengthResolveType type) { | 21 LengthResolveType type) { |
21 // TODO(layout-ng): Handle min/max/fit-content | 22 // TODO(layout-ng): Handle min/max/fit-content |
22 DCHECK(!length.isMaxSizeNone()); | 23 DCHECK(!length.isMaxSizeNone()); |
23 | 24 |
24 if (type == LengthResolveType::MinSize && length.isAuto()) | 25 if (type == LengthResolveType::MinSize && length.isAuto()) |
25 return LayoutUnit(); | 26 return LayoutUnit(); |
26 | 27 |
28 if (type == LengthResolveType::MarginSize && length.isAuto()) | |
29 return LayoutUnit(); | |
30 | |
27 return valueForLength(length, constraintSpace.ContainerSize().inlineSize); | 31 return valueForLength(length, constraintSpace.ContainerSize().inlineSize); |
28 } | 32 } |
29 | 33 |
30 LayoutUnit resolveBlockLength(const NGConstraintSpace& constraintSpace, | 34 LayoutUnit resolveBlockLength(const NGConstraintSpace& constraintSpace, |
31 const Length& length, | 35 const Length& length, |
32 LayoutUnit contentSize, | 36 LayoutUnit contentSize, |
33 LengthResolveType type) { | 37 LengthResolveType type) { |
34 DCHECK(!length.isMaxSizeNone()); | 38 DCHECK(!length.isMaxSizeNone()); |
35 | 39 |
36 if (type == LengthResolveType::MinSize && length.isAuto()) | 40 if (type == LengthResolveType::MinSize && length.isAuto()) |
37 return LayoutUnit(); | 41 return LayoutUnit(); |
38 | 42 |
39 if (length.isAuto()) | 43 if (type != LengthResolveType::MarginSize && length.isAuto()) |
ikilpatrick
2016/08/18 22:54:33
is this needed? should there just be a DCHECK(type
| |
40 return contentSize; | 44 return contentSize; |
41 | 45 |
42 if (length.isMinContent() || length.isMaxContent() || length.isFitContent()) | 46 if (length.isMinContent() || length.isMaxContent() || length.isFitContent()) |
43 return contentSize; | 47 return contentSize; |
44 | 48 |
45 return valueForLength(length, constraintSpace.ContainerSize().blockSize); | 49 return valueForLength(length, constraintSpace.ContainerSize().blockSize); |
46 } | 50 } |
47 | 51 |
48 LayoutUnit computeInlineSizeForFragment( | 52 LayoutUnit computeInlineSizeForFragment( |
49 const NGConstraintSpace& constraintSpace, | 53 const NGConstraintSpace& constraintSpace, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 contentSize, LengthResolveType::MinSize); | 97 contentSize, LengthResolveType::MinSize); |
94 extent = std::max(extent, min); | 98 extent = std::max(extent, min); |
95 | 99 |
96 if (style.boxSizing() == BoxSizingContentBox) { | 100 if (style.boxSizing() == BoxSizingContentBox) { |
97 // TODO(layout-ng): Compute border/padding size and add it | 101 // TODO(layout-ng): Compute border/padding size and add it |
98 } | 102 } |
99 | 103 |
100 return extent; | 104 return extent; |
101 } | 105 } |
102 | 106 |
107 NGBoxMargins computeMargins(const NGConstraintSpace& constraintSpace, | |
108 const ComputedStyle& style) { | |
109 // Margins always get computed relative to the inline size: | |
110 // https://www.w3.org/TR/CSS2/box.html#value-def-margin-width | |
111 NGBoxMargins margins; | |
112 margins.inlineStart = resolveInlineLength( | |
113 constraintSpace, style.marginStart(), LengthResolveType::MarginSize); | |
114 margins.inlineEnd = resolveInlineLength(constraintSpace, style.marginEnd(), | |
115 LengthResolveType::MarginSize); | |
116 margins.blockStart = resolveInlineLength( | |
117 constraintSpace, style.marginBefore(), LengthResolveType::MarginSize); | |
118 margins.blockEnd = resolveInlineLength(constraintSpace, style.marginAfter(), | |
119 LengthResolveType::MarginSize); | |
120 return margins; | |
121 } | |
122 | |
103 } // namespace blink | 123 } // namespace blink |
OLD | NEW |