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

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

Issue 2636253002: Handle nested position:sticky elements (Closed)
Patch Set: Offset rects correctly and accumulate correctly Created 3 years, 11 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..77d7fa7fff59d8df76c51aaef44d680bb66cff5f 100644
--- a/third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.cpp
+++ b/third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.cpp
@@ -7,16 +7,23 @@
namespace blink {
FloatSize StickyPositionScrollingConstraints::computeStickyOffset(
- const FloatRect& viewportRect) const {
- FloatRect boxRect = m_scrollContainerRelativeStickyBoxRect;
+ const FloatRect& viewportRect,
+ const FloatSize& accumulatedToCB,
+ const FloatSize& accumulatedToVP) {
+ // TODO(smcgruer): Explain what this is doing.
+ FloatRect stickyBoxRect = m_scrollContainerRelativeStickyBoxRect;
+ FloatRect containingBlockRect = m_scrollContainerRelativeContainingBlockRect;
+ stickyBoxRect.move(accumulatedToCB);
+ stickyBoxRect.move(accumulatedToVP);
+ containingBlockRect.move(accumulatedToVP);
+
+ 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 +32,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 +43,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 +54,29 @@ 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_accumulatedStickyOffsetToContainingBlock.setWidth(accumulatedToCB.width() +
+ stickyOffset.width());
+ m_accumulatedStickyOffsetToContainingBlock.setHeight(
+ accumulatedToCB.height() + stickyOffset.height());
flackr 2017/01/20 02:42:44 FloatSize has arithmetic operators, should be able
smcgruer 2017/01/24 15:45:22 Done.
+
+ m_accumulatedStickyOffsetFromContainingBlockToScrollContainer.setWidth(
+ accumulatedToVP.width() + stickyOffset.width());
+ m_accumulatedStickyOffsetFromContainingBlockToScrollContainer.setHeight(
+ accumulatedToVP.height() + stickyOffset.height());
+
+ return stickyOffset;
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698