Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cc / input / input_handler.h
blob51db0137a8f6099f19cfa1b351f489b31b057b05
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.
5 #ifndef CC_INPUT_INPUT_HANDLER_H_
6 #define CC_INPUT_INPUT_HANDLER_H_
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"
15 namespace gfx {
16 class Point;
17 class PointF;
18 class ScrollOffset;
19 class Vector2d;
20 class Vector2dF;
23 namespace ui {
24 class LatencyInfo;
27 namespace cc {
29 class LayerScrollOffsetDelegate;
30 class ScrollElasticityHelper;
32 struct CC_EXPORT InputHandlerScrollResult {
33 InputHandlerScrollResult();
34 // Did any layer scroll as a result this ScrollBy call?
35 bool did_scroll;
36 // Was any of the scroll delta argument to this ScrollBy call not used?
37 bool did_overscroll_root;
38 // The total overscroll that has been accumulated by all ScrollBy calls that
39 // have had overscroll since the last ScrollBegin call. This resets upon a
40 // ScrollBy with no overscroll.
41 gfx::Vector2dF accumulated_root_overscroll;
42 // The amount of the scroll delta argument to this ScrollBy call that was not
43 // used for scrolling.
44 gfx::Vector2dF unused_scroll_delta;
47 class CC_EXPORT InputHandlerClient {
48 public:
49 virtual ~InputHandlerClient() {}
51 virtual void WillShutdown() = 0;
52 virtual void Animate(base::TimeTicks time) = 0;
53 virtual void MainThreadHasStoppedFlinging() = 0;
54 virtual void ReconcileElasticOverscrollAndRootScroll() = 0;
55 virtual void UpdateRootLayerStateForSynchronousInputHandler(
56 const gfx::ScrollOffset& total_scroll_offset,
57 const gfx::ScrollOffset& max_scroll_offset,
58 const gfx::SizeF& scrollable_size,
59 float page_scale_factor,
60 float min_page_scale_factor,
61 float max_page_scale_factor) = 0;
63 protected:
64 InputHandlerClient() {}
66 private:
67 DISALLOW_COPY_AND_ASSIGN(InputHandlerClient);
70 // The InputHandler is a way for the embedders to interact with the impl thread
71 // side of the compositor implementation. There is one InputHandler per
72 // LayerTreeHost. To use the input handler, implement the InputHanderClient
73 // interface and bind it to the handler on the compositor thread.
74 class CC_EXPORT InputHandler {
75 public:
76 // Note these are used in a histogram. Do not reorder or delete existing
77 // entries.
78 enum ScrollStatus {
79 SCROLL_ON_MAIN_THREAD = 0,
80 SCROLL_STARTED,
81 SCROLL_IGNORED,
82 SCROLL_UNKNOWN,
83 // This must be the last entry.
84 ScrollStatusCount
86 enum ScrollInputType { GESTURE, WHEEL, NON_BUBBLING_GESTURE };
88 // Binds a client to this handler to receive notifications. Only one client
89 // can be bound to an InputHandler. The client must live at least until the
90 // handler calls WillShutdown() on the client.
91 virtual void BindToClient(InputHandlerClient* client) = 0;
93 // Selects a layer to be scrolled at a given point in viewport (logical
94 // pixel) coordinates. Returns SCROLL_STARTED if the layer at the coordinates
95 // can be scrolled, SCROLL_ON_MAIN_THREAD if the scroll event should instead
96 // be delegated to the main thread, or SCROLL_IGNORED if there is nothing to
97 // be scrolled at the given coordinates.
98 virtual ScrollStatus ScrollBegin(const gfx::Point& viewport_point,
99 ScrollInputType type) = 0;
101 // Similar to ScrollBegin, except the hit test is skipped and scroll always
102 // targets at the root layer.
103 virtual ScrollStatus RootScrollBegin(ScrollInputType type) = 0;
104 virtual ScrollStatus ScrollAnimated(const gfx::Point& viewport_point,
105 const gfx::Vector2dF& scroll_delta) = 0;
107 // Scroll the selected layer starting at the given position. If the scroll
108 // type given to ScrollBegin was a gesture, then the scroll point and delta
109 // should be in viewport (logical pixel) coordinates. Otherwise they are in
110 // scrolling layer's (logical pixel) space. If there is no room to move the
111 // layer in the requested direction, its first ancestor layer that can be
112 // scrolled will be moved instead. The return value's |did_scroll| field is
113 // set to false if no layer can be moved in the requested direction at all,
114 // and set to true if any layer is moved.
115 // If the scroll delta hits the root layer, and the layer can no longer move,
116 // the root overscroll accumulated within this ScrollBegin() scope is reported
117 // in the return value's |accumulated_overscroll| field.
118 // Should only be called if ScrollBegin() returned SCROLL_STARTED.
119 virtual InputHandlerScrollResult ScrollBy(
120 const gfx::Point& viewport_point,
121 const gfx::Vector2dF& scroll_delta) = 0;
123 virtual bool ScrollVerticallyByPage(const gfx::Point& viewport_point,
124 ScrollDirection direction) = 0;
126 // Returns SCROLL_STARTED if a layer was being actively being scrolled,
127 // SCROLL_IGNORED if not.
128 virtual ScrollStatus FlingScrollBegin() = 0;
130 virtual void MouseMoveAt(const gfx::Point& mouse_position) = 0;
132 // Stop scrolling the selected layer. Should only be called if ScrollBegin()
133 // returned SCROLL_STARTED.
134 virtual void ScrollEnd() = 0;
136 // Requests a callback to UpdateRootLayerStateForSynchronousInputHandler()
137 // giving the current root scroll and page scale information.
138 virtual void RequestUpdateForSynchronousInputHandler() = 0;
140 // Called when the root scroll offset has been changed in the synchronous
141 // input handler by the application (outside of input event handling).
142 virtual void SetSynchronousInputHandlerRootScrollOffset(
143 const gfx::ScrollOffset& root_offset) = 0;
145 virtual void PinchGestureBegin() = 0;
146 virtual void PinchGestureUpdate(float magnify_delta,
147 const gfx::Point& anchor) = 0;
148 virtual void PinchGestureEnd() = 0;
150 // Request another callback to InputHandlerClient::Animate().
151 virtual void SetNeedsAnimateInput() = 0;
153 // If there is a scroll active, this reports whether the scroll is on the
154 // root layer, or on some other sublayer.
155 virtual bool IsCurrentlyScrollingRoot() const = 0;
157 // Whether the layer under |viewport_point| is the currently scrolling layer.
158 virtual bool IsCurrentlyScrollingLayerAt(const gfx::Point& viewport_point,
159 ScrollInputType type) const = 0;
161 virtual bool HaveWheelEventHandlersAt(const gfx::Point& viewport_point) = 0;
163 // Whether the page should be given the opportunity to suppress scrolling by
164 // consuming touch events that started at |viewport_point|.
165 virtual bool DoTouchEventsBlockScrollAt(const gfx::Point& viewport_point) = 0;
167 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped
168 // LatencyInfoSwapPromiseMonitor. During the life time of the
169 // LatencyInfoSwapPromiseMonitor, if SetNeedsRedraw() or SetNeedsRedrawRect()
170 // is called on LayerTreeHostImpl, the original latency info will be turned
171 // into a LatencyInfoSwapPromise.
172 virtual scoped_ptr<SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
173 ui::LatencyInfo* latency) = 0;
175 virtual ScrollElasticityHelper* CreateScrollElasticityHelper() = 0;
177 protected:
178 InputHandler() {}
179 virtual ~InputHandler() {}
181 private:
182 DISALLOW_COPY_AND_ASSIGN(InputHandler);
185 } // namespace cc
187 #endif // CC_INPUT_INPUT_HANDLER_H_