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/style/ComputedStyle.h" | 8 #include "core/style/ComputedStyle.h" |
9 #include "platform/LayoutUnit.h" | 9 #include "platform/LayoutUnit.h" |
10 #include "platform/Length.h" | 10 #include "platform/Length.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 // TODO(layout-ng): | 13 // TODO(layout-ng): |
14 // - Handle border-box correctly | 14 // - Handle border-box correctly |
15 // - positioned and/or replaced calculations | 15 // - positioned and/or replaced calculations |
16 // - Handle margins for fill-available and width: auto | 16 // - Handle margins for fill-available and width: auto |
17 // - Take scrollbars into account | |
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 DCHECK_GE(constraintSpace.ContainerSize().inline_size, LayoutUnit()); | 24 DCHECK_GE(constraintSpace.ContainerSize().inline_size, LayoutUnit()); |
24 | 25 |
25 if (type == LengthResolveType::MinSize && length.isAuto()) | 26 if (type == LengthResolveType::MinSize && length.isAuto()) |
26 return LayoutUnit(); | 27 return LayoutUnit(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 constraintSpace, style.marginStart(), LengthResolveType::MarginSize); | 125 constraintSpace, style.marginStart(), LengthResolveType::MarginSize); |
125 margins.inline_end = resolveInlineLength(constraintSpace, style.marginEnd(), | 126 margins.inline_end = resolveInlineLength(constraintSpace, style.marginEnd(), |
126 LengthResolveType::MarginSize); | 127 LengthResolveType::MarginSize); |
127 margins.block_start = resolveInlineLength( | 128 margins.block_start = resolveInlineLength( |
128 constraintSpace, style.marginBefore(), LengthResolveType::MarginSize); | 129 constraintSpace, style.marginBefore(), LengthResolveType::MarginSize); |
129 margins.block_end = resolveInlineLength(constraintSpace, style.marginAfter(), | 130 margins.block_end = resolveInlineLength(constraintSpace, style.marginAfter(), |
130 LengthResolveType::MarginSize); | 131 LengthResolveType::MarginSize); |
131 return margins; | 132 return margins; |
132 } | 133 } |
133 | 134 |
135 NGBoxStrut computeBorders(const ComputedStyle& style) { | |
136 NGBoxStrut borders; | |
137 borders.inline_start = LayoutUnit(style.borderStartWidth()); | |
138 borders.inline_end = LayoutUnit(style.borderEndWidth()); | |
139 borders.block_start = LayoutUnit(style.borderBeforeWidth()); | |
140 borders.block_end = LayoutUnit(style.borderAfterWidth()); | |
141 return borders; | |
142 } | |
143 | |
144 NGBoxStrut computePadding(const NGConstraintSpace& constraintSpace, | |
145 const ComputedStyle& style) { | |
146 // Padding always gets computed relative to the inline size: | |
147 // https://www.w3.org/TR/CSS2/box.html#value-def-padding-width | |
148 NGBoxStrut padding; | |
149 padding.inline_start = resolveInlineLength( | |
150 constraintSpace, style.paddingStart(), LengthResolveType::MarginSize); | |
151 padding.inline_end = resolveInlineLength(constraintSpace, style.paddingEnd(), | |
152 LengthResolveType::MarginSize); | |
153 padding.block_start = resolveInlineLength( | |
154 constraintSpace, style.paddingBefore(), LengthResolveType::MarginSize); | |
ikilpatrick
2016/08/30 20:30:44
Is LengthResolveType::MarginSize better named some
cbiesinger
2016/08/30 20:32:59
Oh right. I guess I'll go with MarginBorderPadding
| |
155 padding.block_end = resolveInlineLength(constraintSpace, style.paddingAfter(), | |
156 LengthResolveType::MarginSize); | |
157 return padding; | |
158 } | |
159 | |
134 } // namespace blink | 160 } // namespace blink |
OLD | NEW |