OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 ASH_WM_CURSOR_MANAGER_H_ | 5 #ifndef UI_VIEWS_COREWM_CURSOR_CONTROLLER_H_ |
6 #define ASH_WM_CURSOR_MANAGER_H_ | 6 #define UI_VIEWS_COREWM_CURSOR_CONTROLLER_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | |
9 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
11 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
12 #include "ui/aura/client/cursor_client.h" | 11 #include "ui/aura/client/cursor_client.h" |
13 #include "ui/gfx/native_widget_types.h" | 12 #include "ui/gfx/native_widget_types.h" |
14 #include "ui/gfx/point.h" | 13 #include "ui/gfx/point.h" |
| 14 #include "ui/views/views_export.h" |
15 | 15 |
16 namespace ash { | 16 namespace views { |
| 17 namespace corewm { |
17 | 18 |
18 namespace internal { | 19 namespace internal { |
19 class CursorState; | 20 class CursorState; |
20 } | 21 } |
21 | 22 |
22 namespace test { | 23 // This class controls the visibility and the type of the cursor. The cursor |
23 class CursorManagerTestApi; | 24 // type can be locked so that the type stays the same until it's unlocked. |
24 } | 25 class VIEWS_EXPORT CursorController : public aura::client::CursorClient { |
25 | |
26 class ImageCursors; | |
27 | |
28 // This class controls the visibility and the type of the cursor. | |
29 // The cursor type can be locked so that the type stays the same | |
30 // until it's unlocked. | |
31 class ASH_EXPORT CursorManager : public aura::client::CursorClient { | |
32 public: | 26 public: |
33 CursorManager(); | 27 CursorController(); |
34 virtual ~CursorManager(); | 28 virtual ~CursorController(); |
35 | 29 |
36 bool is_cursor_locked() const { return cursor_lock_count_ > 0; } | 30 bool is_cursor_locked() const { return cursor_lock_count_ > 0; } |
37 | 31 |
38 // Overridden from aura::client::CursorClient: | 32 // Overridden from aura::client::CursorClient: |
39 virtual void SetCursor(gfx::NativeCursor) OVERRIDE; | 33 virtual void SetCursor(gfx::NativeCursor) OVERRIDE; |
40 virtual void ShowCursor() OVERRIDE; | 34 virtual void ShowCursor() OVERRIDE; |
41 virtual void HideCursor() OVERRIDE; | 35 virtual void HideCursor() OVERRIDE; |
42 virtual bool IsCursorVisible() const OVERRIDE; | 36 virtual bool IsCursorVisible() const OVERRIDE; |
43 virtual void EnableMouseEvents() OVERRIDE; | 37 virtual void EnableMouseEvents() OVERRIDE; |
44 virtual void DisableMouseEvents() OVERRIDE; | 38 virtual void DisableMouseEvents() OVERRIDE; |
45 virtual bool IsMouseEventsEnabled() const OVERRIDE; | 39 virtual bool IsMouseEventsEnabled() const OVERRIDE; |
46 virtual void SetDeviceScaleFactor(float device_scale_factor) OVERRIDE; | |
47 virtual void LockCursor() OVERRIDE; | 40 virtual void LockCursor() OVERRIDE; |
48 virtual void UnlockCursor() OVERRIDE; | 41 virtual void UnlockCursor() OVERRIDE; |
49 | 42 |
50 private: | 43 protected: |
51 friend class test::CursorManagerTestApi; | |
52 | |
53 void SetCursorInternal(gfx::NativeCursor cursor); | |
54 void SetCursorVisibility(bool visible); | |
55 void SetMouseEventsEnabled(bool enabled); | |
56 | |
57 // Returns the current cursor. | 44 // Returns the current cursor. |
58 gfx::NativeCursor GetCurrentCursor() const; | 45 gfx::NativeCursor GetCurrentCursor() const; |
59 | 46 |
| 47 // Subclasses of CursorController control the actual assignment of cursors |
| 48 // through the following template methods. |
| 49 |
| 50 // Called to set the current cursor. Subclasses that need to set platform |
| 51 // state should call the base method from their override after mutating their |
| 52 // incoming cursor with their platform state. |
| 53 virtual void SetCursorInternal(gfx::NativeCursor cursor); |
| 54 |
| 55 // Called to set the visibility. Subclasses should call the base method first |
| 56 // and then do platform visibility mutation. |
| 57 virtual void SetCursorVisibility(bool visible); |
| 58 |
| 59 // Called to set whether mouse events are enabled. Subclasses should call the |
| 60 // base method first and then restore whatever state is necessary on their |
| 61 // platform. |
| 62 virtual void SetMouseEventsEnabled(bool enabled); |
| 63 |
| 64 private: |
60 // Number of times LockCursor() has been invoked without a corresponding | 65 // Number of times LockCursor() has been invoked without a corresponding |
61 // UnlockCursor(). | 66 // UnlockCursor(). |
62 int cursor_lock_count_; | 67 int cursor_lock_count_; |
63 | 68 |
64 // The cursor location where the cursor was disabled. | |
65 gfx::Point disabled_cursor_location_; | |
66 | |
67 // The current state of the cursor. | 69 // The current state of the cursor. |
68 scoped_ptr<internal::CursorState> current_state_; | 70 scoped_ptr<internal::CursorState> current_state_; |
69 | 71 |
70 // The cursor state to restore when the cursor is unlocked. | 72 // The cursor state to restore when the cursor is unlocked. |
71 scoped_ptr<internal::CursorState> state_on_unlock_; | 73 scoped_ptr<internal::CursorState> state_on_unlock_; |
72 | 74 |
73 scoped_ptr<ImageCursors> image_cursors_; | 75 DISALLOW_COPY_AND_ASSIGN(CursorController); |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(CursorManager); | |
76 }; | 76 }; |
77 | 77 |
78 } // namespace ash | 78 } // namespace corewm |
| 79 } // namespace views |
79 | 80 |
80 #endif // UI_AURA_CURSOR_MANAGER_H_ | 81 #endif // UI_VIEWS_COREWM_CURSOR_CONTROLLER_H_ |
OLD | NEW |