| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_EXO_POINTER_H_ | 5 #ifndef COMPONENTS_EXO_POINTER_H_ |
| 6 #define COMPONENTS_EXO_POINTER_H_ | 6 #define COMPONENTS_EXO_POINTER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "components/exo/surface_delegate.h" | 11 #include "components/exo/surface_delegate.h" |
| 12 #include "components/exo/surface_observer.h" | 12 #include "components/exo/surface_observer.h" |
| 13 #include "components/exo/wm_helper.h" | 13 #include "components/exo/wm_helper.h" |
| 14 #include "ui/events/event_handler.h" | 14 #include "ui/events/event_handler.h" |
| 15 #include "ui/gfx/geometry/point.h" | 15 #include "ui/gfx/geometry/point.h" |
| 16 #include "ui/gfx/geometry/point_f.h" | 16 #include "ui/gfx/geometry/point_f.h" |
| 17 | 17 |
| 18 namespace ui { | 18 namespace ui { |
| 19 class Event; | 19 class Event; |
| 20 class MouseEvent; | 20 class MouseEvent; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace views { | 23 namespace views { |
| 24 class Widget; | 24 class Widget; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace exo { | 27 namespace exo { |
| 28 class PointerDelegate; | 28 class PointerDelegate; |
| 29 class PointerStylusDelegate; | |
| 30 class Surface; | 29 class Surface; |
| 31 | 30 |
| 32 // This class implements a client pointer that represents one or more input | 31 // This class implements a client pointer that represents one or more input |
| 33 // devices, such as mice, which control the pointer location and pointer focus. | 32 // devices, such as mice, which control the pointer location and pointer focus. |
| 34 class Pointer : public ui::EventHandler, | 33 class Pointer : public ui::EventHandler, |
| 35 public WMHelper::CursorObserver, | 34 public WMHelper::CursorObserver, |
| 36 public SurfaceDelegate, | 35 public SurfaceDelegate, |
| 37 public SurfaceObserver { | 36 public SurfaceObserver { |
| 38 public: | 37 public: |
| 39 explicit Pointer(PointerDelegate* delegate); | 38 explicit Pointer(PointerDelegate* delegate); |
| 40 ~Pointer() override; | 39 ~Pointer() override; |
| 41 | 40 |
| 42 // Set the pointer surface, i.e., the surface that contains the pointer image | 41 // Set the pointer surface, i.e., the surface that contains the pointer image |
| 43 // (cursor). The |hotspot| argument defines the position of the pointer | 42 // (cursor). The |hotspot| argument defines the position of the pointer |
| 44 // surface relative to the pointer location. Its top-left corner is always at | 43 // surface relative to the pointer location. Its top-left corner is always at |
| 45 // (x, y) - (hotspot.x, hotspot.y), where (x, y) are the coordinates of the | 44 // (x, y) - (hotspot.x, hotspot.y), where (x, y) are the coordinates of the |
| 46 // pointer location, in surface local coordinates. | 45 // pointer location, in surface local coordinates. |
| 47 void SetCursor(Surface* surface, const gfx::Point& hotspot); | 46 void SetCursor(Surface* surface, const gfx::Point& hotspot); |
| 48 | 47 |
| 49 bool HasStylusDelegate() const; | |
| 50 // Set delegate for stylus events. | |
| 51 void SetStylusDelegate(PointerStylusDelegate* delegate); | |
| 52 | |
| 53 // Overridden from ui::EventHandler: | 48 // Overridden from ui::EventHandler: |
| 54 void OnMouseEvent(ui::MouseEvent* event) override; | 49 void OnMouseEvent(ui::MouseEvent* event) override; |
| 55 void OnScrollEvent(ui::ScrollEvent* event) override; | 50 void OnScrollEvent(ui::ScrollEvent* event) override; |
| 56 | 51 |
| 57 // Overridden from WMHelper::CursorObserver: | 52 // Overridden from WMHelper::CursorObserver: |
| 58 void OnCursorSetChanged(ui::CursorSetType cursor_set) override; | 53 void OnCursorSetChanged(ui::CursorSetType cursor_set) override; |
| 59 | 54 |
| 60 // Overridden from SurfaceDelegate: | 55 // Overridden from SurfaceDelegate: |
| 61 void OnSurfaceCommit() override; | 56 void OnSurfaceCommit() override; |
| 62 bool IsSurfaceSynchronized() const override; | 57 bool IsSurfaceSynchronized() const override; |
| 63 | 58 |
| 64 // Overridden from SurfaceObserver: | 59 // Overridden from SurfaceObserver: |
| 65 void OnSurfaceDestroying(Surface* surface) override; | 60 void OnSurfaceDestroying(Surface* surface) override; |
| 66 | 61 |
| 67 private: | 62 private: |
| 68 // Creates the |widget_| for pointer. | 63 // Creates the |widget_| for pointer. |
| 69 void CreatePointerWidget(); | 64 void CreatePointerWidget(); |
| 70 | 65 |
| 71 // Updates the scale of the cursor with the latest state. | 66 // Updates the scale of the cursor with the latest state. |
| 72 void UpdateCursorScale(); | 67 void UpdateCursorScale(); |
| 73 | 68 |
| 74 // Returns the effective target for |event|. | 69 // Returns the effective target for |event|. |
| 75 Surface* GetEffectiveTargetForEvent(ui::Event* event) const; | 70 Surface* GetEffectiveTargetForEvent(ui::Event* event) const; |
| 76 | 71 |
| 77 // The delegate instance that all events are dispatched to. | 72 // The delegate instance that all events are dispatched to. |
| 78 PointerDelegate* const delegate_; | 73 PointerDelegate* const delegate_; |
| 79 | 74 |
| 80 // The delegate instance that all stylus related events are dispatched to. | |
| 81 PointerStylusDelegate* stylus_delegate_ = nullptr; | |
| 82 | |
| 83 // The widget for the pointer cursor. | 75 // The widget for the pointer cursor. |
| 84 std::unique_ptr<views::Widget> widget_; | 76 std::unique_ptr<views::Widget> widget_; |
| 85 | 77 |
| 86 // The current pointer surface. | 78 // The current pointer surface. |
| 87 Surface* surface_ = nullptr; | 79 Surface* surface_ = nullptr; |
| 88 | 80 |
| 89 // The current focus surface for the pointer. | 81 // The current focus surface for the pointer. |
| 90 Surface* focus_ = nullptr; | 82 Surface* focus_ = nullptr; |
| 91 | 83 |
| 92 // The location of the pointer in the current focus surface. | 84 // The location of the pointer in the current focus surface. |
| 93 gfx::PointF location_; | 85 gfx::PointF location_; |
| 94 | 86 |
| 95 // The scale applied to the cursor to compensate for the UI scale. | 87 // The scale applied to the cursor to compensate for the UI scale. |
| 96 float cursor_scale_ = 1.0f; | 88 float cursor_scale_ = 1.0f; |
| 97 | 89 |
| 98 // The position of the pointer surface relative to the pointer location. | 90 // The position of the pointer surface relative to the pointer location. |
| 99 gfx::Point hotspot_; | 91 gfx::Point hotspot_; |
| 100 | 92 |
| 101 // The current pointer type. | |
| 102 ui::EventPointerType pointer_type_; | |
| 103 | |
| 104 // The current pointer tilt. | |
| 105 gfx::Vector2dF tilt_; | |
| 106 | |
| 107 // The current pointer force. | |
| 108 float force_; | |
| 109 | |
| 110 // True if the pointer is controlled via direct input. | |
| 111 bool is_direct_input_ = false; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(Pointer); | 93 DISALLOW_COPY_AND_ASSIGN(Pointer); |
| 114 }; | 94 }; |
| 115 | 95 |
| 116 } // namespace exo | 96 } // namespace exo |
| 117 | 97 |
| 118 #endif // COMPONENTS_EXO_POINTER_H_ | 98 #endif // COMPONENTS_EXO_POINTER_H_ |
| OLD | NEW |