blob: b81ee998f1fc7be74004c99e45158e5bf903d027 [file] [log] [blame]
[email protected]cd57cc5a2012-10-12 22:43:411// Copyright 2011 The Chromium Authors. All rights reserved.
[email protected]0fb25002012-10-12 07:20:022// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]cd57cc5a2012-10-12 22:43:414
[email protected]3052b10f2013-03-18 07:41:215#ifndef CC_INPUT_INPUT_HANDLER_H_
6#define CC_INPUT_INPUT_HANDLER_H_
[email protected]cd57cc5a2012-10-12 22:43:417
avi02a4d172015-12-21 06:14:368#include "base/macros.h"
ccameron36d091f2014-11-07 03:18:509#include "base/memory/scoped_ptr.h"
[email protected]1b0df502013-06-27 23:39:5810#include "base/time/time.h"
[email protected]681ccff2013-03-18 06:13:5211#include "cc/base/cc_export.h"
dtapuskaf206a40d2016-02-05 21:36:0212#include "cc/input/event_listener_properties.h"
danakj35904762016-01-21 20:49:4013#include "cc/input/main_thread_scrolling_reason.h"
majidvp944a8cd2016-01-12 21:05:1814#include "cc/input/scroll_state.h"
[email protected]c28df4c12013-05-22 17:36:4915#include "cc/input/scrollbar.h"
jamesrf313a212015-03-16 21:27:3716#include "cc/trees/swap_promise_monitor.h"
[email protected]cd57cc5a2012-10-12 22:43:4117
[email protected]d455d552012-11-02 00:19:0618namespace gfx {
19class Point;
[email protected]2f1acc262012-11-16 21:42:2220class PointF;
danakj0481b572015-09-10 01:18:0121class ScrollOffset;
danakjddaec912015-09-25 19:38:4022class SizeF;
[email protected]c9c1ebe2012-11-05 20:46:1323class Vector2d;
[email protected]240376c2013-03-07 04:12:3424class Vector2dF;
[email protected]d455d552012-11-02 00:19:0625}
26
miletus45effdc42015-08-05 00:29:1827namespace ui {
28class LatencyInfo;
29}
[email protected]b76329d2013-06-11 04:15:0830
[email protected]cd57cc5a2012-10-12 22:43:4131namespace cc {
32
[email protected]1960a712013-04-30 17:06:4733class LayerScrollOffsetDelegate;
ccameron4163cc352014-11-13 19:06:3634class ScrollElasticityHelper;
[email protected]1960a712013-04-30 17:06:4735
ccameron36d091f2014-11-07 03:18:5036struct CC_EXPORT InputHandlerScrollResult {
37 InputHandlerScrollResult();
38 // Did any layer scroll as a result this ScrollBy call?
39 bool did_scroll;
40 // Was any of the scroll delta argument to this ScrollBy call not used?
41 bool did_overscroll_root;
42 // The total overscroll that has been accumulated by all ScrollBy calls that
43 // have had overscroll since the last ScrollBegin call. This resets upon a
44 // ScrollBy with no overscroll.
45 gfx::Vector2dF accumulated_root_overscroll;
46 // The amount of the scroll delta argument to this ScrollBy call that was not
47 // used for scrolling.
48 gfx::Vector2dF unused_scroll_delta;
49};
50
[email protected]200a9c062013-05-20 04:34:3751class CC_EXPORT InputHandlerClient {
52 public:
53 virtual ~InputHandlerClient() {}
54
55 virtual void WillShutdown() = 0;
56 virtual void Animate(base::TimeTicks time) = 0;
57 virtual void MainThreadHasStoppedFlinging() = 0;
ccamerona8a42b22014-12-23 03:24:0858 virtual void ReconcileElasticOverscrollAndRootScroll() = 0;
danakjdd74e512015-09-21 23:07:5959 virtual void UpdateRootLayerStateForSynchronousInputHandler(
60 const gfx::ScrollOffset& total_scroll_offset,
61 const gfx::ScrollOffset& max_scroll_offset,
62 const gfx::SizeF& scrollable_size,
63 float page_scale_factor,
64 float min_page_scale_factor,
65 float max_page_scale_factor) = 0;
[email protected]200a9c062013-05-20 04:34:3766
67 protected:
68 InputHandlerClient() {}
69
70 private:
71 DISALLOW_COPY_AND_ASSIGN(InputHandlerClient);
72};
73
[email protected]5ff3c9782013-04-29 17:35:1274// The InputHandler is a way for the embedders to interact with the impl thread
75// side of the compositor implementation. There is one InputHandler per
76// LayerTreeHost. To use the input handler, implement the InputHanderClient
77// interface and bind it to the handler on the compositor thread.
78class CC_EXPORT InputHandler {
[email protected]c1bb5af2013-03-13 19:06:2779 public:
[email protected]05ba53c2014-04-16 21:22:5180 // Note these are used in a histogram. Do not reorder or delete existing
81 // entries.
tdresser81e84c672016-01-18 23:21:2282 enum ScrollThread {
ericrk7c030992015-02-20 01:39:3883 SCROLL_ON_MAIN_THREAD = 0,
tdresser81e84c672016-01-18 23:21:2284 SCROLL_ON_IMPL_THREAD,
ericrk7c030992015-02-20 01:39:3885 SCROLL_IGNORED,
86 SCROLL_UNKNOWN,
danakj35904762016-01-21 20:49:4087 LAST_SCROLL_STATUS = SCROLL_UNKNOWN
tdresser81e84c672016-01-18 23:21:2288 };
89
90 struct ScrollStatus {
91 ScrollStatus()
92 : thread(SCROLL_ON_IMPL_THREAD),
danakj35904762016-01-21 20:49:4093 main_thread_scrolling_reasons(
94 MainThreadScrollingReason::kNotScrollingOnMain) {}
95 ScrollStatus(ScrollThread thread, uint32_t main_thread_scrolling_reasons)
tdresser81e84c672016-01-18 23:21:2296 : thread(thread),
97 main_thread_scrolling_reasons(main_thread_scrolling_reasons) {}
98 ScrollThread thread;
danakj35904762016-01-21 20:49:4099 uint32_t main_thread_scrolling_reasons;
tdresser81e84c672016-01-18 23:21:22100 };
101
dtapuska1827dd22016-03-11 15:24:59102 enum ScrollInputType {
103 // TODO(dtapuska): crbug.com/593017; Remove GESTURE and just use
104 // TOUCHSCREEN.
105 GESTURE,
106 TOUCHSCREEN = GESTURE,
107 WHEEL,
108 ANIMATED_WHEEL,
109 NON_BUBBLING_GESTURE
110 };
[email protected]cd57cc5a2012-10-12 22:43:41111
[email protected]200a9c062013-05-20 04:34:37112 // Binds a client to this handler to receive notifications. Only one client
113 // can be bound to an InputHandler. The client must live at least until the
114 // handler calls WillShutdown() on the client.
115 virtual void BindToClient(InputHandlerClient* client) = 0;
116
majidvp944a8cd2016-01-12 21:05:18117 // Selects a layer to be scrolled using the |scroll_state| start position.
118 // Returns SCROLL_STARTED if the layer at the coordinates can be scrolled,
119 // SCROLL_ON_MAIN_THREAD if the scroll event should instead be delegated to
120 // the main thread, or SCROLL_IGNORED if there is nothing to be scrolled at
121 // the given coordinates.
122 virtual ScrollStatus ScrollBegin(ScrollState* scroll_state,
[email protected]c1bb5af2013-03-13 19:06:27123 ScrollInputType type) = 0;
[email protected]cd57cc5a2012-10-12 22:43:41124
hush1c873232015-06-23 21:22:11125 // Similar to ScrollBegin, except the hit test is skipped and scroll always
126 // targets at the root layer.
majidvp944a8cd2016-01-12 21:05:18127 virtual ScrollStatus RootScrollBegin(ScrollState* scroll_state,
128 ScrollInputType type) = 0;
dtapuska1827dd22016-03-11 15:24:59129
130 // Returns SCROLL_ON_IMPL_THREAD if a layer is actively being scrolled or
131 // a subsequent call to ScrollAnimated can begin on the impl thread.
132 virtual ScrollStatus ScrollAnimatedBegin(
133 const gfx::Point& viewport_point) = 0;
134
[email protected]749cbc62014-07-10 01:06:35135 virtual ScrollStatus ScrollAnimated(const gfx::Point& viewport_point,
136 const gfx::Vector2dF& scroll_delta) = 0;
137
majidvp944a8cd2016-01-12 21:05:18138 // Scroll the layer selected by |ScrollBegin| by given |scroll_state| delta.
139 // Internally, the delta is transformed to local layer's coordinate space for
140 // scrolls gestures that are direct manipulation (e.g. touch). If there is no
141 // room to move the layer in the requested direction, its first ancestor layer
142 // that can be scrolled will be moved instead. The return value's |did_scroll|
143 // field is set to false if no layer can be moved in the requested direction
144 // at all, and set to true if any layer is moved. If the scroll delta hits the
145 // root layer, and the layer can no longer move, the root overscroll
146 // accumulated within this ScrollBegin() scope is reported in the return
147 // value's |accumulated_overscroll| field. Should only be called if
148 // ScrollBegin() returned SCROLL_STARTED.
149 virtual InputHandlerScrollResult ScrollBy(ScrollState* scroll_state) = 0;
[email protected]cd57cc5a2012-10-12 22:43:41150
[email protected]47a723f2014-03-05 12:42:49151 virtual bool ScrollVerticallyByPage(const gfx::Point& viewport_point,
152 ScrollDirection direction) = 0;
[email protected]be782f52013-03-23 21:36:14153
dtapuska1827dd22016-03-11 15:24:59154 // Returns SCROLL_STARTED if a layer was actively being scrolled,
ericrk7c030992015-02-20 01:39:38155 // SCROLL_IGNORED if not.
[email protected]7c45d8152013-04-23 18:27:21156 virtual ScrollStatus FlingScrollBegin() = 0;
157
[email protected]47a723f2014-03-05 12:42:49158 virtual void MouseMoveAt(const gfx::Point& mouse_position) = 0;
[email protected]bf1cfd9a2013-09-26 05:43:02159
[email protected]c1bb5af2013-03-13 19:06:27160 // Stop scrolling the selected layer. Should only be called if ScrollBegin()
ericrk7c030992015-02-20 01:39:38161 // returned SCROLL_STARTED.
majidvp944a8cd2016-01-12 21:05:18162 virtual void ScrollEnd(ScrollState* scroll_state) = 0;
[email protected]cd57cc5a2012-10-12 22:43:41163
danakjdd74e512015-09-21 23:07:59164 // Requests a callback to UpdateRootLayerStateForSynchronousInputHandler()
165 // giving the current root scroll and page scale information.
166 virtual void RequestUpdateForSynchronousInputHandler() = 0;
[email protected]1960a712013-04-30 17:06:47167
danakjdd74e512015-09-21 23:07:59168 // Called when the root scroll offset has been changed in the synchronous
169 // input handler by the application (outside of input event handling).
170 virtual void SetSynchronousInputHandlerRootScrollOffset(
danakj0481b572015-09-10 01:18:01171 const gfx::ScrollOffset& root_offset) = 0;
[email protected]1960a712013-04-30 17:06:47172
[email protected]c1bb5af2013-03-13 19:06:27173 virtual void PinchGestureBegin() = 0;
[email protected]47a723f2014-03-05 12:42:49174 virtual void PinchGestureUpdate(float magnify_delta,
175 const gfx::Point& anchor) = 0;
[email protected]c1bb5af2013-03-13 19:06:27176 virtual void PinchGestureEnd() = 0;
[email protected]cd57cc5a2012-10-12 22:43:41177
[email protected]5ff3c9782013-04-29 17:35:12178 // Request another callback to InputHandlerClient::Animate().
hushb0ee8dc2015-06-10 00:48:57179 virtual void SetNeedsAnimateInput() = 0;
[email protected]cd57cc5a2012-10-12 22:43:41180
skobesde5abdb82015-10-20 19:16:34181 // Returns true if there is an active scroll on the inner viewport layer.
182 virtual bool IsCurrentlyScrollingInnerViewport() const = 0;
danakje9f830c2015-09-09 21:36:16183
[email protected]edcc1a12014-05-06 01:26:39184 // Whether the layer under |viewport_point| is the currently scrolling layer.
185 virtual bool IsCurrentlyScrollingLayerAt(const gfx::Point& viewport_point,
danakje9f830c2015-09-09 21:36:16186 ScrollInputType type) const = 0;
[email protected]edcc1a12014-05-06 01:26:39187
dtapuskaf206a40d2016-02-05 21:36:02188 virtual EventListenerProperties GetEventListenerProperties(
189 EventListenerClass event_class) const = 0;
rbyers18779d822015-02-05 06:22:06190
191 // Whether the page should be given the opportunity to suppress scrolling by
192 // consuming touch events that started at |viewport_point|.
193 virtual bool DoTouchEventsBlockScrollAt(const gfx::Point& viewport_point) = 0;
[email protected]2f1acc262012-11-16 21:42:22194
[email protected]6be422b2013-12-08 06:47:31195 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped
196 // LatencyInfoSwapPromiseMonitor. During the life time of the
197 // LatencyInfoSwapPromiseMonitor, if SetNeedsRedraw() or SetNeedsRedrawRect()
198 // is called on LayerTreeHostImpl, the original latency info will be turned
199 // into a LatencyInfoSwapPromise.
200 virtual scoped_ptr<SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor(
201 ui::LatencyInfo* latency) = 0;
[email protected]b76329d2013-06-11 04:15:08202
ccameron4163cc352014-11-13 19:06:36203 virtual ScrollElasticityHelper* CreateScrollElasticityHelper() = 0;
204
[email protected]c1bb5af2013-03-13 19:06:27205 protected:
[email protected]5ff3c9782013-04-29 17:35:12206 InputHandler() {}
[email protected]c1bb5af2013-03-13 19:06:27207 virtual ~InputHandler() {}
[email protected]cd57cc5a2012-10-12 22:43:41208
[email protected]5ff3c9782013-04-29 17:35:12209 private:
210 DISALLOW_COPY_AND_ASSIGN(InputHandler);
211};
212
[email protected]c1bb5af2013-03-13 19:06:27213} // namespace cc
[email protected]cd57cc5a2012-10-12 22:43:41214
[email protected]3052b10f2013-03-18 07:41:21215#endif // CC_INPUT_INPUT_HANDLER_H_