blob: 8e9a06b18b44f56c33de91792b77ca9a61d1a133 [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
[email protected]1b0df502013-06-27 23:39:5810#include "base/time/time.h"
chrishtrac41ff92017-03-17 05:07:3011#include "cc/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"
Sandra Sun2288e8532017-11-30 22:50:1614#include "cc/input/overscroll_behavior.h"
majidvp944a8cd2016-01-12 21:05:1815#include "cc/input/scroll_state.h"
[email protected]c28df4c12013-05-22 17:36:4916#include "cc/input/scrollbar.h"
Hayley Ferr2b14e2a6c2017-07-04 17:34:4317#include "cc/input/touch_action.h"
Xida Chenaf5964b32019-07-18 19:44:2218#include "cc/paint/element_id.h"
jamesrf313a212015-03-16 21:27:3719#include "cc/trees/swap_promise_monitor.h"
Ella Ge7393cf92019-07-09 21:52:5920#include "components/viz/common/frame_sinks/begin_frame_args.h"
Daniel Libbye15b80b2019-05-24 17:18:2421#include "ui/events/types/scroll_types.h"
[email protected]cd57cc5a2012-10-12 22:43:4122
[email protected]d455d552012-11-02 00:19:0623namespace gfx {
24class Point;
danakj0481b572015-09-10 01:18:0125class ScrollOffset;
danakjddaec912015-09-25 19:38:4026class SizeF;
[email protected]240376c2013-03-07 04:12:3427class Vector2dF;
Kaan Alsan8e49b3c32019-10-30 20:04:4228} // namespace gfx
[email protected]d455d552012-11-02 00:19:0629
miletus45effdc42015-08-05 00:29:1830namespace ui {
31class LatencyInfo;
Kaan Alsan8e49b3c32019-10-30 20:04:4232} // namespace ui
[email protected]b76329d2013-06-11 04:15:0833
[email protected]cd57cc5a2012-10-12 22:43:4134namespace cc {
35
ccameron4163cc352014-11-13 19:06:3636class ScrollElasticityHelper;
[email protected]1960a712013-04-30 17:06:4737
Rahul Arakeri5935a302019-04-18 00:04:4438enum PointerResultType { kUnhandled = 0, kScrollbarScroll };
39
40struct CC_EXPORT InputHandlerPointerResult {
41 InputHandlerPointerResult();
42 // Tells what type of processing occurred in the input handler as a result of
43 // the pointer event.
44 PointerResultType type;
45
Rahul Arakeri193a7ef2019-05-07 08:09:5346 // Tells what scroll_units should be used.
Daniel Libbye15b80b2019-05-24 17:18:2447 ui::input_types::ScrollGranularity scroll_units;
Rahul Arakeri193a7ef2019-05-07 08:09:5348
Rahul Arakeri5935a302019-04-18 00:04:4449 // If the input handler processed the event as a scrollbar scroll, it will
50 // return a gfx::ScrollOffset that produces the necessary scroll. However,
51 // it is still the client's responsibility to generate the gesture scrolls
52 // instead of the input handler performing it as a part of handling the
53 // pointer event (due to the latency attribution that happens at the
54 // InputHandlerProxy level).
55 gfx::ScrollOffset scroll_offset;
Rahul Arakeric024599d2019-08-21 23:37:2456
57 // Used to determine which scroll_node needs to be scrolled. The primary
58 // purpose of this is to avoid hit testing for gestures that already know
59 // which scroller to target.
60 ElementId target_scroller;
Rahul Arakeri5935a302019-04-18 00:04:4461};
62
ccameron36d091f2014-11-07 03:18:5063struct CC_EXPORT InputHandlerScrollResult {
64 InputHandlerScrollResult();
65 // Did any layer scroll as a result this ScrollBy call?
66 bool did_scroll;
67 // Was any of the scroll delta argument to this ScrollBy call not used?
68 bool did_overscroll_root;
69 // The total overscroll that has been accumulated by all ScrollBy calls that
70 // have had overscroll since the last ScrollBegin call. This resets upon a
71 // ScrollBy with no overscroll.
72 gfx::Vector2dF accumulated_root_overscroll;
73 // The amount of the scroll delta argument to this ScrollBy call that was not
74 // used for scrolling.
75 gfx::Vector2dF unused_scroll_delta;
sunyunjiabbea8a92017-08-31 11:18:5476 // How the browser should handle the overscroll navigation based on the css
77 // property scroll-boundary-behavior.
Sandra Sun2288e8532017-11-30 22:50:1678 OverscrollBehavior overscroll_behavior;
Sandra Sun61413102018-04-09 22:24:4379 // The current offset of the currently scrolling node. It is in DIP or
Sandra Sun5b21b4e2018-05-17 23:28:3680 // physical pixels depending on the use-zoom-for-dsf flag. If the currently
81 // scrolling node is the viewport, this would be the sum of the scroll offsets
82 // of the inner and outer node, representing the visual scroll offset.
83 gfx::Vector2dF current_visual_offset;
ccameron36d091f2014-11-07 03:18:5084};
85
[email protected]200a9c062013-05-20 04:34:3786class CC_EXPORT InputHandlerClient {
87 public:
Vladimir Levinf06d1cd72019-03-13 18:24:1088 InputHandlerClient(const InputHandlerClient&) = delete;
89 virtual ~InputHandlerClient() = default;
90
91 InputHandlerClient& operator=(const InputHandlerClient&) = delete;
[email protected]200a9c062013-05-20 04:34:3792
93 virtual void WillShutdown() = 0;
94 virtual void Animate(base::TimeTicks time) = 0;
ccamerona8a42b22014-12-23 03:24:0895 virtual void ReconcileElasticOverscrollAndRootScroll() = 0;
danakjdd74e512015-09-21 23:07:5996 virtual void UpdateRootLayerStateForSynchronousInputHandler(
97 const gfx::ScrollOffset& total_scroll_offset,
98 const gfx::ScrollOffset& max_scroll_offset,
99 const gfx::SizeF& scrollable_size,
100 float page_scale_factor,
101 float min_page_scale_factor,
102 float max_page_scale_factor) = 0;
Ella Ge7393cf92019-07-09 21:52:59103 virtual void DeliverInputForBeginFrame(const viz::BeginFrameArgs& args) = 0;
104 virtual void DeliverInputForHighLatencyMode() = 0;
[email protected]200a9c062013-05-20 04:34:37105
106 protected:
Vladimir Levinf06d1cd72019-03-13 18:24:10107 InputHandlerClient() = default;
[email protected]200a9c062013-05-20 04:34:37108};
109
[email protected]5ff3c9782013-04-29 17:35:12110// The InputHandler is a way for the embedders to interact with the impl thread
111// side of the compositor implementation. There is one InputHandler per
112// LayerTreeHost. To use the input handler, implement the InputHanderClient
113// interface and bind it to the handler on the compositor thread.
114class CC_EXPORT InputHandler {
[email protected]c1bb5af2013-03-13 19:06:27115 public:
[email protected]05ba53c2014-04-16 21:22:51116 // Note these are used in a histogram. Do not reorder or delete existing
117 // entries.
tdresser81e84c672016-01-18 23:21:22118 enum ScrollThread {
ericrk7c030992015-02-20 01:39:38119 SCROLL_ON_MAIN_THREAD = 0,
tdresser81e84c672016-01-18 23:21:22120 SCROLL_ON_IMPL_THREAD,
ericrk7c030992015-02-20 01:39:38121 SCROLL_IGNORED,
122 SCROLL_UNKNOWN,
danakj35904762016-01-21 20:49:40123 LAST_SCROLL_STATUS = SCROLL_UNKNOWN
tdresser81e84c672016-01-18 23:21:22124 };
125
Vladimir Levinf06d1cd72019-03-13 18:24:10126 InputHandler(const InputHandler&) = delete;
127 InputHandler& operator=(const InputHandler&) = delete;
128
tdresser81e84c672016-01-18 23:21:22129 struct ScrollStatus {
130 ScrollStatus()
131 : thread(SCROLL_ON_IMPL_THREAD),
danakj35904762016-01-21 20:49:40132 main_thread_scrolling_reasons(
Sahel Sharifydbafed52017-08-03 16:59:12133 MainThreadScrollingReason::kNotScrollingOnMain),
134 bubble(false) {}
danakj35904762016-01-21 20:49:40135 ScrollStatus(ScrollThread thread, uint32_t main_thread_scrolling_reasons)
tdresser81e84c672016-01-18 23:21:22136 : thread(thread),
137 main_thread_scrolling_reasons(main_thread_scrolling_reasons) {}
138 ScrollThread thread;
danakj35904762016-01-21 20:49:40139 uint32_t main_thread_scrolling_reasons;
Sahel Sharifydbafed52017-08-03 16:59:12140 bool bubble;
tdresser81e84c672016-01-18 23:21:22141 };
142
Rahul Arakeri5935a302019-04-18 00:04:44143 enum ScrollInputType {
144 TOUCHSCREEN,
145 WHEEL,
146 AUTOSCROLL,
147 SCROLLBAR,
148 SCROLL_INPUT_UNKNOWN
149 };
[email protected]cd57cc5a2012-10-12 22:43:41150
Dave Tapuska75fe7392017-06-05 14:01:26151 enum class TouchStartOrMoveEventListenerType {
lanwei53c12362016-11-29 06:51:17152 NO_HANDLER,
153 HANDLER,
154 HANDLER_ON_SCROLLING_LAYER
155 };
156
[email protected]200a9c062013-05-20 04:34:37157 // Binds a client to this handler to receive notifications. Only one client
158 // can be bound to an InputHandler. The client must live at least until the
159 // handler calls WillShutdown() on the client.
Sahel Sharifye6d81f472018-07-11 20:40:26160 virtual void BindToClient(InputHandlerClient* client) = 0;
[email protected]200a9c062013-05-20 04:34:37161
majidvp944a8cd2016-01-12 21:05:18162 // Selects a layer to be scrolled using the |scroll_state| start position.
163 // Returns SCROLL_STARTED if the layer at the coordinates can be scrolled,
164 // SCROLL_ON_MAIN_THREAD if the scroll event should instead be delegated to
165 // the main thread, or SCROLL_IGNORED if there is nothing to be scrolled at
166 // the given coordinates.
167 virtual ScrollStatus ScrollBegin(ScrollState* scroll_state,
[email protected]c1bb5af2013-03-13 19:06:27168 ScrollInputType type) = 0;
[email protected]cd57cc5a2012-10-12 22:43:41169
hush1c873232015-06-23 21:22:11170 // Similar to ScrollBegin, except the hit test is skipped and scroll always
171 // targets at the root layer.
majidvp944a8cd2016-01-12 21:05:18172 virtual ScrollStatus RootScrollBegin(ScrollState* scroll_state,
173 ScrollInputType type) = 0;
dtapuska1827dd22016-03-11 15:24:59174
David Bokan9f66ee82020-01-02 18:39:22175 // |delayed_by| is the delay that is taken into account when determining
176 // the duration of the animation. TODO(bokan): Should eventually be merged
177 // into ScrollBy. https://crbug.com/1016229.
178 virtual void ScrollAnimated(const gfx::Point& viewport_point,
179 const gfx::Vector2dF& scroll_delta,
180 base::TimeDelta delayed_by) = 0;
[email protected]749cbc62014-07-10 01:06:35181
majidvp944a8cd2016-01-12 21:05:18182 // Scroll the layer selected by |ScrollBegin| by given |scroll_state| delta.
183 // Internally, the delta is transformed to local layer's coordinate space for
184 // scrolls gestures that are direct manipulation (e.g. touch). If there is no
185 // room to move the layer in the requested direction, its first ancestor layer
186 // that can be scrolled will be moved instead. The return value's |did_scroll|
187 // field is set to false if no layer can be moved in the requested direction
188 // at all, and set to true if any layer is moved. If the scroll delta hits the
189 // root layer, and the layer can no longer move, the root overscroll
190 // accumulated within this ScrollBegin() scope is reported in the return
191 // value's |accumulated_overscroll| field. Should only be called if
192 // ScrollBegin() returned SCROLL_STARTED.
193 virtual InputHandlerScrollResult ScrollBy(ScrollState* scroll_state) = 0;
[email protected]cd57cc5a2012-10-12 22:43:41194
Rahul Arakeri193a7ef2019-05-07 08:09:53195 virtual InputHandlerPointerResult MouseMoveAt(
196 const gfx::Point& mouse_position) = 0;
Rahul Arakericfc807f2019-11-13 08:57:33197 // TODO(arakeri): Pass in the modifier instead of a bool once the refactor
198 // (crbug.com/1022097) is done. For details, see crbug.com/1016955.
Rahul Arakeri605a0662019-09-25 16:22:36199 virtual InputHandlerPointerResult MouseDown(const gfx::PointF& mouse_position,
200 bool shift_modifier) = 0;
Rahul Arakeri5935a302019-04-18 00:04:44201 virtual InputHandlerPointerResult MouseUp(
202 const gfx::PointF& mouse_position) = 0;
chaopengfff2d5a2016-10-13 15:42:01203 virtual void MouseLeave() = 0;
[email protected]bf1cfd9a2013-09-26 05:43:02204
[email protected]c1bb5af2013-03-13 19:06:27205 // Stop scrolling the selected layer. Should only be called if ScrollBegin()
Sandra Sun04ed4562018-01-16 01:49:35206 // returned SCROLL_STARTED. Snap to a snap position if |should_snap| is true.
David Bokan2983fdc2019-12-04 20:53:24207 virtual void ScrollEnd(bool should_snap) = 0;
[email protected]cd57cc5a2012-10-12 22:43:41208
danakjdd74e512015-09-21 23:07:59209 // Requests a callback to UpdateRootLayerStateForSynchronousInputHandler()
210 // giving the current root scroll and page scale information.
211 virtual void RequestUpdateForSynchronousInputHandler() = 0;
[email protected]1960a712013-04-30 17:06:47212
danakjdd74e512015-09-21 23:07:59213 // Called when the root scroll offset has been changed in the synchronous
David Bokan0a3aa0d52019-07-03 18:43:02214 // input handler by the application (outside of input event handling). Offset
215 // is expected in "content/page coordinates".
danakjdd74e512015-09-21 23:07:59216 virtual void SetSynchronousInputHandlerRootScrollOffset(
David Bokan0a3aa0d52019-07-03 18:43:02217 const gfx::ScrollOffset& root_content_offset) = 0;
[email protected]1960a712013-04-30 17:06:47218
[email protected]c1bb5af2013-03-13 19:06:27219 virtual void PinchGestureBegin() = 0;
[email protected]47a723f2014-03-05 12:42:49220 virtual void PinchGestureUpdate(float magnify_delta,
221 const gfx::Point& anchor) = 0;
Sean O'Brien09fb8b72017-11-30 20:45:47222 virtual void PinchGestureEnd(const gfx::Point& anchor, bool snap_to_min) = 0;
[email protected]cd57cc5a2012-10-12 22:43:41223
[email protected]5ff3c9782013-04-29 17:35:12224 // Request another callback to InputHandlerClient::Animate().
hushb0ee8dc2015-06-10 00:48:57225 virtual void SetNeedsAnimateInput() = 0;
[email protected]cd57cc5a2012-10-12 22:43:41226
bokane2481302016-10-03 23:01:07227 // Returns true if there is an active scroll on the viewport.
228 virtual bool IsCurrentlyScrollingViewport() const = 0;
danakje9f830c2015-09-09 21:36:16229
[email protected]edcc1a12014-05-06 01:26:39230 // Whether the layer under |viewport_point| is the currently scrolling layer.
Philip Rogers315062e2019-06-06 19:33:48231 virtual bool IsCurrentlyScrollingLayerAt(
232 const gfx::Point& viewport_point) const = 0;
[email protected]edcc1a12014-05-06 01:26:39233
dtapuskaf206a40d2016-02-05 21:36:02234 virtual EventListenerProperties GetEventListenerProperties(
235 EventListenerClass event_class) const = 0;
rbyers18779d822015-02-05 06:22:06236
sunxd3e3a37a72018-07-06 22:58:43237 // Returns true if |viewport_point| hits a wheel event handler region that
238 // could block scrolling.
sunxd9f98e812018-08-16 15:34:49239 virtual bool HasBlockingWheelEventHandlerAt(
sunxd3e3a37a72018-07-06 22:58:43240 const gfx::Point& viewport_point) const = 0;
241
Dave Tapuska75fe7392017-06-05 14:01:26242 // It returns the type of a touch start or move event listener at
243 // |viewport_point|. Whether the page should be given the opportunity to
244 // suppress scrolling by consuming touch events that started at
245 // |viewport_point|, and whether |viewport_point| is on the currently
246 // scrolling layer.
Hayley Ferr2b14e2a6c2017-07-04 17:34:43247 // |out_touch_action| is assigned the whitelisted touch action for the
248 // |viewport_point|. In the case there are no touch handlers or touch action
Henrique Ferreiro00e24f12019-12-17 01:14:48249 // regions, |out_touch_action| is assigned TouchAction::kAuto since the
250 // default touch action is auto.
Dave Tapuska75fe7392017-06-05 14:01:26251 virtual TouchStartOrMoveEventListenerType
Hayley Ferr2b14e2a6c2017-07-04 17:34:43252 EventListenerTypeForTouchStartOrMoveAt(const gfx::Point& viewport_point,
253 TouchAction* out_touch_action) = 0;
[email protected]2f1acc262012-11-16 21:42:22254
[email protected]6be422b2013-12-08 06:47:31255 // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped
256 // LatencyInfoSwapPromiseMonitor. During the life time of the
257 // LatencyInfoSwapPromiseMonitor, if SetNeedsRedraw() or SetNeedsRedrawRect()
258 // is called on LayerTreeHostImpl, the original latency info will be turned
259 // into a LatencyInfoSwapPromise.
danakj60bc3bc2016-04-09 00:24:48260 virtual std::unique_ptr<SwapPromiseMonitor>
261 CreateLatencyInfoSwapPromiseMonitor(ui::LatencyInfo* latency) = 0;
[email protected]b76329d2013-06-11 04:15:08262
ccameron4163cc352014-11-13 19:06:36263 virtual ScrollElasticityHelper* CreateScrollElasticityHelper() = 0;
264
tapted4b70c522016-08-13 09:09:32265 // Called by the single-threaded UI Compositor to get or set the scroll offset
Robert Flackb62bd422018-07-25 14:54:42266 // on the impl side. Returns false if |element_id| isn't in the active tree.
267 virtual bool GetScrollOffsetForLayer(ElementId element_id,
tapted4b70c522016-08-13 09:09:32268 gfx::ScrollOffset* offset) = 0;
Robert Flackb62bd422018-07-25 14:54:42269 virtual bool ScrollLayerTo(ElementId element_id,
270 const gfx::ScrollOffset& offset) = 0;
tapted4b70c522016-08-13 09:09:32271
sahelfad903f2017-03-31 21:00:41272 virtual bool ScrollingShouldSwitchtoMainThread() = 0;
273
Sandra Suneb85637d2018-03-22 22:35:16274 // Sets the initial and target offset for scroll snapping for the currently
Kaan Alsan9a3cb8352019-12-18 14:30:32275 // scrolling node and the given natural displacement. Also sets the target
276 // element of the snap's scrolling animation.
Sandra Sun61413102018-04-09 22:24:43277 // |natural_displacement_in_viewport| is the estimated total scrolling for
278 // the active scroll sequence.
Sandra Suneb85637d2018-03-22 22:35:16279 // Returns false if their is no position to snap to.
Kaan Alsan9a3cb8352019-12-18 14:30:32280 virtual bool GetSnapFlingInfoAndSetAnimatingSnapTarget(
Sandra Sun61413102018-04-09 22:24:43281 const gfx::Vector2dF& natural_displacement_in_viewport,
282 gfx::Vector2dF* initial_offset,
Kaan Alsan8e49b3c32019-10-30 20:04:42283 gfx::Vector2dF* target_offset) = 0;
Sandra Suneb85637d2018-03-22 22:35:16284
Kaan Alsan9a3cb8352019-12-18 14:30:32285 // |did_finish| is true if the animation reached its target position (i.e.
286 // it wasn't aborted).
287 virtual void ScrollEndForSnapFling(bool did_finish) = 0;
288
[email protected]c1bb5af2013-03-13 19:06:27289 protected:
Vladimir Levinf06d1cd72019-03-13 18:24:10290 InputHandler() = default;
291 virtual ~InputHandler() = default;
[email protected]5ff3c9782013-04-29 17:35:12292};
293
[email protected]c1bb5af2013-03-13 19:06:27294} // namespace cc
[email protected]cd57cc5a2012-10-12 22:43:41295
[email protected]3052b10f2013-03-18 07:41:21296#endif // CC_INPUT_INPUT_HANDLER_H_