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

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

Issue 2790283003: Reset constraint space's BFC offset if block creates a new FC (Closed)
Patch Set: git rebase-update Created 3 years, 8 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_child_iterator.h" 8 #include "core/layout/ng/ng_block_child_iterator.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_constraint_space.h" 10 #include "core/layout/ng/ng_constraint_space.h"
11 #include "core/layout/ng/ng_constraint_space_builder.h" 11 #include "core/layout/ng/ng_constraint_space_builder.h"
12 #include "core/layout/ng/ng_floats_utils.h" 12 #include "core/layout/ng/ng_floats_utils.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_out_of_flow_layout_part.h" 18 #include "core/layout/ng/ng_out_of_flow_layout_part.h"
19 #include "core/layout/ng/ng_space_utils.h" 19 #include "core/layout/ng/ng_space_utils.h"
20 #include "core/style/ComputedStyle.h" 20 #include "core/style/ComputedStyle.h"
21 #include "platform/LengthFunctions.h" 21 #include "platform/LengthFunctions.h"
22 #include "wtf/Optional.h" 22 #include "wtf/Optional.h"
23 23
24 namespace blink { 24 namespace blink {
25 namespace { 25 namespace {
26 26
27 // Positions pending floats stored on the fragment builder starting from
28 // {@code origin_point_block_offset}.
29 void PositionPendingFloats(const LayoutUnit origin_point_block_offset,
30 NGConstraintSpace* new_parent_space,
31 NGFragmentBuilder* builder) {
32 DCHECK(builder->BfcOffset()) << "Parent BFC offset should be known here";
33 LayoutUnit bfc_block_offset = builder->BfcOffset().value().block_offset;
34
35 for (auto& floating_object : builder->UnpositionedFloats()) {
36 const auto* float_space = floating_object->space.get();
37 const NGConstraintSpace* original_parent_space =
38 floating_object->original_parent_space.get();
39
40 NGLogicalOffset origin_point = {float_space->BfcOffset().inline_offset,
41 origin_point_block_offset};
42 NGLogicalOffset from_offset = {
43 original_parent_space->BfcOffset().inline_offset, bfc_block_offset};
44
45 NGLogicalOffset float_fragment_offset = PositionFloat(
46 origin_point, from_offset, floating_object.get(), new_parent_space);
47 builder->AddFloatingObject(floating_object, float_fragment_offset);
48 }
49 builder->MutableUnpositionedFloats().clear();
50 }
51
52 // Returns if a child may be affected by its clear property. I.e. it will 27 // Returns if a child may be affected by its clear property. I.e. it will
53 // actually clear a float. 28 // actually clear a float.
54 bool ClearanceMayAffectLayout( 29 bool ClearanceMayAffectLayout(
55 const NGConstraintSpace& space, 30 const NGConstraintSpace& space,
56 const Vector<RefPtr<NGFloatingObject>>& unpositioned_floats, 31 const Vector<RefPtr<NGFloatingObject>>& unpositioned_floats,
57 const ComputedStyle& child_style) { 32 const ComputedStyle& child_style) {
58 const NGExclusions& exclusions = *space.Exclusions(); 33 const NGExclusions& exclusions = *space.Exclusions();
59 EClear clear = child_style.clear(); 34 EClear clear = child_style.clear();
60 bool should_clear_left = (clear == EClear::kBoth || clear == EClear::kLeft); 35 bool should_clear_left = (clear == EClear::kBoth || clear == EClear::kLeft);
61 bool should_clear_right = (clear == EClear::kBoth || clear == EClear::kRight); 36 bool should_clear_right = (clear == EClear::kBoth || clear == EClear::kRight);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); 184 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum();
210 UpdateFragmentBfcOffset(curr_bfc_offset_); 185 UpdateFragmentBfcOffset(curr_bfc_offset_);
211 curr_margin_strut_ = NGMarginStrut(); 186 curr_margin_strut_ = NGMarginStrut();
212 } 187 }
213 188
214 // If a new formatting context hits the if branch above then the BFC offset is 189 // If a new formatting context hits the if branch above then the BFC offset is
215 // still {} as the margin strut from the constraint space must also be empty. 190 // still {} as the margin strut from the constraint space must also be empty.
216 if (ConstraintSpace().IsNewFormattingContext()) { 191 if (ConstraintSpace().IsNewFormattingContext()) {
217 UpdateFragmentBfcOffset(curr_bfc_offset_); 192 UpdateFragmentBfcOffset(curr_bfc_offset_);
218 DCHECK_EQ(curr_margin_strut_, NGMarginStrut()); 193 DCHECK_EQ(curr_margin_strut_, NGMarginStrut());
219 // TODO(glebl): Uncomment the line below once we add the fragmentation 194 DCHECK_EQ(builder_.BfcOffset().value(), NGLogicalOffset());
220 // support for floats.
221 // DCHECK_EQ(builder_.BfcOffset().value(), NGLogicalOffset());
222 curr_bfc_offset_ = {}; 195 curr_bfc_offset_ = {};
223 } 196 }
224 197
225 curr_bfc_offset_.block_offset += content_size_; 198 curr_bfc_offset_.block_offset += content_size_;
226 199
227 while (child) { 200 while (child) {
228 if (child->IsBlock()) { 201 if (child->IsBlock()) {
229 EPosition position = child->Style().position(); 202 EPosition position = child->Style().position();
230 if (position == EPosition::kAbsolute || position == EPosition::kFixed) { 203 if (position == EPosition::kAbsolute || position == EPosition::kFixed) {
231 // TODO(ikilpatrick): curr_margin_strut_ shouldn't be included if there 204 // TODO(ikilpatrick): curr_margin_strut_ shouldn't be included if there
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 NGBoxFragment fragment( 348 NGBoxFragment fragment(
376 ConstraintSpace().WritingMode(), 349 ConstraintSpace().WritingMode(),
377 toNGPhysicalBoxFragment(layout_result->PhysicalFragment().get())); 350 toNGPhysicalBoxFragment(layout_result->PhysicalFragment().get()));
378 351
379 // Pull out unpositioned floats to the current fragment. This may needed if 352 // Pull out unpositioned floats to the current fragment. This may needed if
380 // for example the child fragment could not position its floats because it's 353 // for example the child fragment could not position its floats because it's
381 // empty and therefore couldn't determine its position in space. 354 // empty and therefore couldn't determine its position in space.
382 builder_.MutableUnpositionedFloats().appendVector( 355 builder_.MutableUnpositionedFloats().appendVector(
383 layout_result->UnpositionedFloats()); 356 layout_result->UnpositionedFloats());
384 357
385 if (child->Type() == NGLayoutInputNode::kLegacyBlock && 358 if (child->IsBlock() && child->Style().isFloating()) {
386 toNGBlockNode(child)->Style().isFloating()) { 359 NGLogicalOffset origin_offset = constraint_space_->BfcOffset();
360 origin_offset.inline_offset += border_and_padding_.inline_start;
387 RefPtr<NGFloatingObject> floating_object = NGFloatingObject::Create( 361 RefPtr<NGFloatingObject> floating_object = NGFloatingObject::Create(
388 child_space, constraint_space_, toNGBlockNode(child)->Style(), 362 child->Style(), child_space->WritingMode(),
389 curr_child_margins_, child_space->AvailableSize(), 363 child_space->AvailableSize(), origin_offset,
364 constraint_space_->BfcOffset(), curr_child_margins_,
390 layout_result->PhysicalFragment().get()); 365 layout_result->PhysicalFragment().get());
391 builder_.AddUnpositionedFloat(floating_object); 366 builder_.AddUnpositionedFloat(floating_object);
392 // No need to postpone the positioning if we know the correct offset. 367 // No need to postpone the positioning if we know the correct offset.
393 if (builder_.BfcOffset()) { 368 if (builder_.BfcOffset()) {
394 NGLogicalOffset origin_point = curr_bfc_offset_; 369 NGLogicalOffset origin_point = curr_bfc_offset_;
395 // Adjust origin point to the margins of the last child. 370 // Adjust origin point to the margins of the last child.
396 // Example: <div style="margin-bottom: 20px"><float></div> 371 // Example: <div style="margin-bottom: 20px"><float></div>
397 // <div style="margin-bottom: 30px"></div> 372 // <div style="margin-bottom: 30px"></div>
398 origin_point.block_offset += curr_margin_strut_.Sum(); 373 origin_point.block_offset += curr_margin_strut_.Sum();
399 PositionPendingFloats(origin_point.block_offset, MutableConstraintSpace(), 374 PositionPendingFloats(origin_point.block_offset, MutableConstraintSpace(),
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 513
539 LayoutUnit space_available; 514 LayoutUnit space_available;
540 if (constraint_space_->HasBlockFragmentation()) { 515 if (constraint_space_->HasBlockFragmentation()) {
541 space_available = ConstraintSpace().FragmentainerSpaceAvailable(); 516 space_available = ConstraintSpace().FragmentainerSpaceAvailable();
542 // If a block establishes a new formatting context we must know our 517 // If a block establishes a new formatting context we must know our
543 // position in the formatting context, and are able to adjust the 518 // position in the formatting context, and are able to adjust the
544 // fragmentation line. 519 // fragmentation line.
545 if (is_new_bfc) { 520 if (is_new_bfc) {
546 DCHECK(builder_.BfcOffset()); 521 DCHECK(builder_.BfcOffset());
547 space_available -= curr_bfc_offset_.block_offset; 522 space_available -= curr_bfc_offset_.block_offset;
548 // TODO(glebl): We need to reset BFCOffset in ToConstraintSpace() after we
549 // started handling the fragmentation for floats.
550 space_builder_.SetBfcOffset(NGLogicalOffset());
551 } 523 }
552 } 524 }
553 space_builder_.SetFragmentainerSpaceAvailable(space_available); 525 space_builder_.SetFragmentainerSpaceAvailable(space_available);
554 526
555 return space_builder_.ToConstraintSpace( 527 return space_builder_.ToConstraintSpace(
556 FromPlatformWritingMode(child_style.getWritingMode())); 528 FromPlatformWritingMode(child_style.getWritingMode()));
557 } 529 }
558 } // namespace blink 530 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698