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_constraint_space_builder.h" | 8 #include "core/layout/ng/ng_constraint_space_builder.h" |
9 #include "core/layout/ng/ng_fragment.h" | 9 #include "core/layout/ng/ng_fragment.h" |
10 #include "core/style/ComputedStyle.h" | 10 #include "core/style/ComputedStyle.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 if (type == LengthResolveType::kMinSize && length.isAuto()) | 49 if (type == LengthResolveType::kMinSize && length.isAuto()) |
50 return LayoutUnit(); | 50 return LayoutUnit(); |
51 | 51 |
52 if (type == LengthResolveType::kMarginBorderPaddingSize && length.isAuto()) | 52 if (type == LengthResolveType::kMarginBorderPaddingSize && length.isAuto()) |
53 return LayoutUnit(); | 53 return LayoutUnit(); |
54 | 54 |
55 // We don't need this when we're resolving margin/border/padding; skip | 55 // We don't need this when we're resolving margin/border/padding; skip |
56 // computing it as an optimization and to simplify the code below. | 56 // computing it as an optimization and to simplify the code below. |
57 NGBoxStrut border_and_padding; | 57 NGBoxStrut border_and_padding; |
58 if (type != LengthResolveType::kMarginBorderPaddingSize) { | 58 if (type != LengthResolveType::kMarginBorderPaddingSize) { |
59 border_and_padding = | 59 border_and_padding = ComputeBorders(constraint_space, style) + |
60 ComputeBorders(style) + ComputePadding(constraint_space, style); | 60 ComputePadding(constraint_space, style); |
61 } | 61 } |
62 switch (length.type()) { | 62 switch (length.type()) { |
63 case Auto: | 63 case Auto: |
64 case FillAvailable: { | 64 case FillAvailable: { |
65 LayoutUnit content_size = constraint_space.AvailableSize().inline_size; | 65 LayoutUnit content_size = constraint_space.AvailableSize().inline_size; |
66 NGBoxStrut margins = ComputeMargins( | 66 NGBoxStrut margins = ComputeMargins( |
67 constraint_space, style, | 67 constraint_space, style, |
68 FromPlatformWritingMode(style.getWritingMode()), style.direction()); | 68 FromPlatformWritingMode(style.getWritingMode()), style.direction()); |
69 return std::max(border_and_padding.InlineSum(), | 69 return std::max(border_and_padding.InlineSum(), |
70 content_size - margins.InlineSum()); | 70 content_size - margins.InlineSum()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // a random negative number. | 131 // a random negative number. |
132 if (length.isPercentOrCalc() && | 132 if (length.isPercentOrCalc() && |
133 constraint_space.PercentageResolutionSize().block_size == | 133 constraint_space.PercentageResolutionSize().block_size == |
134 NGSizeIndefinite) | 134 NGSizeIndefinite) |
135 return content_size; | 135 return content_size; |
136 | 136 |
137 // We don't need this when we're resolving margin/border/padding; skip | 137 // We don't need this when we're resolving margin/border/padding; skip |
138 // computing it as an optimization and to simplify the code below. | 138 // computing it as an optimization and to simplify the code below. |
139 NGBoxStrut border_and_padding; | 139 NGBoxStrut border_and_padding; |
140 if (type != LengthResolveType::kMarginBorderPaddingSize) { | 140 if (type != LengthResolveType::kMarginBorderPaddingSize) { |
141 border_and_padding = | 141 border_and_padding = ComputeBorders(constraint_space, style) + |
142 ComputeBorders(style) + ComputePadding(constraint_space, style); | 142 ComputePadding(constraint_space, style); |
143 } | 143 } |
144 switch (length.type()) { | 144 switch (length.type()) { |
145 case FillAvailable: { | 145 case FillAvailable: { |
146 LayoutUnit content_size = constraint_space.AvailableSize().block_size; | 146 LayoutUnit content_size = constraint_space.AvailableSize().block_size; |
147 NGBoxStrut margins = ComputeMargins( | 147 NGBoxStrut margins = ComputeMargins( |
148 constraint_space, style, | 148 constraint_space, style, |
149 FromPlatformWritingMode(style.getWritingMode()), style.direction()); | 149 FromPlatformWritingMode(style.getWritingMode()), style.direction()); |
150 return std::max(border_and_padding.BlockSum(), | 150 return std::max(border_and_padding.BlockSum(), |
151 content_size - margins.BlockSum()); | 151 content_size - margins.BlockSum()); |
152 } | 152 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 NGConstraintSpaceBuilder builder(writing_mode); | 192 NGConstraintSpaceBuilder builder(writing_mode); |
193 builder.SetInitialContainingBlockSize( | 193 builder.SetInitialContainingBlockSize( |
194 NGPhysicalSize{LayoutUnit(), LayoutUnit()}); | 194 NGPhysicalSize{LayoutUnit(), LayoutUnit()}); |
195 NGConstraintSpace* space = builder.ToConstraintSpace(writing_mode); | 195 NGConstraintSpace* space = builder.ToConstraintSpace(writing_mode); |
196 | 196 |
197 MinAndMaxContentSizes computed_sizes; | 197 MinAndMaxContentSizes computed_sizes; |
198 Length inline_size = style.logicalWidth(); | 198 Length inline_size = style.logicalWidth(); |
199 if (inline_size.isAuto()) { | 199 if (inline_size.isAuto()) { |
200 CHECK(min_and_max.has_value()); | 200 CHECK(min_and_max.has_value()); |
201 NGBoxStrut border_and_padding = | 201 NGBoxStrut border_and_padding = |
202 ComputeBorders(style) + ComputePadding(*space, style); | 202 ComputeBorders(*space, style) + ComputePadding(*space, style); |
203 computed_sizes.min_content = | 203 computed_sizes.min_content = |
204 min_and_max->min_content + border_and_padding.InlineSum(); | 204 min_and_max->min_content + border_and_padding.InlineSum(); |
205 computed_sizes.max_content = | 205 computed_sizes.max_content = |
206 min_and_max->max_content + border_and_padding.InlineSum(); | 206 min_and_max->max_content + border_and_padding.InlineSum(); |
207 } else { | 207 } else { |
208 computed_sizes.min_content = computed_sizes.max_content = | 208 computed_sizes.min_content = computed_sizes.max_content = |
209 ResolveInlineLength(*space, style, min_and_max, inline_size, | 209 ResolveInlineLength(*space, style, min_and_max, inline_size, |
210 LengthResolveType::kContentSize); | 210 LengthResolveType::kContentSize); |
211 } | 211 } |
212 | 212 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 LengthResolveType::kMarginBorderPaddingSize); | 347 LengthResolveType::kMarginBorderPaddingSize); |
348 physical_dim.top = ResolveInlineLength( | 348 physical_dim.top = ResolveInlineLength( |
349 constraint_space, style, empty_sizes, style.marginTop(), | 349 constraint_space, style, empty_sizes, style.marginTop(), |
350 LengthResolveType::kMarginBorderPaddingSize); | 350 LengthResolveType::kMarginBorderPaddingSize); |
351 physical_dim.bottom = ResolveInlineLength( | 351 physical_dim.bottom = ResolveInlineLength( |
352 constraint_space, style, empty_sizes, style.marginBottom(), | 352 constraint_space, style, empty_sizes, style.marginBottom(), |
353 LengthResolveType::kMarginBorderPaddingSize); | 353 LengthResolveType::kMarginBorderPaddingSize); |
354 return physical_dim.ConvertToLogical(writing_mode, direction); | 354 return physical_dim.ConvertToLogical(writing_mode, direction); |
355 } | 355 } |
356 | 356 |
357 NGBoxStrut ComputeBorders(const ComputedStyle& style) { | 357 NGBoxStrut ComputeBorders(const NGConstraintSpace& constraint_space, |
| 358 const ComputedStyle& style) { |
| 359 // If we are producing an anonymous fragment (e.g. a column) we shouldn't |
| 360 // have any borders. |
| 361 if (constraint_space.IsAnonymous()) |
| 362 return NGBoxStrut(); |
| 363 |
358 NGBoxStrut borders; | 364 NGBoxStrut borders; |
359 borders.inline_start = LayoutUnit(style.borderStartWidth()); | 365 borders.inline_start = LayoutUnit(style.borderStartWidth()); |
360 borders.inline_end = LayoutUnit(style.borderEndWidth()); | 366 borders.inline_end = LayoutUnit(style.borderEndWidth()); |
361 borders.block_start = LayoutUnit(style.borderBeforeWidth()); | 367 borders.block_start = LayoutUnit(style.borderBeforeWidth()); |
362 borders.block_end = LayoutUnit(style.borderAfterWidth()); | 368 borders.block_end = LayoutUnit(style.borderAfterWidth()); |
363 return borders; | 369 return borders; |
364 } | 370 } |
365 | 371 |
366 NGBoxStrut ComputePadding(const NGConstraintSpace& constraint_space, | 372 NGBoxStrut ComputePadding(const NGConstraintSpace& constraint_space, |
367 const ComputedStyle& style) { | 373 const ComputedStyle& style) { |
| 374 // If we are producing an anonymous fragment (e.g. a column) we shouldn't |
| 375 // have any padding. |
| 376 if (constraint_space.IsAnonymous()) |
| 377 return NGBoxStrut(); |
| 378 |
368 // We don't need these for padding computations | 379 // We don't need these for padding computations |
369 MinAndMaxContentSizes empty_sizes; | 380 MinAndMaxContentSizes empty_sizes; |
370 // Padding always gets computed relative to the inline size: | 381 // Padding always gets computed relative to the inline size: |
371 // https://www.w3.org/TR/CSS2/box.html#value-def-padding-width | 382 // https://www.w3.org/TR/CSS2/box.html#value-def-padding-width |
372 NGBoxStrut padding; | 383 NGBoxStrut padding; |
373 padding.inline_start = ResolveInlineLength( | 384 padding.inline_start = ResolveInlineLength( |
374 constraint_space, style, empty_sizes, style.paddingStart(), | 385 constraint_space, style, empty_sizes, style.paddingStart(), |
375 LengthResolveType::kMarginBorderPaddingSize); | 386 LengthResolveType::kMarginBorderPaddingSize); |
376 padding.inline_end = ResolveInlineLength( | 387 padding.inline_end = ResolveInlineLength( |
377 constraint_space, style, empty_sizes, style.paddingEnd(), | 388 constraint_space, style, empty_sizes, style.paddingEnd(), |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 Optional<LayoutUnit> min, | 420 Optional<LayoutUnit> min, |
410 Optional<LayoutUnit> max) { | 421 Optional<LayoutUnit> max) { |
411 if (max && length > max.value()) | 422 if (max && length > max.value()) |
412 length = max.value(); | 423 length = max.value(); |
413 if (min && length < min.value()) | 424 if (min && length < min.value()) |
414 length = min.value(); | 425 length = min.value(); |
415 return length; | 426 return length; |
416 } | 427 } |
417 | 428 |
418 } // namespace blink | 429 } // namespace blink |
OLD | NEW |