Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/ng_block_layout_algorithm.cc

Issue 2850893003: Add container_block_offset,top_offset to NGFloatingObject. (Closed)
Patch Set: add-inline-to-block-flow-with-block-children-that-do-not-need-anonymous-boxes.html is still broken Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/inline/ng_inline_node.h" 7 #include "core/layout/ng/inline/ng_inline_node.h"
8 #include "core/layout/ng/ng_absolute_utils.h" 8 #include "core/layout/ng/ng_absolute_utils.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_constraint_space.h" 10 #include "core/layout/ng/ng_constraint_space.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 const NGLogicalOffset& offset, 80 const NGLogicalOffset& offset,
81 NGFragmentBuilder* builder) { 81 NGFragmentBuilder* builder) {
82 DCHECK(builder); 82 DCHECK(builder);
83 if (!builder->BfcOffset()) { 83 if (!builder->BfcOffset()) {
84 NGLogicalOffset mutable_offset(offset); 84 NGLogicalOffset mutable_offset(offset);
85 AdjustToClearance(space.ClearanceOffset(), &mutable_offset); 85 AdjustToClearance(space.ClearanceOffset(), &mutable_offset);
86 builder->SetBfcOffset(mutable_offset); 86 builder->SetBfcOffset(mutable_offset);
87 } 87 }
88 } 88 }
89 89
90 void PositionPendingFloatsFromOffset(LayoutUnit origin_block_offset,
91 LayoutUnit from_block_offset,
92 NGFragmentBuilder* container_builder,
93 NGConstraintSpace* space) {
94 DCHECK(container_builder->BfcOffset())
95 << "Parent BFC offset should be known here";
96 const auto& floating_objects = container_builder->UnpositionedFloats();
97 container_builder->MutablePositionedFloats().AppendVector(
98 PositionFloats(origin_block_offset, from_block_offset,
99 container_builder->BfcOffset().value().block_offset,
100 floating_objects, space));
101 container_builder->MutableUnpositionedFloats().clear();
102 }
103
90 void PositionPendingFloats(LayoutUnit origin_block_offset, 104 void PositionPendingFloats(LayoutUnit origin_block_offset,
91 NGFragmentBuilder* container_builder, 105 NGFragmentBuilder* container_builder,
92 NGConstraintSpace* space) { 106 NGConstraintSpace* space) {
93 DCHECK(container_builder->BfcOffset()) 107 DCHECK(container_builder->BfcOffset())
94 << "Parent BFC offset should be known here"; 108 << "Parent BFC offset should be known here";
95 const auto& floating_objects = container_builder->UnpositionedFloats(); 109 LayoutUnit from_block_offset =
96 container_builder->MutablePositionedFloats().AppendVector(PositionFloats( 110 container_builder->BfcOffset().value().block_offset;
97 origin_block_offset, container_builder->BfcOffset().value().block_offset, 111 PositionPendingFloatsFromOffset(origin_block_offset, from_block_offset,
98 floating_objects, space)); 112 container_builder, space);
99 container_builder->MutableUnpositionedFloats().clear();
100 } 113 }
101 114
102 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm(NGBlockNode* node, 115 NGBlockLayoutAlgorithm::NGBlockLayoutAlgorithm(NGBlockNode* node,
103 NGConstraintSpace* space, 116 NGConstraintSpace* space,
104 NGBlockBreakToken* break_token) 117 NGBlockBreakToken* break_token)
105 : NGLayoutAlgorithm(node, space, break_token), 118 : NGLayoutAlgorithm(node, space, break_token),
106 space_builder_(constraint_space_) {} 119 space_builder_(constraint_space_) {}
107 120
108 Optional<MinMaxContentSize> NGBlockLayoutAlgorithm::ComputeMinMaxContentSize() 121 Optional<MinMaxContentSize> NGBlockLayoutAlgorithm::ComputeMinMaxContentSize()
109 const { 122 const {
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 400
388 // Determine the fragment's position in the parent space. 401 // Determine the fragment's position in the parent space.
389 WTF::Optional<NGLogicalOffset> child_bfc_offset; 402 WTF::Optional<NGLogicalOffset> child_bfc_offset;
390 if (child_space.IsNewFormattingContext()) 403 if (child_space.IsNewFormattingContext())
391 child_bfc_offset = PositionNewFc(fragment, child_space); 404 child_bfc_offset = PositionNewFc(fragment, child_space);
392 else if (fragment.BfcOffset()) 405 else if (fragment.BfcOffset())
393 child_bfc_offset = PositionWithBfcOffset(fragment); 406 child_bfc_offset = PositionWithBfcOffset(fragment);
394 else if (IsLegacyBlock(*child)) 407 else if (IsLegacyBlock(*child))
395 child_bfc_offset = PositionLegacy(child_space); 408 child_bfc_offset = PositionLegacy(child_space);
396 else if (container_builder_.BfcOffset()) 409 else if (container_builder_.BfcOffset())
397 child_bfc_offset = PositionWithParentBfc(fragment); 410 child_bfc_offset = PositionWithParentBfc(child_space, fragment);
398 411
399 NGLogicalOffset logical_offset = CalculateLogicalOffset(child_bfc_offset); 412 NGLogicalOffset logical_offset = CalculateLogicalOffset(child_bfc_offset);
400 413
401 // Update margin strut. 414 // Update margin strut.
402 curr_margin_strut_ = fragment.EndMarginStrut(); 415 curr_margin_strut_ = fragment.EndMarginStrut();
403 curr_margin_strut_.Append(curr_child_margins_.block_end); 416 curr_margin_strut_.Append(curr_child_margins_.block_end);
404 417
405 // Only modify content_size if BlockSize is not empty. It's needed to prevent 418 // Only modify content_size if BlockSize is not empty. It's needed to prevent
406 // the situation when logical_offset is included in content_size for empty 419 // the situation when logical_offset is included in content_size for empty
407 // blocks. Example: 420 // blocks. Example:
(...skipping 13 matching lines...) Expand all
421 434
422 NGLogicalOffset NGBlockLayoutAlgorithm::PositionNewFc( 435 NGLogicalOffset NGBlockLayoutAlgorithm::PositionNewFc(
423 const NGBoxFragment& fragment, 436 const NGBoxFragment& fragment,
424 const NGConstraintSpace& child_space) { 437 const NGConstraintSpace& child_space) {
425 // 1. Position all pending floats to a temporary space. 438 // 1. Position all pending floats to a temporary space.
426 RefPtr<NGConstraintSpace> tmp_space = 439 RefPtr<NGConstraintSpace> tmp_space =
427 NGConstraintSpaceBuilder(&child_space) 440 NGConstraintSpaceBuilder(&child_space)
428 .SetIsNewFormattingContext(false) 441 .SetIsNewFormattingContext(false)
429 .ToConstraintSpace(child_space.WritingMode()); 442 .ToConstraintSpace(child_space.WritingMode());
430 PositionFloats(curr_bfc_offset_.block_offset, curr_bfc_offset_.block_offset, 443 PositionFloats(curr_bfc_offset_.block_offset, curr_bfc_offset_.block_offset,
444 curr_bfc_offset_.block_offset,
431 container_builder_.UnpositionedFloats(), tmp_space.Get()); 445 container_builder_.UnpositionedFloats(), tmp_space.Get());
432 446
433 NGLogicalOffset origin_offset = curr_bfc_offset_; 447 NGLogicalOffset origin_offset = curr_bfc_offset_;
434 origin_offset.inline_offset += border_and_padding_.inline_start; 448 origin_offset.inline_offset += border_and_padding_.inline_start;
435 449
436 // 2. Find an estimated layout opportunity for our fragment. 450 // 2. Find an estimated layout opportunity for our fragment.
437 NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( 451 NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment(
438 tmp_space->Exclusions().get(), child_space.AvailableSize(), origin_offset, 452 tmp_space->Exclusions().get(), child_space.AvailableSize(), origin_offset,
439 curr_child_margins_, fragment); 453 curr_child_margins_, fragment);
440 454
(...skipping 29 matching lines...) Expand all
470 DCHECK(fragment.BfcOffset()); 484 DCHECK(fragment.BfcOffset());
471 curr_bfc_offset_.block_offset = fragment.BfcOffset().value().block_offset; 485 curr_bfc_offset_.block_offset = fragment.BfcOffset().value().block_offset;
472 MaybeUpdateFragmentBfcOffset(ConstraintSpace(), curr_bfc_offset_, 486 MaybeUpdateFragmentBfcOffset(ConstraintSpace(), curr_bfc_offset_,
473 &container_builder_); 487 &container_builder_);
474 PositionPendingFloats(curr_bfc_offset_.block_offset, &container_builder_, 488 PositionPendingFloats(curr_bfc_offset_.block_offset, &container_builder_,
475 MutableConstraintSpace()); 489 MutableConstraintSpace());
476 return fragment.BfcOffset().value(); 490 return fragment.BfcOffset().value();
477 } 491 }
478 492
479 NGLogicalOffset NGBlockLayoutAlgorithm::PositionWithParentBfc( 493 NGLogicalOffset NGBlockLayoutAlgorithm::PositionWithParentBfc(
494 const NGConstraintSpace& space,
480 const NGBoxFragment& fragment) { 495 const NGBoxFragment& fragment) {
481 // The child must be an in-flow zero-block-size fragment, use its end margin 496 // The child must be an in-flow zero-block-size fragment, use its end margin
482 // strut for positioning. 497 // strut for positioning.
483 DCHECK(!fragment.BfcOffset()); 498 DCHECK(!fragment.BfcOffset());
484 DCHECK_EQ(fragment.BlockSize(), LayoutUnit()); 499 DCHECK_EQ(fragment.BlockSize(), LayoutUnit());
485 500
486 NGMarginStrut margin_strut = fragment.EndMarginStrut(); 501 NGMarginStrut margin_strut = fragment.EndMarginStrut();
487 margin_strut.Append(curr_child_margins_.block_end); 502 margin_strut.Append(curr_child_margins_.block_end);
488 503
489 curr_bfc_offset_ += 504 curr_bfc_offset_ +=
490 {border_and_padding_.inline_start + curr_child_margins_.inline_start, 505 {border_and_padding_.inline_start + curr_child_margins_.inline_start,
491 margin_strut.Sum()}; 506 margin_strut.Sum()};
507 AdjustToClearance(space.ClearanceOffset(), &curr_bfc_offset_);
508 PositionPendingFloatsFromOffset(
509 curr_bfc_offset_.block_offset, curr_bfc_offset_.block_offset,
510 &container_builder_, MutableConstraintSpace());
492 return curr_bfc_offset_; 511 return curr_bfc_offset_;
493 } 512 }
494 513
495 NGLogicalOffset NGBlockLayoutAlgorithm::PositionLegacy( 514 NGLogicalOffset NGBlockLayoutAlgorithm::PositionLegacy(
496 const NGConstraintSpace& child_space) { 515 const NGConstraintSpace& child_space) {
497 AdjustToClearance(child_space.ClearanceOffset(), &curr_bfc_offset_); 516 AdjustToClearance(child_space.ClearanceOffset(), &curr_bfc_offset_);
498 return curr_bfc_offset_; 517 return curr_bfc_offset_;
499 } 518 }
500 519
501 void NGBlockLayoutAlgorithm::FinishFloatChildLayout( 520 void NGBlockLayoutAlgorithm::FinishFloatChildLayout(
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 if (is_new_bfc) { 644 if (is_new_bfc) {
626 space_available -= child_bfc_offset.block_offset; 645 space_available -= child_bfc_offset.block_offset;
627 } 646 }
628 } 647 }
629 space_builder_.SetFragmentainerSpaceAvailable(space_available); 648 space_builder_.SetFragmentainerSpaceAvailable(space_available);
630 649
631 return space_builder_.ToConstraintSpace( 650 return space_builder_.ToConstraintSpace(
632 FromPlatformWritingMode(child_style.GetWritingMode())); 651 FromPlatformWritingMode(child_style.GetWritingMode()));
633 } 652 }
634 } // namespace blink 653 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698