reveman | 39b32c87 | 2015-12-08 05:34:05 | [diff] [blame] | 1 | // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef COMPONENTS_EXO_POINTER_DELEGATE_H_ |
| 6 | #define COMPONENTS_EXO_POINTER_DELEGATE_H_ |
| 7 | |
| 8 | #include "base/time/time.h" |
| 9 | #include "ui/events/event_constants.h" |
| 10 | |
| 11 | namespace gfx { |
reveman | 79363c1c | 2016-05-02 23:58:56 | [diff] [blame] | 12 | class PointF; |
denniskempin | 7351387 | 2016-03-02 21:31:07 | [diff] [blame] | 13 | class Vector2dF; |
reveman | 39b32c87 | 2015-12-08 05:34:05 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | namespace exo { |
| 17 | class Pointer; |
| 18 | class Surface; |
| 19 | |
| 20 | // Handles events on pointers in context-specific ways. |
| 21 | class PointerDelegate { |
| 22 | public: |
| 23 | // Called at the top of the pointer's destructor, to give observers a |
| 24 | // chance to remove themselves. |
| 25 | virtual void OnPointerDestroying(Pointer* pointer) = 0; |
| 26 | |
| 27 | // This should return true if |surface| is a valid target for this pointer. |
| 28 | // E.g. the surface is owned by the same client as the pointer. |
| 29 | virtual bool CanAcceptPointerEventsForSurface(Surface* surface) const = 0; |
| 30 | |
| 31 | // Called when pointer enters a new valid target surface. |location| |
| 32 | // is the location of pointer relative to the origin of surface and |
| 33 | // |button_flags| contains all currently pressed buttons. |
| 34 | virtual void OnPointerEnter(Surface* surface, |
reveman | 79363c1c | 2016-05-02 23:58:56 | [diff] [blame] | 35 | const gfx::PointF& location, |
reveman | 39b32c87 | 2015-12-08 05:34:05 | [diff] [blame] | 36 | int pressed_button_flags) = 0; |
| 37 | |
| 38 | // Called when pointer leaves a valid target surface. |
| 39 | virtual void OnPointerLeave(Surface* surface) = 0; |
| 40 | |
| 41 | // Called when pointer moved within the current target surface. |
majidvp | 9b3bda8 | 2016-06-09 18:12:09 | [diff] [blame] | 42 | virtual void OnPointerMotion(base::TimeTicks time_stamp, |
reveman | 79363c1c | 2016-05-02 23:58:56 | [diff] [blame] | 43 | const gfx::PointF& location) = 0; |
reveman | 39b32c87 | 2015-12-08 05:34:05 | [diff] [blame] | 44 | |
| 45 | // Called when pointer button state changed. |changed_button_flags| contains |
| 46 | // all buttons that changed. |pressed| is true if buttons entered pressed |
| 47 | // state. |
majidvp | 9b3bda8 | 2016-06-09 18:12:09 | [diff] [blame] | 48 | virtual void OnPointerButton(base::TimeTicks time_stamp, |
reveman | 39b32c87 | 2015-12-08 05:34:05 | [diff] [blame] | 49 | int changed_button_flags, |
| 50 | bool pressed) = 0; |
| 51 | |
denniskempin | 7351387 | 2016-03-02 21:31:07 | [diff] [blame] | 52 | // Called when pointer is scrolling. |offset| contains the direction and |
| 53 | // distance of the change. |discrete| is true if the scrolling is caused |
| 54 | // by a discrete device such as a scroll wheel. |
majidvp | 9b3bda8 | 2016-06-09 18:12:09 | [diff] [blame] | 55 | virtual void OnPointerScroll(base::TimeTicks time_stamp, |
denniskempin | 7351387 | 2016-03-02 21:31:07 | [diff] [blame] | 56 | const gfx::Vector2dF& offset, |
| 57 | bool discrete) = 0; |
| 58 | |
| 59 | // Called when a current kinetic scroll should be canceled. |
majidvp | 9b3bda8 | 2016-06-09 18:12:09 | [diff] [blame] | 60 | virtual void OnPointerScrollCancel(base::TimeTicks time_stamp) = 0; |
denniskempin | 7351387 | 2016-03-02 21:31:07 | [diff] [blame] | 61 | |
| 62 | // Called when pointer scroll has stopped and a fling is happening (e.g. |
| 63 | // lifting the fingers from the touchpad after scrolling quickly) |
majidvp | 9b3bda8 | 2016-06-09 18:12:09 | [diff] [blame] | 64 | virtual void OnPointerScrollStop(base::TimeTicks time_stamp) = 0; |
denniskempin | 7351387 | 2016-03-02 21:31:07 | [diff] [blame] | 65 | |
| 66 | // Called after all pointer information of this frame has been set and the |
| 67 | // client should evaluate the updated state. No events are being sent before |
| 68 | // this method is called. |
| 69 | virtual void OnPointerFrame() = 0; |
reveman | 39b32c87 | 2015-12-08 05:34:05 | [diff] [blame] | 70 | |
| 71 | protected: |
| 72 | virtual ~PointerDelegate() {} |
| 73 | }; |
| 74 | |
| 75 | } // namespace exo |
| 76 | |
| 77 | #endif // COMPONENTS_EXO_POINTER_DELEGATE_H_ |