| Index: third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.cpp
|
| diff --git a/third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.cpp b/third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.cpp
|
| index d0c2d01708f9e499bcf3344607592d95753dd366..8d547e9e873ddebf506c6f598d547c8c20af246f 100644
|
| --- a/third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.cpp
|
| +++ b/third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.cpp
|
| @@ -7,16 +7,34 @@
|
| namespace blink {
|
|
|
| FloatSize StickyPositionScrollingConstraints::computeStickyOffset(
|
| - const FloatRect& viewportRect) const {
|
| - FloatRect boxRect = m_scrollContainerRelativeStickyBoxRect;
|
| + const FloatRect& viewportRect,
|
| + const StickyPositionScrollingConstraints* ancestorStickyBoxConstraints,
|
| + const StickyPositionScrollingConstraints*
|
| + ancestorContainingBlockConstraints) {
|
| + // Adjust the constraint rect locations based on our ancestor sticky elements
|
| + // These adjustments are necessary to avoid double offsetting in the case of
|
| + // nested sticky elements.
|
| + FloatSize ancestorStickyBoxOffset =
|
| + ancestorStickyBoxConstraints
|
| + ? ancestorStickyBoxConstraints->getTotalStickyBoxStickyOffset()
|
| + : FloatSize();
|
| + FloatSize ancestorContainingBlockOffset =
|
| + ancestorContainingBlockConstraints
|
| + ? ancestorContainingBlockConstraints
|
| + ->getTotalContainingBlockStickyOffset()
|
| + : FloatSize();
|
| + FloatRect stickyBoxRect = m_scrollContainerRelativeStickyBoxRect;
|
| + FloatRect containingBlockRect = m_scrollContainerRelativeContainingBlockRect;
|
| + stickyBoxRect.move(ancestorStickyBoxOffset + ancestorContainingBlockOffset);
|
| + containingBlockRect.move(ancestorContainingBlockOffset);
|
| +
|
| + FloatRect boxRect = stickyBoxRect;
|
|
|
| if (hasAnchorEdge(AnchorEdgeRight)) {
|
| float rightLimit = viewportRect.maxX() - m_rightOffset;
|
| - float rightDelta = std::min<float>(
|
| - 0, rightLimit - m_scrollContainerRelativeStickyBoxRect.maxX());
|
| + float rightDelta = std::min<float>(0, rightLimit - stickyBoxRect.maxX());
|
| float availableSpace =
|
| - std::min<float>(0, m_scrollContainerRelativeContainingBlockRect.x() -
|
| - m_scrollContainerRelativeStickyBoxRect.x());
|
| + std::min<float>(0, containingBlockRect.x() - stickyBoxRect.x());
|
| if (rightDelta < availableSpace)
|
| rightDelta = availableSpace;
|
|
|
| @@ -25,11 +43,9 @@ FloatSize StickyPositionScrollingConstraints::computeStickyOffset(
|
|
|
| if (hasAnchorEdge(AnchorEdgeLeft)) {
|
| float leftLimit = viewportRect.x() + m_leftOffset;
|
| - float leftDelta = std::max<float>(
|
| - 0, leftLimit - m_scrollContainerRelativeStickyBoxRect.x());
|
| + float leftDelta = std::max<float>(0, leftLimit - stickyBoxRect.x());
|
| float availableSpace =
|
| - std::max<float>(0, m_scrollContainerRelativeContainingBlockRect.maxX() -
|
| - m_scrollContainerRelativeStickyBoxRect.maxX());
|
| + std::max<float>(0, containingBlockRect.maxX() - stickyBoxRect.maxX());
|
| if (leftDelta > availableSpace)
|
| leftDelta = availableSpace;
|
|
|
| @@ -38,11 +54,9 @@ FloatSize StickyPositionScrollingConstraints::computeStickyOffset(
|
|
|
| if (hasAnchorEdge(AnchorEdgeBottom)) {
|
| float bottomLimit = viewportRect.maxY() - m_bottomOffset;
|
| - float bottomDelta = std::min<float>(
|
| - 0, bottomLimit - m_scrollContainerRelativeStickyBoxRect.maxY());
|
| + float bottomDelta = std::min<float>(0, bottomLimit - stickyBoxRect.maxY());
|
| float availableSpace =
|
| - std::min<float>(0, m_scrollContainerRelativeContainingBlockRect.y() -
|
| - m_scrollContainerRelativeStickyBoxRect.y());
|
| + std::min<float>(0, containingBlockRect.y() - stickyBoxRect.y());
|
| if (bottomDelta < availableSpace)
|
| bottomDelta = availableSpace;
|
|
|
| @@ -51,18 +65,22 @@ FloatSize StickyPositionScrollingConstraints::computeStickyOffset(
|
|
|
| if (hasAnchorEdge(AnchorEdgeTop)) {
|
| float topLimit = viewportRect.y() + m_topOffset;
|
| - float topDelta = std::max<float>(
|
| - 0, topLimit - m_scrollContainerRelativeStickyBoxRect.y());
|
| + float topDelta = std::max<float>(0, topLimit - stickyBoxRect.y());
|
| float availableSpace =
|
| - std::max<float>(0, m_scrollContainerRelativeContainingBlockRect.maxY() -
|
| - m_scrollContainerRelativeStickyBoxRect.maxY());
|
| + std::max<float>(0, containingBlockRect.maxY() - stickyBoxRect.maxY());
|
| if (topDelta > availableSpace)
|
| topDelta = availableSpace;
|
|
|
| boxRect.move(0, topDelta);
|
| }
|
|
|
| - return boxRect.location() - m_scrollContainerRelativeStickyBoxRect.location();
|
| + FloatSize stickyOffset = boxRect.location() - stickyBoxRect.location();
|
| +
|
| + m_totalStickyBoxStickyOffset = ancestorStickyBoxOffset + stickyOffset;
|
| + m_totalContainingBlockStickyOffset =
|
| + ancestorStickyBoxOffset + ancestorContainingBlockOffset + stickyOffset;
|
| +
|
| + return stickyOffset;
|
| }
|
|
|
| } // namespace blink
|
|
|