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

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

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 #ifndef StickyPositionScrollingConstraints_h 5 #ifndef StickyPositionScrollingConstraints_h
6 #define StickyPositionScrollingConstraints_h 6 #define StickyPositionScrollingConstraints_h
7 7
8 #include "platform/geometry/FloatRect.h" 8 #include "platform/geometry/FloatRect.h"
9 #include "platform/geometry/FloatSize.h"
9 10
10 namespace blink { 11 namespace blink {
11 12
13 class LayoutBoxModelObject;
14
12 class StickyPositionScrollingConstraints final { 15 class StickyPositionScrollingConstraints final {
13 public: 16 public:
14 enum AnchorEdgeFlags { 17 enum AnchorEdgeFlags {
15 AnchorEdgeLeft = 1 << 0, 18 AnchorEdgeLeft = 1 << 0,
16 AnchorEdgeRight = 1 << 1, 19 AnchorEdgeRight = 1 << 1,
17 AnchorEdgeTop = 1 << 2, 20 AnchorEdgeTop = 1 << 2,
18 AnchorEdgeBottom = 1 << 3 21 AnchorEdgeBottom = 1 << 3
19 }; 22 };
20 typedef unsigned AnchorEdges; 23 typedef unsigned AnchorEdges;
21 24
22 StickyPositionScrollingConstraints() 25 StickyPositionScrollingConstraints()
23 : m_anchorEdges(0), 26 : m_anchorEdges(0),
24 m_leftOffset(0), 27 m_leftOffset(0),
25 m_rightOffset(0), 28 m_rightOffset(0),
26 m_topOffset(0), 29 m_topOffset(0),
27 m_bottomOffset(0) {} 30 m_bottomOffset(0),
31 m_nearestStickyElementShiftingStickyBox(nullptr),
32 m_nearestStickyElementShiftingContainingBlock(nullptr) {}
28 33
29 StickyPositionScrollingConstraints( 34 StickyPositionScrollingConstraints(
30 const StickyPositionScrollingConstraints& other) 35 const StickyPositionScrollingConstraints& other)
31 : m_anchorEdges(other.m_anchorEdges), 36 : m_anchorEdges(other.m_anchorEdges),
32 m_leftOffset(other.m_leftOffset), 37 m_leftOffset(other.m_leftOffset),
33 m_rightOffset(other.m_rightOffset), 38 m_rightOffset(other.m_rightOffset),
34 m_topOffset(other.m_topOffset), 39 m_topOffset(other.m_topOffset),
35 m_bottomOffset(other.m_bottomOffset), 40 m_bottomOffset(other.m_bottomOffset),
36 m_scrollContainerRelativeContainingBlockRect( 41 m_scrollContainerRelativeContainingBlockRect(
37 other.m_scrollContainerRelativeContainingBlockRect), 42 other.m_scrollContainerRelativeContainingBlockRect),
38 m_scrollContainerRelativeStickyBoxRect( 43 m_scrollContainerRelativeStickyBoxRect(
39 other.m_scrollContainerRelativeStickyBoxRect) {} 44 other.m_scrollContainerRelativeStickyBoxRect),
45 m_nearestStickyElementShiftingStickyBox(
46 other.m_nearestStickyElementShiftingStickyBox),
47 m_nearestStickyElementShiftingContainingBlock(
48 other.m_nearestStickyElementShiftingContainingBlock),
49 m_totalStickyBoxStickyOffset(other.m_totalStickyBoxStickyOffset),
50 m_totalContainingBlockStickyOffset(
51 other.m_totalContainingBlockStickyOffset),
52 m_cachedComputedStickyOffset(other.m_cachedComputedStickyOffset) {}
40 53
41 FloatSize computeStickyOffset(const FloatRect& viewportRect) const; 54 FloatSize computeStickyOffset(
55 const FloatRect& viewportRect,
56 StickyPositionScrollingConstraints* ancestorStickyBoxConstraints,
flackr 2017/02/22 22:40:15 const StickyPositionScrollingConstraints*
smcgruer 2017/02/23 20:14:17 Done.
57 StickyPositionScrollingConstraints* ancestorContainingBlockConstraints);
58
59 bool hasAncestorStickyElement() const {
60 return m_nearestStickyElementShiftingStickyBox ||
61 m_nearestStickyElementShiftingContainingBlock;
62 }
42 63
43 AnchorEdges anchorEdges() const { return m_anchorEdges; } 64 AnchorEdges anchorEdges() const { return m_anchorEdges; }
44 bool hasAnchorEdge(AnchorEdgeFlags flag) const { 65 bool hasAnchorEdge(AnchorEdgeFlags flag) const {
45 return m_anchorEdges & flag; 66 return m_anchorEdges & flag;
46 } 67 }
47 void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; } 68 void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; }
48 void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; } 69 void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; }
49 70
50 float leftOffset() const { return m_leftOffset; } 71 float leftOffset() const { return m_leftOffset; }
51 float rightOffset() const { return m_rightOffset; } 72 float rightOffset() const { return m_rightOffset; }
(...skipping 12 matching lines...) Expand all
64 return m_scrollContainerRelativeContainingBlockRect; 85 return m_scrollContainerRelativeContainingBlockRect;
65 } 86 }
66 87
67 void setScrollContainerRelativeStickyBoxRect(const FloatRect& rect) { 88 void setScrollContainerRelativeStickyBoxRect(const FloatRect& rect) {
68 m_scrollContainerRelativeStickyBoxRect = rect; 89 m_scrollContainerRelativeStickyBoxRect = rect;
69 } 90 }
70 const FloatRect& scrollContainerRelativeStickyBoxRect() const { 91 const FloatRect& scrollContainerRelativeStickyBoxRect() const {
71 return m_scrollContainerRelativeStickyBoxRect; 92 return m_scrollContainerRelativeStickyBoxRect;
72 } 93 }
73 94
95 void setNearestStickyElementShiftingStickyBox(LayoutBoxModelObject* layer) {
96 m_nearestStickyElementShiftingStickyBox = layer;
97 }
98 LayoutBoxModelObject* nearestStickyElementShiftingStickyBox() const {
99 return m_nearestStickyElementShiftingStickyBox;
100 }
101
102 void setNearestStickyElementShiftingContainingBlock(
103 LayoutBoxModelObject* layer) {
104 m_nearestStickyElementShiftingContainingBlock = layer;
105 }
106 LayoutBoxModelObject* nearestStickyElementShiftingContainingBlock() const {
107 return m_nearestStickyElementShiftingContainingBlock;
108 }
109
110 const FloatSize& getTotalStickyBoxStickyOffset() const {
111 return m_totalStickyBoxStickyOffset;
112 }
113 const FloatSize& getTotalContainingBlockStickyOffset() const {
114 return m_totalContainingBlockStickyOffset;
115 }
116
117 const FloatSize& getCachedComputedStickyOffset() const {
118 return m_cachedComputedStickyOffset;
119 }
120
74 bool operator==(const StickyPositionScrollingConstraints& other) const { 121 bool operator==(const StickyPositionScrollingConstraints& other) const {
75 return m_leftOffset == other.m_leftOffset && 122 return m_leftOffset == other.m_leftOffset &&
76 m_rightOffset == other.m_rightOffset && 123 m_rightOffset == other.m_rightOffset &&
77 m_topOffset == other.m_topOffset && 124 m_topOffset == other.m_topOffset &&
78 m_bottomOffset == other.m_bottomOffset && 125 m_bottomOffset == other.m_bottomOffset &&
79 m_scrollContainerRelativeContainingBlockRect == 126 m_scrollContainerRelativeContainingBlockRect ==
80 other.m_scrollContainerRelativeContainingBlockRect && 127 other.m_scrollContainerRelativeContainingBlockRect &&
81 m_scrollContainerRelativeStickyBoxRect == 128 m_scrollContainerRelativeStickyBoxRect ==
82 other.m_scrollContainerRelativeStickyBoxRect; 129 other.m_scrollContainerRelativeStickyBoxRect &&
130 m_nearestStickyElementShiftingStickyBox ==
131 other.m_nearestStickyElementShiftingStickyBox &&
132 m_nearestStickyElementShiftingContainingBlock ==
133 other.m_nearestStickyElementShiftingContainingBlock &&
134 m_totalStickyBoxStickyOffset == other.m_totalStickyBoxStickyOffset &&
135 m_totalContainingBlockStickyOffset ==
136 other.m_totalContainingBlockStickyOffset &&
137 m_cachedComputedStickyOffset == other.m_cachedComputedStickyOffset;
83 } 138 }
84 139
85 bool operator!=(const StickyPositionScrollingConstraints& other) const { 140 bool operator!=(const StickyPositionScrollingConstraints& other) const {
86 return !(*this == other); 141 return !(*this == other);
87 } 142 }
88 143
89 private: 144 private:
90 AnchorEdges m_anchorEdges; 145 AnchorEdges m_anchorEdges;
91 float m_leftOffset; 146 float m_leftOffset;
92 float m_rightOffset; 147 float m_rightOffset;
93 float m_topOffset; 148 float m_topOffset;
94 float m_bottomOffset; 149 float m_bottomOffset;
95 FloatRect m_scrollContainerRelativeContainingBlockRect; 150 FloatRect m_scrollContainerRelativeContainingBlockRect;
96 FloatRect m_scrollContainerRelativeStickyBoxRect; 151 FloatRect m_scrollContainerRelativeStickyBoxRect;
152
153 // In order to properly compute the stickyOffset, we need to know if we have
154 // any sticky ancestors both between ourselves and our containing block and
155 // between our containing block and the viewport. These ancestors are needed
156 // to properly shift our constraining rects with regards to the containing
157 // block and viewport.
158 LayoutBoxModelObject* m_nearestStickyElementShiftingStickyBox;
159 LayoutBoxModelObject* m_nearestStickyElementShiftingContainingBlock;
flackr 2017/02/22 22:40:15 bikeshed nit: Can we call these nearestBoxShifting
smcgruer 2017/02/23 20:14:17 Done.
160
161 // For performance we cache our accumulated sticky offset to allow descendant
162 // sticky elements to offset their constraint rects. Because we can either
163 // affect the sticky box constraint rect or the containing block constraint
164 // rect, we need to accumulate both.
165 //
166 // The case where we can affect both the sticky box constraint rect and the
167 // constraining block constriant rect for different sticky descendants is
168 // quite complex. See the StickyPositionComplexTableNesting test in
169 // LayoutBoxModelObjectTest.cpp.
170 FloatSize m_totalStickyBoxStickyOffset;
171 FloatSize m_totalContainingBlockStickyOffset;
172
173 FloatSize m_cachedComputedStickyOffset;
flackr 2017/02/22 22:40:15 m_localStickyOffset? But it looks like the code n
smcgruer 2017/02/23 20:14:17 Ah, this is from the cc side. Removed for now.
97 }; 174 };
98 175
99 } // namespace blink 176 } // namespace blink
100 177
101 #endif // StickyPositionScrollingConstraints_h 178 #endif // StickyPositionScrollingConstraints_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698