Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp |
| diff --git a/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp b/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp |
| index cd3587ad63c36c9c01f3a8c43e808791cc8e3b93..88c5c2100c5faab146558b279f47232ccf229bac 100644 |
| --- a/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp |
| +++ b/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp |
| @@ -635,7 +635,6 @@ LayoutSize LayoutBoxModelObject::relativePositionOffset() const |
| void LayoutBoxModelObject::updateStickyPositionConstraints() const |
| { |
| - // TODO(flackr): This method is reasonably complicated and should have some direct unit testing. |
| const FloatSize constrainingSize = computeStickyConstrainingRect().size(); |
| PaintLayerScrollableArea* scrollableArea = layer()->ancestorOverflowLayer()->getScrollableArea(); |
| @@ -649,20 +648,26 @@ void LayoutBoxModelObject::updateStickyPositionConstraints() const |
| } |
| LayoutBox* scrollAncestor = layer()->ancestorOverflowLayer()->isRootLayer() ? nullptr : toLayoutBox(layer()->ancestorOverflowLayer()->layoutObject()); |
| - LayoutRect containerContentRect = containingBlock->contentBoxRect(); |
| - LayoutUnit maxWidth = containingBlock->availableLogicalWidth(); |
| - |
| + LayoutRect containerContentRect = containingBlock->layoutOverflowRect(); |
| + LayoutUnit maxContainerWidth = containingBlock->containingBlockLogicalWidthForContent(); |
| // Sticky positioned element ignore any override logical width on the containing block (as they don't call |
| // containingBlockLogicalWidthForContent). It's unclear whether this is totally 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
|
| // Compute the container-relative area within which the sticky element is allowed to move. |
| + 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.
|
| containerContentRect.contractEdges( |
| - minimumValueForLength(style()->marginTop(), maxWidth), |
| - minimumValueForLength(style()->marginRight(), maxWidth), |
| - minimumValueForLength(style()->marginBottom(), maxWidth), |
| - minimumValueForLength(style()->marginLeft(), maxWidth)); |
| + minimumValueForLength(containingBlock->style()->paddingTop(), maxContainerWidth) + minimumValueForLength(style()->marginTop(), maxWidth), |
| + minimumValueForLength(containingBlock->style()->paddingRight(), maxContainerWidth) + minimumValueForLength(style()->marginRight(), maxWidth), |
| + minimumValueForLength(containingBlock->style()->paddingBottom(), maxContainerWidth) + minimumValueForLength(style()->marginBottom(), maxWidth), |
| + minimumValueForLength(containingBlock->style()->paddingLeft(), maxContainerWidth) + minimumValueForLength(style()->marginLeft(), maxWidth)); |
| // Map to the scroll ancestor. |
| - constraints.setScrollContainerRelativeContainingBlockRect(containingBlock->localToAncestorQuad(FloatRect(containerContentRect), scrollAncestor).boundingBox()); |
| + FloatRect scrollContainerRelativeContainingBlockRect(containingBlock->localToAncestorQuad(FloatRect(containerContentRect), scrollAncestor).boundingBox()); |
| + FloatSize scrollOffset(scrollAncestor ? toFloatSize(scrollAncestor->getScrollableArea()->adjustedScrollOffset()) : FloatSize()); |
| + |
| + // Include scroll offset in container position if the container is not our scroll ancestor. |
| + if (containingBlock != scrollAncestor) |
| + scrollContainerRelativeContainingBlockRect.move(scrollOffset); |
| + constraints.setScrollContainerRelativeContainingBlockRect(scrollContainerRelativeContainingBlockRect); |
| FloatRect stickyBoxRect = isLayoutInline() |
| ? FloatRect(toLayoutInline(this)->linesBoundingBox()) |
| @@ -674,13 +679,12 @@ void LayoutBoxModelObject::updateStickyPositionConstraints() const |
| // TODO(flackr): Unfortunate to call localToAncestorQuad again, but we can't just offset from the previously computed rect if there are transforms. |
| // Map to the scroll ancestor. |
| FloatRect scrollContainerRelativeContainerFrame = containingBlock->localToAncestorQuad(FloatRect(FloatPoint(), FloatSize(containingBlock->size())), scrollAncestor).boundingBox(); |
| + scrollContainerRelativeContainerFrame.move(scrollOffset); |
| // If the containing block is our scroll ancestor, its location will not include the scroll offset which we need to include as |
| // part of the sticky box rect so we include it here. |
| - if (containingBlock->hasOverflowClip()) { |
| - FloatSize scrollOffset(toFloatSize(containingBlock->layer()->getScrollableArea()->adjustedScrollOffset())); |
| + if (containingBlock == scrollAncestor) |
| stickyLocation -= scrollOffset; |
| - } |
| constraints.setScrollContainerRelativeStickyBoxRect(FloatRect(scrollContainerRelativeContainerFrame.location() + toFloatSize(stickyLocation), flippedStickyBoxRect.size())); |
| @@ -738,7 +742,7 @@ FloatRect LayoutBoxModelObject::computeStickyConstrainingRect() const |
| LayoutBox* enclosingClippingBox = toLayoutBox(layer()->ancestorOverflowLayer()->layoutObject()); |
| FloatRect constrainingRect; |
| - constrainingRect = FloatRect(enclosingClippingBox->overflowClipRect(LayoutPoint())); |
| + constrainingRect = FloatRect(enclosingClippingBox->overflowClipRect(LayoutPoint(DoublePoint(enclosingClippingBox->getScrollableArea()->adjustedScrollOffset())))); |
| constrainingRect.move(enclosingClippingBox->paddingLeft(), enclosingClippingBox->paddingTop()); |
| constrainingRect.contract(FloatSize(enclosingClippingBox->paddingLeft() + enclosingClippingBox->paddingRight(), |
| enclosingClippingBox->paddingTop() + enclosingClippingBox->paddingBottom())); |