Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: ui/wm/core/cursor_manager.cc

Issue 2949353003: Implement large cursors in Mushrome. (Closed)
Patch Set: Remove old cursor.h includes. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 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 #include "ui/wm/core/cursor_manager.h" 5 #include "ui/wm/core/cursor_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "ui/aura/client/cursor_client_observer.h" 11 #include "ui/aura/client/cursor_client_observer.h"
12 #include "ui/wm/core/native_cursor_manager.h" 12 #include "ui/wm/core/native_cursor_manager.h"
13 #include "ui/wm/core/native_cursor_manager_delegate.h" 13 #include "ui/wm/core/native_cursor_manager_delegate.h"
14 14
15 namespace wm { 15 namespace wm {
16 16
17 namespace internal { 17 namespace internal {
18 18
19 // Represents the cursor state which is composed of cursor type, visibility, and 19 // Represents the cursor state which is composed of cursor type, visibility, and
20 // mouse events enable state. When mouse events are disabled, the cursor is 20 // mouse events enable state. When mouse events are disabled, the cursor is
21 // always invisible. 21 // always invisible.
22 class CursorState { 22 class CursorState {
23 public: 23 public:
24 CursorState() 24 CursorState()
25 : cursor_(ui::CursorType::kNone), 25 : cursor_(ui::CursorType::kNone),
26 visible_(true), 26 visible_(true),
27 cursor_set_(ui::CURSOR_SET_NORMAL), 27 cursor_set_(ui::CursorSet::kNormal),
28 mouse_events_enabled_(true), 28 mouse_events_enabled_(true),
29 visible_on_mouse_events_enabled_(true) {} 29 visible_on_mouse_events_enabled_(true) {}
30 30
31 gfx::NativeCursor cursor() const { return cursor_; } 31 gfx::NativeCursor cursor() const { return cursor_; }
32 void set_cursor(gfx::NativeCursor cursor) { cursor_ = cursor; } 32 void set_cursor(gfx::NativeCursor cursor) { cursor_ = cursor; }
33 33
34 bool visible() const { return visible_; } 34 bool visible() const { return visible_; }
35 void SetVisible(bool visible) { 35 void SetVisible(bool visible) {
36 if (mouse_events_enabled_) 36 if (mouse_events_enabled_)
37 visible_ = visible; 37 visible_ = visible;
38 // Ignores the call when mouse events disabled. 38 // Ignores the call when mouse events disabled.
39 } 39 }
40 40
41 ui::CursorSetType cursor_set() const { return cursor_set_; } 41 ui::CursorSet cursor_set() const { return cursor_set_; }
42 void set_cursor_set(ui::CursorSetType cursor_set) { 42 void set_cursor_set(ui::CursorSet cursor_set) { cursor_set_ = cursor_set; }
43 cursor_set_ = cursor_set;
44 }
45 43
46 bool mouse_events_enabled() const { return mouse_events_enabled_; } 44 bool mouse_events_enabled() const { return mouse_events_enabled_; }
47 void SetMouseEventsEnabled(bool enabled) { 45 void SetMouseEventsEnabled(bool enabled) {
48 if (mouse_events_enabled_ == enabled) 46 if (mouse_events_enabled_ == enabled)
49 return; 47 return;
50 mouse_events_enabled_ = enabled; 48 mouse_events_enabled_ = enabled;
51 49
52 // Restores the visibility when mouse events are enabled. 50 // Restores the visibility when mouse events are enabled.
53 if (enabled) { 51 if (enabled) {
54 visible_ = visible_on_mouse_events_enabled_; 52 visible_ = visible_on_mouse_events_enabled_;
55 } else { 53 } else {
56 visible_on_mouse_events_enabled_ = visible_; 54 visible_on_mouse_events_enabled_ = visible_;
57 visible_ = false; 55 visible_ = false;
58 } 56 }
59 } 57 }
60 58
61 private: 59 private:
62 gfx::NativeCursor cursor_; 60 gfx::NativeCursor cursor_;
63 bool visible_; 61 bool visible_;
64 ui::CursorSetType cursor_set_; 62 ui::CursorSet cursor_set_;
65 bool mouse_events_enabled_; 63 bool mouse_events_enabled_;
66 64
67 // The visibility to set when mouse events are enabled. 65 // The visibility to set when mouse events are enabled.
68 bool visible_on_mouse_events_enabled_; 66 bool visible_on_mouse_events_enabled_;
69 67
70 DISALLOW_COPY_AND_ASSIGN(CursorState); 68 DISALLOW_COPY_AND_ASSIGN(CursorState);
71 }; 69 };
72 70
73 } // namespace internal 71 } // namespace internal
74 72
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 delegate_->SetVisibility(state_on_unlock_->visible(), this); 120 delegate_->SetVisibility(state_on_unlock_->visible(), this);
123 for (auto& observer : observers_) 121 for (auto& observer : observers_)
124 observer.OnCursorVisibilityChanged(false); 122 observer.OnCursorVisibilityChanged(false);
125 } 123 }
126 } 124 }
127 125
128 bool CursorManager::IsCursorVisible() const { 126 bool CursorManager::IsCursorVisible() const {
129 return current_state_->visible(); 127 return current_state_->visible();
130 } 128 }
131 129
132 void CursorManager::SetCursorSet(ui::CursorSetType cursor_set) { 130 void CursorManager::SetCursorSet(ui::CursorSet cursor_set) {
133 state_on_unlock_->set_cursor_set(cursor_set); 131 state_on_unlock_->set_cursor_set(cursor_set);
134 if (GetCursorSet() != state_on_unlock_->cursor_set()) { 132 if (GetCursorSet() != state_on_unlock_->cursor_set()) {
135 delegate_->SetCursorSet(state_on_unlock_->cursor_set(), this); 133 delegate_->SetCursorSet(state_on_unlock_->cursor_set(), this);
136 for (auto& observer : observers_) 134 for (auto& observer : observers_)
137 observer.OnCursorSetChanged(cursor_set); 135 observer.OnCursorSetChanged(cursor_set);
138 } 136 }
139 } 137 }
140 138
141 ui::CursorSetType CursorManager::GetCursorSet() const { 139 ui::CursorSet CursorManager::GetCursorSet() const {
142 return current_state_->cursor_set(); 140 return current_state_->cursor_set();
143 } 141 }
144 142
145 void CursorManager::EnableMouseEvents() { 143 void CursorManager::EnableMouseEvents() {
146 state_on_unlock_->SetMouseEventsEnabled(true); 144 state_on_unlock_->SetMouseEventsEnabled(true);
147 if (cursor_lock_count_ == 0 && 145 if (cursor_lock_count_ == 0 &&
148 IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) { 146 IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) {
149 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(), 147 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(),
150 this); 148 this);
151 } 149 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 221 }
224 222
225 void CursorManager::CommitVisibility(bool visible) { 223 void CursorManager::CommitVisibility(bool visible) {
226 // TODO(tdanderson): Find a better place for this so we don't 224 // TODO(tdanderson): Find a better place for this so we don't
227 // notify the observers more than is necessary. 225 // notify the observers more than is necessary.
228 for (auto& observer : observers_) 226 for (auto& observer : observers_)
229 observer.OnCursorVisibilityChanged(visible); 227 observer.OnCursorVisibilityChanged(visible);
230 current_state_->SetVisible(visible); 228 current_state_->SetVisible(visible);
231 } 229 }
232 230
233 void CursorManager::CommitCursorSet(ui::CursorSetType cursor_set) { 231 void CursorManager::CommitCursorSet(ui::CursorSet cursor_set) {
234 current_state_->set_cursor_set(cursor_set); 232 current_state_->set_cursor_set(cursor_set);
235 } 233 }
236 234
237 void CursorManager::CommitMouseEventsEnabled(bool enabled) { 235 void CursorManager::CommitMouseEventsEnabled(bool enabled) {
238 current_state_->SetMouseEventsEnabled(enabled); 236 current_state_->SetMouseEventsEnabled(enabled);
239 } 237 }
240 238
241 } // namespace wm 239 } // namespace wm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698