| 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_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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 180 |
| 181 // Margins collapsing: | 181 // Margins collapsing: |
| 182 // Do not collapse margins between parent and its child if there is | 182 // Do not collapse margins between parent and its child if there is |
| 183 // border/padding between them. | 183 // border/padding between them. |
| 184 if (border_and_padding_.block_start) { | 184 if (border_and_padding_.block_start) { |
| 185 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); | 185 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); |
| 186 UpdateFragmentBfcOffset(curr_bfc_offset_); | 186 UpdateFragmentBfcOffset(curr_bfc_offset_); |
| 187 curr_margin_strut_ = NGMarginStrut(); | 187 curr_margin_strut_ = NGMarginStrut(); |
| 188 } | 188 } |
| 189 | 189 |
| 190 // Block that establishes a new BFC knows its BFC offset == {} | |
| 191 // If a new formatting context hits the if branch above then the BFC offset is | 190 // If a new formatting context hits the if branch above then the BFC offset is |
| 192 // still {} as the margin strut from the constraint space must also be empty. | 191 // still {} as the margin strut from the constraint space must also be empty. |
| 193 if (ConstraintSpace().IsNewFormattingContext()) { | 192 if (ConstraintSpace().IsNewFormattingContext()) { |
| 194 UpdateFragmentBfcOffset(curr_bfc_offset_); | 193 UpdateFragmentBfcOffset(curr_bfc_offset_); |
| 195 DCHECK_EQ(builder_.BfcOffset().value(), NGLogicalOffset()); | |
| 196 DCHECK_EQ(curr_margin_strut_, NGMarginStrut()); | 194 DCHECK_EQ(curr_margin_strut_, NGMarginStrut()); |
| 195 // TODO(glebl): Uncomment the line below once we add the fragmentation |
| 196 // support for floats. |
| 197 // DCHECK_EQ(builder_.BfcOffset().value(), NGLogicalOffset()); |
| 198 curr_bfc_offset_ = {}; |
| 197 } | 199 } |
| 198 | 200 |
| 199 curr_bfc_offset_.block_offset += content_size_; | 201 curr_bfc_offset_.block_offset += content_size_; |
| 200 | 202 |
| 201 while (child) { | 203 while (child) { |
| 202 if (child->Type() == NGLayoutInputNode::kLegacyBlock) { | 204 if (child->Type() == NGLayoutInputNode::kLegacyBlock) { |
| 203 NGBlockNode* current_block_child = toNGBlockNode(child); | 205 NGBlockNode* current_block_child = toNGBlockNode(child); |
| 204 EPosition position = current_block_child->Style().position(); | 206 EPosition position = current_block_child->Style().position(); |
| 205 if (position == EPosition::kAbsolute || position == EPosition::kFixed) { | 207 if (position == EPosition::kAbsolute || position == EPosition::kFixed) { |
| 206 NGLogicalOffset offset = {border_and_padding_.inline_start, | 208 NGLogicalOffset offset = {border_and_padding_.inline_start, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 // Pull out unpositioned floats to the current fragment. This may needed if | 340 // Pull out unpositioned floats to the current fragment. This may needed if |
| 339 // for example the child fragment could not position its floats because it's | 341 // for example the child fragment could not position its floats because it's |
| 340 // empty and therefore couldn't determine its position in space. | 342 // empty and therefore couldn't determine its position in space. |
| 341 builder_.MutableUnpositionedFloats().appendVector( | 343 builder_.MutableUnpositionedFloats().appendVector( |
| 342 layout_result->UnpositionedFloats()); | 344 layout_result->UnpositionedFloats()); |
| 343 | 345 |
| 344 if (child->Type() == NGLayoutInputNode::kLegacyBlock && | 346 if (child->Type() == NGLayoutInputNode::kLegacyBlock && |
| 345 toNGBlockNode(child)->Style().isFloating()) { | 347 toNGBlockNode(child)->Style().isFloating()) { |
| 346 RefPtr<NGFloatingObject> floating_object = NGFloatingObject::Create( | 348 RefPtr<NGFloatingObject> floating_object = NGFloatingObject::Create( |
| 347 child_space, constraint_space_, toNGBlockNode(child)->Style(), | 349 child_space, constraint_space_, toNGBlockNode(child)->Style(), |
| 348 curr_child_margins_, layout_result->PhysicalFragment().get()); | 350 curr_child_margins_, child_space->AvailableSize(), |
| 351 layout_result->PhysicalFragment().get()); |
| 349 builder_.AddUnpositionedFloat(floating_object); | 352 builder_.AddUnpositionedFloat(floating_object); |
| 350 // No need to postpone the positioning if we know the correct offset. | 353 // No need to postpone the positioning if we know the correct offset. |
| 351 if (builder_.BfcOffset()) { | 354 if (builder_.BfcOffset()) { |
| 352 NGLogicalOffset origin_point = curr_bfc_offset_; | 355 NGLogicalOffset origin_point = curr_bfc_offset_; |
| 353 // Adjust origin point to the margins of the last child. | 356 // Adjust origin point to the margins of the last child. |
| 354 // Example: <div style="margin-bottom: 20px"><float></div> | 357 // Example: <div style="margin-bottom: 20px"><float></div> |
| 355 // <div style="margin-bottom: 30px"></div> | 358 // <div style="margin-bottom: 30px"></div> |
| 356 origin_point.block_offset += curr_margin_strut_.Sum(); | 359 origin_point.block_offset += curr_margin_strut_.Sum(); |
| 357 PositionPendingFloats(origin_point.block_offset, MutableConstraintSpace(), | 360 PositionPendingFloats(origin_point.block_offset, MutableConstraintSpace(), |
| 358 &builder_); | 361 &builder_); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 if (!child_style.isFloating()) { | 471 if (!child_style.isFloating()) { |
| 469 ApplyAutoMargins(space, child_style, child_inline_size, &margins); | 472 ApplyAutoMargins(space, child_style, child_inline_size, &margins); |
| 470 } | 473 } |
| 471 return margins; | 474 return margins; |
| 472 } | 475 } |
| 473 | 476 |
| 474 RefPtr<NGConstraintSpace> NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( | 477 RefPtr<NGConstraintSpace> NGBlockLayoutAlgorithm::CreateConstraintSpaceForChild( |
| 475 NGLayoutInputNode* child) { | 478 NGLayoutInputNode* child) { |
| 476 DCHECK(child); | 479 DCHECK(child); |
| 477 | 480 |
| 478 if (child->Type() == NGLayoutInputNode::kLegacyInline) { | 481 const ComputedStyle& child_style = child->Style(); |
| 482 bool is_new_bfc = |
| 483 IsNewFormattingContextForBlockLevelChild(ConstraintSpace(), child_style); |
| 484 space_builder_.SetIsNewFormattingContext(is_new_bfc) |
| 485 .SetBfcOffset(curr_bfc_offset_); |
| 486 |
| 487 if (child->IsInline()) { |
| 479 // TODO(kojii): Setup space_builder_ appropriately for inline child. | 488 // TODO(kojii): Setup space_builder_ appropriately for inline child. |
| 480 space_builder_.SetBfcOffset(curr_bfc_offset_); | 489 space_builder_.SetBfcOffset(curr_bfc_offset_); |
| 481 return space_builder_.ToConstraintSpace( | 490 return space_builder_.ToConstraintSpace( |
| 482 FromPlatformWritingMode(Style().getWritingMode())); | 491 FromPlatformWritingMode(Style().getWritingMode())); |
| 483 } | 492 } |
| 484 | 493 |
| 485 const ComputedStyle& child_style = toNGBlockNode(child)->Style(); | 494 space_builder_ |
| 486 | |
| 487 bool is_new_bfc = IsNewFormattingContextForInFlowBlockLevelChild( | |
| 488 ConstraintSpace(), child_style); | |
| 489 space_builder_.SetIsNewFormattingContext(is_new_bfc) | |
| 490 .SetBfcOffset(curr_bfc_offset_) | |
| 491 .SetClearanceOffset( | 495 .SetClearanceOffset( |
| 492 GetClearanceOffset(constraint_space_->Exclusions(), child_style)) | 496 GetClearanceOffset(constraint_space_->Exclusions(), child_style)) |
| 493 .SetIsShrinkToFit(ShouldShrinkToFit(ConstraintSpace(), child_style)) | 497 .SetIsShrinkToFit(ShouldShrinkToFit(ConstraintSpace(), child_style)) |
| 494 .SetTextDirection(child_style.direction()); | 498 .SetTextDirection(child_style.direction()); |
| 495 | 499 |
| 496 // Float's margins are not included in child's space because: | 500 // Float's margins are not included in child's space because: |
| 497 // 1) Floats do not participate in margins collapsing. | 501 // 1) Floats do not participate in margins collapsing. |
| 498 // 2) Floats margins are used separately to calculate floating exclusions. | 502 // 2) Floats margins are used separately to calculate floating exclusions. |
| 499 space_builder_.SetMarginStrut(child_style.isFloating() ? NGMarginStrut() | 503 space_builder_.SetMarginStrut(child_style.isFloating() ? NGMarginStrut() |
| 500 : curr_margin_strut_); | 504 : curr_margin_strut_); |
| 501 | 505 |
| 502 LayoutUnit space_available; | 506 LayoutUnit space_available; |
| 503 if (constraint_space_->HasBlockFragmentation()) { | 507 if (constraint_space_->HasBlockFragmentation()) { |
| 504 space_available = ConstraintSpace().FragmentainerSpaceAvailable(); | 508 space_available = ConstraintSpace().FragmentainerSpaceAvailable(); |
| 505 // If a block establishes a new formatting context we must know our | 509 // If a block establishes a new formatting context we must know our |
| 506 // position in the formatting context, and are able to adjust the | 510 // position in the formatting context, and are able to adjust the |
| 507 // fragmentation line. | 511 // fragmentation line. |
| 508 if (is_new_bfc) { | 512 if (is_new_bfc) { |
| 509 DCHECK(builder_.BfcOffset()); | 513 DCHECK(builder_.BfcOffset()); |
| 510 space_available -= curr_bfc_offset_.block_offset; | 514 space_available -= curr_bfc_offset_.block_offset; |
| 515 // TODO(glebl): We need to reset BFCOffset in ToConstraintSpace() after we |
| 516 // started handling the fragmentation for floats. |
| 517 space_builder_.SetBfcOffset(NGLogicalOffset()); |
| 511 } | 518 } |
| 512 } | 519 } |
| 513 space_builder_.SetFragmentainerSpaceAvailable(space_available); | 520 space_builder_.SetFragmentainerSpaceAvailable(space_available); |
| 514 | 521 |
| 515 return space_builder_.ToConstraintSpace( | 522 return space_builder_.ToConstraintSpace( |
| 516 FromPlatformWritingMode(child_style.getWritingMode())); | 523 FromPlatformWritingMode(child_style.getWritingMode())); |
| 517 } | 524 } |
| 518 } // namespace blink | 525 } // namespace blink |
| OLD | NEW |