Chromium Code Reviews| 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 "ui/aura/client/cursor_client_observer.h" | |
| 13 #include "ui/events/event_handler.h" | 14 #include "ui/events/event_handler.h" |
| 14 #include "ui/gfx/geometry/point.h" | 15 #include "ui/gfx/geometry/point.h" |
| 15 #include "ui/gfx/geometry/point_f.h" | 16 #include "ui/gfx/geometry/point_f.h" |
| 16 | 17 |
| 17 namespace ui { | 18 namespace ui { |
| 18 class Event; | 19 class Event; |
| 19 class MouseEvent; | 20 class MouseEvent; |
| 20 class MouseWheelEvent; | 21 class MouseWheelEvent; |
| 21 } | 22 } |
| 22 | 23 |
| 23 namespace views { | 24 namespace views { |
| 24 class Widget; | 25 class Widget; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace exo { | 28 namespace exo { |
| 28 class PointerDelegate; | 29 class PointerDelegate; |
| 29 class Surface; | 30 class Surface; |
| 30 | 31 |
| 31 // This class implements a client pointer that represents one or more input | 32 // This class implements a client pointer that represents one or more input |
| 32 // devices, such as mice, which control the pointer location and pointer focus. | 33 // devices, such as mice, which control the pointer location and pointer focus. |
| 33 class Pointer : public ui::EventHandler, | 34 class Pointer : public ui::EventHandler, |
| 35 public aura::client::CursorClientObserver, | |
| 34 public SurfaceDelegate, | 36 public SurfaceDelegate, |
| 35 public SurfaceObserver { | 37 public SurfaceObserver { |
| 36 public: | 38 public: |
| 37 explicit Pointer(PointerDelegate* delegate); | 39 explicit Pointer(PointerDelegate* delegate); |
| 38 ~Pointer() override; | 40 ~Pointer() override; |
| 39 | 41 |
| 40 // Set the pointer surface, i.e., the surface that contains the pointer image | 42 // Set the pointer surface, i.e., the surface that contains the pointer image |
| 41 // (cursor). The |hotspot| argument defines the position of the pointer | 43 // (cursor). The |hotspot| argument defines the position of the pointer |
| 42 // surface relative to the pointer location. Its top-left corner is always at | 44 // surface relative to the pointer location. Its top-left corner is always at |
| 43 // (x, y) - (hotspot.x, hotspot.y), where (x, y) are the coordinates of the | 45 // (x, y) - (hotspot.x, hotspot.y), where (x, y) are the coordinates of the |
| 44 // pointer location, in surface local coordinates. | 46 // pointer location, in surface local coordinates. |
| 45 void SetCursor(Surface* surface, const gfx::Point& hotspot); | 47 void SetCursor(Surface* surface, const gfx::Point& hotspot); |
| 46 | 48 |
| 47 // Overridden from ui::EventHandler: | 49 // Overridden from ui::EventHandler: |
| 48 void OnMouseEvent(ui::MouseEvent* event) override; | 50 void OnMouseEvent(ui::MouseEvent* event) override; |
| 49 void OnScrollEvent(ui::ScrollEvent* event) override; | 51 void OnScrollEvent(ui::ScrollEvent* event) override; |
| 50 | 52 |
| 53 // Overridden from aura::client::CursorClientObserver: | |
| 54 void OnCursorSetChanged(ui::CursorSetType cursor_set) override; | |
| 55 | |
| 51 // Overridden from SurfaceDelegate: | 56 // Overridden from SurfaceDelegate: |
| 52 void OnSurfaceCommit() override; | 57 void OnSurfaceCommit() override; |
| 53 bool IsSurfaceSynchronized() const override; | 58 bool IsSurfaceSynchronized() const override; |
| 54 | 59 |
| 55 // Overridden from SurfaceObserver: | 60 // Overridden from SurfaceObserver: |
| 56 void OnSurfaceDestroying(Surface* surface) override; | 61 void OnSurfaceDestroying(Surface* surface) override; |
| 57 | 62 |
| 58 private: | 63 private: |
| 59 // Creates the |widget_| for pointer. | 64 // Creates the |widget_| for pointer. |
| 60 void CreatePointerWidget(); | 65 void CreatePointerWidget(); |
| 61 | 66 |
| 67 // Reset the shape of the cursor with the latest state. | |
| 68 void ResetCursor(); | |
|
reveman
2016/06/15 17:48:30
nit: UpdateCursorScale() seems like a better name
| |
| 69 | |
| 62 // Returns the effective target for |event|. | 70 // Returns the effective target for |event|. |
| 63 Surface* GetEffectiveTargetForEvent(ui::Event* event) const; | 71 Surface* GetEffectiveTargetForEvent(ui::Event* event) const; |
| 64 | 72 |
| 65 // The delegate instance that all events are dispatched to. | 73 // The delegate instance that all events are dispatched to. |
| 66 PointerDelegate* delegate_; | 74 PointerDelegate* delegate_; |
| 67 | 75 |
| 68 // The widget for the pointer cursor. | 76 // The widget for the pointer cursor. |
| 69 std::unique_ptr<views::Widget> widget_; | 77 std::unique_ptr<views::Widget> widget_; |
| 70 | 78 |
| 71 // The current pointer surface. | 79 // The current pointer surface. |
| 72 Surface* surface_; | 80 Surface* surface_; |
| 73 | 81 |
| 74 // The current focus surface for the pointer. | 82 // The current focus surface for the pointer. |
| 75 Surface* focus_; | 83 Surface* focus_; |
| 76 | 84 |
| 77 // The location of the pointer in the current focus surface. | 85 // The location of the pointer in the current focus surface. |
| 78 gfx::PointF location_; | 86 gfx::PointF location_; |
| 79 | 87 |
| 80 // The scale applied to the cursor to compensate for the UI scale. | 88 // The scale applied to the cursor to compensate for the UI scale. |
| 81 float cursor_scale_; | 89 float cursor_scale_; |
| 82 | 90 |
| 91 // The flag to enlarge the cursor. True to show larger cursor. | |
| 92 bool use_large_cursor_; | |
| 93 | |
| 83 // The position of the pointer surface relative to the pointer location. | 94 // The position of the pointer surface relative to the pointer location. |
| 84 gfx::Point hotspot_; | 95 gfx::Point hotspot_; |
| 85 | 96 |
| 86 DISALLOW_COPY_AND_ASSIGN(Pointer); | 97 DISALLOW_COPY_AND_ASSIGN(Pointer); |
| 87 }; | 98 }; |
| 88 | 99 |
| 89 } // namespace exo | 100 } // namespace exo |
| 90 | 101 |
| 91 #endif // COMPONENTS_EXO_POINTER_H_ | 102 #endif // COMPONENTS_EXO_POINTER_H_ |
| OLD | NEW |