Chromium Code Reviews| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 == {} | 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 | 191 // 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. | 192 // still {} as the margin strut from the constraint space must also be empty. |
| 193 if (ConstraintSpace().IsNewFormattingContext()) { | 193 if (ConstraintSpace().IsNewFormattingContext()) { |
| 194 UpdateFragmentBfcOffset(curr_bfc_offset_); | 194 UpdateFragmentBfcOffset(curr_bfc_offset_); |
| 195 DCHECK_EQ(builder_.BfcOffset().value(), NGLogicalOffset()); | 195 DCHECK_EQ(builder_.BfcOffset().value(), NGLogicalOffset()); |
| 196 DCHECK_EQ(curr_margin_strut_, NGMarginStrut()); | 196 DCHECK_EQ(curr_margin_strut_, NGMarginStrut()); |
| 197 curr_bfc_offset_ = {}; | |
|
ikilpatrick
2017/03/24 21:17:34
can you add a todo here that this should be a DCHE
Gleb Lanbin
2017/03/24 21:49:36
Done.
| |
| 197 } | 198 } |
| 198 | 199 |
| 199 curr_bfc_offset_.block_offset += content_size_; | 200 curr_bfc_offset_.block_offset += content_size_; |
| 200 | 201 |
| 201 while (child) { | 202 while (child) { |
| 202 if (child->Type() == NGLayoutInputNode::kLegacyBlock) { | 203 if (child->Type() == NGLayoutInputNode::kLegacyBlock) { |
| 203 NGBlockNode* current_block_child = toNGBlockNode(child); | 204 NGBlockNode* current_block_child = toNGBlockNode(child); |
| 204 EPosition position = current_block_child->Style().position(); | 205 EPosition position = current_block_child->Style().position(); |
| 205 if (position == EPosition::kAbsolute || position == EPosition::kFixed) { | 206 if (position == EPosition::kAbsolute || position == EPosition::kFixed) { |
| 206 builder_.AddOutOfFlowChildCandidate(current_block_child, | 207 builder_.AddOutOfFlowChildCandidate(current_block_child, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 // Pull out unpositioned floats to the current fragment. This may needed if | 341 // Pull out unpositioned floats to the current fragment. This may needed if |
| 341 // for example the child fragment could not position its floats because it's | 342 // for example the child fragment could not position its floats because it's |
| 342 // empty and therefore couldn't determine its position in space. | 343 // empty and therefore couldn't determine its position in space. |
| 343 builder_.MutableUnpositionedFloats().appendVector( | 344 builder_.MutableUnpositionedFloats().appendVector( |
| 344 layout_result->UnpositionedFloats()); | 345 layout_result->UnpositionedFloats()); |
| 345 | 346 |
| 346 if (child->Type() == NGLayoutInputNode::kLegacyBlock && | 347 if (child->Type() == NGLayoutInputNode::kLegacyBlock && |
| 347 toNGBlockNode(child)->Style().isFloating()) { | 348 toNGBlockNode(child)->Style().isFloating()) { |
| 348 RefPtr<NGFloatingObject> floating_object = NGFloatingObject::Create( | 349 RefPtr<NGFloatingObject> floating_object = NGFloatingObject::Create( |
| 349 child_space, constraint_space_, toNGBlockNode(child)->Style(), | 350 child_space, constraint_space_, toNGBlockNode(child)->Style(), |
| 350 curr_child_margins_, layout_result->PhysicalFragment().get()); | 351 curr_child_margins_, child_space->AvailableSize(), |
| 352 layout_result->PhysicalFragment().get()); | |
| 351 builder_.AddUnpositionedFloat(floating_object); | 353 builder_.AddUnpositionedFloat(floating_object); |
| 352 // No need to postpone the positioning if we know the correct offset. | 354 // No need to postpone the positioning if we know the correct offset. |
| 353 if (builder_.BfcOffset()) { | 355 if (builder_.BfcOffset()) { |
| 354 NGLogicalOffset origin_point = curr_bfc_offset_; | 356 NGLogicalOffset origin_point = curr_bfc_offset_; |
| 355 // Adjust origin point to the margins of the last child. | 357 // Adjust origin point to the margins of the last child. |
| 356 // Example: <div style="margin-bottom: 20px"><float></div> | 358 // Example: <div style="margin-bottom: 20px"><float></div> |
| 357 // <div style="margin-bottom: 30px"></div> | 359 // <div style="margin-bottom: 30px"></div> |
| 358 origin_point.block_offset += curr_margin_strut_.Sum(); | 360 origin_point.block_offset += curr_margin_strut_.Sum(); |
| 359 PositionPendingFloats(origin_point.block_offset, MutableConstraintSpace(), | 361 PositionPendingFloats(origin_point.block_offset, MutableConstraintSpace(), |
| 360 &builder_); | 362 &builder_); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 | 481 |
| 480 if (child->Type() == NGLayoutInputNode::kLegacyInline) { | 482 if (child->Type() == NGLayoutInputNode::kLegacyInline) { |
| 481 // TODO(kojii): Setup space_builder_ appropriately for inline child. | 483 // TODO(kojii): Setup space_builder_ appropriately for inline child. |
| 482 space_builder_.SetBfcOffset(curr_bfc_offset_); | 484 space_builder_.SetBfcOffset(curr_bfc_offset_); |
| 483 return space_builder_.ToConstraintSpace( | 485 return space_builder_.ToConstraintSpace( |
| 484 FromPlatformWritingMode(Style().getWritingMode())); | 486 FromPlatformWritingMode(Style().getWritingMode())); |
| 485 } | 487 } |
| 486 | 488 |
| 487 const ComputedStyle& child_style = toNGBlockNode(child)->Style(); | 489 const ComputedStyle& child_style = toNGBlockNode(child)->Style(); |
| 488 | 490 |
| 489 bool is_new_bfc = IsNewFormattingContextForInFlowBlockLevelChild( | 491 bool is_new_bfc = |
| 490 ConstraintSpace(), child_style); | 492 IsNewFormattingContextForBlockLevelChild(ConstraintSpace(), child_style); |
| 491 space_builder_.SetIsNewFormattingContext(is_new_bfc) | 493 space_builder_.SetIsNewFormattingContext(is_new_bfc) |
| 492 .SetBfcOffset(curr_bfc_offset_) | 494 .SetBfcOffset(curr_bfc_offset_) |
| 493 .SetClearanceOffset( | 495 .SetClearanceOffset( |
| 494 GetClearanceOffset(constraint_space_->Exclusions(), child_style)) | 496 GetClearanceOffset(constraint_space_->Exclusions(), child_style)) |
| 495 .SetIsShrinkToFit(ShouldShrinkToFit(ConstraintSpace(), child_style)) | 497 .SetIsShrinkToFit(ShouldShrinkToFit(ConstraintSpace(), child_style)) |
| 496 .SetTextDirection(child_style.direction()); | 498 .SetTextDirection(child_style.direction()); |
| 497 | 499 |
| 498 // Float's margins are not included in child's space because: | 500 // Float's margins are not included in child's space because: |
| 499 // 1) Floats do not participate in margins collapsing. | 501 // 1) Floats do not participate in margins collapsing. |
| 500 // 2) Floats margins are used separately to calculate floating exclusions. | 502 // 2) Floats margins are used separately to calculate floating exclusions. |
| 501 space_builder_.SetMarginStrut(child_style.isFloating() ? NGMarginStrut() | 503 space_builder_.SetMarginStrut(child_style.isFloating() ? NGMarginStrut() |
| 502 : curr_margin_strut_); | 504 : curr_margin_strut_); |
| 503 | 505 |
| 504 LayoutUnit space_available; | 506 LayoutUnit space_available; |
| 505 if (constraint_space_->HasBlockFragmentation()) { | 507 if (constraint_space_->HasBlockFragmentation()) { |
| 506 space_available = ConstraintSpace().FragmentainerSpaceAvailable(); | 508 space_available = ConstraintSpace().FragmentainerSpaceAvailable(); |
| 507 // 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 |
| 508 // position in the formatting context, and are able to adjust the | 510 // position in the formatting context, and are able to adjust the |
| 509 // fragmentation line. | 511 // fragmentation line. |
| 510 if (is_new_bfc) { | 512 if (is_new_bfc) { |
| 511 DCHECK(builder_.BfcOffset()); | 513 DCHECK(builder_.BfcOffset()); |
| 512 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()); | |
| 513 } | 518 } |
| 514 } | 519 } |
| 515 space_builder_.SetFragmentainerSpaceAvailable(space_available); | 520 space_builder_.SetFragmentainerSpaceAvailable(space_available); |
| 516 | 521 |
| 517 return space_builder_.ToConstraintSpace( | 522 return space_builder_.ToConstraintSpace( |
| 518 FromPlatformWritingMode(child_style.getWritingMode())); | 523 FromPlatformWritingMode(child_style.getWritingMode())); |
| 519 } | 524 } |
| 520 } // namespace blink | 525 } // namespace blink |
| OLD | NEW |