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

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, 9 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_nearestStickyBoxShiftingStickyBox(nullptr),
32 m_nearestStickyBoxShiftingContainingBlock(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_nearestStickyBoxShiftingStickyBox(
46 other.m_nearestStickyBoxShiftingStickyBox),
47 m_nearestStickyBoxShiftingContainingBlock(
48 other.m_nearestStickyBoxShiftingContainingBlock),
49 m_totalStickyBoxStickyOffset(other.m_totalStickyBoxStickyOffset),
50 m_totalContainingBlockStickyOffset(
51 other.m_totalContainingBlockStickyOffset) {}
40 52
41 FloatSize computeStickyOffset(const FloatRect& viewportRect) const; 53 FloatSize computeStickyOffset(
54 const FloatRect& viewportRect,
55 const StickyPositionScrollingConstraints* ancestorStickyBoxConstraints,
56 const StickyPositionScrollingConstraints*
57 ancestorContainingBlockConstraints);
58
59 bool hasAncestorStickyElement() const {
60 return m_nearestStickyBoxShiftingStickyBox ||
61 m_nearestStickyBoxShiftingContainingBlock;
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 setNearestStickyBoxShiftingStickyBox(LayoutBoxModelObject* layer) {
96 m_nearestStickyBoxShiftingStickyBox = layer;
97 }
98 LayoutBoxModelObject* nearestStickyBoxShiftingStickyBox() const {
99 return m_nearestStickyBoxShiftingStickyBox;
100 }
101
102 void setNearestStickyBoxShiftingContainingBlock(LayoutBoxModelObject* layer) {
103 m_nearestStickyBoxShiftingContainingBlock = layer;
104 }
105 LayoutBoxModelObject* nearestStickyBoxShiftingContainingBlock() const {
106 return m_nearestStickyBoxShiftingContainingBlock;
107 }
108
109 const FloatSize& getTotalStickyBoxStickyOffset() const {
110 return m_totalStickyBoxStickyOffset;
111 }
112 const FloatSize& getTotalContainingBlockStickyOffset() const {
113 return m_totalContainingBlockStickyOffset;
114 }
115
74 bool operator==(const StickyPositionScrollingConstraints& other) const { 116 bool operator==(const StickyPositionScrollingConstraints& other) const {
75 return m_leftOffset == other.m_leftOffset && 117 return m_leftOffset == other.m_leftOffset &&
76 m_rightOffset == other.m_rightOffset && 118 m_rightOffset == other.m_rightOffset &&
77 m_topOffset == other.m_topOffset && 119 m_topOffset == other.m_topOffset &&
78 m_bottomOffset == other.m_bottomOffset && 120 m_bottomOffset == other.m_bottomOffset &&
79 m_scrollContainerRelativeContainingBlockRect == 121 m_scrollContainerRelativeContainingBlockRect ==
80 other.m_scrollContainerRelativeContainingBlockRect && 122 other.m_scrollContainerRelativeContainingBlockRect &&
81 m_scrollContainerRelativeStickyBoxRect == 123 m_scrollContainerRelativeStickyBoxRect ==
82 other.m_scrollContainerRelativeStickyBoxRect; 124 other.m_scrollContainerRelativeStickyBoxRect &&
125 m_nearestStickyBoxShiftingStickyBox ==
126 other.m_nearestStickyBoxShiftingStickyBox &&
127 m_nearestStickyBoxShiftingContainingBlock ==
128 other.m_nearestStickyBoxShiftingContainingBlock &&
129 m_totalStickyBoxStickyOffset == other.m_totalStickyBoxStickyOffset &&
130 m_totalContainingBlockStickyOffset ==
131 other.m_totalContainingBlockStickyOffset;
83 } 132 }
84 133
85 bool operator!=(const StickyPositionScrollingConstraints& other) const { 134 bool operator!=(const StickyPositionScrollingConstraints& other) const {
86 return !(*this == other); 135 return !(*this == other);
87 } 136 }
88 137
89 private: 138 private:
90 AnchorEdges m_anchorEdges; 139 AnchorEdges m_anchorEdges;
91 float m_leftOffset; 140 float m_leftOffset;
92 float m_rightOffset; 141 float m_rightOffset;
93 float m_topOffset; 142 float m_topOffset;
94 float m_bottomOffset; 143 float m_bottomOffset;
95 FloatRect m_scrollContainerRelativeContainingBlockRect; 144 FloatRect m_scrollContainerRelativeContainingBlockRect;
96 FloatRect m_scrollContainerRelativeStickyBoxRect; 145 FloatRect m_scrollContainerRelativeStickyBoxRect;
146
147 // In order to properly compute the stickyOffset, we need to know if we have
148 // any sticky ancestors both between ourselves and our containing block and
149 // between our containing block and the viewport. These ancestors are needed
150 // to properly shift our constraining rects with regards to the containing
151 // block and viewport.
152 LayoutBoxModelObject* m_nearestStickyBoxShiftingStickyBox;
153 LayoutBoxModelObject* m_nearestStickyBoxShiftingContainingBlock;
154
155 // For performance we cache our accumulated sticky offset to allow descendant
156 // sticky elements to offset their constraint rects. Because we can either
157 // affect the sticky box constraint rect or the containing block constraint
158 // rect, we need to accumulate both.
159 //
160 // The case where we can affect both the sticky box constraint rect and the
161 // constraining block constriant rect for different sticky descendants is
162 // quite complex. See the StickyPositionComplexTableNesting test in
163 // LayoutBoxModelObjectTest.cpp.
164 FloatSize m_totalStickyBoxStickyOffset;
165 FloatSize m_totalContainingBlockStickyOffset;
97 }; 166 };
98 167
99 } // namespace blink 168 } // namespace blink
100 169
101 #endif // StickyPositionScrollingConstraints_h 170 #endif // StickyPositionScrollingConstraints_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698