OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2012 Apple Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions | |
6 * are met: | |
7 * 1. Redistributions of source code must retain the above copyright | |
8 * notice, this list of conditions and the following disclaimer. | |
9 * 2. Redistributions in binary form must reproduce the above copyright | |
10 * notice, this list of conditions and the following disclaimer in the | |
11 * documentation and/or other materials provided with the distribution. | |
12 * | |
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, | |
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | |
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
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 | |
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 | |
23 * THE POSSIBILITY OF SUCH DAMAGE. | |
24 */ | |
25 | |
26 #ifndef ScrollingConstraints_h | |
27 #define ScrollingConstraints_h | |
28 | |
29 #include "platform/geometry/FloatRect.h" | |
30 #include "wtf/Allocator.h" | |
31 | |
32 namespace blink { | |
33 | |
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. | |
36 class ViewportConstraints { | |
37 STACK_ALLOCATED(); | |
38 public: | |
39 // FIXME: Simplify this code now that position: sticky doesn't exist. | |
40 enum ConstraintType { | |
41 FixedPositionConstaint, | |
42 }; | |
43 | |
44 enum AnchorEdgeFlags { | |
45 AnchorEdgeLeft = 1 << 0, | |
46 AnchorEdgeRight = 1 << 1, | |
47 AnchorEdgeTop = 1 << 2, | |
48 AnchorEdgeBottom = 1 << 3 | |
49 }; | |
50 typedef unsigned AnchorEdges; | |
51 | |
52 ViewportConstraints(const ViewportConstraints& other) | |
53 : m_alignmentOffset(other.m_alignmentOffset) | |
54 , m_anchorEdges(other.m_anchorEdges) | |
55 { } | |
56 | |
57 virtual ~ViewportConstraints() { } | |
58 | |
59 virtual ConstraintType constraintType() const = 0; | |
60 | |
61 AnchorEdges anchorEdges() const { return m_anchorEdges; } | |
62 bool hasAnchorEdge(AnchorEdgeFlags flag) const { return m_anchorEdges & flag
; } | |
63 void addAnchorEdge(AnchorEdgeFlags edgeFlag) { m_anchorEdges |= edgeFlag; } | |
64 void setAnchorEdges(AnchorEdges edges) { m_anchorEdges = edges; } | |
65 | |
66 FloatSize alignmentOffset() const { return m_alignmentOffset; } | |
67 void setAlignmentOffset(const FloatSize& offset) { m_alignmentOffset = offse
t; } | |
68 | |
69 protected: | |
70 ViewportConstraints() | |
71 : m_anchorEdges(0) | |
72 { } | |
73 | |
74 FloatSize m_alignmentOffset; | |
75 AnchorEdges m_anchorEdges; | |
76 }; | |
77 | |
78 class FixedPositionViewportConstraints final : public ViewportConstraints { | |
79 STACK_ALLOCATED(); | |
80 public: | |
81 FixedPositionViewportConstraints() | |
82 : ViewportConstraints() | |
83 { } | |
84 | |
85 FixedPositionViewportConstraints(const FixedPositionViewportConstraints& oth
er) | |
86 : ViewportConstraints(other) | |
87 , m_viewportRectAtLastLayout(other.m_viewportRectAtLastLayout) | |
88 , m_layerPositionAtLastLayout(other.m_layerPositionAtLastLayout) | |
89 { } | |
90 | |
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 | |
100 { | |
101 return m_alignmentOffset == other.m_alignmentOffset | |
102 && m_anchorEdges == other.m_anchorEdges | |
103 && m_viewportRectAtLastLayout == other.m_viewportRectAtLastLayout | |
104 && m_layerPositionAtLastLayout == other.m_layerPositionAtLastLayout; | |
105 } | |
106 | |
107 bool operator!=(const FixedPositionViewportConstraints& other) const { retur
n !(*this == other); } | |
108 | |
109 private: | |
110 ConstraintType constraintType() const override { return FixedPositionConstai
nt; } | |
111 | |
112 FloatRect m_viewportRectAtLastLayout; | |
113 FloatPoint m_layerPositionAtLastLayout; | |
114 }; | |
115 | |
116 } // namespace blink | |
117 | |
118 #endif // ScrollingConstraints_h | |
OLD | NEW |