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 const FloatSize& accumulatedToCB, |
| 12 const FloatSize& accumulatedToVP) { | |
| 13 // TODO(smcgruer): Explain what this is doing. | |
| 14 // TODO(smcgruer): Determine which we need to move for what (fairly sure | |
| 15 // moving both by both is incorrect, but currently done because I don't | |
|
flackr
2017/01/18 14:42:56
I think the stickyBoxRect does need to be moved by
smcgruer
2017/01/19 19:28:01
Done.
| |
| 16 // accumulate properly.) | |
| 17 FloatRect stickyBoxRect = m_scrollContainerRelativeStickyBoxRect; | |
| 18 FloatRect containingBlockRect = m_scrollContainerRelativeContainingBlockRect; | |
| 19 stickyBoxRect.move(accumulatedToCB); | |
| 20 stickyBoxRect.move(accumulatedToVP); | |
| 21 containingBlockRect.move(accumulatedToCB); | |
|
flackr
2017/01/18 14:42:56
The containing block rect should only be moved by
smcgruer
2017/01/19 19:28:01
Done.
| |
| 22 containingBlockRect.move(accumulatedToVP); | |
| 23 | |
| 24 FloatRect boxRect = stickyBoxRect; | |
| 12 | 25 |
| 13 if (hasAnchorEdge(AnchorEdgeRight)) { | 26 if (hasAnchorEdge(AnchorEdgeRight)) { |
| 14 float rightLimit = viewportRect.maxX() - m_rightOffset; | 27 float rightLimit = viewportRect.maxX() - m_rightOffset; |
| 15 float rightDelta = std::min<float>( | 28 float rightDelta = std::min<float>(0, rightLimit - stickyBoxRect.maxX()); |
| 16 0, rightLimit - m_scrollContainerRelativeStickyBoxRect.maxX()); | |
| 17 float availableSpace = | 29 float availableSpace = |
| 18 std::min<float>(0, m_scrollContainerRelativeContainingBlockRect.x() - | 30 std::min<float>(0, containingBlockRect.x() - stickyBoxRect.x()); |
| 19 m_scrollContainerRelativeStickyBoxRect.x()); | |
| 20 if (rightDelta < availableSpace) | 31 if (rightDelta < availableSpace) |
| 21 rightDelta = availableSpace; | 32 rightDelta = availableSpace; |
| 22 | 33 |
| 23 boxRect.move(rightDelta, 0); | 34 boxRect.move(rightDelta, 0); |
| 24 } | 35 } |
| 25 | 36 |
| 26 if (hasAnchorEdge(AnchorEdgeLeft)) { | 37 if (hasAnchorEdge(AnchorEdgeLeft)) { |
| 27 float leftLimit = viewportRect.x() + m_leftOffset; | 38 float leftLimit = viewportRect.x() + m_leftOffset; |
| 28 float leftDelta = std::max<float>( | 39 float leftDelta = std::max<float>(0, leftLimit - stickyBoxRect.x()); |
| 29 0, leftLimit - m_scrollContainerRelativeStickyBoxRect.x()); | |
| 30 float availableSpace = | 40 float availableSpace = |
| 31 std::max<float>(0, m_scrollContainerRelativeContainingBlockRect.maxX() - | 41 std::max<float>(0, containingBlockRect.maxX() - stickyBoxRect.maxX()); |
| 32 m_scrollContainerRelativeStickyBoxRect.maxX()); | |
| 33 if (leftDelta > availableSpace) | 42 if (leftDelta > availableSpace) |
| 34 leftDelta = availableSpace; | 43 leftDelta = availableSpace; |
| 35 | 44 |
| 36 boxRect.move(leftDelta, 0); | 45 boxRect.move(leftDelta, 0); |
| 37 } | 46 } |
| 38 | 47 |
| 39 if (hasAnchorEdge(AnchorEdgeBottom)) { | 48 if (hasAnchorEdge(AnchorEdgeBottom)) { |
| 40 float bottomLimit = viewportRect.maxY() - m_bottomOffset; | 49 float bottomLimit = viewportRect.maxY() - m_bottomOffset; |
| 41 float bottomDelta = std::min<float>( | 50 float bottomDelta = std::min<float>(0, bottomLimit - stickyBoxRect.maxY()); |
| 42 0, bottomLimit - m_scrollContainerRelativeStickyBoxRect.maxY()); | |
| 43 float availableSpace = | 51 float availableSpace = |
| 44 std::min<float>(0, m_scrollContainerRelativeContainingBlockRect.y() - | 52 std::min<float>(0, containingBlockRect.y() - stickyBoxRect.y()); |
| 45 m_scrollContainerRelativeStickyBoxRect.y()); | |
| 46 if (bottomDelta < availableSpace) | 53 if (bottomDelta < availableSpace) |
| 47 bottomDelta = availableSpace; | 54 bottomDelta = availableSpace; |
| 48 | 55 |
| 49 boxRect.move(0, bottomDelta); | 56 boxRect.move(0, bottomDelta); |
| 50 } | 57 } |
| 51 | 58 |
| 52 if (hasAnchorEdge(AnchorEdgeTop)) { | 59 if (hasAnchorEdge(AnchorEdgeTop)) { |
| 53 float topLimit = viewportRect.y() + m_topOffset; | 60 float topLimit = viewportRect.y() + m_topOffset; |
| 54 float topDelta = std::max<float>( | 61 float topDelta = std::max<float>(0, topLimit - stickyBoxRect.y()); |
| 55 0, topLimit - m_scrollContainerRelativeStickyBoxRect.y()); | |
| 56 float availableSpace = | 62 float availableSpace = |
| 57 std::max<float>(0, m_scrollContainerRelativeContainingBlockRect.maxY() - | 63 std::max<float>(0, containingBlockRect.maxY() - stickyBoxRect.maxY()); |
| 58 m_scrollContainerRelativeStickyBoxRect.maxY()); | 64 |
| 59 if (topDelta > availableSpace) | 65 if (topDelta > availableSpace) |
| 60 topDelta = availableSpace; | 66 topDelta = availableSpace; |
| 61 | 67 |
| 62 boxRect.move(0, topDelta); | 68 boxRect.move(0, topDelta); |
| 63 } | 69 } |
| 64 | 70 |
| 65 return boxRect.location() - m_scrollContainerRelativeStickyBoxRect.location(); | 71 FloatSize stickyOffset = boxRect.location() - stickyBoxRect.location(); |
| 72 | |
| 73 // TODO(smcgruer): Determine what exactly we need to accumulate. | |
| 74 m_cachedAccumulatedStickyOffset.setWidth(stickyOffset.width()); | |
| 75 m_cachedAccumulatedStickyOffset.setHeight(stickyOffset.height()); | |
|
flackr
2017/01/18 14:42:56
I think we need to add the ToCB and ToVP offsets h
| |
| 76 | |
| 77 return stickyOffset; | |
| 66 } | 78 } |
| 67 | 79 |
| 68 } // namespace blink | 80 } // namespace blink |
| OLD | NEW |