| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/page/scrolling/StickyPositionScrollingConstraints.h" | 5 #include "core/page/scrolling/StickyPositionScrollingConstraints.h" |
| 6 | 6 |
| 7 namespace blink { | 7 namespace blink { |
| 8 | 8 |
| 9 FloatSize StickyPositionScrollingConstraints::computeStickyOffset( | 9 FloatSize StickyPositionScrollingConstraints::computeStickyOffset( |
| 10 const FloatRect& viewportRect) const { | 10 const FloatRect& viewportRect) const { |
| 11 FloatRect boxRect = m_scrollContainerRelativeStickyBoxRect; | 11 FloatRect boxRect = m_scrollContainerRelativeStickyBoxRect; |
| 12 | 12 |
| 13 if (hasAnchorEdge(AnchorEdgeRight)) { | 13 if (hasAnchorEdge(AnchorEdgeRight)) { |
| 14 float rightLimit = viewportRect.maxX() - m_rightOffset; | 14 float rightLimit = viewportRect.maxX() - m_rightOffset; |
| 15 float rightDelta = std::min<float>( | 15 float rightDelta = std::min<float>( |
| 16 0, rightLimit - m_scrollContainerRelativeStickyBoxRect.maxX()); | 16 0, rightLimit - m_scrollContainerRelativeStickyBoxRect.maxX()); |
| 17 float availableSpace = | 17 float availableSpace = |
| 18 std::min<float>(0, m_scrollContainerRelativeContainingBlockRect.x() - | 18 std::min<float>(0, |
| 19 m_scrollContainerRelativeStickyBoxRect.x()); | 19 m_scrollContainerRelativeContainingBlockRect.x() - |
| 20 m_scrollContainerRelativeStickyBoxRect.x()); |
| 20 if (rightDelta < availableSpace) | 21 if (rightDelta < availableSpace) |
| 21 rightDelta = availableSpace; | 22 rightDelta = availableSpace; |
| 22 | 23 |
| 23 boxRect.move(rightDelta, 0); | 24 boxRect.move(rightDelta, 0); |
| 24 } | 25 } |
| 25 | 26 |
| 26 if (hasAnchorEdge(AnchorEdgeLeft)) { | 27 if (hasAnchorEdge(AnchorEdgeLeft)) { |
| 27 float leftLimit = viewportRect.x() + m_leftOffset; | 28 float leftLimit = viewportRect.x() + m_leftOffset; |
| 28 float leftDelta = std::max<float>( | 29 float leftDelta = std::max<float>( |
| 29 0, leftLimit - m_scrollContainerRelativeStickyBoxRect.x()); | 30 0, leftLimit - m_scrollContainerRelativeStickyBoxRect.x()); |
| 30 float availableSpace = | 31 float availableSpace = |
| 31 std::max<float>(0, m_scrollContainerRelativeContainingBlockRect.maxX() - | 32 std::max<float>(0, |
| 32 m_scrollContainerRelativeStickyBoxRect.maxX()); | 33 m_scrollContainerRelativeContainingBlockRect.maxX() - |
| 34 m_scrollContainerRelativeStickyBoxRect.maxX()); |
| 33 if (leftDelta > availableSpace) | 35 if (leftDelta > availableSpace) |
| 34 leftDelta = availableSpace; | 36 leftDelta = availableSpace; |
| 35 | 37 |
| 36 boxRect.move(leftDelta, 0); | 38 boxRect.move(leftDelta, 0); |
| 37 } | 39 } |
| 38 | 40 |
| 39 if (hasAnchorEdge(AnchorEdgeBottom)) { | 41 if (hasAnchorEdge(AnchorEdgeBottom)) { |
| 40 float bottomLimit = viewportRect.maxY() - m_bottomOffset; | 42 float bottomLimit = viewportRect.maxY() - m_bottomOffset; |
| 41 float bottomDelta = std::min<float>( | 43 float bottomDelta = std::min<float>( |
| 42 0, bottomLimit - m_scrollContainerRelativeStickyBoxRect.maxY()); | 44 0, bottomLimit - m_scrollContainerRelativeStickyBoxRect.maxY()); |
| 43 float availableSpace = | 45 float availableSpace = |
| 44 std::min<float>(0, m_scrollContainerRelativeContainingBlockRect.y() - | 46 std::min<float>(0, |
| 45 m_scrollContainerRelativeStickyBoxRect.y()); | 47 m_scrollContainerRelativeContainingBlockRect.y() - |
| 48 m_scrollContainerRelativeStickyBoxRect.y()); |
| 46 if (bottomDelta < availableSpace) | 49 if (bottomDelta < availableSpace) |
| 47 bottomDelta = availableSpace; | 50 bottomDelta = availableSpace; |
| 48 | 51 |
| 49 boxRect.move(0, bottomDelta); | 52 boxRect.move(0, bottomDelta); |
| 50 } | 53 } |
| 51 | 54 |
| 52 if (hasAnchorEdge(AnchorEdgeTop)) { | 55 if (hasAnchorEdge(AnchorEdgeTop)) { |
| 53 float topLimit = viewportRect.y() + m_topOffset; | 56 float topLimit = viewportRect.y() + m_topOffset; |
| 54 float topDelta = std::max<float>( | 57 float topDelta = std::max<float>( |
| 55 0, topLimit - m_scrollContainerRelativeStickyBoxRect.y()); | 58 0, topLimit - m_scrollContainerRelativeStickyBoxRect.y()); |
| 56 float availableSpace = | 59 float availableSpace = |
| 57 std::max<float>(0, m_scrollContainerRelativeContainingBlockRect.maxY() - | 60 std::max<float>(0, |
| 58 m_scrollContainerRelativeStickyBoxRect.maxY()); | 61 m_scrollContainerRelativeContainingBlockRect.maxY() - |
| 62 m_scrollContainerRelativeStickyBoxRect.maxY()); |
| 59 if (topDelta > availableSpace) | 63 if (topDelta > availableSpace) |
| 60 topDelta = availableSpace; | 64 topDelta = availableSpace; |
| 61 | 65 |
| 62 boxRect.move(0, topDelta); | 66 boxRect.move(0, topDelta); |
| 63 } | 67 } |
| 64 | 68 |
| 65 return boxRect.location() - m_scrollContainerRelativeStickyBoxRect.location(); | 69 return boxRect.location() - m_scrollContainerRelativeStickyBoxRect.location(); |
| 66 } | 70 } |
| 67 | 71 |
| 68 } // namespace blink | 72 } // namespace blink |
| OLD | NEW |