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

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

Issue 2636253002: Handle nested position:sticky elements (Closed)
Patch Set: First attempt at compositing side, does NOT work properly yet 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) {}
40 52
41 FloatSize computeStickyOffset(const FloatRect& viewportRect) const; 53 FloatSize computeStickyOffset(
54 const FloatRect& viewportRect,
55 StickyPositionScrollingConstraints* ancestorStickyBoxConstraints,
56 StickyPositionScrollingConstraints* ancestorContainingBlockConstraints);
57
58 bool hasAncestorStickyElement() const {
59 return m_nearestStickyElementShiftingStickyBox ||
60 m_nearestStickyElementShiftingContainingBlock;
61 }
42 62
43 AnchorEdges anchorEdges() const { return m_anchorEdges; } 63 AnchorEdges anchorEdges() const { return m_anchorEdges; }
44 bool hasAnchorEdge(AnchorEdgeFlags flag) const { 64 bool hasAnchorEdge(AnchorEdgeFlags flag) const {
45 return m_anchorEdges & flag; 65 return m_anchorEdges & flag;
46 } 66 }
47 void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; } 67 void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; }
48 void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; } 68 void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; }
49 69
50 float leftOffset() const { return m_leftOffset; } 70 float leftOffset() const { return m_leftOffset; }
51 float rightOffset() const { return m_rightOffset; } 71 float rightOffset() const { return m_rightOffset; }
(...skipping 12 matching lines...) Expand all
64 return m_scrollContainerRelativeContainingBlockRect; 84 return m_scrollContainerRelativeContainingBlockRect;
65 } 85 }
66 86
67 void setScrollContainerRelativeStickyBoxRect(const FloatRect& rect) { 87 void setScrollContainerRelativeStickyBoxRect(const FloatRect& rect) {
68 m_scrollContainerRelativeStickyBoxRect = rect; 88 m_scrollContainerRelativeStickyBoxRect = rect;
69 } 89 }
70 const FloatRect& scrollContainerRelativeStickyBoxRect() const { 90 const FloatRect& scrollContainerRelativeStickyBoxRect() const {
71 return m_scrollContainerRelativeStickyBoxRect; 91 return m_scrollContainerRelativeStickyBoxRect;
72 } 92 }
73 93
94 void setNearestStickyElementShiftingStickyBox(LayoutBoxModelObject* layer) {
95 m_nearestStickyElementShiftingStickyBox = layer;
96 }
97 LayoutBoxModelObject* nearestStickyElementShiftingStickyBox() const {
98 return m_nearestStickyElementShiftingStickyBox;
99 }
100
101 void setNearestStickyElementShiftingContainingBlock(
102 LayoutBoxModelObject* layer) {
103 m_nearestStickyElementShiftingContainingBlock = layer;
104 }
105 LayoutBoxModelObject* nearestStickyElementShiftingContainingBlock() const {
106 return m_nearestStickyElementShiftingContainingBlock;
107 }
108
109 const FloatSize& getTotalStickyBoxStickyOffset() {
110 return m_totalStickyBoxStickyOffset;
111 }
112 const FloatSize& getTotalContainingBlockStickyOffset() {
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_nearestStickyElementShiftingStickyBox ==
126 other.m_nearestStickyElementShiftingStickyBox &&
127 m_nearestStickyElementShiftingContainingBlock ==
128 other.m_nearestStickyElementShiftingContainingBlock &&
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_nearestStickyElementShiftingStickyBox;
153 LayoutBoxModelObject* m_nearestStickyElementShiftingContainingBlock;
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 // NOTE(smcgruer): The case where we can affect both the sticky box constraint
flackr 2017/02/02 18:18:11 nit: No need for NOTE(smcgruer)
smcgruer 2017/02/02 20:21:27 Done.
161 // rect and the constraining block constriant rect for different sticky
162 // descendants is quite complex. See the StickyPositionComplexTableNesting
163 // test in 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