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

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

Issue 1308273010: Adapt and reland old position sticky implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Force main thread scrolling, set experimental status, and address review comments. Created 5 years 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 /* 1 /*
2 * Copyright (C) 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE. 23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef ScrollingConstraints_h 26 #ifndef ScrollingConstraints_h
chrishtr 2015/12/11 02:06:12 Rename this file ViewportConstraints and add a new
flackr 2016/01/19 15:40:48 Done.
27 #define ScrollingConstraints_h 27 #define ScrollingConstraints_h
28 28
29 #include "platform/geometry/FloatRect.h" 29 #include "platform/geometry/LayoutRect.h"
30 #include "wtf/Allocator.h" 30 #include "wtf/Allocator.h"
31 31
32 namespace blink { 32 namespace blink {
33 33
34 // ViewportConstraints classes encapsulate data and logic required to reposition elements whose layout 34 // ViewportConstraints classes encapsulate data and logic required to reposition elements whose layout
35 // depends on the viewport rect (i.e., position fixed), when scrolling and zoomi ng. 35 // depends on the viewport rect (positioned fixed and sticky), when scrolling an d zooming.
36 class ViewportConstraints { 36 class ViewportConstraints {
37 STACK_ALLOCATED(); 37 STACK_ALLOCATED();
38 public: 38 public:
39 // FIXME: Simplify this code now that position: sticky doesn't exist.
40 enum ConstraintType { 39 enum ConstraintType {
41 FixedPositionConstaint, 40 FixedPositionConstaint,
41 StickyPositionConstraint,
42 }; 42 };
43 43
44 enum AnchorEdgeFlags { 44 enum AnchorEdgeFlags {
45 AnchorEdgeLeft = 1 << 0, 45 AnchorEdgeLeft = 1 << 0,
46 AnchorEdgeRight = 1 << 1, 46 AnchorEdgeRight = 1 << 1,
47 AnchorEdgeTop = 1 << 2, 47 AnchorEdgeTop = 1 << 2,
48 AnchorEdgeBottom = 1 << 3 48 AnchorEdgeBottom = 1 << 3
49 }; 49 };
50 typedef unsigned AnchorEdges; 50 typedef unsigned AnchorEdges;
51 51
52 ViewportConstraints(const ViewportConstraints& other) 52 ViewportConstraints(const ViewportConstraints& other)
53 : m_alignmentOffset(other.m_alignmentOffset) 53 : m_alignmentOffset(other.m_alignmentOffset)
54 , m_anchorEdges(other.m_anchorEdges) 54 , m_anchorEdges(other.m_anchorEdges)
55 { } 55 { }
56 56
57 virtual ~ViewportConstraints() { } 57 virtual ~ViewportConstraints() { }
58 58
59 virtual ConstraintType constraintType() const = 0; 59 virtual ConstraintType constraintType() const = 0;
60 60
61 AnchorEdges anchorEdges() const { return m_anchorEdges; } 61 AnchorEdges anchorEdges() const { return m_anchorEdges; }
62 bool hasAnchorEdge(AnchorEdgeFlags flag) const { return m_anchorEdges & flag ; } 62 bool hasAnchorEdge(AnchorEdgeFlags flag) const { return m_anchorEdges & flag ; }
63 void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; } 63 void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; }
64 void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; } 64 void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; }
65 65
66 FloatSize alignmentOffset() const { return m_alignmentOffset; } 66 LayoutSize alignmentOffset() const { return m_alignmentOffset; }
chrishtr 2015/12/11 02:06:12 Why the change from float to layout units here? Th
flackr 2016/01/19 15:40:48 Undone. At the time I thought it'd made for fewer
67 void setAlignmentOffset(const FloatSize& offset) { m_alignmentOffset = offse t; } 67 void setAlignmentOffset(const LayoutSize& offset) { m_alignmentOffset = offs et; }
68 68
69 protected: 69 protected:
70 ViewportConstraints() 70 ViewportConstraints()
71 : m_anchorEdges(0) 71 : m_anchorEdges(0)
72 { } 72 { }
73 73
74 FloatSize m_alignmentOffset; 74 LayoutSize m_alignmentOffset;
75 AnchorEdges m_anchorEdges; 75 AnchorEdges m_anchorEdges;
76 }; 76 };
77 77
78 class FixedPositionViewportConstraints final : public ViewportConstraints { 78 class FixedPositionViewportConstraints final : public ViewportConstraints {
79 STACK_ALLOCATED(); 79 STACK_ALLOCATED();
80 public: 80 public:
81 FixedPositionViewportConstraints() 81 FixedPositionViewportConstraints()
82 : ViewportConstraints() 82 : ViewportConstraints()
83 { } 83 { }
84 84
85 FixedPositionViewportConstraints(const FixedPositionViewportConstraints& oth er) 85 FixedPositionViewportConstraints(const FixedPositionViewportConstraints& oth er)
86 : ViewportConstraints(other) 86 : ViewportConstraints(other)
87 , m_viewportRectAtLastLayout(other.m_viewportRectAtLastLayout)
88 , m_layerPositionAtLastLayout(other.m_layerPositionAtLastLayout)
89 { } 87 { }
90 88
91 FloatPoint layerPositionForViewportRect(const FloatRect& viewportRect) const ;
92
93 const FloatRect& viewportRectAtLastLayout() const { return m_viewportRectAtL astLayout; }
94 void setViewportRectAtLastLayout(const FloatRect& rect) { m_viewportRectAtLa stLayout = rect; }
95
96 const FloatPoint& layerPositionAtLastLayout() const { return m_layerPosition AtLastLayout; }
97 void setLayerPositionAtLastLayout(const FloatPoint& point) { m_layerPosition AtLastLayout = point; }
98
99 bool operator==(const FixedPositionViewportConstraints& other) const 89 bool operator==(const FixedPositionViewportConstraints& other) const
100 { 90 {
101 return m_alignmentOffset == other.m_alignmentOffset 91 return m_alignmentOffset == other.m_alignmentOffset
102 && m_anchorEdges == other.m_anchorEdges 92 && m_anchorEdges == other.m_anchorEdges;
103 && m_viewportRectAtLastLayout == other.m_viewportRectAtLastLayout
104 && m_layerPositionAtLastLayout == other.m_layerPositionAtLastLayout;
105 } 93 }
106 94
107 bool operator!=(const FixedPositionViewportConstraints& other) const { retur n !(*this == other); } 95 bool operator!=(const FixedPositionViewportConstraints& other) const { retur n !(*this == other); }
108 96
109 private: 97 private:
110 ConstraintType constraintType() const override { return FixedPositionConstai nt; } 98 ConstraintType constraintType() const override { return FixedPositionConstai nt; }
99 };
111 100
112 FloatRect m_viewportRectAtLastLayout; 101 class StickyPositionViewportConstraints final : public ViewportConstraints {
113 FloatPoint m_layerPositionAtLastLayout; 102 public:
103 StickyPositionViewportConstraints()
104 : m_leftOffset(0)
105 , m_rightOffset(0)
106 , m_topOffset(0)
107 , m_bottomOffset(0)
108 { }
109
110 StickyPositionViewportConstraints(const StickyPositionViewportConstraints& o ther)
111 : ViewportConstraints(other)
112 , m_leftOffset(other.m_leftOffset)
113 , m_rightOffset(other.m_rightOffset)
114 , m_topOffset(other.m_topOffset)
115 , m_bottomOffset(other.m_bottomOffset)
116 , m_absoluteContainingBlockRect(other.m_absoluteContainingBlockRect)
117 , m_absoluteStickyBoxRect(other.m_absoluteStickyBoxRect)
118 { }
119
120 LayoutSize computeStickyOffset(const LayoutRect& viewportRect) const;
121
122 LayoutUnit leftOffset() const { return m_leftOffset; }
123 LayoutUnit rightOffset() const { return m_rightOffset; }
124 LayoutUnit topOffset() const { return m_topOffset; }
125 LayoutUnit bottomOffset() const { return m_bottomOffset; }
126
127 void setLeftOffset(LayoutUnit offset) { m_leftOffset = offset; }
128 void setRightOffset(LayoutUnit offset) { m_rightOffset = offset; }
129 void setTopOffset(LayoutUnit offset) { m_topOffset = offset; }
130 void setBottomOffset(LayoutUnit offset) { m_bottomOffset = offset; }
131
132 void setAbsoluteContainingBlockRect(const LayoutRect& rect) { m_absoluteCont ainingBlockRect = rect; }
133
134 void setAbsoluteStickyBoxRect(const LayoutRect& rect) { m_absoluteStickyBoxR ect = rect; }
135
136 bool operator==(const StickyPositionViewportConstraints& other) const
137 {
138 return m_leftOffset == other.m_leftOffset
139 && m_rightOffset == other.m_rightOffset
140 && m_topOffset == other.m_topOffset
141 && m_bottomOffset == other.m_bottomOffset
142 && m_absoluteContainingBlockRect == other.m_absoluteContainingBlockR ect
143 && m_absoluteStickyBoxRect == other.m_absoluteStickyBoxRect;
144 }
145
146 bool operator!=(const StickyPositionViewportConstraints& other) const { retu rn !(*this == other); }
147
148 private:
149 ConstraintType constraintType() const override { return StickyPositionConstr aint; }
150
151 LayoutUnit m_leftOffset;
152 LayoutUnit m_rightOffset;
153 LayoutUnit m_topOffset;
154 LayoutUnit m_bottomOffset;
155 LayoutRect m_absoluteContainingBlockRect;
156 LayoutRect m_absoluteStickyBoxRect;
114 }; 157 };
115 158
116 } // namespace blink 159 } // namespace blink
117 160
118 #endif // ScrollingConstraints_h 161 #endif // ScrollingConstraints_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698