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

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

Issue 2636253002: Handle nested position:sticky elements (Closed)
Patch Set: Ignore position:sticky offsets when computing localToAncestorQuad offsets 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(const FloatRect& viewportRect,
54 const FloatSize& ancestorStickyBoxOffset,
55 const FloatSize& ancestorContainingBlockOffset);
56
57 bool hasAncestorStickyElement() {
58 return m_nearestStickyElementShiftingStickyBox ||
59 m_nearestStickyElementShiftingContainingBlock;
60 }
42 61
43 AnchorEdges anchorEdges() const { return m_anchorEdges; } 62 AnchorEdges anchorEdges() const { return m_anchorEdges; }
44 bool hasAnchorEdge(AnchorEdgeFlags flag) const { 63 bool hasAnchorEdge(AnchorEdgeFlags flag) const {
45 return m_anchorEdges & flag; 64 return m_anchorEdges & flag;
46 } 65 }
47 void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; } 66 void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; }
48 void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; } 67 void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; }
49 68
50 float leftOffset() const { return m_leftOffset; } 69 float leftOffset() const { return m_leftOffset; }
51 float rightOffset() const { return m_rightOffset; } 70 float rightOffset() const { return m_rightOffset; }
(...skipping 12 matching lines...) Expand all
64 return m_scrollContainerRelativeContainingBlockRect; 83 return m_scrollContainerRelativeContainingBlockRect;
65 } 84 }
66 85
67 void setScrollContainerRelativeStickyBoxRect(const FloatRect& rect) { 86 void setScrollContainerRelativeStickyBoxRect(const FloatRect& rect) {
68 m_scrollContainerRelativeStickyBoxRect = rect; 87 m_scrollContainerRelativeStickyBoxRect = rect;
69 } 88 }
70 const FloatRect& scrollContainerRelativeStickyBoxRect() const { 89 const FloatRect& scrollContainerRelativeStickyBoxRect() const {
71 return m_scrollContainerRelativeStickyBoxRect; 90 return m_scrollContainerRelativeStickyBoxRect;
72 } 91 }
73 92
93 void setNearestStickyElementShiftingStickyBox(LayoutBoxModelObject* layer) {
94 m_nearestStickyElementShiftingStickyBox = layer;
95 }
96 const LayoutBoxModelObject* nearestStickyElementShiftingStickyBox() {
97 return m_nearestStickyElementShiftingStickyBox;
98 }
99
100 void setNearestStickyElementShiftingContainingBlock(
101 LayoutBoxModelObject* layer) {
102 m_nearestStickyElementShiftingContainingBlock = layer;
103 }
104 const LayoutBoxModelObject* nearestStickyElementShiftingContainingBlock() {
105 return m_nearestStickyElementShiftingContainingBlock;
106 }
107
108 const FloatSize& getTotalStickyBoxStickyOffset() {
109 return m_totalStickyBoxStickyOffset;
110 }
111 const FloatSize& getTotalContainingBlockStickyOffset() {
112 return m_totalContainingBlockStickyOffset;
113 }
114
74 bool operator==(const StickyPositionScrollingConstraints& other) const { 115 bool operator==(const StickyPositionScrollingConstraints& other) const {
75 return m_leftOffset == other.m_leftOffset && 116 return m_leftOffset == other.m_leftOffset &&
76 m_rightOffset == other.m_rightOffset && 117 m_rightOffset == other.m_rightOffset &&
77 m_topOffset == other.m_topOffset && 118 m_topOffset == other.m_topOffset &&
78 m_bottomOffset == other.m_bottomOffset && 119 m_bottomOffset == other.m_bottomOffset &&
79 m_scrollContainerRelativeContainingBlockRect == 120 m_scrollContainerRelativeContainingBlockRect ==
80 other.m_scrollContainerRelativeContainingBlockRect && 121 other.m_scrollContainerRelativeContainingBlockRect &&
81 m_scrollContainerRelativeStickyBoxRect == 122 m_scrollContainerRelativeStickyBoxRect ==
82 other.m_scrollContainerRelativeStickyBoxRect; 123 other.m_scrollContainerRelativeStickyBoxRect &&
124 m_nearestStickyElementShiftingStickyBox ==
125 other.m_nearestStickyElementShiftingStickyBox &&
126 m_nearestStickyElementShiftingContainingBlock ==
127 other.m_nearestStickyElementShiftingContainingBlock &&
128 m_totalStickyBoxStickyOffset == other.m_totalStickyBoxStickyOffset &&
129 m_totalContainingBlockStickyOffset ==
130 other.m_totalContainingBlockStickyOffset;
83 } 131 }
84 132
85 bool operator!=(const StickyPositionScrollingConstraints& other) const { 133 bool operator!=(const StickyPositionScrollingConstraints& other) const {
86 return !(*this == other); 134 return !(*this == other);
87 } 135 }
88 136
89 private: 137 private:
90 AnchorEdges m_anchorEdges; 138 AnchorEdges m_anchorEdges;
91 float m_leftOffset; 139 float m_leftOffset;
92 float m_rightOffset; 140 float m_rightOffset;
93 float m_topOffset; 141 float m_topOffset;
94 float m_bottomOffset; 142 float m_bottomOffset;
95 FloatRect m_scrollContainerRelativeContainingBlockRect; 143 FloatRect m_scrollContainerRelativeContainingBlockRect;
96 FloatRect m_scrollContainerRelativeStickyBoxRect; 144 FloatRect m_scrollContainerRelativeStickyBoxRect;
145
146 // In order to properly compute the stickyOffset, we need to know if we have
147 // any sticky ancestors both between ourselves and our containing block and
148 // between our containing block and the viewport. These ancestors are needed
149 // to properly shift our constraining rects with regards to the containing
150 // block and viewport.
151 LayoutBoxModelObject* m_nearestStickyElementShiftingStickyBox;
152 LayoutBoxModelObject* m_nearestStickyElementShiftingContainingBlock;
153
154 // For performance we cache our accumulated sticky offset to allow descendant
155 // sticky elements to offset their constraint rects. Because we can either
156 // affect the sticky box constraint rect or the containing block constraint
157 // rect, we need to accumulate both.
158 //
159 // NOTE(smcgruer): The case where we can affect both the sticky box constraint
160 // rect and the constraining block constriant rect for different sticky
161 // descendants is quite complex. See the StickyPositionComplexTableNesting
162 // test in LayoutBoxModelObjectTest.cpp.
163 FloatSize m_totalStickyBoxStickyOffset;
164 FloatSize m_totalContainingBlockStickyOffset;
97 }; 165 };
98 166
99 } // namespace blink 167 } // namespace blink
100 168
101 #endif // StickyPositionScrollingConstraints_h 169 #endif // StickyPositionScrollingConstraints_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698