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