Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 3619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3630 FloatingObjectSetIterator end = floatingObjectSet.end(); | 3630 FloatingObjectSetIterator end = floatingObjectSet.end(); |
| 3631 // Now walk through the set of unpositioned floats and place them. | 3631 // Now walk through the set of unpositioned floats and place them. |
| 3632 for (; it != end; ++it) { | 3632 for (; it != end; ++it) { |
| 3633 FloatingObject& floatingObject = *it->get(); | 3633 FloatingObject& floatingObject = *it->get(); |
| 3634 // The containing block is responsible for positioning floats, so if we have | 3634 // The containing block is responsible for positioning floats, so if we have |
| 3635 // floats in our list that come from somewhere else, do not attempt to | 3635 // floats in our list that come from somewhere else, do not attempt to |
| 3636 // position them. | 3636 // position them. |
| 3637 if (floatingObject.layoutObject()->containingBlock() != this) | 3637 if (floatingObject.layoutObject()->containingBlock() != this) |
| 3638 continue; | 3638 continue; |
| 3639 | 3639 |
| 3640 LayoutBox* childBox = floatingObject.layoutObject(); | 3640 positionAndLayoutFloat(floatingObject, logicalTop); |
|
mstensho (USE GERRIT)
2016/11/16 10:18:59
Oops! Forgot to actually update logicalTop here. p
mstensho (USE GERRIT)
2016/11/16 10:28:13
See crbug.com/665804
| |
| 3641 | |
| 3642 // FIXME Investigate if this can be removed. crbug.com/370006 | |
| 3643 childBox->setMayNeedPaintInvalidation(); | |
| 3644 | |
| 3645 LayoutUnit childLogicalLeftMargin = style()->isLeftToRightDirection() | |
| 3646 ? marginStartForChild(*childBox) | |
| 3647 : marginEndForChild(*childBox); | |
| 3648 if (childBox->style()->clear() & ClearLeft) | |
| 3649 logicalTop = std::max(lowestFloatLogicalBottom(FloatingObject::FloatLeft), | |
| 3650 logicalTop); | |
| 3651 if (childBox->style()->clear() & ClearRight) | |
| 3652 logicalTop = std::max( | |
| 3653 lowestFloatLogicalBottom(FloatingObject::FloatRight), logicalTop); | |
| 3654 | |
| 3655 bool isPaginated = view()->layoutState()->isPaginated(); | |
| 3656 if (isPaginated && !childrenInline()) { | |
| 3657 // Forced breaks are inserted at class A break points. Floats may be | |
| 3658 // affected by a break-after value on the previous in-flow sibling. | |
| 3659 if (LayoutBox* previousInFlowBox = childBox->previousInFlowSiblingBox()) | |
| 3660 logicalTop = | |
| 3661 applyForcedBreak(logicalTop, previousInFlowBox->breakAfter()); | |
| 3662 } | |
| 3663 | |
| 3664 LayoutPoint floatLogicalLocation = | |
| 3665 computeLogicalLocationForFloat(floatingObject, logicalTop); | |
| 3666 | |
| 3667 setLogicalLeftForFloat(floatingObject, floatLogicalLocation.x()); | |
| 3668 | |
| 3669 setLogicalLeftForChild(*childBox, | |
| 3670 floatLogicalLocation.x() + childLogicalLeftMargin); | |
| 3671 setLogicalTopForChild( | |
| 3672 *childBox, floatLogicalLocation.y() + marginBeforeForChild(*childBox)); | |
| 3673 | |
| 3674 SubtreeLayoutScope layoutScope(*childBox); | |
| 3675 if (isPaginated && !childBox->needsLayout()) | |
| 3676 markChildForPaginationRelayoutIfNeeded(*childBox, layoutScope); | |
| 3677 | |
| 3678 childBox->layoutIfNeeded(); | |
| 3679 | |
| 3680 if (isPaginated) { | |
| 3681 LayoutBlockFlow* childBlockFlow = | |
| 3682 childBox->isLayoutBlockFlow() ? toLayoutBlockFlow(childBox) : nullptr; | |
| 3683 // The first piece of content inside the child may have set a strut during | |
| 3684 // layout. | |
| 3685 LayoutUnit strut = | |
| 3686 childBlockFlow ? childBlockFlow->paginationStrutPropagatedFromChild() | |
| 3687 : LayoutUnit(); | |
| 3688 | |
| 3689 LayoutUnit marginBefore = marginBeforeForChild(*childBox); | |
| 3690 if (marginBefore > LayoutUnit()) { | |
| 3691 // Avoid breaking inside the top margin of a float. | |
| 3692 if (strut) { | |
| 3693 // If we already had decided to break, just add the margin. The strut | |
| 3694 // so far only accounts for pushing the top border edge to the next | |
| 3695 // fragmentainer. We need to push the margin over as well, because | |
| 3696 // there's no break opportunity between margin and border. | |
| 3697 strut += marginBefore; | |
| 3698 } else { | |
| 3699 // Even if we didn't break before the border box to the next | |
| 3700 // fragmentainer, we need to check if we can fit the margin before | |
| 3701 // it. | |
| 3702 LayoutUnit marginEdge = childBox->logicalTop() - marginBefore; | |
| 3703 if (LayoutUnit pageHeight = pageLogicalHeightForOffset(marginEdge)) { | |
| 3704 LayoutUnit remainingSpace = pageRemainingLogicalHeightForOffset( | |
| 3705 marginEdge, AssociateWithLatterPage); | |
| 3706 if (remainingSpace <= marginBefore) | |
| 3707 strut += remainingSpace; | |
| 3708 } | |
| 3709 } | |
| 3710 } | |
| 3711 if (!strut) { | |
| 3712 // If we are unsplittable and don't fit, move to the next page or column | |
| 3713 // if that helps the situation. | |
| 3714 strut = | |
| 3715 adjustForUnsplittableChild(*childBox, floatLogicalLocation.y()) - | |
| 3716 floatLogicalLocation.y(); | |
| 3717 } | |
| 3718 | |
| 3719 childBox->setPaginationStrut(strut); | |
| 3720 if (strut) { | |
| 3721 floatLogicalLocation = computeLogicalLocationForFloat( | |
| 3722 floatingObject, floatLogicalLocation.y() + strut); | |
| 3723 setLogicalLeftForFloat(floatingObject, floatLogicalLocation.x()); | |
| 3724 | |
| 3725 setLogicalLeftForChild( | |
| 3726 *childBox, floatLogicalLocation.x() + childLogicalLeftMargin); | |
| 3727 setLogicalTopForChild(*childBox, floatLogicalLocation.y() + | |
| 3728 marginBeforeForChild(*childBox)); | |
| 3729 | |
| 3730 if (childBox->isLayoutBlock()) | |
| 3731 childBox->setChildNeedsLayout(MarkOnlyThis); | |
| 3732 childBox->layoutIfNeeded(); | |
| 3733 } | |
| 3734 } | |
| 3735 | |
| 3736 setLogicalTopForFloat(floatingObject, floatLogicalLocation.y()); | |
| 3737 | |
| 3738 setLogicalHeightForFloat(floatingObject, | |
| 3739 logicalHeightForChild(*childBox) + | |
| 3740 marginBeforeForChild(*childBox) + | |
| 3741 marginAfterForChild(*childBox)); | |
| 3742 | 3641 |
| 3743 m_floatingObjects->addPlacedObject(floatingObject); | 3642 m_floatingObjects->addPlacedObject(floatingObject); |
| 3744 | 3643 |
| 3745 if (ShapeOutsideInfo* shapeOutside = childBox->shapeOutsideInfo()) | |
| 3746 shapeOutside->setReferenceBoxLogicalSize(logicalSizeForChild(*childBox)); | |
| 3747 | |
| 3748 if (width) | 3644 if (width) |
| 3749 width->shrinkAvailableWidthForNewFloatIfNeeded(floatingObject); | 3645 width->shrinkAvailableWidthForNewFloatIfNeeded(floatingObject); |
| 3750 } | 3646 } |
| 3751 return true; | 3647 return true; |
| 3752 } | 3648 } |
| 3753 | 3649 |
| 3650 LayoutUnit LayoutBlockFlow::positionAndLayoutFloat( | |
| 3651 FloatingObject& floatingObject, | |
| 3652 LayoutUnit logicalTop) { | |
| 3653 LayoutBox& childBox = *floatingObject.layoutObject(); | |
| 3654 | |
| 3655 // FIXME Investigate if this can be removed. crbug.com/370006 | |
| 3656 childBox.setMayNeedPaintInvalidation(); | |
| 3657 | |
| 3658 LayoutUnit childLogicalLeftMargin = style()->isLeftToRightDirection() | |
| 3659 ? marginStartForChild(childBox) | |
| 3660 : marginEndForChild(childBox); | |
| 3661 if (childBox.style()->clear() & ClearLeft) { | |
| 3662 logicalTop = std::max(lowestFloatLogicalBottom(FloatingObject::FloatLeft), | |
| 3663 logicalTop); | |
| 3664 } | |
| 3665 if (childBox.style()->clear() & ClearRight) { | |
| 3666 logicalTop = std::max(lowestFloatLogicalBottom(FloatingObject::FloatRight), | |
| 3667 logicalTop); | |
| 3668 } | |
| 3669 | |
| 3670 bool isPaginated = view()->layoutState()->isPaginated(); | |
| 3671 if (isPaginated && !childrenInline()) { | |
| 3672 // Forced breaks are inserted at class A break points. Floats may be | |
| 3673 // affected by a break-after value on the previous in-flow sibling. | |
| 3674 if (LayoutBox* previousInFlowBox = childBox.previousInFlowSiblingBox()) { | |
| 3675 logicalTop = | |
| 3676 applyForcedBreak(logicalTop, previousInFlowBox->breakAfter()); | |
| 3677 } | |
| 3678 } | |
| 3679 | |
| 3680 LayoutPoint floatLogicalLocation = | |
| 3681 computeLogicalLocationForFloat(floatingObject, logicalTop); | |
| 3682 | |
| 3683 setLogicalLeftForFloat(floatingObject, floatLogicalLocation.x()); | |
| 3684 | |
| 3685 setLogicalLeftForChild(childBox, | |
| 3686 floatLogicalLocation.x() + childLogicalLeftMargin); | |
| 3687 setLogicalTopForChild( | |
| 3688 childBox, floatLogicalLocation.y() + marginBeforeForChild(childBox)); | |
| 3689 | |
| 3690 SubtreeLayoutScope layoutScope(childBox); | |
| 3691 if (isPaginated && !childBox.needsLayout()) | |
| 3692 markChildForPaginationRelayoutIfNeeded(childBox, layoutScope); | |
| 3693 | |
| 3694 childBox.layoutIfNeeded(); | |
| 3695 | |
| 3696 if (isPaginated) { | |
| 3697 LayoutBlockFlow* childBlockFlow = | |
| 3698 childBox.isLayoutBlockFlow() ? toLayoutBlockFlow(&childBox) : nullptr; | |
| 3699 // The first piece of content inside the child may have set a strut during | |
| 3700 // layout. | |
| 3701 LayoutUnit strut = | |
| 3702 childBlockFlow ? childBlockFlow->paginationStrutPropagatedFromChild() | |
| 3703 : LayoutUnit(); | |
| 3704 | |
| 3705 LayoutUnit marginBefore = marginBeforeForChild(childBox); | |
| 3706 if (marginBefore > LayoutUnit()) { | |
| 3707 // Avoid breaking inside the top margin of a float. | |
| 3708 if (strut) { | |
| 3709 // If we already had decided to break, just add the margin. The strut | |
| 3710 // so far only accounts for pushing the top border edge to the next | |
| 3711 // fragmentainer. We need to push the margin over as well, because | |
| 3712 // there's no break opportunity between margin and border. | |
| 3713 strut += marginBefore; | |
| 3714 } else { | |
| 3715 // Even if we didn't break before the border box to the next | |
| 3716 // fragmentainer, we need to check if we can fit the margin before | |
| 3717 // it. | |
| 3718 LayoutUnit marginEdge = childBox.logicalTop() - marginBefore; | |
| 3719 if (LayoutUnit pageHeight = pageLogicalHeightForOffset(marginEdge)) { | |
| 3720 LayoutUnit remainingSpace = pageRemainingLogicalHeightForOffset( | |
| 3721 marginEdge, AssociateWithLatterPage); | |
| 3722 if (remainingSpace <= marginBefore) | |
| 3723 strut += remainingSpace; | |
| 3724 } | |
| 3725 } | |
| 3726 } | |
| 3727 if (!strut) { | |
| 3728 // If we are unsplittable and don't fit, move to the next page or column | |
| 3729 // if that helps the situation. | |
| 3730 strut = adjustForUnsplittableChild(childBox, floatLogicalLocation.y()) - | |
| 3731 floatLogicalLocation.y(); | |
| 3732 } | |
| 3733 | |
| 3734 childBox.setPaginationStrut(strut); | |
| 3735 if (strut) { | |
| 3736 floatLogicalLocation = computeLogicalLocationForFloat( | |
| 3737 floatingObject, floatLogicalLocation.y() + strut); | |
| 3738 setLogicalLeftForFloat(floatingObject, floatLogicalLocation.x()); | |
| 3739 | |
| 3740 setLogicalLeftForChild(childBox, | |
| 3741 floatLogicalLocation.x() + childLogicalLeftMargin); | |
| 3742 setLogicalTopForChild( | |
| 3743 childBox, floatLogicalLocation.y() + marginBeforeForChild(childBox)); | |
| 3744 | |
| 3745 if (childBox.isLayoutBlock()) | |
| 3746 childBox.setChildNeedsLayout(MarkOnlyThis); | |
| 3747 childBox.layoutIfNeeded(); | |
| 3748 } | |
| 3749 } | |
| 3750 | |
| 3751 setLogicalTopForFloat(floatingObject, floatLogicalLocation.y()); | |
| 3752 | |
| 3753 setLogicalHeightForFloat(floatingObject, logicalHeightForChild(childBox) + | |
| 3754 marginBeforeForChild(childBox) + | |
| 3755 marginAfterForChild(childBox)); | |
| 3756 | |
| 3757 if (ShapeOutsideInfo* shapeOutside = childBox.shapeOutsideInfo()) | |
| 3758 shapeOutside->setReferenceBoxLogicalSize(logicalSizeForChild(childBox)); | |
| 3759 | |
| 3760 return floatLogicalLocation.y(); | |
| 3761 } | |
| 3762 | |
| 3754 bool LayoutBlockFlow::hasOverhangingFloat(LayoutBox* layoutBox) { | 3763 bool LayoutBlockFlow::hasOverhangingFloat(LayoutBox* layoutBox) { |
| 3755 if (!m_floatingObjects || !parent()) | 3764 if (!m_floatingObjects || !parent()) |
| 3756 return false; | 3765 return false; |
| 3757 | 3766 |
| 3758 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); | 3767 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); |
| 3759 FloatingObjectSetIterator it = | 3768 FloatingObjectSetIterator it = |
| 3760 floatingObjectSet.find<FloatingObjectHashTranslator>(layoutBox); | 3769 floatingObjectSet.find<FloatingObjectHashTranslator>(layoutBox); |
| 3761 if (it == floatingObjectSet.end()) | 3770 if (it == floatingObjectSet.end()) |
| 3762 return false; | 3771 return false; |
| 3763 | 3772 |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4566 return LayoutBlock::invalidatePaintIfNeeded(paintInvalidationState); | 4575 return LayoutBlock::invalidatePaintIfNeeded(paintInvalidationState); |
| 4567 } | 4576 } |
| 4568 | 4577 |
| 4569 void LayoutBlockFlow::invalidateDisplayItemClients( | 4578 void LayoutBlockFlow::invalidateDisplayItemClients( |
| 4570 PaintInvalidationReason invalidationReason) const { | 4579 PaintInvalidationReason invalidationReason) const { |
| 4571 BlockFlowPaintInvalidator(*this).invalidateDisplayItemClients( | 4580 BlockFlowPaintInvalidator(*this).invalidateDisplayItemClients( |
| 4572 invalidationReason); | 4581 invalidationReason); |
| 4573 } | 4582 } |
| 4574 | 4583 |
| 4575 } // namespace blink | 4584 } // namespace blink |
| OLD | NEW |