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..d1bf4986c5da525a6e65ed4f932d44020bed1421 100644 |
--- a/third_party/WebKit/Source/core/page/scrolling/ScrollingConstraints.cpp |
+++ b/third_party/WebKit/Source/core/page/scrolling/ScrollingConstraints.cpp |
@@ -28,21 +28,51 @@ |
namespace blink { |
-FloatPoint FixedPositionViewportConstraints::layerPositionForViewportRect(const FloatRect& viewportRect) const |
+LayoutSize StickyPositionViewportConstraints::computeStickyOffset(const LayoutRect& viewportRect) const |
{ |
- FloatSize offset; |
+ LayoutRect boxRect = m_absoluteStickyBoxRect; |
- if (hasAnchorEdge(AnchorEdgeLeft)) |
- offset.setWidth(viewportRect.x() - m_viewportRectAtLastLayout.x()); |
- else if (hasAnchorEdge(AnchorEdgeRight)) |
- offset.setWidth(viewportRect.maxX() - m_viewportRectAtLastLayout.maxX()); |
+ 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; |
- if (hasAnchorEdge(AnchorEdgeTop)) |
- offset.setHeight(viewportRect.y() - m_viewportRectAtLastLayout.y()); |
- else if (hasAnchorEdge(AnchorEdgeBottom)) |
- offset.setHeight(viewportRect.maxY() - m_viewportRectAtLastLayout.maxY()); |
+ boxRect.move(rightDelta, 0); |
+ } |
- return m_layerPositionAtLastLayout + offset; |
+ 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(); |
} |
} // namespace blink |