[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] | 8fcbaa37 | 2012-11-05 04:12:41 | [diff] [blame] | 5 | #ifndef CC_INPUT_HANDLER_H_ |
| 6 | #define CC_INPUT_HANDLER_H_ |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 7 | |
| 8 | #include "base/basictypes.h" |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 9 | #include "base/time.h" |
[email protected] | 52347c84 | 2012-11-02 21:06:20 | [diff] [blame] | 10 | #include "cc/cc_export.h" |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 11 | |
[email protected] | d455d55 | 2012-11-02 00:19:06 | [diff] [blame] | 12 | namespace gfx { |
| 13 | class Point; |
[email protected] | 2f1acc26 | 2012-11-16 21:42:22 | [diff] [blame] | 14 | class PointF; |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 15 | class Vector2d; |
[email protected] | d455d55 | 2012-11-02 00:19:06 | [diff] [blame] | 16 | } |
| 17 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 18 | namespace cc { |
| 19 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 20 | // The InputHandler is a way for the embedders to interact with |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 21 | // the impl thread side of the compositor implementation. |
| 22 | // |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 23 | // There is one InputHandler for every LayerTreeHost. It is |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 24 | // created on the main thread and used only on the impl thread. |
| 25 | // |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 26 | // The InputHandler is constructed with a InputHandlerClient, which is the |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 27 | // interface by which the handler can manipulate the LayerTree. |
[email protected] | 52347c84 | 2012-11-02 21:06:20 | [diff] [blame] | 28 | class CC_EXPORT InputHandlerClient { |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 29 | public: |
| 30 | enum ScrollStatus { ScrollOnMainThread, ScrollStarted, ScrollIgnored }; |
[email protected] | 7dfa686 | 2013-01-31 01:29:09 | [diff] [blame] | 31 | enum ScrollInputType { Gesture, Wheel, NonBubblingGesture }; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 32 | |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 33 | // Selects a layer to be scrolled at a given point in viewport (logical |
| 34 | // pixel) coordinates. Returns ScrollStarted if the layer at the coordinates |
| 35 | // can be scrolled, ScrollOnMainThread if the scroll event should instead be |
| 36 | // delegated to the main thread, or ScrollIgnored if there is nothing to be |
| 37 | // scrolled at the given coordinates. |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 38 | virtual ScrollStatus scrollBegin(gfx::Point, ScrollInputType) = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 39 | |
[email protected] | 31bfe27 | 2012-10-19 18:49:52 | [diff] [blame] | 40 | // Scroll the selected layer starting at the given position. If the scroll |
| 41 | // type given to scrollBegin was a gesture, then the scroll point and delta |
| 42 | // should be in viewport (logical pixel) coordinates. Otherwise they are in |
| 43 | // scrolling layer's (logical pixel) space. If there is no room to move the |
| 44 | // layer in the requested direction, its first ancestor layer that can be |
[email protected] | a971096 | 2012-11-14 20:11:02 | [diff] [blame] | 45 | // scrolled will be moved instead. If no layer can be moved in the requested |
| 46 | // direction at all, then false is returned. If any layer is moved, then |
| 47 | // true is returned. |
| 48 | // Should only be called if scrollBegin() returned ScrollStarted. |
| 49 | virtual bool scrollBy(const gfx::Point&, const gfx::Vector2d&) = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 50 | |
| 51 | // Stop scrolling the selected layer. Should only be called if scrollBegin() |
| 52 | // returned ScrollStarted. |
| 53 | virtual void scrollEnd() = 0; |
| 54 | |
| 55 | virtual void pinchGestureBegin() = 0; |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 56 | virtual void pinchGestureUpdate(float magnifyDelta, gfx::Point anchor) = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 57 | virtual void pinchGestureEnd() = 0; |
| 58 | |
[email protected] | c9c1ebe | 2012-11-05 20:46:13 | [diff] [blame] | 59 | virtual void startPageScaleAnimation(gfx::Vector2d targetOffset, |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 60 | bool anchorPoint, |
| 61 | float pageScale, |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 62 | base::TimeTicks startTime, |
| 63 | base::TimeDelta duration) = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 64 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 65 | // Request another callback to InputHandler::animate(). |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 66 | virtual void scheduleAnimation() = 0; |
| 67 | |
[email protected] | 2f1acc26 | 2012-11-16 21:42:22 | [diff] [blame] | 68 | virtual bool haveTouchEventHandlersAt(const gfx::Point&) = 0; |
| 69 | |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 70 | protected: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 71 | InputHandlerClient() { } |
| 72 | virtual ~InputHandlerClient() { } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 73 | |
| 74 | private: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 75 | DISALLOW_COPY_AND_ASSIGN(InputHandlerClient); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 76 | }; |
| 77 | |
[email protected] | 52347c84 | 2012-11-02 21:06:20 | [diff] [blame] | 78 | class CC_EXPORT InputHandler { |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 79 | public: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 80 | virtual ~InputHandler() { } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 81 | |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 82 | virtual void bindToClient(InputHandlerClient*) = 0; |
[email protected] | 30faac9 | 2012-10-29 00:06:29 | [diff] [blame] | 83 | virtual void animate(base::TimeTicks time) = 0; |
[email protected] | 9b2c7efc | 2012-12-17 18:23:55 | [diff] [blame] | 84 | virtual void mainThreadHasStoppedFlinging() = 0; |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 85 | |
| 86 | protected: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 87 | InputHandler() { } |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 88 | |
| 89 | private: |
[email protected] | 96baf3e | 2012-10-22 23:09:55 | [diff] [blame] | 90 | DISALLOW_COPY_AND_ASSIGN(InputHandler); |
[email protected] | cd57cc5a | 2012-10-12 22:43:41 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | } |
| 94 | |
[email protected] | 8fcbaa37 | 2012-11-05 04:12:41 | [diff] [blame] | 95 | #endif // CC_INPUT_HANDLER_H_ |