Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: third_party/WebKit/Source/core/page/scrolling/StickyPositionScrollingConstraints.cpp

Issue 2708883005: Handle nested position:sticky elements correctly (main thread) (Closed)
Patch Set: Rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // Adjust the constraint rect locations based on our ancestor sticky elements
14 // These adjustments are necessary to avoid double offsetting in the case of
15 // nested sticky elements.
16 FloatSize ancestorStickyBoxOffset =
17 ancestorStickyBoxConstraints
18 ? ancestorStickyBoxConstraints->getTotalStickyBoxStickyOffset()
19 : FloatSize();
20 FloatSize ancestorContainingBlockOffset =
21 ancestorContainingBlockConstraints
22 ? ancestorContainingBlockConstraints
23 ->getTotalContainingBlockStickyOffset()
24 : FloatSize();
25 FloatRect stickyBoxRect = m_scrollContainerRelativeStickyBoxRect;
26 FloatRect containingBlockRect = m_scrollContainerRelativeContainingBlockRect;
27 stickyBoxRect.move(ancestorStickyBoxOffset + ancestorContainingBlockOffset);
28 containingBlockRect.move(ancestorContainingBlockOffset);
29
30 FloatRect boxRect = stickyBoxRect;
12 31
13 if (hasAnchorEdge(AnchorEdgeRight)) { 32 if (hasAnchorEdge(AnchorEdgeRight)) {
14 float rightLimit = viewportRect.maxX() - m_rightOffset; 33 float rightLimit = viewportRect.maxX() - m_rightOffset;
15 float rightDelta = std::min<float>( 34 float rightDelta = std::min<float>(0, rightLimit - stickyBoxRect.maxX());
16 0, rightLimit - m_scrollContainerRelativeStickyBoxRect.maxX());
17 float availableSpace = 35 float availableSpace =
18 std::min<float>(0, m_scrollContainerRelativeContainingBlockRect.x() - 36 std::min<float>(0, containingBlockRect.x() - stickyBoxRect.x());
19 m_scrollContainerRelativeStickyBoxRect.x());
20 if (rightDelta < availableSpace) 37 if (rightDelta < availableSpace)
21 rightDelta = availableSpace; 38 rightDelta = availableSpace;
22 39
23 boxRect.move(rightDelta, 0); 40 boxRect.move(rightDelta, 0);
24 } 41 }
25 42
26 if (hasAnchorEdge(AnchorEdgeLeft)) { 43 if (hasAnchorEdge(AnchorEdgeLeft)) {
27 float leftLimit = viewportRect.x() + m_leftOffset; 44 float leftLimit = viewportRect.x() + m_leftOffset;
28 float leftDelta = std::max<float>( 45 float leftDelta = std::max<float>(0, leftLimit - stickyBoxRect.x());
29 0, leftLimit - m_scrollContainerRelativeStickyBoxRect.x());
30 float availableSpace = 46 float availableSpace =
31 std::max<float>(0, m_scrollContainerRelativeContainingBlockRect.maxX() - 47 std::max<float>(0, containingBlockRect.maxX() - stickyBoxRect.maxX());
32 m_scrollContainerRelativeStickyBoxRect.maxX());
33 if (leftDelta > availableSpace) 48 if (leftDelta > availableSpace)
34 leftDelta = availableSpace; 49 leftDelta = availableSpace;
35 50
36 boxRect.move(leftDelta, 0); 51 boxRect.move(leftDelta, 0);
37 } 52 }
38 53
39 if (hasAnchorEdge(AnchorEdgeBottom)) { 54 if (hasAnchorEdge(AnchorEdgeBottom)) {
40 float bottomLimit = viewportRect.maxY() - m_bottomOffset; 55 float bottomLimit = viewportRect.maxY() - m_bottomOffset;
41 float bottomDelta = std::min<float>( 56 float bottomDelta = std::min<float>(0, bottomLimit - stickyBoxRect.maxY());
42 0, bottomLimit - m_scrollContainerRelativeStickyBoxRect.maxY());
43 float availableSpace = 57 float availableSpace =
44 std::min<float>(0, m_scrollContainerRelativeContainingBlockRect.y() - 58 std::min<float>(0, containingBlockRect.y() - stickyBoxRect.y());
45 m_scrollContainerRelativeStickyBoxRect.y());
46 if (bottomDelta < availableSpace) 59 if (bottomDelta < availableSpace)
47 bottomDelta = availableSpace; 60 bottomDelta = availableSpace;
48 61
49 boxRect.move(0, bottomDelta); 62 boxRect.move(0, bottomDelta);
50 } 63 }
51 64
52 if (hasAnchorEdge(AnchorEdgeTop)) { 65 if (hasAnchorEdge(AnchorEdgeTop)) {
53 float topLimit = viewportRect.y() + m_topOffset; 66 float topLimit = viewportRect.y() + m_topOffset;
54 float topDelta = std::max<float>( 67 float topDelta = std::max<float>(0, topLimit - stickyBoxRect.y());
55 0, topLimit - m_scrollContainerRelativeStickyBoxRect.y());
56 float availableSpace = 68 float availableSpace =
57 std::max<float>(0, m_scrollContainerRelativeContainingBlockRect.maxY() - 69 std::max<float>(0, containingBlockRect.maxY() - stickyBoxRect.maxY());
58 m_scrollContainerRelativeStickyBoxRect.maxY());
59 if (topDelta > availableSpace) 70 if (topDelta > availableSpace)
60 topDelta = availableSpace; 71 topDelta = availableSpace;
61 72
62 boxRect.move(0, topDelta); 73 boxRect.move(0, topDelta);
63 } 74 }
64 75
65 return boxRect.location() - m_scrollContainerRelativeStickyBoxRect.location(); 76 FloatSize stickyOffset = boxRect.location() - stickyBoxRect.location();
77
78 m_totalStickyBoxStickyOffset = ancestorStickyBoxOffset + stickyOffset;
79 m_totalContainingBlockStickyOffset =
80 ancestorStickyBoxOffset + ancestorContainingBlockOffset + stickyOffset;
81
82 m_cachedComputedStickyOffset = stickyOffset;
83
84 return stickyOffset;
66 } 85 }
67 86
68 } // namespace blink 87 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698