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/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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 const NGBoxFragment& fragment, | 409 const NGBoxFragment& fragment, |
410 const NGConstraintSpace& child_space) { | 410 const NGConstraintSpace& child_space) { |
411 // 1. Position all pending floats to a temporary space. | 411 // 1. Position all pending floats to a temporary space. |
412 RefPtr<NGConstraintSpace> tmp_space = | 412 RefPtr<NGConstraintSpace> tmp_space = |
413 NGConstraintSpaceBuilder(&child_space) | 413 NGConstraintSpaceBuilder(&child_space) |
414 .SetIsNewFormattingContext(false) | 414 .SetIsNewFormattingContext(false) |
415 .ToConstraintSpace(child_space.WritingMode()); | 415 .ToConstraintSpace(child_space.WritingMode()); |
416 PositionFloats(curr_bfc_offset_.block_offset, curr_bfc_offset_.block_offset, | 416 PositionFloats(curr_bfc_offset_.block_offset, curr_bfc_offset_.block_offset, |
417 container_builder_.UnpositionedFloats(), tmp_space.Get()); | 417 container_builder_.UnpositionedFloats(), tmp_space.Get()); |
418 | 418 |
| 419 NGLogicalOffset origin_offset = curr_bfc_offset_; |
| 420 origin_offset.inline_offset += border_and_padding_.inline_start; |
| 421 |
419 // 2. Find an estimated layout opportunity for our fragment. | 422 // 2. Find an estimated layout opportunity for our fragment. |
420 NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( | 423 NGLayoutOpportunity opportunity = FindLayoutOpportunityForFragment( |
421 tmp_space->Exclusions().get(), child_space.AvailableSize(), | 424 tmp_space->Exclusions().get(), child_space.AvailableSize(), origin_offset, |
422 curr_bfc_offset_, curr_child_margins_, fragment); | 425 curr_child_margins_, fragment); |
423 | 426 |
424 // 3. If the found opportunity lies on the same line with our estimated | 427 // 3. If the found opportunity lies on the same line with our estimated |
425 // child's BFC offset then merge fragment's margins with the current | 428 // child's BFC offset then merge fragment's margins with the current |
426 // MarginStrut. | 429 // MarginStrut. |
427 if (opportunity.offset.block_offset == curr_bfc_offset_.block_offset) | 430 if (opportunity.offset.block_offset == curr_bfc_offset_.block_offset) |
428 curr_margin_strut_.Append(curr_child_margins_.block_start); | 431 curr_margin_strut_.Append(curr_child_margins_.block_start); |
429 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); | 432 curr_bfc_offset_.block_offset += curr_margin_strut_.Sum(); |
430 curr_margin_strut_ = {}; | 433 curr_margin_strut_ = {}; |
431 | 434 |
432 // 4. The child's BFC block offset is known here. | 435 // 4. The child's BFC block offset is known here. |
433 MaybeUpdateFragmentBfcOffset(ConstraintSpace(), curr_bfc_offset_, | 436 MaybeUpdateFragmentBfcOffset(ConstraintSpace(), curr_bfc_offset_, |
434 &container_builder_); | 437 &container_builder_); |
435 PositionPendingFloats(curr_bfc_offset_.block_offset, &container_builder_, | 438 PositionPendingFloats(curr_bfc_offset_.block_offset, &container_builder_, |
436 MutableConstraintSpace()); | 439 MutableConstraintSpace()); |
437 | 440 |
| 441 origin_offset = curr_bfc_offset_; |
| 442 origin_offset.inline_offset += border_and_padding_.inline_start; |
| 443 |
438 // 5. Find the final layout opportunity for the fragment after all pending | 444 // 5. Find the final layout opportunity for the fragment after all pending |
439 // floats are positioned at the correct BFC block's offset. | 445 // floats are positioned at the correct BFC block's offset. |
440 opportunity = FindLayoutOpportunityForFragment( | 446 opportunity = FindLayoutOpportunityForFragment( |
441 MutableConstraintSpace()->Exclusions().get(), child_space.AvailableSize(), | 447 MutableConstraintSpace()->Exclusions().get(), child_space.AvailableSize(), |
442 curr_bfc_offset_, curr_child_margins_, fragment); | 448 origin_offset, curr_child_margins_, fragment); |
443 | 449 |
444 curr_bfc_offset_ = opportunity.offset; | 450 curr_bfc_offset_ = opportunity.offset; |
445 return curr_bfc_offset_; | 451 return curr_bfc_offset_; |
446 } | 452 } |
447 | 453 |
448 NGLogicalOffset NGBlockLayoutAlgorithm::PositionWithBfcOffset( | 454 NGLogicalOffset NGBlockLayoutAlgorithm::PositionWithBfcOffset( |
449 const NGBoxFragment& fragment) { | 455 const NGBoxFragment& fragment) { |
450 DCHECK(fragment.BfcOffset()); | 456 DCHECK(fragment.BfcOffset()); |
451 curr_bfc_offset_.block_offset = fragment.BfcOffset().value().block_offset; | 457 curr_bfc_offset_.block_offset = fragment.BfcOffset().value().block_offset; |
452 MaybeUpdateFragmentBfcOffset(ConstraintSpace(), curr_bfc_offset_, | 458 MaybeUpdateFragmentBfcOffset(ConstraintSpace(), curr_bfc_offset_, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 if (is_new_bfc) { | 591 if (is_new_bfc) { |
586 space_available -= child_bfc_offset.block_offset; | 592 space_available -= child_bfc_offset.block_offset; |
587 } | 593 } |
588 } | 594 } |
589 space_builder_.SetFragmentainerSpaceAvailable(space_available); | 595 space_builder_.SetFragmentainerSpaceAvailable(space_available); |
590 | 596 |
591 return space_builder_.ToConstraintSpace( | 597 return space_builder_.ToConstraintSpace( |
592 FromPlatformWritingMode(child_style.GetWritingMode())); | 598 FromPlatformWritingMode(child_style.GetWritingMode())); |
593 } | 599 } |
594 } // namespace blink | 600 } // namespace blink |
OLD | NEW |