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" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 LayoutUnit max = resolveInlineLength(constraintSpace, maxLength, | 71 LayoutUnit max = resolveInlineLength(constraintSpace, maxLength, |
72 LengthResolveType::MaxSize); | 72 LengthResolveType::MaxSize); |
73 extent = std::min(extent, max); | 73 extent = std::min(extent, max); |
74 } | 74 } |
75 | 75 |
76 LayoutUnit min = resolveInlineLength(constraintSpace, style.logicalMinWidth(), | 76 LayoutUnit min = resolveInlineLength(constraintSpace, style.logicalMinWidth(), |
77 LengthResolveType::MinSize); | 77 LengthResolveType::MinSize); |
78 extent = std::max(extent, min); | 78 extent = std::max(extent, min); |
79 | 79 |
80 if (style.boxSizing() == BoxSizingContentBox) { | 80 if (style.boxSizing() == BoxSizingContentBox) { |
81 // TODO(layout-ng): Compute border/padding size and add it | 81 extent += computeBorderAndPaddingStart(constraintSpace, style); |
82 extent += computeBorderAndPaddingEnd(constraintSpace, style); | |
82 } | 83 } |
83 | 84 |
84 return extent; | 85 return extent; |
85 } | 86 } |
86 | 87 |
87 LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace, | 88 LayoutUnit computeBlockSizeForFragment(const NGConstraintSpace& constraintSpace, |
88 const ComputedStyle& style, | 89 const ComputedStyle& style, |
89 LayoutUnit contentSize) { | 90 LayoutUnit contentSize) { |
90 if (constraintSpace.FixedBlockSize()) | 91 if (constraintSpace.FixedBlockSize()) |
91 return constraintSpace.ContainerSize().block_size; | 92 return constraintSpace.ContainerSize().block_size; |
(...skipping 11 matching lines...) Expand all Loading... | |
103 LayoutUnit max = resolveBlockLength(constraintSpace, maxLength, contentSize, | 104 LayoutUnit max = resolveBlockLength(constraintSpace, maxLength, contentSize, |
104 LengthResolveType::MaxSize); | 105 LengthResolveType::MaxSize); |
105 extent = std::min(extent, max); | 106 extent = std::min(extent, max); |
106 } | 107 } |
107 | 108 |
108 LayoutUnit min = resolveBlockLength(constraintSpace, style.logicalMinHeight(), | 109 LayoutUnit min = resolveBlockLength(constraintSpace, style.logicalMinHeight(), |
109 contentSize, LengthResolveType::MinSize); | 110 contentSize, LengthResolveType::MinSize); |
110 extent = std::max(extent, min); | 111 extent = std::max(extent, min); |
111 | 112 |
112 if (style.boxSizing() == BoxSizingContentBox) { | 113 if (style.boxSizing() == BoxSizingContentBox) { |
113 // TODO(layout-ng): Compute border/padding size and add it | 114 extent += computeBorderAndPaddingBefore(constraintSpace, style); |
115 extent += computeBorderAndPaddingAfter(constraintSpace, style); | |
114 } | 116 } |
115 | 117 |
116 return extent; | 118 return extent; |
117 } | 119 } |
118 | 120 |
121 LayoutUnit computeBorderAndPaddingBefore( | |
ikilpatrick
2016/09/09 16:33:06
small nit; trying to be consistent with css and on
| |
122 const NGConstraintSpace& constraintSpace, | |
123 const ComputedStyle& style) { | |
124 // Percentages on block-direction padding are resolved against the containing | |
125 // block *inline size* - hence the call to resolveInlineLength(). | |
126 LayoutUnit padding = | |
127 resolveInlineLength(constraintSpace, style.paddingBefore(), | |
128 LengthResolveType::MarginBorderPaddingSize); | |
129 return padding + LayoutUnit(style.borderBeforeWidth()); | |
130 } | |
131 | |
132 LayoutUnit computeBorderAndPaddingAfter( | |
133 const NGConstraintSpace& constraintSpace, | |
134 const ComputedStyle& style) { | |
135 // Percentages on block-direction padding are resolved against the containing | |
136 // block *inline size* - hence the call to resolveInlineLength(). | |
137 LayoutUnit padding = | |
138 resolveInlineLength(constraintSpace, style.paddingAfter(), | |
139 LengthResolveType::MarginBorderPaddingSize); | |
140 return padding + LayoutUnit(style.borderAfterWidth()); | |
141 } | |
142 | |
143 LayoutUnit computeBorderAndPaddingStart( | |
144 const NGConstraintSpace& constraintSpace, | |
145 const ComputedStyle& style) { | |
146 LayoutUnit padding = | |
147 resolveInlineLength(constraintSpace, style.paddingStart(), | |
148 LengthResolveType::MarginBorderPaddingSize); | |
149 return padding + LayoutUnit(style.borderStartWidth()); | |
150 } | |
151 | |
152 LayoutUnit computeBorderAndPaddingEnd(const NGConstraintSpace& constraintSpace, | |
153 const ComputedStyle& style) { | |
154 LayoutUnit padding = | |
155 resolveInlineLength(constraintSpace, style.paddingEnd(), | |
156 LengthResolveType::MarginBorderPaddingSize); | |
157 return padding + LayoutUnit(style.borderEndWidth()); | |
158 } | |
159 | |
119 NGBoxStrut computeMargins(const NGConstraintSpace& constraintSpace, | 160 NGBoxStrut computeMargins(const NGConstraintSpace& constraintSpace, |
120 const ComputedStyle& style) { | 161 const ComputedStyle& style) { |
121 // Margins always get computed relative to the inline size: | 162 // Margins always get computed relative to the inline size: |
122 // https://www.w3.org/TR/CSS2/box.html#value-def-margin-width | 163 // https://www.w3.org/TR/CSS2/box.html#value-def-margin-width |
123 NGBoxStrut margins; | 164 NGBoxStrut margins; |
124 margins.inline_start = | 165 margins.inline_start = |
125 resolveInlineLength(constraintSpace, style.marginStart(), | 166 resolveInlineLength(constraintSpace, style.marginStart(), |
126 LengthResolveType::MarginBorderPaddingSize); | 167 LengthResolveType::MarginBorderPaddingSize); |
127 margins.inline_end = | 168 margins.inline_end = |
128 resolveInlineLength(constraintSpace, style.marginEnd(), | 169 resolveInlineLength(constraintSpace, style.marginEnd(), |
(...skipping 30 matching lines...) Expand all Loading... | |
159 padding.block_start = | 200 padding.block_start = |
160 resolveInlineLength(constraintSpace, style.paddingBefore(), | 201 resolveInlineLength(constraintSpace, style.paddingBefore(), |
161 LengthResolveType::MarginBorderPaddingSize); | 202 LengthResolveType::MarginBorderPaddingSize); |
162 padding.block_end = | 203 padding.block_end = |
163 resolveInlineLength(constraintSpace, style.paddingAfter(), | 204 resolveInlineLength(constraintSpace, style.paddingAfter(), |
164 LengthResolveType::MarginBorderPaddingSize); | 205 LengthResolveType::MarginBorderPaddingSize); |
165 return padding; | 206 return padding; |
166 } | 207 } |
167 | 208 |
168 } // namespace blink | 209 } // namespace blink |
OLD | NEW |