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

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

Issue 2732483002: Change NGLayoutOpportunityIterator constructor to work with const CS. (Closed)
Patch Set: git rebase-update3 Created 3 years, 9 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/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"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // 127 //
128 // @param space Constraint space that is used to find layout opportunity for 128 // @param space Constraint space that is used to find layout opportunity for
129 // the fragment. 129 // the fragment.
130 // @param fragment Fragment that needs to be placed. 130 // @param fragment Fragment that needs to be placed.
131 // @param origin_point {@code space}'s offset relative to the space that 131 // @param origin_point {@code space}'s offset relative to the space that
132 // establishes a new formatting context that we're currently 132 // establishes a new formatting context that we're currently
133 // in and where all our exclusions reside. 133 // in and where all our exclusions reside.
134 // @param margins Margins of the fragment. 134 // @param margins Margins of the fragment.
135 // @return Layout opportunity for the fragment. 135 // @return Layout opportunity for the fragment.
136 const NGLayoutOpportunity FindLayoutOpportunityForFragment( 136 const NGLayoutOpportunity FindLayoutOpportunityForFragment(
137 NGConstraintSpace* space, 137 const NGConstraintSpace* space,
138 const NGFragment& fragment, 138 const NGFragment& fragment,
139 const NGLogicalOffset& origin_point, 139 const NGLogicalOffset& origin_point,
140 const NGBoxStrut& margins) { 140 const NGBoxStrut& margins) {
141 NGLogicalOffset adjusted_origin_point = 141 NGLogicalOffset adjusted_origin_point =
142 AdjustToTopEdgeAlignmentRule(*space, origin_point); 142 AdjustToTopEdgeAlignmentRule(*space, origin_point);
143 143
144 NGLayoutOpportunityIterator opportunity_iter(space, adjusted_origin_point); 144 NGLayoutOpportunityIterator opportunity_iter(space, adjusted_origin_point);
145 NGLayoutOpportunity opportunity; 145 NGLayoutOpportunity opportunity;
146 NGLayoutOpportunity opportunity_candidate = opportunity_iter.Next(); 146 NGLayoutOpportunity opportunity_candidate = opportunity_iter.Next();
147 147
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 block_offset -= from_offset.block_offset; 179 block_offset -= from_offset.block_offset;
180 inline_offset -= from_offset.inline_offset; 180 inline_offset -= from_offset.inline_offset;
181 181
182 return NGLogicalOffset(inline_offset, block_offset); 182 return NGLogicalOffset(inline_offset, block_offset);
183 } 183 }
184 184
185 // Calculates the relative position from {@code from_offset} of the 185 // Calculates the relative position from {@code from_offset} of the
186 // floating object that is requested to be positioned from {@code origin_point}. 186 // floating object that is requested to be positioned from {@code origin_point}.
187 NGLogicalOffset PositionFloat(const NGLogicalOffset& origin_point, 187 NGLogicalOffset PositionFloat(const NGLogicalOffset& origin_point,
188 const NGLogicalOffset& from_offset, 188 const NGLogicalOffset& from_offset,
189 NGFloatingObject* floating_object) { 189 NGFloatingObject* floating_object,
190 NGConstraintSpace* float_space = floating_object->space.get(); 190 NGConstraintSpace* new_parent_space) {
191 const auto* float_space = floating_object->space.get();
191 DCHECK(floating_object->fragment) << "Fragment cannot be null here"; 192 DCHECK(floating_object->fragment) << "Fragment cannot be null here";
192 193
193 // TODO(ikilpatrick): The writing mode switching here looks wrong. 194 // TODO(ikilpatrick): The writing mode switching here looks wrong.
194 NGBoxFragment float_fragment( 195 NGBoxFragment float_fragment(
195 float_space->WritingMode(), 196 float_space->WritingMode(),
196 toNGPhysicalBoxFragment(floating_object->fragment.get())); 197 toNGPhysicalBoxFragment(floating_object->fragment.get()));
197 198
198 // Find a layout opportunity that will fit our float. 199 // Find a layout opportunity that will fit our float.
199 const NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( 200 const NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment(
200 float_space, float_fragment, origin_point, floating_object->margins); 201 float_space, float_fragment, origin_point, floating_object->margins);
201 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be"; 202 DCHECK(!opportunity.IsEmpty()) << "Opportunity is empty but it shouldn't be";
202 203
203 // Calculate the float offset if needed. 204 // Calculate the float offset if needed.
204 LayoutUnit float_offset; 205 LayoutUnit float_offset;
205 if (floating_object->exclusion_type == NGExclusion::kFloatRight) { 206 if (floating_object->exclusion_type == NGExclusion::kFloatRight) {
206 LayoutUnit float_margin_box_inline_size = 207 LayoutUnit float_margin_box_inline_size =
207 float_fragment.InlineSize() + floating_object->margins.InlineSum(); 208 float_fragment.InlineSize() + floating_object->margins.InlineSum();
208 float_offset = opportunity.size.inline_size - float_margin_box_inline_size; 209 float_offset = opportunity.size.inline_size - float_margin_box_inline_size;
209 } 210 }
210 211
211 // Add the float as an exclusion. 212 // Add the float as an exclusion.
212 const NGExclusion exclusion = CreateExclusion( 213 const NGExclusion exclusion = CreateExclusion(
213 float_fragment, opportunity, float_offset, floating_object->margins, 214 float_fragment, opportunity, float_offset, floating_object->margins,
214 floating_object->exclusion_type); 215 floating_object->exclusion_type);
215 float_space->AddExclusion(exclusion); 216 new_parent_space->AddExclusion(exclusion);
216 217
217 return CalculateLogicalOffsetForOpportunity(opportunity, float_offset, 218 return CalculateLogicalOffsetForOpportunity(opportunity, float_offset,
218 from_offset, floating_object); 219 from_offset, floating_object);
219 } 220 }
220 221
221 // Updates the Floating Object's left offset from the provided parent_space 222 // Updates the Floating Object's left offset from the provided parent_space
222 // and {@code floating_object}'s space and margins. 223 // and {@code floating_object}'s space and margins.
223 void UpdateFloatingObjectLeftOffset( 224 void UpdateFloatingObjectLeftOffset(
224 const NGConstraintSpace& new_parent_space, 225 const NGConstraintSpace& new_parent_space,
225 const Persistent<NGFloatingObject>& floating_object, 226 const Persistent<NGFloatingObject>& floating_object,
226 const NGLogicalOffset& float_logical_offset) { 227 const NGLogicalOffset& float_logical_offset) {
227 // TODO(glebl): We should use physical offset here. 228 // TODO(glebl): We should use physical offset here.
228 floating_object->left_offset = 229 floating_object->left_offset =
229 floating_object->original_parent_space->BfcOffset().inline_offset - 230 floating_object->original_parent_space->BfcOffset().inline_offset -
230 new_parent_space.BfcOffset().inline_offset + 231 new_parent_space.BfcOffset().inline_offset +
231 float_logical_offset.inline_offset; 232 float_logical_offset.inline_offset;
232 } 233 }
233 234
234 // Positions pending floats stored on the fragment builder starting from 235 // Positions pending floats stored on the fragment builder starting from
235 // {@code origin_point_block_offset}. 236 // {@code origin_point_block_offset}.
236 void PositionPendingFloats(const LayoutUnit origin_point_block_offset, 237 void PositionPendingFloats(const LayoutUnit origin_point_block_offset,
237 const NGConstraintSpace& new_parent_space, 238 NGConstraintSpace* new_parent_space,
238 NGFragmentBuilder* builder) { 239 NGFragmentBuilder* builder) {
239 DCHECK(builder->BfcOffset()) << "Parent BFC offset should be known here"; 240 DCHECK(builder->BfcOffset()) << "Parent BFC offset should be known here";
240 LayoutUnit bfc_block_offset = builder->BfcOffset().value().block_offset; 241 LayoutUnit bfc_block_offset = builder->BfcOffset().value().block_offset;
241 242
242 for (auto& floating_object : builder->UnpositionedFloats()) { 243 for (auto& floating_object : builder->UnpositionedFloats()) {
243 NGConstraintSpace* float_space = floating_object->space.get(); 244 const auto* float_space = floating_object->space.get();
244 const NGConstraintSpace* original_parent_space = 245 const NGConstraintSpace* original_parent_space =
245 floating_object->original_parent_space.get(); 246 floating_object->original_parent_space.get();
246 247
247 NGLogicalOffset origin_point = {float_space->BfcOffset().inline_offset, 248 NGLogicalOffset origin_point = {float_space->BfcOffset().inline_offset,
248 origin_point_block_offset}; 249 origin_point_block_offset};
249 NGLogicalOffset from_offset = { 250 NGLogicalOffset from_offset = {
250 original_parent_space->BfcOffset().inline_offset, bfc_block_offset}; 251 original_parent_space->BfcOffset().inline_offset, bfc_block_offset};
251 252
252 NGLogicalOffset float_fragment_offset = 253 NGLogicalOffset float_fragment_offset = PositionFloat(
253 PositionFloat(origin_point, from_offset, floating_object); 254 origin_point, from_offset, floating_object, new_parent_space);
254 builder->AddFloatingObject(floating_object, float_fragment_offset); 255 builder->AddFloatingObject(floating_object, float_fragment_offset);
255 UpdateFloatingObjectLeftOffset(new_parent_space, floating_object, 256 UpdateFloatingObjectLeftOffset(*new_parent_space, floating_object,
256 float_fragment_offset); 257 float_fragment_offset);
257 } 258 }
258 builder->MutableUnpositionedFloats().clear(); 259 builder->MutableUnpositionedFloats().clear();
259 } 260 }
260 261
261 // Whether an in-flow block-level child creates a new formatting context. 262 // Whether an in-flow block-level child creates a new formatting context.
262 // 263 //
263 // This will *NOT* check the following cases: 264 // This will *NOT* check the following cases:
264 // - The child is out-of-flow, e.g. floating or abs-pos. 265 // - The child is out-of-flow, e.g. floating or abs-pos.
265 // - The child is a inline-level, e.g. "display: inline-block". 266 // - The child is a inline-level, e.g. "display: inline-block".
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 ComputeBlockSizeForFragment(ConstraintSpace(), Style(), content_size_); 493 ComputeBlockSizeForFragment(ConstraintSpace(), Style(), content_size_);
493 builder_.SetBlockSize(block_size); 494 builder_.SetBlockSize(block_size);
494 495
495 // Layout our absolute and fixed positioned children. 496 // Layout our absolute and fixed positioned children.
496 NGOutOfFlowLayoutPart(ConstraintSpace(), Style(), &builder_).Run(); 497 NGOutOfFlowLayoutPart(ConstraintSpace(), Style(), &builder_).Run();
497 498
498 // Non-empty blocks always know their position in space: 499 // Non-empty blocks always know their position in space:
499 if (block_size) { 500 if (block_size) {
500 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); 501 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum();
501 UpdateFragmentBfcOffset(curr_bfc_offset_); 502 UpdateFragmentBfcOffset(curr_bfc_offset_);
502 PositionPendingFloats(curr_bfc_offset_.block_offset, ConstraintSpace(), 503 PositionPendingFloats(curr_bfc_offset_.block_offset,
503 &builder_); 504 MutableConstraintSpace(), &builder_);
504 } 505 }
505 506
506 // Margins collapsing: 507 // Margins collapsing:
507 // Do not collapse margins between the last in-flow child and bottom margin 508 // Do not collapse margins between the last in-flow child and bottom margin
508 // of its parent if the parent has height != auto() 509 // of its parent if the parent has height != auto()
509 if (!Style().logicalHeight().isAuto()) { 510 if (!Style().logicalHeight().isAuto()) {
510 // TODO(glebl): handle minLogicalHeight, maxLogicalHeight. 511 // TODO(glebl): handle minLogicalHeight, maxLogicalHeight.
511 curr_margin_strut_ = NGMarginStrut(); 512 curr_margin_strut_ = NGMarginStrut();
512 } 513 }
513 builder_.SetEndMarginStrut(curr_margin_strut_); 514 builder_.SetEndMarginStrut(curr_margin_strut_);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 552
552 // Pull out unpositioned floats to the current fragment. This may needed if 553 // Pull out unpositioned floats to the current fragment. This may needed if
553 // for example the child fragment could not position its floats because it's 554 // for example the child fragment could not position its floats because it's
554 // empty and therefore couldn't determine its position in space. 555 // empty and therefore couldn't determine its position in space.
555 builder_.MutableUnpositionedFloats().appendVector( 556 builder_.MutableUnpositionedFloats().appendVector(
556 layout_result->UnpositionedFloats()); 557 layout_result->UnpositionedFloats());
557 558
558 if (child->Type() == NGLayoutInputNode::kLegacyBlock && 559 if (child->Type() == NGLayoutInputNode::kLegacyBlock &&
559 toNGBlockNode(child)->Style().isFloating()) { 560 toNGBlockNode(child)->Style().isFloating()) {
560 NGFloatingObject* floating_object = new NGFloatingObject( 561 NGFloatingObject* floating_object = new NGFloatingObject(
561 layout_result->PhysicalFragment().get(), child_space, constraint_space_, 562 child_space, constraint_space_, toNGBlockNode(child)->Style(),
562 toNGBlockNode(child), toNGBlockNode(child)->Style(), 563 curr_child_margins_, layout_result->PhysicalFragment().get());
563 curr_child_margins_);
564 builder_.AddUnpositionedFloat(floating_object); 564 builder_.AddUnpositionedFloat(floating_object);
565 // No need to postpone the positioning if we know the correct offset. 565 // No need to postpone the positioning if we know the correct offset.
566 if (builder_.BfcOffset()) { 566 if (builder_.BfcOffset()) {
567 NGLogicalOffset origin_point = curr_bfc_offset_; 567 NGLogicalOffset origin_point = curr_bfc_offset_;
568 // Adjust origin point to the margins of the last child. 568 // Adjust origin point to the margins of the last child.
569 // Example: <div style="margin-bottom: 20px"><float></div> 569 // Example: <div style="margin-bottom: 20px"><float></div>
570 // <div style="margin-bottom: 30px"></div> 570 // <div style="margin-bottom: 30px"></div>
571 origin_point.block_offset += curr_margin_strut_.Sum(); 571 origin_point.block_offset += curr_margin_strut_.Sum();
572 PositionPendingFloats(origin_point.block_offset, ConstraintSpace(), 572 PositionPendingFloats(origin_point.block_offset, MutableConstraintSpace(),
573 &builder_); 573 &builder_);
574 } 574 }
575 return; 575 return;
576 } 576 }
577 577
578 // Determine the fragment's position in the parent space either by using 578 // Determine the fragment's position in the parent space either by using
579 // content_size_ or known fragment's BFC offset. 579 // content_size_ or known fragment's BFC offset.
580 WTF::Optional<NGLogicalOffset> bfc_offset; 580 WTF::Optional<NGLogicalOffset> bfc_offset;
581 if (child_space->IsNewFormattingContext()) { 581 if (child_space->IsNewFormattingContext()) {
582 // TODO(ikilpatrick): We may need to place ourself within the BFC 582 // TODO(ikilpatrick): We may need to place ourself within the BFC
(...skipping 10 matching lines...) Expand all
593 // position because the parent fragment's BFC is known. 593 // position because the parent fragment's BFC is known.
594 // Example: 594 // Example:
595 // BFC Offset is known here because of the padding. 595 // BFC Offset is known here because of the padding.
596 // <div style="padding: 1px"> 596 // <div style="padding: 1px">
597 // <div id="empty-div" style="margins: 1px"></div> 597 // <div id="empty-div" style="margins: 1px"></div>
598 bfc_offset = curr_bfc_offset_; 598 bfc_offset = curr_bfc_offset_;
599 bfc_offset.value().block_offset += curr_margin_strut_.Sum(); 599 bfc_offset.value().block_offset += curr_margin_strut_.Sum();
600 } 600 }
601 if (bfc_offset) { 601 if (bfc_offset) {
602 UpdateFragmentBfcOffset(curr_bfc_offset_); 602 UpdateFragmentBfcOffset(curr_bfc_offset_);
603 PositionPendingFloats(curr_bfc_offset_.block_offset, ConstraintSpace(), 603 PositionPendingFloats(curr_bfc_offset_.block_offset,
604 &builder_); 604 MutableConstraintSpace(), &builder_);
605 } 605 }
606 NGLogicalOffset logical_offset = CalculateLogicalOffset(bfc_offset); 606 NGLogicalOffset logical_offset = CalculateLogicalOffset(bfc_offset);
607 607
608 // Update margin strut. 608 // Update margin strut.
609 curr_margin_strut_ = fragment.EndMarginStrut(); 609 curr_margin_strut_ = fragment.EndMarginStrut();
610 curr_margin_strut_.Append(curr_child_margins_.block_end); 610 curr_margin_strut_.Append(curr_child_margins_.block_end);
611 611
612 // Only modify content_size if BlockSize is not empty. It's needed to prevent 612 // Only modify content_size if BlockSize is not empty. It's needed to prevent
613 // the situation when logical_offset is included in content_size for empty 613 // the situation when logical_offset is included in content_size for empty
614 // blocks. Example: 614 // blocks. Example:
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 RefPtr<NGConstraintSpace> NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( 689 RefPtr<NGConstraintSpace> NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild(
690 NGLayoutInputNode* child) { 690 NGLayoutInputNode* child) {
691 DCHECK(child); 691 DCHECK(child);
692 692
693 if (child->Type() == NGLayoutInputNode::kLegacyInline) { 693 if (child->Type() == NGLayoutInputNode::kLegacyInline) {
694 // TODO(kojii): Setup space_builder_ appropriately for inline child. 694 // TODO(kojii): Setup space_builder_ appropriately for inline child.
695 695
696 // Margins collapsing: Inline block. 696 // Margins collapsing: Inline block.
697 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); 697 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum();
698 UpdateFragmentBfcOffset(curr_bfc_offset_); 698 UpdateFragmentBfcOffset(curr_bfc_offset_);
699 PositionPendingFloats(curr_bfc_offset_.block_offset, ConstraintSpace(), 699 PositionPendingFloats(curr_bfc_offset_.block_offset,
700 &builder_); 700 MutableConstraintSpace(), &builder_);
701 curr_margin_strut_ = {}; 701 curr_margin_strut_ = {};
702 702
703 return space_builder_.ToConstraintSpace( 703 return space_builder_.ToConstraintSpace(
704 FromPlatformWritingMode(Style().getWritingMode())); 704 FromPlatformWritingMode(Style().getWritingMode()));
705 } 705 }
706 706
707 NGBlockNode* block_child = toNGBlockNode(child); 707 NGBlockNode* block_child = toNGBlockNode(child);
708 const ComputedStyle& child_style = block_child->Style(); 708 const ComputedStyle& child_style = block_child->Style();
709 709
710 // Calculate margins in parent's writing mode. 710 // Calculate margins in parent's writing mode.
(...skipping 12 matching lines...) Expand all
723 // - Position all pending floats since the fragment's BFC offset is known. 723 // - Position all pending floats since the fragment's BFC offset is known.
724 // - Set the clearance offset on the constraint space's builder. 724 // - Set the clearance offset on the constraint space's builder.
725 if (child_style.clear() != EClear::kNone) { 725 if (child_style.clear() != EClear::kNone) {
726 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); 726 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum();
727 UpdateFragmentBfcOffset(curr_bfc_offset_); 727 UpdateFragmentBfcOffset(curr_bfc_offset_);
728 // Only collapse margins if it's an adjoining block with clearance. 728 // Only collapse margins if it's an adjoining block with clearance.
729 if (!content_size_) { 729 if (!content_size_) {
730 curr_margin_strut_ = NGMarginStrut(); 730 curr_margin_strut_ = NGMarginStrut();
731 curr_child_margins_.block_start = LayoutUnit(); 731 curr_child_margins_.block_start = LayoutUnit();
732 } 732 }
733 PositionPendingFloats(curr_bfc_offset_.block_offset, ConstraintSpace(), 733 PositionPendingFloats(curr_bfc_offset_.block_offset,
734 &builder_); 734 MutableConstraintSpace(), &builder_);
735 WTF::Optional<LayoutUnit> clearance_offset = 735 WTF::Optional<LayoutUnit> clearance_offset =
736 GetClearanceOffset(constraint_space_->Exclusions(), child_style); 736 GetClearanceOffset(constraint_space_->Exclusions(), child_style);
737 space_builder_.SetClearanceOffset(clearance_offset); 737 space_builder_.SetClearanceOffset(clearance_offset);
738 } 738 }
739 739
740 // Set estimated BFC offset to the next child's constraint space. 740 // Set estimated BFC offset to the next child's constraint space.
741 curr_bfc_offset_ = builder_.BfcOffset() ? builder_.BfcOffset().value() 741 curr_bfc_offset_ = builder_.BfcOffset() ? builder_.BfcOffset().value()
742 : ConstraintSpace().BfcOffset(); 742 : ConstraintSpace().BfcOffset();
743 curr_bfc_offset_.block_offset += content_size_; 743 curr_bfc_offset_.block_offset += content_size_;
744 curr_bfc_offset_.inline_offset += border_and_padding_.inline_start; 744 curr_bfc_offset_.inline_offset += border_and_padding_.inline_start;
(...skipping 22 matching lines...) Expand all
767 DCHECK(builder_.BfcOffset()); 767 DCHECK(builder_.BfcOffset());
768 space_available -= curr_bfc_offset_.block_offset; 768 space_available -= curr_bfc_offset_.block_offset;
769 } 769 }
770 } 770 }
771 space_builder_.SetFragmentainerSpaceAvailable(space_available); 771 space_builder_.SetFragmentainerSpaceAvailable(space_available);
772 772
773 return space_builder_.ToConstraintSpace( 773 return space_builder_.ToConstraintSpace(
774 FromPlatformWritingMode(child_style.getWritingMode())); 774 FromPlatformWritingMode(child_style.getWritingMode()));
775 } 775 }
776 } // namespace blink 776 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698