| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/page/scrolling/StickyPositionScrollingConstraints.h" | |
| 6 | |
| 7 namespace blink { | |
| 8 | |
| 9 FloatSize StickyPositionScrollingConstraints::computeStickyOffset(const FloatRec
t& viewportRect) const | |
| 10 { | |
| 11 FloatRect boxRect = m_scrollContainerRelativeStickyBoxRect; | |
| 12 | |
| 13 if (hasAnchorEdge(AnchorEdgeRight)) { | |
| 14 float rightLimit = viewportRect.maxX() - m_rightOffset; | |
| 15 float rightDelta = std::min<float>(0, rightLimit - m_scrollContainerRela
tiveStickyBoxRect.maxX()); | |
| 16 float availableSpace = std::min<float>(0, m_scrollContainerRelativeConta
iningBlockRect.x() - m_scrollContainerRelativeStickyBoxRect.x()); | |
| 17 if (rightDelta < availableSpace) | |
| 18 rightDelta = availableSpace; | |
| 19 | |
| 20 boxRect.move(rightDelta, 0); | |
| 21 } | |
| 22 | |
| 23 if (hasAnchorEdge(AnchorEdgeLeft)) { | |
| 24 float leftLimit = viewportRect.x() + m_leftOffset; | |
| 25 float leftDelta = std::max<float>(0, leftLimit - m_scrollContainerRelati
veStickyBoxRect.x()); | |
| 26 float availableSpace = std::max<float>(0, m_scrollContainerRelativeConta
iningBlockRect.maxX() - m_scrollContainerRelativeStickyBoxRect.maxX()); | |
| 27 if (leftDelta > availableSpace) | |
| 28 leftDelta = availableSpace; | |
| 29 | |
| 30 boxRect.move(leftDelta, 0); | |
| 31 } | |
| 32 | |
| 33 if (hasAnchorEdge(AnchorEdgeBottom)) { | |
| 34 float bottomLimit = viewportRect.maxY() - m_bottomOffset; | |
| 35 float bottomDelta = std::min<float>(0, bottomLimit - m_scrollContainerRe
lativeStickyBoxRect.maxY()); | |
| 36 float availableSpace = std::min<float>(0, m_scrollContainerRelativeConta
iningBlockRect.y() - m_scrollContainerRelativeStickyBoxRect.y()); | |
| 37 if (bottomDelta < availableSpace) | |
| 38 bottomDelta = availableSpace; | |
| 39 | |
| 40 boxRect.move(0, bottomDelta); | |
| 41 } | |
| 42 | |
| 43 if (hasAnchorEdge(AnchorEdgeTop)) { | |
| 44 float topLimit = viewportRect.y() + m_topOffset; | |
| 45 float topDelta = std::max<float>(0, topLimit - m_scrollContainerRelative
StickyBoxRect.y()); | |
| 46 float availableSpace = std::max<float>(0, m_scrollContainerRelativeConta
iningBlockRect.maxY() - m_scrollContainerRelativeStickyBoxRect.maxY()); | |
| 47 if (topDelta > availableSpace) | |
| 48 topDelta = availableSpace; | |
| 49 | |
| 50 boxRect.move(0, topDelta); | |
| 51 } | |
| 52 | |
| 53 return boxRect.location() - m_scrollContainerRelativeStickyBoxRect.location(
); | |
| 54 } | |
| 55 | |
| 56 } // namespace blink | |
| OLD | NEW |