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

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

Issue 2583063004: [layoutng] Add a function to compute the min- and max-content contribution (Closed)
Patch Set: include margins Created 4 years 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/layout/ng/ng_constraint_space_builder.h"
8 #include "core/layout/ng/ng_fragment_base.h" 9 #include "core/layout/ng/ng_fragment_base.h"
9 #include "core/style/ComputedStyle.h" 10 #include "core/style/ComputedStyle.h"
10 #include "platform/LayoutUnit.h" 11 #include "platform/LayoutUnit.h"
11 #include "platform/Length.h" 12 #include "platform/Length.h"
12 #include "wtf/Optional.h" 13 #include "wtf/Optional.h"
13 14
14 namespace blink { 15 namespace blink {
15 // TODO(layout-ng): 16 // TODO(layout-ng):
16 // - positioned and/or replaced calculations 17 // - positioned and/or replaced calculations
17 // - Take scrollbars into account 18 // - Take scrollbars into account
18 19
19 bool NeedMinAndMaxContentSizes(const ComputedStyle& style) { 20 bool NeedMinAndMaxContentSizes(const ComputedStyle& style) {
20 // TODO(layout-ng): In the future we may pass a shrink-to-fit flag through the 21 // TODO(layout-ng): In the future we may pass a shrink-to-fit flag through the
21 // constraint space; if so, this function needs to take a constraint space 22 // constraint space; if so, this function needs to take a constraint space
22 // as well to take that into account. 23 // as well to take that into account.
23 // This check is technically too broad (fill-available does not need intrinsic 24 // This check is technically too broad (fill-available does not need intrinsic
24 // size computation) but that's a rare case and only affects performance, not 25 // size computation) but that's a rare case and only affects performance, not
25 // correctness. 26 // correctness.
26 return style.logicalWidth().isIntrinsic() || 27 return style.logicalWidth().isIntrinsic() ||
27 style.logicalMinWidth().isIntrinsic() || 28 style.logicalMinWidth().isIntrinsic() ||
28 style.logicalMaxWidth().isIntrinsic(); 29 style.logicalMaxWidth().isIntrinsic();
29 } 30 }
30 31
32 bool NeedMinAndMaxContentSizesForContentContribution(
33 const ComputedStyle& style) {
34 return NeedMinAndMaxContentSizes(style) || style.logicalWidth().isAuto();
35 }
36
31 LayoutUnit ResolveInlineLength( 37 LayoutUnit ResolveInlineLength(
32 const NGConstraintSpace& constraint_space, 38 const NGConstraintSpace& constraint_space,
33 const ComputedStyle& style, 39 const ComputedStyle& style,
34 const WTF::Optional<MinAndMaxContentSizes>& min_and_max, 40 const WTF::Optional<MinAndMaxContentSizes>& min_and_max,
35 const Length& length, 41 const Length& length,
36 LengthResolveType type) { 42 LengthResolveType type) {
37 // TODO(layout-ng): Handle min/max/fit-content 43 // TODO(layout-ng): Handle min/max/fit-content
38 DCHECK(!length.isMaxSizeNone()); 44 DCHECK(!length.isMaxSizeNone());
39 DCHECK_GE(constraint_space.AvailableSize().inline_size, LayoutUnit()); 45 DCHECK_GE(constraint_space.AvailableSize().inline_size, LayoutUnit());
40 46
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 case DeviceHeight: 174 case DeviceHeight:
169 case ExtendToZoom: 175 case ExtendToZoom:
170 NOTREACHED() << "These should only be used for viewport definitions"; 176 NOTREACHED() << "These should only be used for viewport definitions";
171 case MaxSizeNone: 177 case MaxSizeNone:
172 default: 178 default:
173 NOTREACHED(); 179 NOTREACHED();
174 return border_and_padding.BlockSum(); 180 return border_and_padding.BlockSum();
175 } 181 }
176 } 182 }
177 183
184 MinAndMaxContentSizes ComputeMinAndMaxContentContribution(
185 const ComputedStyle& style,
186 const WTF::Optional<MinAndMaxContentSizes>& min_and_max) {
187 // Synthesize a zero-sized constraint space for passing to
188 // ResolveInlineLength.
189 NGWritingMode writing_mode = FromPlatformWritingMode(style.getWritingMode());
190 NGConstraintSpaceBuilder builder(writing_mode);
191 NGConstraintSpace* space = builder.ToConstraintSpace();
192
193 MinAndMaxContentSizes computed_sizes;
194 Length inline_size = style.logicalWidth();
195 if (inline_size.isAuto()) {
196 CHECK(min_and_max.has_value());
197 NGBoxStrut border_and_padding =
198 ComputeBorders(style) + ComputePadding(*space, style);
199 computed_sizes.min_content =
200 min_and_max->min_content + border_and_padding.InlineSum();
201 computed_sizes.max_content =
202 min_and_max->max_content + border_and_padding.InlineSum();
203 } else {
204 computed_sizes.min_content = computed_sizes.max_content =
205 ResolveInlineLength(*space, style, min_and_max, inline_size,
206 LengthResolveType::kContentSize);
207 }
208
209 Length max_length = style.logicalMaxWidth();
210 if (!max_length.isMaxSizeNone()) {
211 LayoutUnit max = ResolveInlineLength(*space, style, min_and_max, max_length,
212 LengthResolveType::kMaxSize);
213 computed_sizes.min_content = std::min(computed_sizes.min_content, max);
214 computed_sizes.max_content = std::min(computed_sizes.max_content, max);
215 }
216
217 LayoutUnit min =
218 ResolveInlineLength(*space, style, min_and_max, style.logicalMinWidth(),
219 LengthResolveType::kMinSize);
220 computed_sizes.min_content = std::max(computed_sizes.min_content, min);
221 computed_sizes.max_content = std::max(computed_sizes.max_content, min);
222
223 NGBoxStrut margins =
224 ComputeMargins(*space, style, writing_mode, style.direction());
225 computed_sizes.min_content += margins.InlineSum();
226 computed_sizes.max_content += margins.InlineSum();
227 return computed_sizes;
228 }
229
178 LayoutUnit ComputeInlineSizeForFragment( 230 LayoutUnit ComputeInlineSizeForFragment(
179 const NGConstraintSpace& space, 231 const NGConstraintSpace& space,
180 const ComputedStyle& style, 232 const ComputedStyle& style,
181 const WTF::Optional<MinAndMaxContentSizes>& min_and_max) { 233 const WTF::Optional<MinAndMaxContentSizes>& min_and_max) {
182 if (space.IsFixedSizeInline()) 234 if (space.IsFixedSizeInline())
183 return space.AvailableSize().inline_size; 235 return space.AvailableSize().inline_size;
184 236
185 LayoutUnit extent = 237 LayoutUnit extent =
186 ResolveInlineLength(space, style, min_and_max, style.logicalWidth(), 238 ResolveInlineLength(space, style, min_and_max, style.logicalWidth(),
187 LengthResolveType::kContentSize); 239 LengthResolveType::kContentSize);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 margins->inline_start = available_space / 2; 398 margins->inline_start = available_space / 2;
347 margins->inline_end = available_space - margins->inline_start; 399 margins->inline_end = available_space - margins->inline_start;
348 } else if (style.marginStart().isAuto()) { 400 } else if (style.marginStart().isAuto()) {
349 margins->inline_start = available_space; 401 margins->inline_start = available_space;
350 } else if (style.marginEnd().isAuto()) { 402 } else if (style.marginEnd().isAuto()) {
351 margins->inline_end = available_space; 403 margins->inline_end = available_space;
352 } 404 }
353 } 405 }
354 406
355 } // namespace blink 407 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698