Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_length_utils.cc

Issue 2289353002: [layoutng] Add methods to compute border and padding (Closed)
Patch Set: better enum name Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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();
27 28
28 if (type == LengthResolveType::MarginSize && length.isAuto()) 29 if (type == LengthResolveType::MarginBorderPaddingSize && length.isAuto())
29 return LayoutUnit(); 30 return LayoutUnit();
30 31
31 return valueForLength(length, constraintSpace.ContainerSize().inline_size); 32 return valueForLength(length, constraintSpace.ContainerSize().inline_size);
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::MarginBorderPaddingSize);
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
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 114 }
114 115
115 return extent; 116 return extent;
116 } 117 }
117 118
118 NGBoxStrut computeMargins(const NGConstraintSpace& constraintSpace, 119 NGBoxStrut computeMargins(const NGConstraintSpace& constraintSpace,
119 const ComputedStyle& style) { 120 const ComputedStyle& style) {
120 // Margins always get computed relative to the inline size: 121 // Margins always get computed relative to the inline size:
121 // https://www.w3.org/TR/CSS2/box.html#value-def-margin-width 122 // https://www.w3.org/TR/CSS2/box.html#value-def-margin-width
122 NGBoxStrut margins; 123 NGBoxStrut margins;
123 margins.inline_start = resolveInlineLength( 124 margins.inline_start =
124 constraintSpace, style.marginStart(), LengthResolveType::MarginSize); 125 resolveInlineLength(constraintSpace, style.marginStart(),
125 margins.inline_end = resolveInlineLength(constraintSpace, style.marginEnd(), 126 LengthResolveType::MarginBorderPaddingSize);
126 LengthResolveType::MarginSize); 127 margins.inline_end =
127 margins.block_start = resolveInlineLength( 128 resolveInlineLength(constraintSpace, style.marginEnd(),
128 constraintSpace, style.marginBefore(), LengthResolveType::MarginSize); 129 LengthResolveType::MarginBorderPaddingSize);
129 margins.block_end = resolveInlineLength(constraintSpace, style.marginAfter(), 130 margins.block_start =
130 LengthResolveType::MarginSize); 131 resolveInlineLength(constraintSpace, style.marginBefore(),
132 LengthResolveType::MarginBorderPaddingSize);
133 margins.block_end =
134 resolveInlineLength(constraintSpace, style.marginAfter(),
135 LengthResolveType::MarginBorderPaddingSize);
131 return margins; 136 return margins;
132 } 137 }
133 138
139 NGBoxStrut computeBorders(const ComputedStyle& style) {
140 NGBoxStrut borders;
141 borders.inline_start = LayoutUnit(style.borderStartWidth());
142 borders.inline_end = LayoutUnit(style.borderEndWidth());
143 borders.block_start = LayoutUnit(style.borderBeforeWidth());
144 borders.block_end = LayoutUnit(style.borderAfterWidth());
145 return borders;
146 }
147
148 NGBoxStrut computePadding(const NGConstraintSpace& constraintSpace,
149 const ComputedStyle& style) {
150 // Padding always gets computed relative to the inline size:
151 // https://www.w3.org/TR/CSS2/box.html#value-def-padding-width
152 NGBoxStrut padding;
153 padding.inline_start =
154 resolveInlineLength(constraintSpace, style.paddingStart(),
155 LengthResolveType::MarginBorderPaddingSize);
156 padding.inline_end =
157 resolveInlineLength(constraintSpace, style.paddingEnd(),
158 LengthResolveType::MarginBorderPaddingSize);
159 padding.block_start =
160 resolveInlineLength(constraintSpace, style.paddingBefore(),
161 LengthResolveType::MarginBorderPaddingSize);
162 padding.block_end =
163 resolveInlineLength(constraintSpace, style.paddingAfter(),
164 LengthResolveType::MarginBorderPaddingSize);
165 return padding;
166 }
167
134 } // namespace blink 168 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698