[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 | |
| 8 | #include "base/basictypes.h" |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 9 | #include "base/memory/scoped_ptr.h" |
[email protected] | 1b0df50 | 2013-06-27 23:39:58 | [diff] [blame] | 10 | #include "base/time/time.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 11 | #include "cc/base/cc_export.h" |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 12 | #include "cc/input/scrollbar.h" |
jamesr | f313a21 | 2015-03-16 21:27:37 | [diff] [blame] | 13 | #include "cc/trees/swap_promise_monitor.h" |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 14 | |
[email protected] | d455d55 | 2012-11-02 00:19:06 | [diff] [blame] | 15 | namespace gfx { |
| 16 | class Point; |
[email protected] | 2f1acc26 | 2012-11-16 21:42:22 | [diff] [blame] | 17 | class PointF; |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 18 | class Vector2d; |
[email protected] | 240376c | 2013-03-07 04:12:34 | [diff] [blame] | 19 | class Vector2dF; |
[email protected] | d455d55 | 2012-11-02 00:19:06 | [diff] [blame] | 20 | } |
| 21 | |
[email protected] | b76329d | 2013-06-11 04:15:08 | [diff] [blame] | 22 | namespace ui { struct LatencyInfo; } |
| 23 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 24 | namespace cc { |
| 25 | |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 26 | class LayerScrollOffsetDelegate; |
ccameron | 4163cc35 | 2014-11-13 19:06:36 | [diff] [blame] | 27 | class ScrollElasticityHelper; |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 28 | |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 29 | struct CC_EXPORT InputHandlerScrollResult { |
| 30 | InputHandlerScrollResult(); |
| 31 | // Did any layer scroll as a result this ScrollBy call? |
| 32 | bool did_scroll; |
| 33 | // Was any of the scroll delta argument to this ScrollBy call not used? |
| 34 | bool did_overscroll_root; |
| 35 | // The total overscroll that has been accumulated by all ScrollBy calls that |
| 36 | // have had overscroll since the last ScrollBegin call. This resets upon a |
| 37 | // ScrollBy with no overscroll. |
| 38 | gfx::Vector2dF accumulated_root_overscroll; |
| 39 | // The amount of the scroll delta argument to this ScrollBy call that was not |
| 40 | // used for scrolling. |
| 41 | gfx::Vector2dF unused_scroll_delta; |
| 42 | }; |
| 43 | |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 44 | class CC_EXPORT InputHandlerClient { |
| 45 | public: |
| 46 | virtual ~InputHandlerClient() {} |
| 47 | |
| 48 | virtual void WillShutdown() = 0; |
| 49 | virtual void Animate(base::TimeTicks time) = 0; |
| 50 | virtual void MainThreadHasStoppedFlinging() = 0; |
ccameron | a8a42b2 | 2014-12-23 03:24:08 | [diff] [blame] | 51 | virtual void ReconcileElasticOverscrollAndRootScroll() = 0; |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 52 | |
| 53 | protected: |
| 54 | InputHandlerClient() {} |
| 55 | |
| 56 | private: |
| 57 | DISALLOW_COPY_AND_ASSIGN(InputHandlerClient); |
| 58 | }; |
| 59 | |
[email protected] | 5ff3c978 | 2013-04-29 17:35:12 | [diff] [blame] | 60 | // The InputHandler is a way for the embedders to interact with the impl thread |
| 61 | // side of the compositor implementation. There is one InputHandler per |
| 62 | // LayerTreeHost. To use the input handler, implement the InputHanderClient |
| 63 | // interface and bind it to the handler on the compositor thread. |
| 64 | class CC_EXPORT InputHandler { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 65 | public: |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 66 | // Note these are used in a histogram. Do not reorder or delete existing |
| 67 | // entries. |
| 68 | enum ScrollStatus { |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 69 | SCROLL_ON_MAIN_THREAD = 0, |
| 70 | SCROLL_STARTED, |
| 71 | SCROLL_IGNORED, |
| 72 | SCROLL_UNKNOWN, |
[email protected] | 05ba53c | 2014-04-16 21:22:51 | [diff] [blame] | 73 | // This must be the last entry. |
| 74 | ScrollStatusCount |
| 75 | }; |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 76 | enum ScrollInputType { GESTURE, WHEEL, NON_BUBBLING_GESTURE }; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 77 | |
[email protected] | 200a9c06 | 2013-05-20 04:34:37 | [diff] [blame] | 78 | // Binds a client to this handler to receive notifications. Only one client |
| 79 | // can be bound to an InputHandler. The client must live at least until the |
| 80 | // handler calls WillShutdown() on the client. |
| 81 | virtual void BindToClient(InputHandlerClient* client) = 0; |
| 82 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 83 | // Selects a layer to be scrolled at a given point in viewport (logical |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 84 | // pixel) coordinates. Returns SCROLL_STARTED if the layer at the coordinates |
| 85 | // can be scrolled, SCROLL_ON_MAIN_THREAD if the scroll event should instead |
| 86 | // be delegated to the main thread, or SCROLL_IGNORED if there is nothing to |
| 87 | // be scrolled at the given coordinates. |
[email protected] | 47a723f | 2014-03-05 12:42:49 | [diff] [blame] | 88 | virtual ScrollStatus ScrollBegin(const gfx::Point& viewport_point, |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 89 | ScrollInputType type) = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 90 | |
hush | 1c87323 | 2015-06-23 21:22:11 | [diff] [blame^] | 91 | // Similar to ScrollBegin, except the hit test is skipped and scroll always |
| 92 | // targets at the root layer. |
| 93 | virtual ScrollStatus RootScrollBegin(ScrollInputType type) = 0; |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 94 | virtual ScrollStatus ScrollAnimated(const gfx::Point& viewport_point, |
| 95 | const gfx::Vector2dF& scroll_delta) = 0; |
| 96 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 97 | // Scroll the selected layer starting at the given position. If the scroll |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 98 | // type given to ScrollBegin was a gesture, then the scroll point and delta |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 99 | // should be in viewport (logical pixel) coordinates. Otherwise they are in |
| 100 | // scrolling layer's (logical pixel) space. If there is no room to move the |
| 101 | // layer in the requested direction, its first ancestor layer that can be |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 102 | // scrolled will be moved instead. The return value's |did_scroll| field is |
| 103 | // set to false if no layer can be moved in the requested direction at all, |
| 104 | // and set to true if any layer is moved. |
[email protected] | a2b5ded | 2013-05-20 21:32:53 | [diff] [blame] | 105 | // If the scroll delta hits the root layer, and the layer can no longer move, |
| 106 | // the root overscroll accumulated within this ScrollBegin() scope is reported |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 107 | // in the return value's |accumulated_overscroll| field. |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 108 | // Should only be called if ScrollBegin() returned SCROLL_STARTED. |
ccameron | 36d091f | 2014-11-07 03:18:50 | [diff] [blame] | 109 | virtual InputHandlerScrollResult ScrollBy( |
| 110 | const gfx::Point& viewport_point, |
| 111 | const gfx::Vector2dF& scroll_delta) = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 112 | |
[email protected] | 47a723f | 2014-03-05 12:42:49 | [diff] [blame] | 113 | virtual bool ScrollVerticallyByPage(const gfx::Point& viewport_point, |
| 114 | ScrollDirection direction) = 0; |
[email protected] | be782f5 | 2013-03-23 21:36:14 | [diff] [blame] | 115 | |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 116 | // Returns SCROLL_STARTED if a layer was being actively being scrolled, |
| 117 | // SCROLL_IGNORED if not. |
[email protected] | 7c45d815 | 2013-04-23 18:27:21 | [diff] [blame] | 118 | virtual ScrollStatus FlingScrollBegin() = 0; |
| 119 | |
[email protected] | 47a723f | 2014-03-05 12:42:49 | [diff] [blame] | 120 | virtual void MouseMoveAt(const gfx::Point& mouse_position) = 0; |
[email protected] | bf1cfd9a | 2013-09-26 05:43:02 | [diff] [blame] | 121 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 122 | // Stop scrolling the selected layer. Should only be called if ScrollBegin() |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 123 | // returned SCROLL_STARTED. |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 124 | virtual void ScrollEnd() = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 125 | |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 126 | virtual void SetRootLayerScrollOffsetDelegate( |
| 127 | LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) = 0; |
| 128 | |
| 129 | // Called when the value returned by |
| 130 | // LayerScrollOffsetDelegate.GetTotalScrollOffset has changed for reasons |
| 131 | // other than a SetTotalScrollOffset call. |
| 132 | // NOTE: This should only called after a valid delegate was set via a call to |
| 133 | // SetRootLayerScrollOffsetDelegate. |
| 134 | virtual void OnRootLayerDelegatedScrollOffsetChanged() = 0; |
| 135 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 136 | virtual void PinchGestureBegin() = 0; |
[email protected] | 47a723f | 2014-03-05 12:42:49 | [diff] [blame] | 137 | virtual void PinchGestureUpdate(float magnify_delta, |
| 138 | const gfx::Point& anchor) = 0; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 139 | virtual void PinchGestureEnd() = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 140 | |
[email protected] | 5ff3c978 | 2013-04-29 17:35:12 | [diff] [blame] | 141 | // Request another callback to InputHandlerClient::Animate(). |
hush | b0ee8dc | 2015-06-10 00:48:57 | [diff] [blame] | 142 | virtual void SetNeedsAnimateInput() = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 143 | |
[email protected] | edcc1a1 | 2014-05-06 01:26:39 | [diff] [blame] | 144 | // Whether the layer under |viewport_point| is the currently scrolling layer. |
| 145 | virtual bool IsCurrentlyScrollingLayerAt(const gfx::Point& viewport_point, |
| 146 | ScrollInputType type) = 0; |
| 147 | |
ccameron | 3b60736 | 2015-02-02 22:46:29 | [diff] [blame] | 148 | virtual bool HaveWheelEventHandlersAt(const gfx::Point& viewport_point) = 0; |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 149 | |
| 150 | // Whether the page should be given the opportunity to suppress scrolling by |
| 151 | // consuming touch events that started at |viewport_point|. |
| 152 | virtual bool DoTouchEventsBlockScrollAt(const gfx::Point& viewport_point) = 0; |
[email protected] | 2f1acc26 | 2012-11-16 21:42:22 | [diff] [blame] | 153 | |
[email protected] | 6be422b | 2013-12-08 06:47:31 | [diff] [blame] | 154 | // Calling CreateLatencyInfoSwapPromiseMonitor() to get a scoped |
| 155 | // LatencyInfoSwapPromiseMonitor. During the life time of the |
| 156 | // LatencyInfoSwapPromiseMonitor, if SetNeedsRedraw() or SetNeedsRedrawRect() |
| 157 | // is called on LayerTreeHostImpl, the original latency info will be turned |
| 158 | // into a LatencyInfoSwapPromise. |
| 159 | virtual scoped_ptr<SwapPromiseMonitor> CreateLatencyInfoSwapPromiseMonitor( |
| 160 | ui::LatencyInfo* latency) = 0; |
[email protected] | b76329d | 2013-06-11 04:15:08 | [diff] [blame] | 161 | |
ccameron | 4163cc35 | 2014-11-13 19:06:36 | [diff] [blame] | 162 | virtual ScrollElasticityHelper* CreateScrollElasticityHelper() = 0; |
| 163 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 164 | protected: |
[email protected] | 5ff3c978 | 2013-04-29 17:35:12 | [diff] [blame] | 165 | InputHandler() {} |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 166 | virtual ~InputHandler() {} |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 167 | |
[email protected] | 5ff3c978 | 2013-04-29 17:35:12 | [diff] [blame] | 168 | private: |
| 169 | DISALLOW_COPY_AND_ASSIGN(InputHandler); |
| 170 | }; |
| 171 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 172 | } // namespace cc |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 173 | |
[email protected] | 3052b10f | 2013-03-18 07:41:21 | [diff] [blame] | 174 | #endif // CC_INPUT_INPUT_HANDLER_H_ |