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

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

Issue 1308273010: Adapt and reland old position sticky implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Merge with master (removing horizontal-bt test) Created 5 years 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/ScrollingConstraints.cpp
diff --git a/third_party/WebKit/Source/core/page/scrolling/ScrollingConstraints.cpp b/third_party/WebKit/Source/core/page/scrolling/ScrollingConstraints.cpp
index 0e59a00cdb3e4b03e77fb82564dc83ada4d4b827..89badd279ae44d2fd9067e74a709977b2558aefc 100644
--- a/third_party/WebKit/Source/core/page/scrolling/ScrollingConstraints.cpp
+++ b/third_party/WebKit/Source/core/page/scrolling/ScrollingConstraints.cpp
@@ -28,9 +28,9 @@
namespace blink {
-FloatPoint FixedPositionViewportConstraints::layerPositionForViewportRect(const FloatRect& viewportRect) const
+LayoutPoint FixedPositionViewportConstraints::layerPositionForViewportRect(const LayoutRect& viewportRect) const
{
- FloatSize offset;
+ LayoutSize offset;
if (hasAnchorEdge(AnchorEdgeLeft))
offset.setWidth(viewportRect.x() - m_viewportRectAtLastLayout.x());
@@ -45,4 +45,57 @@ FloatPoint FixedPositionViewportConstraints::layerPositionForViewportRect(const
return m_layerPositionAtLastLayout + offset;
}
+LayoutSize StickyPositionViewportConstraints::computeStickyOffset(const LayoutRect& viewportRect) const
+{
+ LayoutRect boxRect = m_absoluteStickyBoxRect;
+
+ if (hasAnchorEdge(AnchorEdgeRight)) {
+ LayoutUnit rightLimit = viewportRect.maxX() - m_rightOffset;
+ LayoutUnit rightDelta = std::min<LayoutUnit>(0, rightLimit - m_absoluteStickyBoxRect.maxX());
+ LayoutUnit availableSpace = std::min<LayoutUnit>(0, m_absoluteContainingBlockRect.x() - m_absoluteStickyBoxRect.x());
+ if (rightDelta < availableSpace)
+ rightDelta = availableSpace;
+
+ boxRect.move(rightDelta, 0);
+ }
+
+ if (hasAnchorEdge(AnchorEdgeLeft)) {
+ LayoutUnit leftLimit = viewportRect.x() + m_leftOffset;
+ LayoutUnit leftDelta = std::max<LayoutUnit>(0, leftLimit - m_absoluteStickyBoxRect.x());
+ LayoutUnit availableSpace = std::max<LayoutUnit>(0, m_absoluteContainingBlockRect.maxX() - m_absoluteStickyBoxRect.maxX());
+ if (leftDelta > availableSpace)
+ leftDelta = availableSpace;
+
+ boxRect.move(leftDelta, 0);
+ }
+
+ if (hasAnchorEdge(AnchorEdgeBottom)) {
+ LayoutUnit bottomLimit = viewportRect.maxY() - m_bottomOffset;
+ LayoutUnit bottomDelta = std::min<LayoutUnit>(0, bottomLimit - m_absoluteStickyBoxRect.maxY());
+ LayoutUnit availableSpace = std::min<LayoutUnit>(0, m_absoluteContainingBlockRect.y() - m_absoluteStickyBoxRect.y());
+ if (bottomDelta < availableSpace)
+ bottomDelta = availableSpace;
+
+ boxRect.move(0, bottomDelta);
+ }
+
+ if (hasAnchorEdge(AnchorEdgeTop)) {
+ LayoutUnit topLimit = viewportRect.y() + m_topOffset;
+ LayoutUnit topDelta = std::max<LayoutUnit>(0, topLimit - m_absoluteStickyBoxRect.y());
+ LayoutUnit availableSpace = std::max<LayoutUnit>(0, m_absoluteContainingBlockRect.maxY() - m_absoluteStickyBoxRect.maxY());
+ if (topDelta > availableSpace)
+ topDelta = availableSpace;
+
+ boxRect.move(0, topDelta);
+ }
+
+ return boxRect.location() - m_absoluteStickyBoxRect.location();
+}
+
+LayoutPoint StickyPositionViewportConstraints::layerPositionForViewportRect(const LayoutRect& viewportRect) const
chrishtr 2015/12/09 19:12:21 Remove, not called
flackr 2015/12/10 23:43:15 Done.
+{
+ LayoutSize offset = computeStickyOffset(viewportRect);
+ return m_layerPositionAtLastLayout + offset - m_stickyOffsetAtLastLayout;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698