| 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 "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/unguessable_token.h" | 12 #include "base/unguessable_token.h" |
| 13 #include "components/exo/surface_delegate.h" | 13 #include "components/exo/surface_delegate.h" |
| 14 #include "components/exo/surface_observer.h" | 14 #include "components/exo/surface_observer.h" |
| 15 #include "components/exo/wm_helper.h" | 15 #include "components/exo/wm_helper.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 #include "ui/base/cursor/cursor.h" | 17 #include "ui/base/cursor/cursor.h" |
| 17 #include "ui/events/event_constants.h" | 18 #include "ui/events/event_constants.h" |
| 18 #include "ui/events/event_handler.h" | 19 #include "ui/events/event_handler.h" |
| 19 #include "ui/gfx/geometry/point.h" | 20 #include "ui/gfx/geometry/point.h" |
| 20 #include "ui/gfx/geometry/point_f.h" | 21 #include "ui/gfx/geometry/point_f.h" |
| 21 #include "ui/gfx/native_widget_types.h" | 22 #include "ui/gfx/native_widget_types.h" |
| 22 | 23 |
| 23 namespace cc { | 24 namespace cc { |
| 24 class CopyOutputResult; | 25 class CopyOutputResult; |
| 25 } | 26 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 52 | 53 |
| 53 // Returns the current cursor for the pointer. | 54 // Returns the current cursor for the pointer. |
| 54 gfx::NativeCursor GetCursor(); | 55 gfx::NativeCursor GetCursor(); |
| 55 | 56 |
| 56 // Overridden from ui::EventHandler: | 57 // Overridden from ui::EventHandler: |
| 57 void OnMouseEvent(ui::MouseEvent* event) override; | 58 void OnMouseEvent(ui::MouseEvent* event) override; |
| 58 void OnScrollEvent(ui::ScrollEvent* event) override; | 59 void OnScrollEvent(ui::ScrollEvent* event) override; |
| 59 | 60 |
| 60 // Overridden from WMHelper::CursorObserver: | 61 // Overridden from WMHelper::CursorObserver: |
| 61 void OnCursorSetChanged(ui::CursorSetType cursor_set) override; | 62 void OnCursorSetChanged(ui::CursorSetType cursor_set) override; |
| 63 void OnCursorDisplayChanged(const display::Display& display) override; |
| 62 | 64 |
| 63 // Overridden from SurfaceDelegate: | 65 // Overridden from SurfaceDelegate: |
| 64 void OnSurfaceCommit() override; | 66 void OnSurfaceCommit() override; |
| 65 bool IsSurfaceSynchronized() const override; | 67 bool IsSurfaceSynchronized() const override; |
| 66 | 68 |
| 67 // Overridden from SurfaceObserver: | 69 // Overridden from SurfaceObserver: |
| 68 void OnSurfaceDestroying(Surface* surface) override; | 70 void OnSurfaceDestroying(Surface* surface) override; |
| 69 | 71 |
| 70 private: | 72 private: |
| 71 // Returns the effective target for |event|. | 73 // Returns the effective target for |event|. |
| 72 Surface* GetEffectiveTargetForEvent(ui::Event* event) const; | 74 Surface* GetEffectiveTargetForEvent(ui::Event* event) const; |
| 73 | 75 |
| 74 // Recompute cursor scale and update cursor if scale changed. | |
| 75 void UpdateCursorScale(); | |
| 76 | |
| 77 // Asynchronously update the cursor by capturing a snapshot of |surface_|. | 76 // Asynchronously update the cursor by capturing a snapshot of |surface_|. |
| 78 void CaptureCursor(); | 77 void CaptureCursor(const gfx::Point& hotspot); |
| 79 | 78 |
| 80 // Called when cursor snapshot has been captured. | 79 // Called when cursor snapshot has been captured. |
| 81 void OnCursorCaptured(const gfx::Point& hotspot, | 80 void OnCursorCaptured(const gfx::Point& hotspot, |
| 82 std::unique_ptr<cc::CopyOutputResult> result); | 81 std::unique_ptr<cc::CopyOutputResult> result); |
| 83 | 82 |
| 84 // Update cursor to reflect the current value of |cursor_|. | 83 // Update |cursor_| to |cursor_bitmap_| transformed for the current display. |
| 85 void UpdateCursor(); | 84 void UpdateCursor(); |
| 86 | 85 |
| 87 // The delegate instance that all events are dispatched to. | 86 // The delegate instance that all events are dispatched to. |
| 88 PointerDelegate* const delegate_; | 87 PointerDelegate* const delegate_; |
| 89 | 88 |
| 90 // The current pointer surface. | 89 // The current pointer surface. |
| 91 Surface* surface_ = nullptr; | 90 Surface* surface_ = nullptr; |
| 92 | 91 |
| 93 // The current focus surface for the pointer. | 92 // The current focus surface for the pointer. |
| 94 Surface* focus_ = nullptr; | 93 Surface* focus_ = nullptr; |
| 95 | 94 |
| 96 // The location of the pointer in the current focus surface. | 95 // The location of the pointer in the current focus surface. |
| 97 gfx::PointF location_; | 96 gfx::PointF location_; |
| 98 | 97 |
| 99 // The scale applied to the cursor to compensate for the UI scale. | |
| 100 float cursor_scale_ = 1.0f; | |
| 101 | |
| 102 // The position of the pointer surface relative to the pointer location. | 98 // The position of the pointer surface relative to the pointer location. |
| 103 gfx::Point hotspot_; | 99 gfx::Point hotspot_; |
| 104 | 100 |
| 101 // Latest cursor snapshot. |
| 102 SkBitmap cursor_bitmap_; |
| 103 |
| 105 // The current cursor. | 104 // The current cursor. |
| 106 ui::Cursor cursor_; | 105 ui::Cursor cursor_; |
| 107 | 106 |
| 108 // Source used for cursor capture copy output requests. | 107 // Source used for cursor capture copy output requests. |
| 109 const base::UnguessableToken cursor_capture_source_id_; | 108 const base::UnguessableToken cursor_capture_source_id_; |
| 110 | 109 |
| 111 // Last received event type. | 110 // Last received event type. |
| 112 ui::EventType last_event_type_ = ui::ET_UNKNOWN; | 111 ui::EventType last_event_type_ = ui::ET_UNKNOWN; |
| 113 | 112 |
| 114 // Weak pointer factory used for cursor capture callbacks. | 113 // Weak pointer factory used for cursor capture callbacks. |
| 115 base::WeakPtrFactory<Pointer> cursor_capture_weak_ptr_factory_; | 114 base::WeakPtrFactory<Pointer> cursor_capture_weak_ptr_factory_; |
| 116 | 115 |
| 117 DISALLOW_COPY_AND_ASSIGN(Pointer); | 116 DISALLOW_COPY_AND_ASSIGN(Pointer); |
| 118 }; | 117 }; |
| 119 | 118 |
| 120 } // namespace exo | 119 } // namespace exo |
| 121 | 120 |
| 122 #endif // COMPONENTS_EXO_POINTER_H_ | 121 #endif // COMPONENTS_EXO_POINTER_H_ |
| OLD | NEW |