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_box_fragment.h" | 9 #include "core/layout/ng/ng_box_fragment.h" |
10 #include "core/layout/ng/ng_column_mapper.h" | 10 #include "core/layout/ng/ng_column_mapper.h" |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 | 293 |
294 if (space.WritingMode() != FromPlatformWritingMode(style.getWritingMode())) | 294 if (space.WritingMode() != FromPlatformWritingMode(style.getWritingMode())) |
295 return true; | 295 return true; |
296 | 296 |
297 return false; | 297 return false; |
298 } | 298 } |
299 | 299 |
300 } // namespace | 300 } // namespace |
301 | 301 |
302 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( | 302 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm( |
303 LayoutObject* layout_object, | 303 NGBlockNode* node, |
304 PassRefPtr<const ComputedStyle> style, | |
305 NGLayoutInputNode* first_child, | |
306 NGConstraintSpace* constraint_space, | 304 NGConstraintSpace* constraint_space, |
307 NGBreakToken* break_token) | 305 NGBreakToken* break_token) |
308 : style_(style), | 306 : node_(node), |
309 first_child_(first_child), | |
310 constraint_space_(constraint_space), | 307 constraint_space_(constraint_space), |
311 break_token_(break_token), | 308 break_token_(break_token), |
312 builder_(WTF::wrapUnique( | 309 builder_(WTF::wrapUnique( |
313 new NGFragmentBuilder(NGPhysicalFragment::kFragmentBox, | 310 new NGFragmentBuilder(NGPhysicalFragment::kFragmentBox, node))) {} |
314 layout_object))) { | |
315 DCHECK(style_); | |
316 } | |
317 | 311 |
318 Optional<MinAndMaxContentSizes> | 312 Optional<MinAndMaxContentSizes> |
319 NGBlockLayoutAlgorithm::ComputeMinAndMaxContentSizes() const { | 313 NGBlockLayoutAlgorithm::ComputeMinAndMaxContentSizes() const { |
320 MinAndMaxContentSizes sizes; | 314 MinAndMaxContentSizes sizes; |
321 | 315 |
322 // Size-contained elements don't consider their contents for intrinsic sizing. | 316 // Size-contained elements don't consider their contents for intrinsic sizing. |
323 if (Style().containsSize()) | 317 if (Style().containsSize()) |
324 return sizes; | 318 return sizes; |
325 | 319 |
326 // TODO: handle floats & orthogonal children. | 320 // TODO: handle floats & orthogonal children. |
327 for (NGLayoutInputNode* node = first_child_; node; | 321 for (NGLayoutInputNode* node = node_->FirstChild(); node; |
328 node = node->NextSibling()) { | 322 node = node->NextSibling()) { |
329 Optional<MinAndMaxContentSizes> child_minmax; | 323 Optional<MinAndMaxContentSizes> child_minmax; |
330 if (node->Type() == NGLayoutInputNode::kLegacyInline) { | 324 if (node->Type() == NGLayoutInputNode::kLegacyInline) { |
331 // TODO(kojii): Implement when there are inline children. | 325 // TODO(kojii): Implement when there are inline children. |
332 return child_minmax; | 326 return child_minmax; |
333 } | 327 } |
334 NGBlockNode* block_child = toNGBlockNode(node); | 328 NGBlockNode* block_child = toNGBlockNode(node); |
335 if (NeedMinAndMaxContentSizesForContentContribution(block_child->Style())) { | 329 if (NeedMinAndMaxContentSizesForContentContribution(block_child->Style())) { |
336 child_minmax = block_child->ComputeMinAndMaxContentSizes(); | 330 child_minmax = block_child->ComputeMinAndMaxContentSizes(); |
337 } | 331 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); | 396 builder_->SetInlineSize(inline_size).SetBlockSize(block_size); |
403 | 397 |
404 // TODO(glebl): fix multicol after the new margin collapsing/floats algorithm | 398 // TODO(glebl): fix multicol after the new margin collapsing/floats algorithm |
405 // based on BFCOffset is checked in. | 399 // based on BFCOffset is checked in. |
406 if (NGBlockBreakToken* token = CurrentBlockBreakToken()) { | 400 if (NGBlockBreakToken* token = CurrentBlockBreakToken()) { |
407 // Resume after a previous break. | 401 // Resume after a previous break. |
408 content_size_ = token->BreakOffset(); | 402 content_size_ = token->BreakOffset(); |
409 current_child_ = token->InputNode(); | 403 current_child_ = token->InputNode(); |
410 } else { | 404 } else { |
411 content_size_ = border_and_padding_.block_start; | 405 content_size_ = border_and_padding_.block_start; |
412 current_child_ = first_child_; | 406 current_child_ = node_->FirstChild(); |
413 } | 407 } |
414 | 408 |
415 curr_margin_strut_ = ConstraintSpace().MarginStrut(); | 409 curr_margin_strut_ = ConstraintSpace().MarginStrut(); |
416 curr_bfc_offset_ = ConstraintSpace().BfcOffset(); | 410 curr_bfc_offset_ = ConstraintSpace().BfcOffset(); |
417 | 411 |
418 // Margins collapsing: | 412 // Margins collapsing: |
419 // Do not collapse margins between parent and its child if there is | 413 // Do not collapse margins between parent and its child if there is |
420 // border/padding between them. | 414 // border/padding between them. |
421 if (border_and_padding_.block_start || | 415 if (border_and_padding_.block_start || |
422 ConstraintSpace().IsNewFormattingContext()) { | 416 ConstraintSpace().IsNewFormattingContext()) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 } | 495 } |
502 | 496 |
503 void NGBlockLayoutAlgorithm::LayoutInlineChildren(NGInlineNode* current_child) { | 497 void NGBlockLayoutAlgorithm::LayoutInlineChildren(NGInlineNode* current_child) { |
504 // TODO(kojii): This logic does not handle when children are mix of | 498 // TODO(kojii): This logic does not handle when children are mix of |
505 // inline/block. We need to detect the case and setup appropriately; e.g., | 499 // inline/block. We need to detect the case and setup appropriately; e.g., |
506 // constraint space, margin collapsing, next siblings, etc. | 500 // constraint space, margin collapsing, next siblings, etc. |
507 NGLineBuilder line_builder(current_child, space_for_current_child_); | 501 NGLineBuilder line_builder(current_child, space_for_current_child_); |
508 current_child->LayoutInline(space_for_current_child_, &line_builder); | 502 current_child->LayoutInline(space_for_current_child_, &line_builder); |
509 // TODO(kojii): The wrapper fragment should not be needed. | 503 // TODO(kojii): The wrapper fragment should not be needed. |
510 NGFragmentBuilder wrapper_fragment_builder(NGPhysicalFragment::kFragmentBox, | 504 NGFragmentBuilder wrapper_fragment_builder(NGPhysicalFragment::kFragmentBox, |
511 current_child->GetLayoutObject()); | 505 current_child); |
512 line_builder.CreateFragments(&wrapper_fragment_builder); | 506 line_builder.CreateFragments(&wrapper_fragment_builder); |
513 RefPtr<NGPhysicalBoxFragment> child_fragment = | 507 RefPtr<NGPhysicalBoxFragment> child_fragment = |
514 wrapper_fragment_builder.ToBoxFragment(); | 508 wrapper_fragment_builder.ToBoxFragment(); |
515 line_builder.CopyFragmentDataToLayoutBlockFlow(); | 509 line_builder.CopyFragmentDataToLayoutBlockFlow(); |
516 FinishCurrentChildLayout(child_fragment.get()); | 510 FinishCurrentChildLayout(child_fragment.get()); |
517 current_child_ = nullptr; | 511 current_child_ = nullptr; |
518 } | 512 } |
519 | 513 |
520 void NGBlockLayoutAlgorithm::FinishCurrentChildLayout( | 514 void NGBlockLayoutAlgorithm::FinishCurrentChildLayout( |
521 RefPtr<NGPhysicalBoxFragment> physical_fragment) { | 515 RefPtr<NGPhysicalBoxFragment> physical_fragment) { |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 curr_bfc_offset_.inline_offset += curr_child_margins_.inline_start; | 807 curr_bfc_offset_.inline_offset += curr_child_margins_.inline_start; |
814 } | 808 } |
815 | 809 |
816 space_builder_->SetBfcOffset(curr_bfc_offset_); | 810 space_builder_->SetBfcOffset(curr_bfc_offset_); |
817 | 811 |
818 return space_builder_->ToConstraintSpace( | 812 return space_builder_->ToConstraintSpace( |
819 FromPlatformWritingMode(current_child_style.getWritingMode())); | 813 FromPlatformWritingMode(current_child_style.getWritingMode())); |
820 } | 814 } |
821 | 815 |
822 } // namespace blink | 816 } // namespace blink |
OLD | NEW |