OLD | NEW |
| (Empty) |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CC_INPUT_INPUT_HANDLER_H_ | |
6 #define CC_INPUT_INPUT_HANDLER_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/time/time.h" | |
11 #include "cc/base/cc_export.h" | |
12 #include "cc/input/scrollbar.h" | |
13 #include "cc/trees/swap_promise_monitor.h" | |
14 | |
15 namespace gfx { | |
16 class Point; | |
17 class PointF; | |
18 class Vector2d; | |
19 class Vector2dF; | |
20 } | |
21 | |
22 namespace ui { struct LatencyInfo; } | |
23 | |
24 namespace cc { | |
25 | |
26 class LayerScrollOffsetDelegate; | |
27 class ScrollElasticityHelper; | |
28 | |
29 struct CC_EXPORT InputHandlerScrollResult { | |
30 InputHandlerScrollResult(); | |
31 // Did any layer scroll as a result this ScrollBy call? | |
32 bool did_scroll; | |
33 // Was any of the scroll delta argument to this ScrollBy call not used? | |
34 bool did_overscroll_root; | |
35 // The total overscroll that has been accumulated by all ScrollBy calls that | |
36 // have had overscroll since the last ScrollBegin call. This resets upon a | |
37 // ScrollBy with no overscroll. | |
38 gfx::Vector2dF accumulated_root_overscroll; | |
39 // The amount of the scroll delta argument to this ScrollBy call that was not | |
40 // used for scrolling. | |
41 gfx::Vector2dF unused_scroll_delta; | |
42 }; | |
43 | |
44 class CC_EXPORT InputHandlerClient { | |
45 public: | |
46 virtual ~InputHandlerClient() {} | |
47 | |
48 virtual void WillShutdown() = 0; | |
49 virtual void Animate(base::TimeTicks time) = 0; | |
50 virtual void MainThreadHasStoppedFlinging() = 0; | |
51 virtual void ReconcileElasticOverscrollAndRootScroll() = 0; | |
52 | |
53 protected: | |
54 InputHandlerClient() {} | |
55 | |
56 private: | |
57 DISALLOW_COPY_AND_ASSIGN(InputHandlerClient); | |
58 }; | |
59 | |
60 // The InputHandler is a way for the embedders to interact with the impl thread | |
61 // side of the compositor implementation. There is one InputHandler per | |
62 // LayerTreeHost. To use the input handler, implement the InputHanderClient | |
63 // interface and bind it to the handler on the compositor thread. | |
64 class CC_EXPORT InputHandler { | |
65 public: | |
66 // Note these are used in a histogram. Do not reorder or delete existing | |
67 // entries. | |
68 enum ScrollStatus { | |
69 SCROLL_ON_MAIN_THREAD = 0, | |
70 SCROLL_STARTED, | |
71 SCROLL_IGNORED, | |
72 SCROLL_UNKNOWN, | |
73 // This must be the last entry. | |
74 ScrollStatusCount | |
75 }; | |
76 enum ScrollInputType { GESTURE, WHEEL, NON_BUBBLING_GESTURE }; | |
77 | |
78 // Binds a client to this handler to receive notifications. Only one client | |
79 // can be bound to an InputHandler. The client must live at least until the | |
80 // handler calls WillShutdown() on the client. | |
81 virtual void BindToClient(InputHandlerClient* client) = 0; | |
82 | |
83 // Selects a layer to be scrolled at a given point in viewport (logical | |
84 // pixel) coordinates. Returns SCROLL_STARTED if the layer at the coordinates | |
85 // can be scrolled, SCROLL_ON_MAIN_THREAD if the scroll event should instead | |
86 // be delegated to the main thread, or SCROLL_IGNORED if there is nothing to | |
87 // be scrolled at the given coordinates. | |
88 virtual ScrollStatus ScrollBegin(const gfx::Point& viewport_point, | |
89 ScrollInputType type) = 0; | |
90 | |
91 virtual ScrollStatus ScrollAnimated(const gfx::Point& viewport_point, | |
92 const gfx::Vector2dF& scroll_delta) = 0; | |
93 | |
94 // Scroll the selected layer starting at the given position. If the scroll | |
95 // type given to ScrollBegin was a gesture, then the scroll point and delta | |
96 // should be in viewport (logical pixel) coordinates. Otherwise they are in | |
97 // scrolling layer's (logical pixel) space. If there is no room to move the | |
98 // layer in the requested direction, its first ancestor layer that can be | |
99 // scrolled will be moved instead. The return value's |did_scroll| field is | |
100 // set to false if no layer can be moved in the requested direction at all, | |
101 // and set to true if any layer is moved. | |
102 // If the scroll delta hits the root layer, and the layer can no longer move, | |
103 // the root overscroll accumulated within this ScrollBegin() scope is reported | |
104 // in the return value's |accumulated_overscroll| field. | |
105 // Should only be called if ScrollBegin() returned SCROLL_STARTED. | |
106 virtual InputHandlerScrollResult ScrollBy( | |
107 const gfx::Point& viewport_point, | |
108 const gfx::Vector2dF& scroll_delta) = 0; | |
109 | |
110 virtual bool ScrollVerticallyByPage(const gfx::Point& viewport_point, | |
111 ScrollDirection direction) = 0; | |
112 | |
113 // Returns SCROLL_STARTED if a layer was being actively being scrolled, | |
114 // SCROLL_IGNORED if not. | |
115 virtual ScrollStatus FlingScrollBegin() = 0; | |
116 | |
117 virtual void MouseMoveAt(const gfx::Point& mouse_position) = 0; | |
118 | |
119 // Stop scrolling the selected layer. Should only be called if ScrollBegin() | |
120 // returned SCROLL_STARTED. | |
121 virtual void ScrollEnd() = 0; | |
122 | |
123 virtual void SetRootLayerScrollOffsetDelegate( | |
124 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) = 0; | |
125 | |
126 // Called when the value returned by | |
127 // LayerScrollOffsetDelegate.GetTotalScrollOffset has changed for reasons | |
128 // other than a SetTotalScrollOffset call. | |
129 // NOTE: This should only called after a valid delegate was set via a call to | |
130 // SetRootLayerScrollOffsetDelegate. | |
131 virtual void OnRootLayerDelegatedScrollOffsetChanged() = 0; | |
132 | |
133 virtual void PinchGestureBegin() = 0; | |
134 virtual void PinchGestureUpdate(float magnify_delta, | |
135 const gfx::Point& anchor) = 0; | |
136 virtual void PinchGestureEnd() = 0; | |
137 | |
138 // Request another callback to InputHandlerClient::Animate(). | |
139 virtual void SetNeedsAnimate() = 0; | |
140 | |
141 // Whether the layer under |viewport_point| is the currently scrolling layer. | |
142 virtual bool IsCurrentlyScrollingLayerAt(const gfx::Point& viewport_point, | |
143 ScrollInputType type) = 0; | |
144 | |
145 virtual bool HaveWheelEventHandlersAt(const gfx::Point& viewport_point) = 0; | |
146 | |
147 // Whether the page should be given the opportunity to suppress scrolling by | |
148 // consuming touch events that started at |viewport_point|. | |
149 virtual bool DoTouchEventsBlockScrollAt(const gfx::Point& viewport_point) = 0; | |
150 | |
151 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped | |
152 // LatencyInfoSwapPromiseMonitor. During the life time of the | |
153 // LatencyInfoSwapPromiseMonitor, if SetNeedsRedraw() or SetNeedsRedrawRect() | |
154 // is called on LayerTreeHostImpl, the original latency info will be turned | |
155 // into a LatencyInfoSwapPromise. | |
156 virtual scoped_ptr<SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor( | |
157 ui::LatencyInfo* latency) = 0; | |
158 | |
159 virtual ScrollElasticityHelper* CreateScrollElasticityHelper() = 0; | |
160 | |
161 protected: | |
162 InputHandler() {} | |
163 virtual ~InputHandler() {} | |
164 | |
165 private: | |
166 DISALLOW_COPY_AND_ASSIGN(InputHandler); | |
167 }; | |
168 | |
169 } // namespace cc | |
170 | |
171 #endif // CC_INPUT_INPUT_HANDLER_H_ | |
OLD | NEW |