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_block_layout_algorithm.h" | 5 #include "core/layout/ng/ng_block_layout_algorithm.h" |
6 | 6 |
7 #include "core/layout/ng/ng_absolute_utils.h" | 7 #include "core/layout/ng/ng_absolute_utils.h" |
8 #include "core/layout/ng/ng_block_break_token.h" | 8 #include "core/layout/ng/ng_block_break_token.h" |
9 #include "core/layout/ng/ng_block_child_iterator.h" | 9 #include "core/layout/ng/ng_block_child_iterator.h" |
10 #include "core/layout/ng/ng_box_fragment.h" | 10 #include "core/layout/ng/ng_box_fragment.h" |
11 #include "core/layout/ng/ng_constraint_space.h" | 11 #include "core/layout/ng/ng_constraint_space.h" |
12 #include "core/layout/ng/ng_constraint_space_builder.h" | 12 #include "core/layout/ng/ng_constraint_space_builder.h" |
13 #include "core/layout/ng/ng_fragment.h" | 13 #include "core/layout/ng/ng_fragment.h" |
14 #include "core/layout/ng/ng_fragment_builder.h" | 14 #include "core/layout/ng/ng_fragment_builder.h" |
15 #include "core/layout/ng/ng_inline_node.h" | 15 #include "core/layout/ng/ng_inline_node.h" |
16 #include "core/layout/ng/ng_layout_opportunity_iterator.h" | 16 #include "core/layout/ng/ng_layout_opportunity_iterator.h" |
17 #include "core/layout/ng/ng_length_utils.h" | 17 #include "core/layout/ng/ng_length_utils.h" |
18 #include "core/layout/ng/ng_line_builder.h" | 18 #include "core/layout/ng/ng_line_builder.h" |
19 #include "core/layout/ng/ng_out_of_flow_layout_part.h" | 19 #include "core/layout/ng/ng_out_of_flow_layout_part.h" |
| 20 #include "core/layout/ng/ng_units.h" |
20 #include "core/style/ComputedStyle.h" | 21 #include "core/style/ComputedStyle.h" |
21 #include "platform/LengthFunctions.h" | 22 #include "platform/LengthFunctions.h" |
22 #include "wtf/Optional.h" | 23 #include "wtf/Optional.h" |
23 | 24 |
24 namespace blink { | 25 namespace blink { |
25 namespace { | 26 namespace { |
26 | 27 |
27 // Whether child's constraint space should shrink to its intrinsic width. | 28 // Whether child's constraint space should shrink to its intrinsic width. |
28 // This is needed for buttons, select, input, floats and orthogonal children. | 29 // This is needed for buttons, select, input, floats and orthogonal children. |
29 // See LayoutBox::sizesLogicalWidthToFitContent for the rationale behind this. | 30 // See LayoutBox::sizesLogicalWidthToFitContent for the rationale behind this. |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( | 306 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( |
306 NGBlockNode* node, | 307 NGBlockNode* node, |
307 NGConstraintSpace* constraint_space, | 308 NGConstraintSpace* constraint_space, |
308 NGBlockBreakToken* break_token) | 309 NGBlockBreakToken* break_token) |
309 : node_(node), | 310 : node_(node), |
310 constraint_space_(constraint_space), | 311 constraint_space_(constraint_space), |
311 break_token_(break_token), | 312 break_token_(break_token), |
312 builder_(WTF::wrapUnique( | 313 builder_(WTF::wrapUnique( |
313 new NGFragmentBuilder(NGPhysicalFragment::kFragmentBox, node))) {} | 314 new NGFragmentBuilder(NGPhysicalFragment::kFragmentBox, node))) {} |
314 | 315 |
315 Optional<MinMaxContentSize> NGBlockLayoutAlgorithm::ComputeMinMaxContentSize() | 316 Optional<MinAndMaxContentSizes> |
316 const { | 317 NGBlockLayoutAlgorithm::ComputeMinAndMaxContentSizes() const { |
317 MinMaxContentSize sizes; | 318 MinAndMaxContentSizes sizes; |
318 | 319 |
319 // Size-contained elements don't consider their contents for intrinsic sizing. | 320 // Size-contained elements don't consider their contents for intrinsic sizing. |
320 if (Style().containsSize()) | 321 if (Style().containsSize()) |
321 return sizes; | 322 return sizes; |
322 | 323 |
323 // TODO: handle floats & orthogonal children. | 324 // TODO: handle floats & orthogonal children. |
324 for (NGLayoutInputNode* node = node_->FirstChild(); node; | 325 for (NGLayoutInputNode* node = node_->FirstChild(); node; |
325 node = node->NextSibling()) { | 326 node = node->NextSibling()) { |
326 MinMaxContentSize child_sizes; | 327 MinAndMaxContentSizes child_sizes; |
327 if (node->Type() == NGLayoutInputNode::kLegacyInline) { | 328 if (node->Type() == NGLayoutInputNode::kLegacyInline) { |
328 // From |NGBlockLayoutAlgorithm| perspective, we can handle |NGInlineNode| | 329 // From |NGBlockLayoutAlgorithm| perspective, we can handle |NGInlineNode| |
329 // almost the same as |NGBlockNode|, because an |NGInlineNode| includes | 330 // almost the same as |NGBlockNode|, because an |NGInlineNode| includes |
330 // all inline nodes following |node| and their descendants, and produces | 331 // all inline nodes following |node| and their descendants, and produces |
331 // an anonymous box that contains all line boxes. | 332 // an anonymous box that contains all line boxes. |
332 // |NextSibling| returns the next block sibling, or nullptr, skipping all | 333 // |NextSibling| returns the next block sibling, or nullptr, skipping all |
333 // following inline siblings and descendants. | 334 // following inline siblings and descendants. |
334 child_sizes = toNGInlineNode(node)->ComputeMinMaxContentSize(); | 335 child_sizes = toNGInlineNode(node)->ComputeMinAndMaxContentSizes(); |
335 } else { | 336 } else { |
336 Optional<MinMaxContentSize> child_minmax; | 337 Optional<MinAndMaxContentSizes> child_minmax; |
337 NGBlockNode* block_child = toNGBlockNode(node); | 338 NGBlockNode* block_child = toNGBlockNode(node); |
338 if (NeedMinMaxContentSizeForContentContribution(block_child->Style())) { | 339 if (NeedMinAndMaxContentSizesForContentContribution( |
339 child_minmax = block_child->ComputeMinMaxContentSize(); | 340 block_child->Style())) { |
| 341 child_minmax = block_child->ComputeMinAndMaxContentSizes(); |
340 } | 342 } |
341 | 343 |
342 child_sizes = ComputeMinAndMaxContentContribution(block_child->Style(), | 344 child_sizes = ComputeMinAndMaxContentContribution(block_child->Style(), |
343 child_minmax); | 345 child_minmax); |
344 } | 346 } |
345 | 347 |
346 sizes.min_content = std::max(sizes.min_content, child_sizes.min_content); | 348 sizes.min_content = std::max(sizes.min_content, child_sizes.min_content); |
347 sizes.max_content = std::max(sizes.max_content, child_sizes.max_content); | 349 sizes.max_content = std::max(sizes.max_content, child_sizes.max_content); |
348 } | 350 } |
349 | 351 |
(...skipping 19 matching lines...) Expand all Loading... |
369 NGLogicalOffset bfc_offset = offset; | 371 NGLogicalOffset bfc_offset = offset; |
370 if (ConstraintSpace().ClearanceOffset()) { | 372 if (ConstraintSpace().ClearanceOffset()) { |
371 bfc_offset.block_offset = std::max( | 373 bfc_offset.block_offset = std::max( |
372 ConstraintSpace().ClearanceOffset().value(), offset.block_offset); | 374 ConstraintSpace().ClearanceOffset().value(), offset.block_offset); |
373 } | 375 } |
374 builder_->SetBfcOffset(bfc_offset); | 376 builder_->SetBfcOffset(bfc_offset); |
375 } | 377 } |
376 } | 378 } |
377 | 379 |
378 RefPtr<NGLayoutResult> NGBlockLayoutAlgorithm::Layout() { | 380 RefPtr<NGLayoutResult> NGBlockLayoutAlgorithm::Layout() { |
379 WTF::Optional<MinMaxContentSize> sizes; | 381 WTF::Optional<MinAndMaxContentSizes> sizes; |
380 if (NeedMinMaxContentSize(ConstraintSpace(), Style())) | 382 if (NeedMinAndMaxContentSizes(ConstraintSpace(), Style())) |
381 sizes = ComputeMinMaxContentSize(); | 383 sizes = ComputeMinAndMaxContentSizes(); |
382 | 384 |
383 border_and_padding_ = ComputeBorders(ConstraintSpace(), Style()) + | 385 border_and_padding_ = ComputeBorders(ConstraintSpace(), Style()) + |
384 ComputePadding(ConstraintSpace(), Style()); | 386 ComputePadding(ConstraintSpace(), Style()); |
385 | 387 |
386 LayoutUnit inline_size = | 388 LayoutUnit inline_size = |
387 ComputeInlineSizeForFragment(ConstraintSpace(), Style(), sizes); | 389 ComputeInlineSizeForFragment(ConstraintSpace(), Style(), sizes); |
388 LayoutUnit adjusted_inline_size = | 390 LayoutUnit adjusted_inline_size = |
389 inline_size - border_and_padding_.InlineSum(); | 391 inline_size - border_and_padding_.InlineSum(); |
390 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of | 392 // TODO(layout-ng): For quirks mode, should we pass blockSize instead of |
391 // -1? | 393 // -1? |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 } | 660 } |
659 | 661 |
660 // The end of the block fits in the current fragmentainer. | 662 // The end of the block fits in the current fragmentainer. |
661 builder_->SetBlockSize(block_size); | 663 builder_->SetBlockSize(block_size); |
662 builder_->SetBlockOverflow(content_size_); | 664 builder_->SetBlockOverflow(content_size_); |
663 } | 665 } |
664 | 666 |
665 NGBoxStrut NGBlockLayoutAlgorithm::CalculateMargins( | 667 NGBoxStrut NGBlockLayoutAlgorithm::CalculateMargins( |
666 const NGConstraintSpace& space, | 668 const NGConstraintSpace& space, |
667 const ComputedStyle& style) { | 669 const ComputedStyle& style) { |
668 WTF::Optional<MinMaxContentSize> sizes; | 670 WTF::Optional<MinAndMaxContentSizes> sizes; |
669 if (NeedMinMaxContentSize(space, style)) { | 671 if (NeedMinAndMaxContentSizes(space, style)) { |
670 // TODO(ikilpatrick): Change ComputeMinMaxContentSize to return | 672 // TODO(ikilpatrick): Change ComputeMinAndMaxContentSizes to return |
671 // MinMaxContentSize. | 673 // MinAndMaxContentSizes. |
672 sizes = toNGBlockNode(current_child_)->ComputeMinMaxContentSize(); | 674 sizes = toNGBlockNode(current_child_)->ComputeMinAndMaxContentSizes(); |
673 } | 675 } |
674 LayoutUnit child_inline_size = | 676 LayoutUnit child_inline_size = |
675 ComputeInlineSizeForFragment(space, style, sizes); | 677 ComputeInlineSizeForFragment(space, style, sizes); |
676 NGBoxStrut margins = | 678 NGBoxStrut margins = |
677 ComputeMargins(space, style, space.WritingMode(), space.Direction()); | 679 ComputeMargins(space, style, space.WritingMode(), space.Direction()); |
678 if (!style.isFloating()) { | 680 if (!style.isFloating()) { |
679 ApplyAutoMargins(space, style, child_inline_size, &margins); | 681 ApplyAutoMargins(space, style, child_inline_size, &margins); |
680 } | 682 } |
681 return margins; | 683 return margins; |
682 } | 684 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 DCHECK(builder_->BfcOffset()); | 763 DCHECK(builder_->BfcOffset()); |
762 space_available -= curr_bfc_offset_.block_offset; | 764 space_available -= curr_bfc_offset_.block_offset; |
763 } | 765 } |
764 } | 766 } |
765 space_builder_->SetFragmentainerSpaceAvailable(space_available); | 767 space_builder_->SetFragmentainerSpaceAvailable(space_available); |
766 | 768 |
767 return space_builder_->ToConstraintSpace( | 769 return space_builder_->ToConstraintSpace( |
768 FromPlatformWritingMode(current_child_style.getWritingMode())); | 770 FromPlatformWritingMode(current_child_style.getWritingMode())); |
769 } | 771 } |
770 } // namespace blink | 772 } // namespace blink |
OLD | NEW |