OLD | NEW |
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 |
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; } |
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) | 87 , m_viewportRectAtLastLayout(other.m_viewportRectAtLastLayout) |
88 , m_layerPositionAtLastLayout(other.m_layerPositionAtLastLayout) | 88 , m_layerPositionAtLastLayout(other.m_layerPositionAtLastLayout) |
89 { } | 89 { } |
90 | 90 |
91 FloatPoint layerPositionForViewportRect(const FloatRect& viewportRect) const
; | 91 LayoutPoint layerPositionForViewportRect(const LayoutRect& viewportRect) con
st; |
92 | 92 |
93 const FloatRect& viewportRectAtLastLayout() const { return m_viewportRectAtL
astLayout; } | 93 const LayoutRect& viewportRectAtLastLayout() const { return m_viewportRectAt
LastLayout; } |
94 void setViewportRectAtLastLayout(const FloatRect& rect) { m_viewportRectAtLa
stLayout = rect; } | 94 void setViewportRectAtLastLayout(const LayoutRect& rect) { m_viewportRectAtL
astLayout = rect; } |
95 | 95 |
96 const FloatPoint& layerPositionAtLastLayout() const { return m_layerPosition
AtLastLayout; } | 96 const LayoutPoint& layerPositionAtLastLayout() const { return m_layerPositio
nAtLastLayout; } |
97 void setLayerPositionAtLastLayout(const FloatPoint& point) { m_layerPosition
AtLastLayout = point; } | 97 void setLayerPositionAtLastLayout(const LayoutPoint& point) { m_layerPositio
nAtLastLayout = point; } |
98 | 98 |
99 bool operator==(const FixedPositionViewportConstraints& other) const | 99 bool operator==(const FixedPositionViewportConstraints& other) const |
100 { | 100 { |
101 return m_alignmentOffset == other.m_alignmentOffset | 101 return m_alignmentOffset == other.m_alignmentOffset |
102 && m_anchorEdges == other.m_anchorEdges | 102 && m_anchorEdges == other.m_anchorEdges |
103 && m_viewportRectAtLastLayout == other.m_viewportRectAtLastLayout | 103 && m_viewportRectAtLastLayout == other.m_viewportRectAtLastLayout |
104 && m_layerPositionAtLastLayout == other.m_layerPositionAtLastLayout; | 104 && m_layerPositionAtLastLayout == other.m_layerPositionAtLastLayout; |
105 } | 105 } |
106 | 106 |
107 bool operator!=(const FixedPositionViewportConstraints& other) const { retur
n !(*this == other); } | 107 bool operator!=(const FixedPositionViewportConstraints& other) const { retur
n !(*this == other); } |
108 | 108 |
109 private: | 109 private: |
110 ConstraintType constraintType() const override { return FixedPositionConstai
nt; } | 110 ConstraintType constraintType() const override { return FixedPositionConstai
nt; } |
111 | 111 |
112 FloatRect m_viewportRectAtLastLayout; | 112 LayoutRect m_viewportRectAtLastLayout; |
113 FloatPoint m_layerPositionAtLastLayout; | 113 LayoutPoint m_layerPositionAtLastLayout; |
| 114 }; |
| 115 |
| 116 class StickyPositionViewportConstraints final : public ViewportConstraints { |
| 117 public: |
| 118 StickyPositionViewportConstraints() |
| 119 : m_leftOffset(0) |
| 120 , m_rightOffset(0) |
| 121 , m_topOffset(0) |
| 122 , m_bottomOffset(0) |
| 123 { } |
| 124 |
| 125 StickyPositionViewportConstraints(const StickyPositionViewportConstraints& o
ther) |
| 126 : ViewportConstraints(other) |
| 127 , m_leftOffset(other.m_leftOffset) |
| 128 , m_rightOffset(other.m_rightOffset) |
| 129 , m_topOffset(other.m_topOffset) |
| 130 , m_bottomOffset(other.m_bottomOffset) |
| 131 , m_absoluteContainingBlockRect(other.m_absoluteContainingBlockRect) |
| 132 , m_absoluteStickyBoxRect(other.m_absoluteStickyBoxRect) |
| 133 , m_stickyOffsetAtLastLayout(other.m_stickyOffsetAtLastLayout) |
| 134 , m_layerPositionAtLastLayout(other.m_layerPositionAtLastLayout) |
| 135 { } |
| 136 |
| 137 LayoutSize computeStickyOffset(const LayoutRect& viewportRect) const; |
| 138 |
| 139 const LayoutSize stickyOffsetAtLastLayout() const { return m_stickyOffsetAtL
astLayout; } |
| 140 void setStickyOffsetAtLastLayout(const LayoutSize& offset) { m_stickyOffsetA
tLastLayout = offset; } |
| 141 |
| 142 LayoutPoint layerPositionForViewportRect(const LayoutRect& viewportRect) con
st; |
| 143 |
| 144 const LayoutPoint& layerPositionAtLastLayout() const { return m_layerPositio
nAtLastLayout; } |
| 145 void setLayerPositionAtLastLayout(const LayoutPoint& point) { m_layerPositio
nAtLastLayout = point; } |
| 146 |
| 147 LayoutUnit leftOffset() const { return m_leftOffset; } |
| 148 LayoutUnit rightOffset() const { return m_rightOffset; } |
| 149 LayoutUnit topOffset() const { return m_topOffset; } |
| 150 LayoutUnit bottomOffset() const { return m_bottomOffset; } |
| 151 |
| 152 void setLeftOffset(LayoutUnit offset) { m_leftOffset = offset; } |
| 153 void setRightOffset(LayoutUnit offset) { m_rightOffset = offset; } |
| 154 void setTopOffset(LayoutUnit offset) { m_topOffset = offset; } |
| 155 void setBottomOffset(LayoutUnit offset) { m_bottomOffset = offset; } |
| 156 |
| 157 LayoutRect absoluteContainingBlockRect() const { return m_absoluteContaining
BlockRect; } |
| 158 void setAbsoluteContainingBlockRect(const LayoutRect& rect) { m_absoluteCont
ainingBlockRect = rect; } |
| 159 |
| 160 LayoutRect absoluteStickyBoxRect() const { return m_absoluteStickyBoxRect; } |
| 161 void setAbsoluteStickyBoxRect(const LayoutRect& rect) { m_absoluteStickyBoxR
ect = rect; } |
| 162 |
| 163 bool operator==(const StickyPositionViewportConstraints& other) const |
| 164 { |
| 165 return m_leftOffset == other.m_leftOffset |
| 166 && m_rightOffset == other.m_rightOffset |
| 167 && m_topOffset == other.m_topOffset |
| 168 && m_bottomOffset == other.m_bottomOffset |
| 169 && m_absoluteContainingBlockRect == other.m_absoluteContainingBlockR
ect |
| 170 && m_absoluteStickyBoxRect == other.m_absoluteStickyBoxRect |
| 171 && m_stickyOffsetAtLastLayout == other.m_stickyOffsetAtLastLayout |
| 172 && m_layerPositionAtLastLayout == other.m_layerPositionAtLastLayout; |
| 173 } |
| 174 |
| 175 bool operator!=(const StickyPositionViewportConstraints& other) const { retu
rn !(*this == other); } |
| 176 |
| 177 private: |
| 178 ConstraintType constraintType() const override { return StickyPositionConstr
aint; } |
| 179 |
| 180 LayoutUnit m_leftOffset; |
| 181 LayoutUnit m_rightOffset; |
| 182 LayoutUnit m_topOffset; |
| 183 LayoutUnit m_bottomOffset; |
| 184 LayoutRect m_absoluteContainingBlockRect; |
| 185 LayoutRect m_absoluteStickyBoxRect; |
| 186 LayoutSize m_stickyOffsetAtLastLayout; |
| 187 LayoutPoint m_layerPositionAtLastLayout; |
114 }; | 188 }; |
115 | 189 |
116 } // namespace blink | 190 } // namespace blink |
117 | 191 |
118 #endif // ScrollingConstraints_h | 192 #endif // ScrollingConstraints_h |
OLD | NEW |