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" | |
9 #include "core/layout/ng/ng_block_child_iterator.h" | 8 #include "core/layout/ng/ng_block_child_iterator.h" |
10 #include "core/layout/ng/ng_box_fragment.h" | 9 #include "core/layout/ng/ng_box_fragment.h" |
11 #include "core/layout/ng/ng_constraint_space.h" | 10 #include "core/layout/ng/ng_constraint_space.h" |
12 #include "core/layout/ng/ng_constraint_space_builder.h" | 11 #include "core/layout/ng/ng_constraint_space_builder.h" |
13 #include "core/layout/ng/ng_floats_utils.h" | 12 #include "core/layout/ng/ng_floats_utils.h" |
14 #include "core/layout/ng/ng_fragment.h" | 13 #include "core/layout/ng/ng_fragment.h" |
15 #include "core/layout/ng/ng_fragment_builder.h" | 14 #include "core/layout/ng/ng_fragment_builder.h" |
16 #include "core/layout/ng/ng_inline_node.h" | 15 #include "core/layout/ng/ng_inline_node.h" |
17 #include "core/layout/ng/ng_layout_opportunity_iterator.h" | 16 #include "core/layout/ng/ng_layout_opportunity_iterator.h" |
18 #include "core/layout/ng/ng_length_utils.h" | 17 #include "core/layout/ng/ng_length_utils.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 51 |
53 // Whether we've run out of space in this flow. If so, there will be no work | 52 // Whether we've run out of space in this flow. If so, there will be no work |
54 // left to do for this block in this fragmentainer. | 53 // left to do for this block in this fragmentainer. |
55 bool IsOutOfSpace(const NGConstraintSpace& space, LayoutUnit content_size) { | 54 bool IsOutOfSpace(const NGConstraintSpace& space, LayoutUnit content_size) { |
56 return space.HasBlockFragmentation() && | 55 return space.HasBlockFragmentation() && |
57 content_size >= space.FragmentainerSpaceAvailable(); | 56 content_size >= space.FragmentainerSpaceAvailable(); |
58 } | 57 } |
59 | 58 |
60 } // namespace | 59 } // namespace |
61 | 60 |
62 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( | 61 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm(NGBlockNode* node, |
63 NGBlockNode* node, | 62 NGConstraintSpace* space, |
64 NGConstraintSpace* constraint_space, | 63 NGBlockBreakToken* break_token) |
65 NGBlockBreakToken* break_token) | 64 : NGLayoutAlgorithm(node, space, break_token), |
66 : node_(node), | |
67 constraint_space_(constraint_space), | |
68 break_token_(break_token), | |
69 builder_(NGPhysicalFragment::kFragmentBox, node), | 65 builder_(NGPhysicalFragment::kFragmentBox, node), |
70 space_builder_(constraint_space_) {} | 66 space_builder_(constraint_space_) {} |
71 | 67 |
72 Optional<MinMaxContentSize> NGBlockLayoutAlgorithm::ComputeMinMaxContentSize() | 68 Optional<MinMaxContentSize> NGBlockLayoutAlgorithm::ComputeMinMaxContentSize() |
73 const { | 69 const { |
74 MinMaxContentSize sizes; | 70 MinMaxContentSize sizes; |
75 | 71 |
76 // Size-contained elements don't consider their contents for intrinsic sizing. | 72 // Size-contained elements don't consider their contents for intrinsic sizing. |
77 if (Style().containsSize()) | 73 if (Style().containsSize()) |
78 return sizes; | 74 return sizes; |
79 | 75 |
80 // TODO: handle floats & orthogonal children. | 76 // TODO: handle floats & orthogonal children. |
81 for (NGLayoutInputNode* node = node_->FirstChild(); node; | 77 for (NGLayoutInputNode* node = Node()->FirstChild(); node; |
82 node = node->NextSibling()) { | 78 node = node->NextSibling()) { |
83 MinMaxContentSize child_sizes; | 79 MinMaxContentSize child_sizes; |
84 if (node->Type() == NGLayoutInputNode::kLegacyInline) { | 80 if (node->Type() == NGLayoutInputNode::kLegacyInline) { |
85 // From |NGBlockLayoutAlgorithm| perspective, we can handle |NGInlineNode| | 81 // From |NGBlockLayoutAlgorithm| perspective, we can handle |NGInlineNode| |
86 // almost the same as |NGBlockNode|, because an |NGInlineNode| includes | 82 // almost the same as |NGBlockNode|, because an |NGInlineNode| includes |
87 // all inline nodes following |node| and their descendants, and produces | 83 // all inline nodes following |node| and their descendants, and produces |
88 // an anonymous box that contains all line boxes. | 84 // an anonymous box that contains all line boxes. |
89 // |NextSibling| returns the next block sibling, or nullptr, skipping all | 85 // |NextSibling| returns the next block sibling, or nullptr, skipping all |
90 // following inline siblings and descendants. | 86 // following inline siblings and descendants. |
91 child_sizes = toNGInlineNode(node)->ComputeMinMaxContentSize(); | 87 child_sizes = toNGInlineNode(node)->ComputeMinMaxContentSize(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 space_builder_ | 154 space_builder_ |
159 .SetAvailableSize( | 155 .SetAvailableSize( |
160 NGLogicalSize(adjusted_inline_size, adjusted_block_size)) | 156 NGLogicalSize(adjusted_inline_size, adjusted_block_size)) |
161 .SetPercentageResolutionSize( | 157 .SetPercentageResolutionSize( |
162 NGLogicalSize(adjusted_inline_size, adjusted_block_size)); | 158 NGLogicalSize(adjusted_inline_size, adjusted_block_size)); |
163 | 159 |
164 builder_.SetDirection(constraint_space_->Direction()); | 160 builder_.SetDirection(constraint_space_->Direction()); |
165 builder_.SetWritingMode(constraint_space_->WritingMode()); | 161 builder_.SetWritingMode(constraint_space_->WritingMode()); |
166 builder_.SetInlineSize(inline_size).SetBlockSize(block_size); | 162 builder_.SetInlineSize(inline_size).SetBlockSize(block_size); |
167 | 163 |
168 NGBlockChildIterator child_iterator(node_->FirstChild(), break_token_); | 164 NGBlockChildIterator child_iterator(Node()->FirstChild(), BreakToken()); |
169 NGBlockChildIterator::Entry entry = child_iterator.NextChild(); | 165 NGBlockChildIterator::Entry entry = child_iterator.NextChild(); |
170 NGLayoutInputNode* child = entry.node; | 166 NGLayoutInputNode* child = entry.node; |
171 NGBreakToken* child_break_token = entry.token; | 167 NGBreakToken* child_break_token = entry.token; |
172 | 168 |
173 // If we are resuming from a break token our start border and padding is | 169 // If we are resuming from a break token our start border and padding is |
174 // within a previous fragment. | 170 // within a previous fragment. |
175 content_size_ = break_token_ ? LayoutUnit() : border_and_padding_.block_start; | 171 content_size_ = BreakToken() ? LayoutUnit() : border_and_padding_.block_start; |
176 | 172 |
177 curr_margin_strut_ = ConstraintSpace().MarginStrut(); | 173 curr_margin_strut_ = ConstraintSpace().MarginStrut(); |
178 curr_bfc_offset_ = ConstraintSpace().BfcOffset(); | 174 curr_bfc_offset_ = ConstraintSpace().BfcOffset(); |
179 | 175 |
180 // Margins collapsing: | 176 // Margins collapsing: |
181 // Do not collapse margins between parent and its child if there is | 177 // Do not collapse margins between parent and its child if there is |
182 // border/padding between them. | 178 // border/padding between them. |
183 if (border_and_padding_.block_start) { | 179 if (border_and_padding_.block_start) { |
184 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); | 180 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); |
185 UpdateFragmentBfcOffset(curr_bfc_offset_); | 181 UpdateFragmentBfcOffset(curr_bfc_offset_); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 max_inline_size_ = | 404 max_inline_size_ = |
409 std::max(max_inline_size_, fragment.InlineSize() + | 405 std::max(max_inline_size_, fragment.InlineSize() + |
410 curr_child_margins_.InlineSum() + | 406 curr_child_margins_.InlineSum() + |
411 border_and_padding_.InlineSum()); | 407 border_and_padding_.InlineSum()); |
412 | 408 |
413 builder_.AddChild(layout_result, logical_offset); | 409 builder_.AddChild(layout_result, logical_offset); |
414 } | 410 } |
415 | 411 |
416 void NGBlockLayoutAlgorithm::FinalizeForFragmentation() { | 412 void NGBlockLayoutAlgorithm::FinalizeForFragmentation() { |
417 LayoutUnit used_block_size = | 413 LayoutUnit used_block_size = |
418 break_token_ ? break_token_->UsedBlockSize() : LayoutUnit(); | 414 BreakToken() ? BreakToken()->UsedBlockSize() : LayoutUnit(); |
419 LayoutUnit block_size = ComputeBlockSizeForFragment( | 415 LayoutUnit block_size = ComputeBlockSizeForFragment( |
420 ConstraintSpace(), Style(), used_block_size + content_size_); | 416 ConstraintSpace(), Style(), used_block_size + content_size_); |
421 | 417 |
422 block_size -= used_block_size; | 418 block_size -= used_block_size; |
423 DCHECK_GE(block_size, LayoutUnit()) | 419 DCHECK_GE(block_size, LayoutUnit()) |
424 << "Adding and subtracting the used_block_size shouldn't leave the " | 420 << "Adding and subtracting the used_block_size shouldn't leave the " |
425 "block_size for this fragment smaller than zero."; | 421 "block_size for this fragment smaller than zero."; |
426 | 422 |
427 DCHECK(builder_.BfcOffset()) << "We must have our BfcOffset by this point " | 423 DCHECK(builder_.BfcOffset()) << "We must have our BfcOffset by this point " |
428 "to determine the space left in the flow."; | 424 "to determine the space left in the flow."; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 // started handling the fragmentation for floats. | 511 // started handling the fragmentation for floats. |
516 space_builder_.SetBfcOffset(NGLogicalOffset()); | 512 space_builder_.SetBfcOffset(NGLogicalOffset()); |
517 } | 513 } |
518 } | 514 } |
519 space_builder_.SetFragmentainerSpaceAvailable(space_available); | 515 space_builder_.SetFragmentainerSpaceAvailable(space_available); |
520 | 516 |
521 return space_builder_.ToConstraintSpace( | 517 return space_builder_.ToConstraintSpace( |
522 FromPlatformWritingMode(child_style.getWritingMode())); | 518 FromPlatformWritingMode(child_style.getWritingMode())); |
523 } | 519 } |
524 } // namespace blink | 520 } // namespace blink |
OLD | NEW |