Chromium Code Reviews| 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, |
| 11 FloatRect boxRect = m_scrollContainerRelativeStickyBoxRect; | 11 StickyPositionScrollingConstraints* ancestorStickyBoxConstraints, |
| 12 StickyPositionScrollingConstraints* ancestorContainingBlockConstraints) { | |
| 13 FloatSize ancestorStickyBoxOffset = | |
| 14 ancestorStickyBoxConstraints | |
| 15 ? ancestorStickyBoxConstraints->getTotalStickyBoxStickyOffset() | |
| 16 : FloatSize(); | |
| 17 FloatSize ancestorContainingBlockOffset = | |
| 18 ancestorContainingBlockConstraints | |
| 19 ? ancestorContainingBlockConstraints | |
| 20 ->getTotalContainingBlockStickyOffset() | |
| 21 : FloatSize(); | |
| 22 | |
| 23 // Adjust the constraint rect locations based on our ancestor sticky elements, | |
| 24 // if they exist. These adjustments are necessary to avoid double offsetting | |
| 25 // in the case of nested sticky elements. | |
| 26 FloatRect stickyBoxRect = m_scrollContainerRelativeStickyBoxRect; | |
| 27 FloatRect containingBlockRect = m_scrollContainerRelativeContainingBlockRect; | |
| 28 stickyBoxRect.move(ancestorStickyBoxOffset); | |
| 29 stickyBoxRect.move(ancestorContainingBlockOffset); | |
|
flackr
2017/02/02 18:18:11
nit: stickyBoxRect.move(ancestorStickyBoxOffset +
smcgruer
2017/02/02 20:21:27
Done.
| |
| 30 containingBlockRect.move(ancestorContainingBlockOffset); | |
| 31 | |
| 32 FloatRect boxRect = stickyBoxRect; | |
| 12 | 33 |
| 13 if (hasAnchorEdge(AnchorEdgeRight)) { | 34 if (hasAnchorEdge(AnchorEdgeRight)) { |
| 14 float rightLimit = viewportRect.maxX() - m_rightOffset; | 35 float rightLimit = viewportRect.maxX() - m_rightOffset; |
| 15 float rightDelta = std::min<float>( | 36 float rightDelta = std::min<float>(0, rightLimit - stickyBoxRect.maxX()); |
| 16 0, rightLimit - m_scrollContainerRelativeStickyBoxRect.maxX()); | |
| 17 float availableSpace = | 37 float availableSpace = |
| 18 std::min<float>(0, m_scrollContainerRelativeContainingBlockRect.x() - | 38 std::min<float>(0, containingBlockRect.x() - stickyBoxRect.x()); |
| 19 m_scrollContainerRelativeStickyBoxRect.x()); | |
| 20 if (rightDelta < availableSpace) | 39 if (rightDelta < availableSpace) |
| 21 rightDelta = availableSpace; | 40 rightDelta = availableSpace; |
| 22 | 41 |
| 23 boxRect.move(rightDelta, 0); | 42 boxRect.move(rightDelta, 0); |
| 24 } | 43 } |
| 25 | 44 |
| 26 if (hasAnchorEdge(AnchorEdgeLeft)) { | 45 if (hasAnchorEdge(AnchorEdgeLeft)) { |
| 27 float leftLimit = viewportRect.x() + m_leftOffset; | 46 float leftLimit = viewportRect.x() + m_leftOffset; |
| 28 float leftDelta = std::max<float>( | 47 float leftDelta = std::max<float>(0, leftLimit - stickyBoxRect.x()); |
| 29 0, leftLimit - m_scrollContainerRelativeStickyBoxRect.x()); | |
| 30 float availableSpace = | 48 float availableSpace = |
| 31 std::max<float>(0, m_scrollContainerRelativeContainingBlockRect.maxX() - | 49 std::max<float>(0, containingBlockRect.maxX() - stickyBoxRect.maxX()); |
| 32 m_scrollContainerRelativeStickyBoxRect.maxX()); | |
| 33 if (leftDelta > availableSpace) | 50 if (leftDelta > availableSpace) |
| 34 leftDelta = availableSpace; | 51 leftDelta = availableSpace; |
| 35 | 52 |
| 36 boxRect.move(leftDelta, 0); | 53 boxRect.move(leftDelta, 0); |
| 37 } | 54 } |
| 38 | 55 |
| 39 if (hasAnchorEdge(AnchorEdgeBottom)) { | 56 if (hasAnchorEdge(AnchorEdgeBottom)) { |
| 40 float bottomLimit = viewportRect.maxY() - m_bottomOffset; | 57 float bottomLimit = viewportRect.maxY() - m_bottomOffset; |
| 41 float bottomDelta = std::min<float>( | 58 float bottomDelta = std::min<float>(0, bottomLimit - stickyBoxRect.maxY()); |
| 42 0, bottomLimit - m_scrollContainerRelativeStickyBoxRect.maxY()); | |
| 43 float availableSpace = | 59 float availableSpace = |
| 44 std::min<float>(0, m_scrollContainerRelativeContainingBlockRect.y() - | 60 std::min<float>(0, containingBlockRect.y() - stickyBoxRect.y()); |
| 45 m_scrollContainerRelativeStickyBoxRect.y()); | |
| 46 if (bottomDelta < availableSpace) | 61 if (bottomDelta < availableSpace) |
| 47 bottomDelta = availableSpace; | 62 bottomDelta = availableSpace; |
| 48 | 63 |
| 49 boxRect.move(0, bottomDelta); | 64 boxRect.move(0, bottomDelta); |
| 50 } | 65 } |
| 51 | 66 |
| 52 if (hasAnchorEdge(AnchorEdgeTop)) { | 67 if (hasAnchorEdge(AnchorEdgeTop)) { |
| 53 float topLimit = viewportRect.y() + m_topOffset; | 68 float topLimit = viewportRect.y() + m_topOffset; |
| 54 float topDelta = std::max<float>( | 69 float topDelta = std::max<float>(0, topLimit - stickyBoxRect.y()); |
| 55 0, topLimit - m_scrollContainerRelativeStickyBoxRect.y()); | |
| 56 float availableSpace = | 70 float availableSpace = |
| 57 std::max<float>(0, m_scrollContainerRelativeContainingBlockRect.maxY() - | 71 std::max<float>(0, containingBlockRect.maxY() - stickyBoxRect.maxY()); |
| 58 m_scrollContainerRelativeStickyBoxRect.maxY()); | 72 |
| 59 if (topDelta > availableSpace) | 73 if (topDelta > availableSpace) |
| 60 topDelta = availableSpace; | 74 topDelta = availableSpace; |
| 61 | 75 |
| 62 boxRect.move(0, topDelta); | 76 boxRect.move(0, topDelta); |
| 63 } | 77 } |
| 64 | 78 |
| 65 return boxRect.location() - m_scrollContainerRelativeStickyBoxRect.location(); | 79 FloatSize stickyOffset = boxRect.location() - stickyBoxRect.location(); |
| 80 | |
| 81 m_totalStickyBoxStickyOffset = ancestorStickyBoxOffset + stickyOffset; | |
| 82 m_totalContainingBlockStickyOffset = | |
| 83 ancestorContainingBlockOffset + stickyOffset; | |
| 84 | |
| 85 return stickyOffset; | |
| 66 } | 86 } |
| 67 | 87 |
| 68 } // namespace blink | 88 } // namespace blink |
| OLD | NEW |