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()); |
| 39 DCHECK(type != LengthResolveType::MarginSize); |
35 | 40 |
36 if (type == LengthResolveType::MinSize && length.isAuto()) | 41 if (type == LengthResolveType::MinSize && length.isAuto()) |
37 return LayoutUnit(); | 42 return LayoutUnit(); |
38 | 43 |
39 if (length.isAuto()) | 44 if (length.isAuto()) |
40 return contentSize; | 45 return contentSize; |
41 | 46 |
42 if (length.isMinContent() || length.isMaxContent() || length.isFitContent()) | 47 if (length.isMinContent() || length.isMaxContent() || length.isFitContent()) |
43 return contentSize; | 48 return contentSize; |
44 | 49 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 contentSize, LengthResolveType::MinSize); | 98 contentSize, LengthResolveType::MinSize); |
94 extent = std::max(extent, min); | 99 extent = std::max(extent, min); |
95 | 100 |
96 if (style.boxSizing() == BoxSizingContentBox) { | 101 if (style.boxSizing() == BoxSizingContentBox) { |
97 // TODO(layout-ng): Compute border/padding size and add it | 102 // TODO(layout-ng): Compute border/padding size and add it |
98 } | 103 } |
99 | 104 |
100 return extent; | 105 return extent; |
101 } | 106 } |
102 | 107 |
| 108 NGBoxMargins computeMargins(const NGConstraintSpace& constraintSpace, |
| 109 const ComputedStyle& style) { |
| 110 // Margins always get computed relative to the inline size: |
| 111 // https://www.w3.org/TR/CSS2/box.html#value-def-margin-width |
| 112 NGBoxMargins margins; |
| 113 margins.inlineStart = resolveInlineLength( |
| 114 constraintSpace, style.marginStart(), LengthResolveType::MarginSize); |
| 115 margins.inlineEnd = resolveInlineLength(constraintSpace, style.marginEnd(), |
| 116 LengthResolveType::MarginSize); |
| 117 margins.blockStart = resolveInlineLength( |
| 118 constraintSpace, style.marginBefore(), LengthResolveType::MarginSize); |
| 119 margins.blockEnd = resolveInlineLength(constraintSpace, style.marginAfter(), |
| 120 LengthResolveType::MarginSize); |
| 121 return margins; |
| 122 } |
| 123 |
103 } // namespace blink | 124 } // namespace blink |
OLD | NEW |