[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors. All rights reserved. |
[email protected] | 0fb2500 | 2012-10-12 07:20:02 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 4 | |
[email protected] | 3052b10f | 2013-03-18 07:41:21 | [diff] [blame] | 5 | #ifndef CC_INPUT_INPUT_HANDLER_H_ |
| 6 | #define CC_INPUT_INPUT_HANDLER_H_ |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 7 | |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | 1b0df50 | 2013-06-27 23:39:58 | [diff] [blame] | 11 | #include "base/time/time.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 12 | #include "cc/base/cc_export.h" |
dtapuska | f206a40d | 2016-02-05 21:36:02 | [diff] [blame] | 13 | #include "cc/input/event_listener_properties.h" |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 14 | #include "cc/input/main_thread_scrolling_reason.h" |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 15 | #include "cc/input/scroll_state.h" |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 16 | #include "cc/input/scrollbar.h" |
jamesr | f313a21 | 2015-03-16 21:27:37 | [diff] [blame] | 17 | #include "cc/trees/swap_promise_monitor.h" |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 18 | |
[email protected] | d455d55 | 2012-11-02 00:19:06 | [diff] [blame] | 19 | namespace gfx { |
| 20 | class Point; |
danakj | 0481b57 | 2015-09-10 01:18:01 | [diff] [blame] | 21 | class ScrollOffset; |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 22 | class SizeF; |
[email protected] | 240376c | 2013-03-07 04:12:34 | [diff] [blame] | 23 | class Vector2dF; |
[email protected] | d455d55 | 2012-11-02 00:19:06 | [diff] [blame] | 24 | } |
| 25 | |
miletus | 45effdc4 | 2015-08-05 00:29:18 | [diff] [blame] | 26 | namespace ui { |
| 27 | class LatencyInfo; |
| 28 | } |
[email protected] | b76329d | 2013-06-11 04:15:08 | [diff] [blame] | 29 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 30 | namespace cc { |
| 31 | |
ccameron | 4163cc35 | 2014-11-13 19:06:36 | [diff] [blame] | 32 | class ScrollElasticityHelper; |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 33 | |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 34 | struct CC_EXPORT InputHandlerScrollResult { |
| 35 | InputHandlerScrollResult(); |
| 36 | // Did any layer scroll as a result this ScrollBy call? |
| 37 | bool did_scroll; |
| 38 | // Was any of the scroll delta argument to this ScrollBy call not used? |
| 39 | bool did_overscroll_root; |
| 40 | // The total overscroll that has been accumulated by all ScrollBy calls that |
| 41 | // have had overscroll since the last ScrollBegin call. This resets upon a |
| 42 | // ScrollBy with no overscroll. |
| 43 | gfx::Vector2dF accumulated_root_overscroll; |
| 44 | // The amount of the scroll delta argument to this ScrollBy call that was not |
| 45 | // used for scrolling. |
| 46 | gfx::Vector2dF unused_scroll_delta; |
| 47 | }; |
| 48 | |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 49 | class CC_EXPORT InputHandlerClient { |
| 50 | public: |
| 51 | virtual ~InputHandlerClient() {} |
| 52 | |
| 53 | virtual void WillShutdown() = 0; |
| 54 | virtual void Animate(base::TimeTicks time) = 0; |
| 55 | virtual void MainThreadHasStoppedFlinging() = 0; |
ccameron | a8a42b2 | 2014-12-23 03:24:08 | [diff] [blame] | 56 | virtual void ReconcileElasticOverscrollAndRootScroll() = 0; |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 57 | virtual void UpdateRootLayerStateForSynchronousInputHandler( |
| 58 | const gfx::ScrollOffset& total_scroll_offset, |
| 59 | const gfx::ScrollOffset& max_scroll_offset, |
| 60 | const gfx::SizeF& scrollable_size, |
| 61 | float page_scale_factor, |
| 62 | float min_page_scale_factor, |
| 63 | float max_page_scale_factor) = 0; |
chongz | 679c4fb | 2016-11-18 20:04:40 | [diff] [blame^] | 64 | virtual void DeliverInputForBeginFrame() = 0; |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 65 | |
| 66 | protected: |
| 67 | InputHandlerClient() {} |
| 68 | |
| 69 | private: |
| 70 | DISALLOW_COPY_AND_ASSIGN(InputHandlerClient); |
| 71 | }; |
| 72 | |
[email protected] | 5ff3c978 | 2013-04-29 17:35:12 | [diff] [blame] | 73 | // The InputHandler is a way for the embedders to interact with the impl thread |
| 74 | // side of the compositor implementation. There is one InputHandler per |
| 75 | // LayerTreeHost. To use the input handler, implement the InputHanderClient |
| 76 | // interface and bind it to the handler on the compositor thread. |
| 77 | class CC_EXPORT InputHandler { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 78 | public: |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 79 | // Note these are used in a histogram. Do not reorder or delete existing |
| 80 | // entries. |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 81 | enum ScrollThread { |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 82 | SCROLL_ON_MAIN_THREAD = 0, |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 83 | SCROLL_ON_IMPL_THREAD, |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 84 | SCROLL_IGNORED, |
| 85 | SCROLL_UNKNOWN, |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 86 | LAST_SCROLL_STATUS = SCROLL_UNKNOWN |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | struct ScrollStatus { |
| 90 | ScrollStatus() |
| 91 | : thread(SCROLL_ON_IMPL_THREAD), |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 92 | main_thread_scrolling_reasons( |
| 93 | MainThreadScrollingReason::kNotScrollingOnMain) {} |
| 94 | ScrollStatus(ScrollThread thread, uint32_t main_thread_scrolling_reasons) |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 95 | : thread(thread), |
| 96 | main_thread_scrolling_reasons(main_thread_scrolling_reasons) {} |
| 97 | ScrollThread thread; |
danakj | 3590476 | 2016-01-21 20:49:40 | [diff] [blame] | 98 | uint32_t main_thread_scrolling_reasons; |
tdresser | 81e84c67 | 2016-01-18 23:21:22 | [diff] [blame] | 99 | }; |
| 100 | |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 101 | enum ScrollInputType { |
dtapuska | 40e8aff | 2016-03-11 21:45:03 | [diff] [blame] | 102 | TOUCHSCREEN, |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 103 | WHEEL, |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 104 | NON_BUBBLING_GESTURE |
| 105 | }; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 106 | |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 107 | // Binds a client to this handler to receive notifications. Only one client |
| 108 | // can be bound to an InputHandler. The client must live at least until the |
| 109 | // handler calls WillShutdown() on the client. |
| 110 | virtual void BindToClient(InputHandlerClient* client) = 0; |
| 111 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 112 | // Selects a layer to be scrolled using the |scroll_state| start position. |
| 113 | // Returns SCROLL_STARTED if the layer at the coordinates can be scrolled, |
| 114 | // SCROLL_ON_MAIN_THREAD if the scroll event should instead be delegated to |
| 115 | // the main thread, or SCROLL_IGNORED if there is nothing to be scrolled at |
| 116 | // the given coordinates. |
| 117 | virtual ScrollStatus ScrollBegin(ScrollState* scroll_state, |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 118 | ScrollInputType type) = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 119 | |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame] | 120 | // Similar to ScrollBegin, except the hit test is skipped and scroll always |
| 121 | // targets at the root layer. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 122 | virtual ScrollStatus RootScrollBegin(ScrollState* scroll_state, |
| 123 | ScrollInputType type) = 0; |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 124 | |
| 125 | // Returns SCROLL_ON_IMPL_THREAD if a layer is actively being scrolled or |
| 126 | // a subsequent call to ScrollAnimated can begin on the impl thread. |
| 127 | virtual ScrollStatus ScrollAnimatedBegin( |
| 128 | const gfx::Point& viewport_point) = 0; |
| 129 | |
ymalik | ddfc352 | 2016-09-05 18:40:37 | [diff] [blame] | 130 | // Returns SCROLL_ON_IMPL_THREAD if an animation is initiated on the impl |
| 131 | // thread. delayed_by is the delay that is taken into account when determining |
| 132 | // the duration of the animation. |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 133 | virtual ScrollStatus ScrollAnimated(const gfx::Point& viewport_point, |
ymalik | ddfc352 | 2016-09-05 18:40:37 | [diff] [blame] | 134 | const gfx::Vector2dF& scroll_delta, |
| 135 | base::TimeDelta delayed_by) = 0; |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 136 | |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 137 | // Scroll the layer selected by |ScrollBegin| by given |scroll_state| delta. |
| 138 | // Internally, the delta is transformed to local layer's coordinate space for |
| 139 | // scrolls gestures that are direct manipulation (e.g. touch). If there is no |
| 140 | // room to move the layer in the requested direction, its first ancestor layer |
| 141 | // that can be scrolled will be moved instead. The return value's |did_scroll| |
| 142 | // field is set to false if no layer can be moved in the requested direction |
| 143 | // at all, and set to true if any layer is moved. If the scroll delta hits the |
| 144 | // root layer, and the layer can no longer move, the root overscroll |
| 145 | // accumulated within this ScrollBegin() scope is reported in the return |
| 146 | // value's |accumulated_overscroll| field. Should only be called if |
| 147 | // ScrollBegin() returned SCROLL_STARTED. |
| 148 | virtual InputHandlerScrollResult ScrollBy(ScrollState* scroll_state) = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 149 | |
dtapuska | 1827dd2 | 2016-03-11 15:24:59 | [diff] [blame] | 150 | // Returns SCROLL_STARTED if a layer was actively being scrolled, |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 151 | // SCROLL_IGNORED if not. |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 152 | virtual ScrollStatus FlingScrollBegin() = 0; |
| 153 | |
[email protected] | 47a723f | 2014-03-05 12:42:49 | [diff] [blame] | 154 | virtual void MouseMoveAt(const gfx::Point& mouse_position) = 0; |
chaopeng | 54c1c28 | 2016-09-30 21:17:09 | [diff] [blame] | 155 | virtual void MouseDown() = 0; |
| 156 | virtual void MouseUp() = 0; |
chaopeng | fff2d5a | 2016-10-13 15:42:01 | [diff] [blame] | 157 | virtual void MouseLeave() = 0; |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 158 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 159 | // Stop scrolling the selected layer. Should only be called if ScrollBegin() |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 160 | // returned SCROLL_STARTED. |
majidvp | 944a8cd | 2016-01-12 21:05:18 | [diff] [blame] | 161 | virtual void ScrollEnd(ScrollState* scroll_state) = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 162 | |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 163 | // Requests a callback to UpdateRootLayerStateForSynchronousInputHandler() |
| 164 | // giving the current root scroll and page scale information. |
| 165 | virtual void RequestUpdateForSynchronousInputHandler() = 0; |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 166 | |
danakj | dd74e51 | 2015-09-21 23:07:59 | [diff] [blame] | 167 | // Called when the root scroll offset has been changed in the synchronous |
| 168 | // input handler by the application (outside of input event handling). |
| 169 | virtual void SetSynchronousInputHandlerRootScrollOffset( |
danakj | 0481b57 | 2015-09-10 01:18:01 | [diff] [blame] | 170 | const gfx::ScrollOffset& root_offset) = 0; |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 171 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 172 | virtual void PinchGestureBegin() = 0; |
[email protected] | 47a723f | 2014-03-05 12:42:49 | [diff] [blame] | 173 | virtual void PinchGestureUpdate(float magnify_delta, |
| 174 | const gfx::Point& anchor) = 0; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 175 | virtual void PinchGestureEnd() = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 176 | |
[email protected] | 5ff3c978 | 2013-04-29 17:35:12 | [diff] [blame] | 177 | // Request another callback to InputHandlerClient::Animate(). |
hush | b0ee8dc | 2015-06-10 00:48:57 | [diff] [blame] | 178 | virtual void SetNeedsAnimateInput() = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 179 | |
bokan | e248130 | 2016-10-03 23:01:07 | [diff] [blame] | 180 | // Returns true if there is an active scroll on the viewport. |
| 181 | virtual bool IsCurrentlyScrollingViewport() const = 0; |
danakj | e9f830c | 2015-09-09 21:36:16 | [diff] [blame] | 182 | |
[email protected] | edcc1a1 | 2014-05-06 01:26:39 | [diff] [blame] | 183 | // Whether the layer under |viewport_point| is the currently scrolling layer. |
| 184 | virtual bool IsCurrentlyScrollingLayerAt(const gfx::Point& viewport_point, |
danakj | e9f830c | 2015-09-09 21:36:16 | [diff] [blame] | 185 | ScrollInputType type) const = 0; |
[email protected] | edcc1a1 | 2014-05-06 01:26:39 | [diff] [blame] | 186 | |
dtapuska | f206a40d | 2016-02-05 21:36:02 | [diff] [blame] | 187 | virtual EventListenerProperties GetEventListenerProperties( |
| 188 | EventListenerClass event_class) const = 0; |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 189 | |
| 190 | // Whether the page should be given the opportunity to suppress scrolling by |
| 191 | // consuming touch events that started at |viewport_point|. |
| 192 | virtual bool DoTouchEventsBlockScrollAt(const gfx::Point& viewport_point) = 0; |
[email protected] | 2f1acc26 | 2012-11-16 21:42:22 | [diff] [blame] | 193 | |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 194 | // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped |
| 195 | // LatencyInfoSwapPromiseMonitor. During the life time of the |
| 196 | // LatencyInfoSwapPromiseMonitor, if SetNeedsRedraw() or SetNeedsRedrawRect() |
| 197 | // is called on LayerTreeHostImpl, the original latency info will be turned |
| 198 | // into a LatencyInfoSwapPromise. |
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 199 | virtual std::unique_ptr<SwapPromiseMonitor> |
| 200 | CreateLatencyInfoSwapPromiseMonitor(ui::LatencyInfo* latency) = 0; |
[email protected] | b76329d | 2013-06-11 04:15:08 | [diff] [blame] | 201 | |
ccameron | 4163cc35 | 2014-11-13 19:06:36 | [diff] [blame] | 202 | virtual ScrollElasticityHelper* CreateScrollElasticityHelper() = 0; |
| 203 | |
tapted | 4b70c52 | 2016-08-13 09:09:32 | [diff] [blame] | 204 | // Called by the single-threaded UI Compositor to get or set the scroll offset |
| 205 | // on the impl side. Retruns false if |layer_id| isn't in the active tree. |
| 206 | virtual bool GetScrollOffsetForLayer(int layer_id, |
| 207 | gfx::ScrollOffset* offset) = 0; |
| 208 | virtual bool ScrollLayerTo(int layer_id, const gfx::ScrollOffset& offset) = 0; |
| 209 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 210 | protected: |
[email protected] | 5ff3c978 | 2013-04-29 17:35:12 | [diff] [blame] | 211 | InputHandler() {} |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 212 | virtual ~InputHandler() {} |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 213 | |
[email protected] | 5ff3c978 | 2013-04-29 17:35:12 | [diff] [blame] | 214 | private: |
| 215 | DISALLOW_COPY_AND_ASSIGN(InputHandler); |
| 216 | }; |
| 217 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 218 | } // namespace cc |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 219 | |
[email protected] | 3052b10f | 2013-03-18 07:41:21 | [diff] [blame] | 220 | #endif // CC_INPUT_INPUT_HANDLER_H_ |