Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Unified Diff: third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp

Issue 2020103002: Fix sticky constraints and update sticky layer positions recursively after scroll. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master and add comment explaining container content rect. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 cb416dca18088a6b66608b98352cce926530b206..2139534693ef16d6708ac98260548db8864250c9 100644
--- a/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
+++ b/third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp
@@ -632,7 +632,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();
@@ -646,20 +645,31 @@ 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.
// Compute the container-relative area within which the sticky element is allowed to move.
+ LayoutUnit maxWidth = containingBlock->availableLogicalWidth();
+
+ // This is removing the padding of the containing block's overflow rect to get the flow
+ // box rectangle and removing the margin of the sticky element to ensure that space between
+ // the sticky element and its containing flow box. It is an open issue whether the margin
+ // should collapse (See https://www.w3.org/TR/css-position-3/#sticky-pos).
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)
chrishtr 2016/06/16 11:03:59 If containingBlock == scrollAncestor, scrollContai
flackr 2016/06/29 13:21:06 Correct.
+ scrollContainerRelativeContainingBlockRect.move(scrollOffset);
+ constraints.setScrollContainerRelativeContainingBlockRect(scrollContainerRelativeContainingBlockRect);
FloatRect stickyBoxRect = isLayoutInline()
? FloatRect(toLayoutInline(this)->linesBoundingBox())
@@ -671,13 +681,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()));
@@ -735,7 +744,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()));

Powered by Google App Engine
This is Rietveld 408576698