Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) | 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
| 7 * Copyright (C) 2010 Google Inc. All rights reserved. | 7 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 628 && (!containingBlock->hasAutoHeightOrContainingBlockWithAutoHeight() | 628 && (!containingBlock->hasAutoHeightOrContainingBlockWithAutoHeight() |
| 629 || !style()->bottom().hasPercent() | 629 || !style()->bottom().hasPercent() |
| 630 || containingBlock->stretchesToViewport())) | 630 || containingBlock->stretchesToViewport())) |
| 631 offset.expand(LayoutUnit(), -valueForLength(style()->bottom(), containin gBlock->availableHeight())); | 631 offset.expand(LayoutUnit(), -valueForLength(style()->bottom(), containin gBlock->availableHeight())); |
| 632 | 632 |
| 633 return offset; | 633 return offset; |
| 634 } | 634 } |
| 635 | 635 |
| 636 void LayoutBoxModelObject::updateStickyPositionConstraints() const | 636 void LayoutBoxModelObject::updateStickyPositionConstraints() const |
| 637 { | 637 { |
| 638 // TODO(flackr): This method is reasonably complicated and should have some direct unit testing. | |
| 639 const FloatSize constrainingSize = computeStickyConstrainingRect().size(); | 638 const FloatSize constrainingSize = computeStickyConstrainingRect().size(); |
| 640 | 639 |
| 641 PaintLayerScrollableArea* scrollableArea = layer()->ancestorOverflowLayer()- >getScrollableArea(); | 640 PaintLayerScrollableArea* scrollableArea = layer()->ancestorOverflowLayer()- >getScrollableArea(); |
| 642 StickyPositionScrollingConstraints constraints; | 641 StickyPositionScrollingConstraints constraints; |
| 643 FloatSize skippedContainersOffset; | 642 FloatSize skippedContainersOffset; |
| 644 LayoutBlock* containingBlock = this->containingBlock(); | 643 LayoutBlock* containingBlock = this->containingBlock(); |
| 645 // Skip anonymous containing blocks. | 644 // Skip anonymous containing blocks. |
| 646 while (containingBlock->isAnonymous()) { | 645 while (containingBlock->isAnonymous()) { |
| 647 skippedContainersOffset += toFloatSize(FloatPoint(containingBlock->frame Rect().location())); | 646 skippedContainersOffset += toFloatSize(FloatPoint(containingBlock->frame Rect().location())); |
| 648 containingBlock = containingBlock->containingBlock(); | 647 containingBlock = containingBlock->containingBlock(); |
| 649 } | 648 } |
| 650 LayoutBox* scrollAncestor = layer()->ancestorOverflowLayer()->isRootLayer() ? nullptr : toLayoutBox(layer()->ancestorOverflowLayer()->layoutObject()); | 649 LayoutBox* scrollAncestor = layer()->ancestorOverflowLayer()->isRootLayer() ? nullptr : toLayoutBox(layer()->ancestorOverflowLayer()->layoutObject()); |
| 651 | 650 |
| 652 LayoutRect containerContentRect = containingBlock->contentBoxRect(); | 651 LayoutRect containerContentRect = containingBlock->layoutOverflowRect(); |
| 653 LayoutUnit maxWidth = containingBlock->availableLogicalWidth(); | 652 LayoutUnit maxContainerWidth = containingBlock->containingBlockLogicalWidthF orContent(); |
| 654 | |
| 655 // Sticky positioned element ignore any override logical width on the contai ning block (as they don't call | 653 // Sticky positioned element ignore any override logical width on the contai ning block (as they don't call |
| 656 // containingBlockLogicalWidthForContent). It's unclear whether this is tota lly fine. | 654 // containingBlockLogicalWidthForContent). It's unclear whether this is tota lly fine. |
|
chrishtr
2016/06/13 19:46:39
Is this comment obsolete now that you are calling
flackr
2016/06/15 13:45:49
No, we're only calling containingBlockLogicalWidth
| |
| 657 // Compute the container-relative area within which the sticky element is al lowed to move. | 655 // Compute the container-relative area within which the sticky element is al lowed to move. |
| 656 LayoutUnit maxWidth = containingBlock->availableLogicalWidth(); | |
|
chrishtr
2016/06/13 19:46:39
Add a comment explaining that this is padding of c
flackr
2016/06/15 13:45:49
Done.
| |
| 658 containerContentRect.contractEdges( | 657 containerContentRect.contractEdges( |
| 659 minimumValueForLength(style()->marginTop(), maxWidth), | 658 minimumValueForLength(containingBlock->style()->paddingTop(), maxContain erWidth) + minimumValueForLength(style()->marginTop(), maxWidth), |
| 660 minimumValueForLength(style()->marginRight(), maxWidth), | 659 minimumValueForLength(containingBlock->style()->paddingRight(), maxConta inerWidth) + minimumValueForLength(style()->marginRight(), maxWidth), |
| 661 minimumValueForLength(style()->marginBottom(), maxWidth), | 660 minimumValueForLength(containingBlock->style()->paddingBottom(), maxCont ainerWidth) + minimumValueForLength(style()->marginBottom(), maxWidth), |
| 662 minimumValueForLength(style()->marginLeft(), maxWidth)); | 661 minimumValueForLength(containingBlock->style()->paddingLeft(), maxContai nerWidth) + minimumValueForLength(style()->marginLeft(), maxWidth)); |
| 663 | 662 |
| 664 // Map to the scroll ancestor. | 663 // Map to the scroll ancestor. |
| 665 constraints.setScrollContainerRelativeContainingBlockRect(containingBlock->l ocalToAncestorQuad(FloatRect(containerContentRect), scrollAncestor).boundingBox( )); | 664 FloatRect scrollContainerRelativeContainingBlockRect(containingBlock->localT oAncestorQuad(FloatRect(containerContentRect), scrollAncestor).boundingBox()); |
| 665 FloatSize scrollOffset(scrollAncestor ? toFloatSize(scrollAncestor->getScrol lableArea()->adjustedScrollOffset()) : FloatSize()); | |
| 666 | |
| 667 // Include scroll offset in container position if the container is not our s croll ancestor. | |
| 668 if (containingBlock != scrollAncestor) | |
| 669 scrollContainerRelativeContainingBlockRect.move(scrollOffset); | |
| 670 constraints.setScrollContainerRelativeContainingBlockRect(scrollContainerRel ativeContainingBlockRect); | |
| 666 | 671 |
| 667 FloatRect stickyBoxRect = isLayoutInline() | 672 FloatRect stickyBoxRect = isLayoutInline() |
| 668 ? FloatRect(toLayoutInline(this)->linesBoundingBox()) | 673 ? FloatRect(toLayoutInline(this)->linesBoundingBox()) |
| 669 : FloatRect(toLayoutBox(this)->frameRect()); | 674 : FloatRect(toLayoutBox(this)->frameRect()); |
| 670 FloatRect flippedStickyBoxRect = stickyBoxRect; | 675 FloatRect flippedStickyBoxRect = stickyBoxRect; |
| 671 containingBlock->flipForWritingMode(flippedStickyBoxRect); | 676 containingBlock->flipForWritingMode(flippedStickyBoxRect); |
| 672 FloatPoint stickyLocation = flippedStickyBoxRect.location() + skippedContain ersOffset; | 677 FloatPoint stickyLocation = flippedStickyBoxRect.location() + skippedContain ersOffset; |
| 673 | 678 |
| 674 // TODO(flackr): Unfortunate to call localToAncestorQuad again, but we can't just offset from the previously computed rect if there are transforms. | 679 // TODO(flackr): Unfortunate to call localToAncestorQuad again, but we can't just offset from the previously computed rect if there are transforms. |
| 675 // Map to the scroll ancestor. | 680 // Map to the scroll ancestor. |
| 676 FloatRect scrollContainerRelativeContainerFrame = containingBlock->localToAn cestorQuad(FloatRect(FloatPoint(), FloatSize(containingBlock->size())), scrollAn cestor).boundingBox(); | 681 FloatRect scrollContainerRelativeContainerFrame = containingBlock->localToAn cestorQuad(FloatRect(FloatPoint(), FloatSize(containingBlock->size())), scrollAn cestor).boundingBox(); |
| 682 scrollContainerRelativeContainerFrame.move(scrollOffset); | |
| 677 | 683 |
| 678 // If the containing block is our scroll ancestor, its location will not inc lude the scroll offset which we need to include as | 684 // If the containing block is our scroll ancestor, its location will not inc lude the scroll offset which we need to include as |
| 679 // part of the sticky box rect so we include it here. | 685 // part of the sticky box rect so we include it here. |
| 680 if (containingBlock->hasOverflowClip()) { | 686 if (containingBlock == scrollAncestor) |
| 681 FloatSize scrollOffset(toFloatSize(containingBlock->layer()->getScrollab leArea()->adjustedScrollOffset())); | |
| 682 stickyLocation -= scrollOffset; | 687 stickyLocation -= scrollOffset; |
| 683 } | |
| 684 | 688 |
| 685 constraints.setScrollContainerRelativeStickyBoxRect(FloatRect(scrollContaine rRelativeContainerFrame.location() + toFloatSize(stickyLocation), flippedStickyB oxRect.size())); | 689 constraints.setScrollContainerRelativeStickyBoxRect(FloatRect(scrollContaine rRelativeContainerFrame.location() + toFloatSize(stickyLocation), flippedStickyB oxRect.size())); |
| 686 | 690 |
| 687 // We skip the right or top sticky offset if there is not enough space to ho nor both the left/right or top/bottom offsets. | 691 // We skip the right or top sticky offset if there is not enough space to ho nor both the left/right or top/bottom offsets. |
| 688 LayoutUnit horizontalOffsets = minimumValueForLength(style()->right(), Layou tUnit(constrainingSize.width())) + | 692 LayoutUnit horizontalOffsets = minimumValueForLength(style()->right(), Layou tUnit(constrainingSize.width())) + |
| 689 minimumValueForLength(style()->left(), LayoutUnit(constrainingSize.width ())); | 693 minimumValueForLength(style()->left(), LayoutUnit(constrainingSize.width ())); |
| 690 bool skipRight = false; | 694 bool skipRight = false; |
| 691 bool skipLeft = false; | 695 bool skipLeft = false; |
| 692 if (!style()->left().isAuto() && !style()->right().isAuto()) { | 696 if (!style()->left().isAuto() && !style()->right().isAuto()) { |
| 693 if (horizontalOffsets > containerContentRect.width() | 697 if (horizontalOffsets > containerContentRect.width() |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 731 scrollableArea->stickyConstraintsMap().set(layer(), constraints); | 735 scrollableArea->stickyConstraintsMap().set(layer(), constraints); |
| 732 } | 736 } |
| 733 | 737 |
| 734 FloatRect LayoutBoxModelObject::computeStickyConstrainingRect() const | 738 FloatRect LayoutBoxModelObject::computeStickyConstrainingRect() const |
| 735 { | 739 { |
| 736 if (layer()->ancestorOverflowLayer()->isRootLayer()) | 740 if (layer()->ancestorOverflowLayer()->isRootLayer()) |
| 737 return view()->frameView()->visibleContentRect(); | 741 return view()->frameView()->visibleContentRect(); |
| 738 | 742 |
| 739 LayoutBox* enclosingClippingBox = toLayoutBox(layer()->ancestorOverflowLayer ()->layoutObject()); | 743 LayoutBox* enclosingClippingBox = toLayoutBox(layer()->ancestorOverflowLayer ()->layoutObject()); |
| 740 FloatRect constrainingRect; | 744 FloatRect constrainingRect; |
| 741 constrainingRect = FloatRect(enclosingClippingBox->overflowClipRect(LayoutPo int())); | 745 constrainingRect = FloatRect(enclosingClippingBox->overflowClipRect(LayoutPo int(DoublePoint(enclosingClippingBox->getScrollableArea()->adjustedScrollOffset( ))))); |
| 742 constrainingRect.move(enclosingClippingBox->paddingLeft(), enclosingClipping Box->paddingTop()); | 746 constrainingRect.move(enclosingClippingBox->paddingLeft(), enclosingClipping Box->paddingTop()); |
| 743 constrainingRect.contract(FloatSize(enclosingClippingBox->paddingLeft() + en closingClippingBox->paddingRight(), | 747 constrainingRect.contract(FloatSize(enclosingClippingBox->paddingLeft() + en closingClippingBox->paddingRight(), |
| 744 enclosingClippingBox->paddingTop() + enclosingClippingBox->paddingBottom ())); | 748 enclosingClippingBox->paddingTop() + enclosingClippingBox->paddingBottom ())); |
| 745 return constrainingRect; | 749 return constrainingRect; |
| 746 } | 750 } |
| 747 | 751 |
| 748 LayoutSize LayoutBoxModelObject::stickyPositionOffset() const | 752 LayoutSize LayoutBoxModelObject::stickyPositionOffset() const |
| 749 { | 753 { |
| 750 const PaintLayer* ancestorOverflowLayer = layer()->ancestorOverflowLayer(); | 754 const PaintLayer* ancestorOverflowLayer = layer()->ancestorOverflowLayer(); |
| 751 // TODO: Force compositing input update if we ask for offset before composit ing inputs have been computed? | 755 // TODO: Force compositing input update if we ask for offset before composit ing inputs have been computed? |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1129 if (rootElementStyle->hasBackground()) | 1133 if (rootElementStyle->hasBackground()) |
| 1130 return false; | 1134 return false; |
| 1131 | 1135 |
| 1132 if (node() != document().firstBodyElement()) | 1136 if (node() != document().firstBodyElement()) |
| 1133 return false; | 1137 return false; |
| 1134 | 1138 |
| 1135 return true; | 1139 return true; |
| 1136 } | 1140 } |
| 1137 | 1141 |
| 1138 } // namespace blink | 1142 } // namespace blink |
| OLD | NEW |