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

Unified Diff: third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.cpp

Issue 2636253002: Handle nested position:sticky elements (Closed)
Patch Set: Rebase Created 3 years, 10 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/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..66037232f50fe03a1ce29101430a61dc5556f44c 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,
+ StickyPositionScrollingConstraints* ancestorStickyBoxConstraints,
+ StickyPositionScrollingConstraints* ancestorContainingBlockConstraints) {
+ FloatSize ancestorStickyBoxOffset =
+ ancestorStickyBoxConstraints
+ ? ancestorStickyBoxConstraints->getTotalStickyBoxStickyOffset()
+ : FloatSize();
+ FloatSize ancestorContainingBlockOffset =
+ ancestorContainingBlockConstraints
+ ? ancestorContainingBlockConstraints
+ ->getTotalContainingBlockStickyOffset()
+ : FloatSize();
+
+ // Adjust the constraint rect locations based on our ancestor sticky elements,
+ // if they exist. These adjustments are necessary to avoid double offsetting
+ // in the case of nested sticky elements.
+ 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,25 @@ 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;
+
+ m_cachedComputedStickyOffset = stickyOffset;
+
+ return stickyOffset;
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698