blob: 500ab898cbcc03b5dfdda31c292dfa95eb5c0f1a [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
danakj60bc3bc2016-04-09 00:24:488#include <memory>
9
avi02a4d172015-12-21 06:14:3610#include "base/macros.h"
[email protected]1b0df502013-06-27 23:39:5811#include "base/time/time.h"
chrishtrac41ff92017-03-17 05:07:3012#include "cc/cc_export.h"
dtapuskaf206a40d2016-02-05 21:36:0213#include "cc/input/event_listener_properties.h"
danakj35904762016-01-21 20:49:4014#include "cc/input/main_thread_scrolling_reason.h"
Sandra Sun2288e8532017-11-30 22:50:1615#include "cc/input/overscroll_behavior.h"
majidvp944a8cd2016-01-12 21:05:1816#include "cc/input/scroll_state.h"
[email protected]c28df4c12013-05-22 17:36:4917#include "cc/input/scrollbar.h"
Hayley Ferr2b14e2a6c2017-07-04 17:34:4318#include "cc/input/touch_action.h"
Robert Flackb62bd422018-07-25 14:54:4219#include "cc/trees/element_id.h"
jamesrf313a212015-03-16 21:27:3720#include "cc/trees/swap_promise_monitor.h"
[email protected]cd57cc5a2012-10-12 22:43:4121
[email protected]d455d552012-11-02 00:19:0622namespace gfx {
23class Point;
danakj0481b572015-09-10 01:18:0124class ScrollOffset;
danakjddaec912015-09-25 19:38:4025class SizeF;
[email protected]240376c2013-03-07 04:12:3426class Vector2dF;
[email protected]d455d552012-11-02 00:19:0627}
28
miletus45effdc42015-08-05 00:29:1829namespace ui {
30class LatencyInfo;
31}
[email protected]b76329d2013-06-11 04:15:0832
[email protected]cd57cc5a2012-10-12 22:43:4133namespace cc {
34
ccameron4163cc352014-11-13 19:06:3635class ScrollElasticityHelper;
[email protected]1960a712013-04-30 17:06:4736
ccameron36d091f2014-11-07 03:18:5037struct CC_EXPORT InputHandlerScrollResult {
38 InputHandlerScrollResult();
39 // Did any layer scroll as a result this ScrollBy call?
40 bool did_scroll;
41 // Was any of the scroll delta argument to this ScrollBy call not used?
42 bool did_overscroll_root;
43 // The total overscroll that has been accumulated by all ScrollBy calls that
44 // have had overscroll since the last ScrollBegin call. This resets upon a
45 // ScrollBy with no overscroll.
46 gfx::Vector2dF accumulated_root_overscroll;
47 // The amount of the scroll delta argument to this ScrollBy call that was not
48 // used for scrolling.
49 gfx::Vector2dF unused_scroll_delta;
sunyunjiabbea8a92017-08-31 11:18:5450 // How the browser should handle the overscroll navigation based on the css
51 // property scroll-boundary-behavior.
Sandra Sun2288e8532017-11-30 22:50:1652 OverscrollBehavior overscroll_behavior;
Sandra Sun61413102018-04-09 22:24:4353 // The current offset of the currently scrolling node. It is in DIP or
Sandra Sun5b21b4e2018-05-17 23:28:3654 // physical pixels depending on the use-zoom-for-dsf flag. If the currently
55 // scrolling node is the viewport, this would be the sum of the scroll offsets
56 // of the inner and outer node, representing the visual scroll offset.
57 gfx::Vector2dF current_visual_offset;
ccameron36d091f2014-11-07 03:18:5058};
59
[email protected]200a9c062013-05-20 04:34:3760class CC_EXPORT InputHandlerClient {
61 public:
62 virtual ~InputHandlerClient() {}
63
64 virtual void WillShutdown() = 0;
65 virtual void Animate(base::TimeTicks time) = 0;
ccamerona8a42b22014-12-23 03:24:0866 virtual void ReconcileElasticOverscrollAndRootScroll() = 0;
danakjdd74e512015-09-21 23:07:5967 virtual void UpdateRootLayerStateForSynchronousInputHandler(
68 const gfx::ScrollOffset& total_scroll_offset,
69 const gfx::ScrollOffset& max_scroll_offset,
70 const gfx::SizeF& scrollable_size,
71 float page_scale_factor,
72 float min_page_scale_factor,
73 float max_page_scale_factor) = 0;
chongz679c4fb2016-11-18 20:04:4074 virtual void DeliverInputForBeginFrame() = 0;
[email protected]200a9c062013-05-20 04:34:3775
76 protected:
77 InputHandlerClient() {}
78
79 private:
80 DISALLOW_COPY_AND_ASSIGN(InputHandlerClient);
81};
82
[email protected]5ff3c9782013-04-29 17:35:1283// The InputHandler is a way for the embedders to interact with the impl thread
84// side of the compositor implementation. There is one InputHandler per
85// LayerTreeHost. To use the input handler, implement the InputHanderClient
86// interface and bind it to the handler on the compositor thread.
87class CC_EXPORT InputHandler {
[email protected]c1bb5af2013-03-13 19:06:2788 public:
[email protected]05ba53c2014-04-16 21:22:5189 // Note these are used in a histogram. Do not reorder or delete existing
90 // entries.
tdresser81e84c672016-01-18 23:21:2291 enum ScrollThread {
ericrk7c030992015-02-20 01:39:3892 SCROLL_ON_MAIN_THREAD = 0,
tdresser81e84c672016-01-18 23:21:2293 SCROLL_ON_IMPL_THREAD,
ericrk7c030992015-02-20 01:39:3894 SCROLL_IGNORED,
95 SCROLL_UNKNOWN,
danakj35904762016-01-21 20:49:4096 LAST_SCROLL_STATUS = SCROLL_UNKNOWN
tdresser81e84c672016-01-18 23:21:2297 };
98
99 struct ScrollStatus {
100 ScrollStatus()
101 : thread(SCROLL_ON_IMPL_THREAD),
danakj35904762016-01-21 20:49:40102 main_thread_scrolling_reasons(
Sahel Sharifydbafed52017-08-03 16:59:12103 MainThreadScrollingReason::kNotScrollingOnMain),
104 bubble(false) {}
danakj35904762016-01-21 20:49:40105 ScrollStatus(ScrollThread thread, uint32_t main_thread_scrolling_reasons)
tdresser81e84c672016-01-18 23:21:22106 : thread(thread),
107 main_thread_scrolling_reasons(main_thread_scrolling_reasons) {}
108 ScrollThread thread;
danakj35904762016-01-21 20:49:40109 uint32_t main_thread_scrolling_reasons;
Sahel Sharifydbafed52017-08-03 16:59:12110 bool bubble;
tdresser81e84c672016-01-18 23:21:22111 };
112
dtapuska1827dd22016-03-11 15:24:59113 enum ScrollInputType {
dtapuska40e8aff2016-03-11 21:45:03114 TOUCHSCREEN,
dtapuska1827dd22016-03-11 15:24:59115 WHEEL,
dtapuska1827dd22016-03-11 15:24:59116 };
[email protected]cd57cc5a2012-10-12 22:43:41117
Dave Tapuska75fe7392017-06-05 14:01:26118 enum class TouchStartOrMoveEventListenerType {
lanwei53c12362016-11-29 06:51:17119 NO_HANDLER,
120 HANDLER,
121 HANDLER_ON_SCROLLING_LAYER
122 };
123
[email protected]200a9c062013-05-20 04:34:37124 // Binds a client to this handler to receive notifications. Only one client
125 // can be bound to an InputHandler. The client must live at least until the
126 // handler calls WillShutdown() on the client.
Sahel Sharifye6d81f472018-07-11 20:40:26127 virtual void BindToClient(InputHandlerClient* client) = 0;
[email protected]200a9c062013-05-20 04:34:37128
majidvp944a8cd2016-01-12 21:05:18129 // Selects a layer to be scrolled using the |scroll_state| start position.
130 // Returns SCROLL_STARTED if the layer at the coordinates can be scrolled,
131 // SCROLL_ON_MAIN_THREAD if the scroll event should instead be delegated to
132 // the main thread, or SCROLL_IGNORED if there is nothing to be scrolled at
133 // the given coordinates.
134 virtual ScrollStatus ScrollBegin(ScrollState* scroll_state,
[email protected]c1bb5af2013-03-13 19:06:27135 ScrollInputType type) = 0;
[email protected]cd57cc5a2012-10-12 22:43:41136
hush1c873232015-06-23 21:22:11137 // Similar to ScrollBegin, except the hit test is skipped and scroll always
138 // targets at the root layer.
majidvp944a8cd2016-01-12 21:05:18139 virtual ScrollStatus RootScrollBegin(ScrollState* scroll_state,
140 ScrollInputType type) = 0;
dtapuska1827dd22016-03-11 15:24:59141
142 // Returns SCROLL_ON_IMPL_THREAD if a layer is actively being scrolled or
143 // a subsequent call to ScrollAnimated can begin on the impl thread.
sahel60b41cdf2017-06-26 21:34:17144 virtual ScrollStatus ScrollAnimatedBegin(ScrollState* scroll_state) = 0;
dtapuska1827dd22016-03-11 15:24:59145
ymalikddfc3522016-09-05 18:40:37146 // Returns SCROLL_ON_IMPL_THREAD if an animation is initiated on the impl
147 // thread. delayed_by is the delay that is taken into account when determining
148 // the duration of the animation.
[email protected]749cbc62014-07-10 01:06:35149 virtual ScrollStatus ScrollAnimated(const gfx::Point& viewport_point,
ymalikddfc3522016-09-05 18:40:37150 const gfx::Vector2dF& scroll_delta,
151 base::TimeDelta delayed_by) = 0;
[email protected]749cbc62014-07-10 01:06:35152
majidvp944a8cd2016-01-12 21:05:18153 // Scroll the layer selected by |ScrollBegin| by given |scroll_state| delta.
154 // Internally, the delta is transformed to local layer's coordinate space for
155 // scrolls gestures that are direct manipulation (e.g. touch). If there is no
156 // room to move the layer in the requested direction, its first ancestor layer
157 // that can be scrolled will be moved instead. The return value's |did_scroll|
158 // field is set to false if no layer can be moved in the requested direction
159 // at all, and set to true if any layer is moved. If the scroll delta hits the
160 // root layer, and the layer can no longer move, the root overscroll
161 // accumulated within this ScrollBegin() scope is reported in the return
162 // value's |accumulated_overscroll| field. Should only be called if
163 // ScrollBegin() returned SCROLL_STARTED.
164 virtual InputHandlerScrollResult ScrollBy(ScrollState* scroll_state) = 0;
[email protected]cd57cc5a2012-10-12 22:43:41165
[email protected]47a723f2014-03-05 12:42:49166 virtual void MouseMoveAt(const gfx::Point& mouse_position) = 0;
chaopeng54c1c282016-09-30 21:17:09167 virtual void MouseDown() = 0;
168 virtual void MouseUp() = 0;
chaopengfff2d5a2016-10-13 15:42:01169 virtual void MouseLeave() = 0;
[email protected]bf1cfd9a2013-09-26 05:43:02170
[email protected]c1bb5af2013-03-13 19:06:27171 // Stop scrolling the selected layer. Should only be called if ScrollBegin()
Sandra Sun04ed4562018-01-16 01:49:35172 // returned SCROLL_STARTED. Snap to a snap position if |should_snap| is true.
173 virtual void ScrollEnd(ScrollState* scroll_state, bool should_snap) = 0;
[email protected]cd57cc5a2012-10-12 22:43:41174
danakjdd74e512015-09-21 23:07:59175 // Requests a callback to UpdateRootLayerStateForSynchronousInputHandler()
176 // giving the current root scroll and page scale information.
177 virtual void RequestUpdateForSynchronousInputHandler() = 0;
[email protected]1960a712013-04-30 17:06:47178
danakjdd74e512015-09-21 23:07:59179 // Called when the root scroll offset has been changed in the synchronous
180 // input handler by the application (outside of input event handling).
181 virtual void SetSynchronousInputHandlerRootScrollOffset(
danakj0481b572015-09-10 01:18:01182 const gfx::ScrollOffset& root_offset) = 0;
[email protected]1960a712013-04-30 17:06:47183
[email protected]c1bb5af2013-03-13 19:06:27184 virtual void PinchGestureBegin() = 0;
[email protected]47a723f2014-03-05 12:42:49185 virtual void PinchGestureUpdate(float magnify_delta,
186 const gfx::Point& anchor) = 0;
Sean O'Brien09fb8b72017-11-30 20:45:47187 virtual void PinchGestureEnd(const gfx::Point& anchor, bool snap_to_min) = 0;
[email protected]cd57cc5a2012-10-12 22:43:41188
[email protected]5ff3c9782013-04-29 17:35:12189 // Request another callback to InputHandlerClient::Animate().
hushb0ee8dc2015-06-10 00:48:57190 virtual void SetNeedsAnimateInput() = 0;
[email protected]cd57cc5a2012-10-12 22:43:41191
bokane2481302016-10-03 23:01:07192 // Returns true if there is an active scroll on the viewport.
193 virtual bool IsCurrentlyScrollingViewport() const = 0;
danakje9f830c2015-09-09 21:36:16194
[email protected]edcc1a12014-05-06 01:26:39195 // Whether the layer under |viewport_point| is the currently scrolling layer.
196 virtual bool IsCurrentlyScrollingLayerAt(const gfx::Point& viewport_point,
danakje9f830c2015-09-09 21:36:16197 ScrollInputType type) const = 0;
[email protected]edcc1a12014-05-06 01:26:39198
dtapuskaf206a40d2016-02-05 21:36:02199 virtual EventListenerProperties GetEventListenerProperties(
200 EventListenerClass event_class) const = 0;
rbyers18779d822015-02-05 06:22:06201
sunxd3e3a37a72018-07-06 22:58:43202 // Returns true if |viewport_point| hits a wheel event handler region that
203 // could block scrolling.
sunxd9f98e812018-08-16 15:34:49204 virtual bool HasBlockingWheelEventHandlerAt(
sunxd3e3a37a72018-07-06 22:58:43205 const gfx::Point& viewport_point) const = 0;
206
Dave Tapuska75fe7392017-06-05 14:01:26207 // It returns the type of a touch start or move event listener at
208 // |viewport_point|. Whether the page should be given the opportunity to
209 // suppress scrolling by consuming touch events that started at
210 // |viewport_point|, and whether |viewport_point| is on the currently
211 // scrolling layer.
Hayley Ferr2b14e2a6c2017-07-04 17:34:43212 // |out_touch_action| is assigned the whitelisted touch action for the
213 // |viewport_point|. In the case there are no touch handlers or touch action
214 // regions, |out_touch_action| is assigned kTouchActionAuto since the default
215 // touch action is auto.
Dave Tapuska75fe7392017-06-05 14:01:26216 virtual TouchStartOrMoveEventListenerType
Hayley Ferr2b14e2a6c2017-07-04 17:34:43217 EventListenerTypeForTouchStartOrMoveAt(const gfx::Point& viewport_point,
218 TouchAction* out_touch_action) = 0;
[email protected]2f1acc262012-11-16 21:42:22219
[email protected]6be422b2013-12-08 06:47:31220 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped
221 // LatencyInfoSwapPromiseMonitor. During the life time of the
222 // LatencyInfoSwapPromiseMonitor, if SetNeedsRedraw() or SetNeedsRedrawRect()
223 // is called on LayerTreeHostImpl, the original latency info will be turned
224 // into a LatencyInfoSwapPromise.
danakj60bc3bc2016-04-09 00:24:48225 virtual std::unique_ptr<SwapPromiseMonitor>
226 CreateLatencyInfoSwapPromiseMonitor(ui::LatencyInfo* latency) = 0;
[email protected]b76329d2013-06-11 04:15:08227
ccameron4163cc352014-11-13 19:06:36228 virtual ScrollElasticityHelper* CreateScrollElasticityHelper() = 0;
229
tapted4b70c522016-08-13 09:09:32230 // Called by the single-threaded UI Compositor to get or set the scroll offset
Robert Flackb62bd422018-07-25 14:54:42231 // on the impl side. Returns false if |element_id| isn't in the active tree.
232 virtual bool GetScrollOffsetForLayer(ElementId element_id,
tapted4b70c522016-08-13 09:09:32233 gfx::ScrollOffset* offset) = 0;
Robert Flackb62bd422018-07-25 14:54:42234 virtual bool ScrollLayerTo(ElementId element_id,
235 const gfx::ScrollOffset& offset) = 0;
tapted4b70c522016-08-13 09:09:32236
sahelfad903f2017-03-31 21:00:41237 virtual bool ScrollingShouldSwitchtoMainThread() = 0;
238
Sandra Suneb85637d2018-03-22 22:35:16239 // Sets the initial and target offset for scroll snapping for the currently
240 // scrolling node and the given natural displacement.
Sandra Sun61413102018-04-09 22:24:43241 // |natural_displacement_in_viewport| is the estimated total scrolling for
242 // the active scroll sequence.
Sandra Suneb85637d2018-03-22 22:35:16243 // Returns false if their is no position to snap to.
Sandra Sun61413102018-04-09 22:24:43244 virtual bool GetSnapFlingInfo(
245 const gfx::Vector2dF& natural_displacement_in_viewport,
246 gfx::Vector2dF* initial_offset,
247 gfx::Vector2dF* target_offset) const = 0;
Sandra Suneb85637d2018-03-22 22:35:16248
[email protected]c1bb5af2013-03-13 19:06:27249 protected:
[email protected]5ff3c9782013-04-29 17:35:12250 InputHandler() {}
[email protected]c1bb5af2013-03-13 19:06:27251 virtual ~InputHandler() {}
[email protected]cd57cc5a2012-10-12 22:43:41252
[email protected]5ff3c9782013-04-29 17:35:12253 private:
254 DISALLOW_COPY_AND_ASSIGN(InputHandler);
255};
256
[email protected]c1bb5af2013-03-13 19:06:27257} // namespace cc
[email protected]cd57cc5a2012-10-12 22:43:41258
[email protected]3052b10f2013-03-18 07:41:21259#endif // CC_INPUT_INPUT_HANDLER_H_