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

Side by Side Diff: ui/views/corewm/cursor_manager.cc

Issue 92413002: Cursor state should be global for all CursorManagers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch for review Created 7 years 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 | Annotate | Revision Log
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/views/corewm/cursor_manager.h" 5 #include "ui/views/corewm/cursor_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/aura/client/cursor_client_observer.h" 8 #include "ui/aura/client/cursor_client_observer.h"
9 #include "ui/views/corewm/native_cursor_manager.h" 9 #include "ui/views/corewm/native_cursor_manager.h"
10 #include "ui/views/corewm/native_cursor_manager_delegate.h" 10 #include "ui/views/corewm/native_cursor_manager_delegate.h"
(...skipping 10 matching lines...) Expand all
21 public: 21 public:
22 CursorState() 22 CursorState()
23 : cursor_(ui::kCursorNone), 23 : cursor_(ui::kCursorNone),
24 visible_(true), 24 visible_(true),
25 scale_(1.f), 25 scale_(1.f),
26 cursor_set_(ui::CURSOR_SET_NORMAL), 26 cursor_set_(ui::CURSOR_SET_NORMAL),
27 mouse_events_enabled_(true), 27 mouse_events_enabled_(true),
28 visible_on_mouse_events_enabled_(true) { 28 visible_on_mouse_events_enabled_(true) {
29 } 29 }
30 30
31 void ResetState() {
sky 2013/12/05 01:32:43 Instead of ResetState, could you create a new Curs
tdanderson 2013/12/05 23:07:41 Done.
32 cursor_ = ui::kCursorNone;
33 visible_ = true;
34 scale_ = 1.f;
35 cursor_set_ = ui::CURSOR_SET_NORMAL;
36 mouse_events_enabled_ = true;
37 visible_on_mouse_events_enabled_ = true;
38 }
39
31 gfx::NativeCursor cursor() const { return cursor_; } 40 gfx::NativeCursor cursor() const { return cursor_; }
32 void set_cursor(gfx::NativeCursor cursor) { cursor_ = cursor; } 41 void set_cursor(gfx::NativeCursor cursor) { cursor_ = cursor; }
33 42
34 bool visible() const { return visible_; } 43 bool visible() const { return visible_; }
35 void SetVisible(bool visible) { 44 void SetVisible(bool visible) {
36 if (mouse_events_enabled_) 45 if (mouse_events_enabled_)
37 visible_ = visible; 46 visible_ = visible;
38 // Ignores the call when mouse events disabled. 47 // Ignores the call when mouse events disabled.
39 } 48 }
40 49
(...skipping 30 matching lines...) Expand all
71 bool mouse_events_enabled_; 80 bool mouse_events_enabled_;
72 81
73 // The visibility to set when mouse events are enabled. 82 // The visibility to set when mouse events are enabled.
74 bool visible_on_mouse_events_enabled_; 83 bool visible_on_mouse_events_enabled_;
75 84
76 DISALLOW_COPY_AND_ASSIGN(CursorState); 85 DISALLOW_COPY_AND_ASSIGN(CursorState);
77 }; 86 };
78 87
79 } // namespace internal 88 } // namespace internal
80 89
90 int CursorManager::cursor_lock_count_ = 0;
91 scoped_ptr<internal::CursorState> CursorManager::current_state_(
92 new internal::CursorState);
93 scoped_ptr<internal::CursorState> CursorManager::state_on_unlock_(
94 new internal::CursorState);
95 ObserverList<aura::client::CursorClientObserver> CursorManager::observers_;
oshima 2013/12/05 19:29:07 as sky said, no NON POD static initializer.
tdanderson 2013/12/05 23:07:41 Done.
96
81 CursorManager::CursorManager(scoped_ptr<NativeCursorManager> delegate) 97 CursorManager::CursorManager(scoped_ptr<NativeCursorManager> delegate)
82 : delegate_(delegate.Pass()), 98 : delegate_(delegate.Pass()) {
83 cursor_lock_count_(0),
84 current_state_(new internal::CursorState),
85 state_on_unlock_(new internal::CursorState) {
86 } 99 }
87 100
88 CursorManager::~CursorManager() { 101 CursorManager::~CursorManager() {
89 } 102 }
90 103
104 void CursorManager::ResetState() {
105 CursorManager::cursor_lock_count_ = 0;
106 CursorManager::current_state_->ResetState();
107 CursorManager::state_on_unlock_->ResetState();
108 CursorManager::observers_.Clear();
109 }
110
91 void CursorManager::SetCursor(gfx::NativeCursor cursor) { 111 void CursorManager::SetCursor(gfx::NativeCursor cursor) {
92 state_on_unlock_->set_cursor(cursor); 112 state_on_unlock_->set_cursor(cursor);
93 if (cursor_lock_count_ == 0 && 113 if (cursor_lock_count_ == 0 &&
94 GetCurrentCursor() != state_on_unlock_->cursor()) { 114 GetCursor() != state_on_unlock_->cursor()) {
95 delegate_->SetCursor(state_on_unlock_->cursor(), this); 115 delegate_->SetCursor(state_on_unlock_->cursor(), this);
96 } 116 }
97 } 117 }
98 118
119 gfx::NativeCursor CursorManager::GetCursor() const {
120 return current_state_->cursor();
121 }
122
99 void CursorManager::ShowCursor() { 123 void CursorManager::ShowCursor() {
100 state_on_unlock_->SetVisible(true); 124 state_on_unlock_->SetVisible(true);
101 if (cursor_lock_count_ == 0 && 125 if (cursor_lock_count_ == 0 &&
102 IsCursorVisible() != state_on_unlock_->visible()) { 126 IsCursorVisible() != state_on_unlock_->visible()) {
103 delegate_->SetVisibility(state_on_unlock_->visible(), this); 127 delegate_->SetVisibility(state_on_unlock_->visible(), this);
104 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, 128 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
105 OnCursorVisibilityChanged(true)); 129 OnCursorVisibilityChanged(true));
106 } 130 }
107 } 131 }
108 132
109 void CursorManager::HideCursor() { 133 void CursorManager::HideCursor() {
110 state_on_unlock_->SetVisible(false); 134 state_on_unlock_->SetVisible(false);
111 if (cursor_lock_count_ == 0 && 135 if (cursor_lock_count_ == 0 &&
112 IsCursorVisible() != state_on_unlock_->visible()) { 136 IsCursorVisible() != state_on_unlock_->visible()) {
113 delegate_->SetVisibility(state_on_unlock_->visible(), this); 137 delegate_->SetVisibility(state_on_unlock_->visible(), this);
114 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, 138 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
115 OnCursorVisibilityChanged(false)); 139 OnCursorVisibilityChanged(false));
116 } 140 }
117 } 141 }
118 142
119 bool CursorManager::IsCursorVisible() const { 143 bool CursorManager::IsCursorVisible() const {
120 return current_state_->visible(); 144 return current_state_->visible();
121 } 145 }
122 146
123 void CursorManager::SetScale(float scale) { 147 void CursorManager::SetScale(float scale) {
124 state_on_unlock_->set_scale(scale); 148 state_on_unlock_->set_scale(scale);
125 if (GetCurrentScale() != state_on_unlock_->scale()) 149 if (GetScale() != state_on_unlock_->scale())
126 delegate_->SetScale(state_on_unlock_->scale(), this); 150 delegate_->SetScale(state_on_unlock_->scale(), this);
127 } 151 }
128 152
153 float CursorManager::GetScale() const {
154 return current_state_->scale();
155 }
156
129 void CursorManager::SetCursorSet(ui::CursorSetType cursor_set) { 157 void CursorManager::SetCursorSet(ui::CursorSetType cursor_set) {
130 state_on_unlock_->set_cursor_set(cursor_set); 158 state_on_unlock_->set_cursor_set(cursor_set);
131 if (GetCurrentCursorSet() != state_on_unlock_->cursor_set()) 159 if (GetCursorSet() != state_on_unlock_->cursor_set())
132 delegate_->SetCursorSet(state_on_unlock_->cursor_set(), this); 160 delegate_->SetCursorSet(state_on_unlock_->cursor_set(), this);
133 } 161 }
134 162
135 float CursorManager::GetCurrentScale() const { 163 ui::CursorSetType CursorManager::GetCursorSet() const {
136 return current_state_->scale();
137 }
138
139 ui::CursorSetType CursorManager::GetCurrentCursorSet() const {
140 return current_state_->cursor_set(); 164 return current_state_->cursor_set();
141 } 165 }
142 166
143 void CursorManager::EnableMouseEvents() { 167 void CursorManager::EnableMouseEvents() {
144 state_on_unlock_->SetMouseEventsEnabled(true); 168 state_on_unlock_->SetMouseEventsEnabled(true);
145 if (cursor_lock_count_ == 0 && 169 if (cursor_lock_count_ == 0 &&
146 IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) { 170 IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) {
147 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(), 171 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(),
148 this); 172 this);
149 } 173 }
(...skipping 19 matching lines...) Expand all
169 void CursorManager::LockCursor() { 193 void CursorManager::LockCursor() {
170 cursor_lock_count_++; 194 cursor_lock_count_++;
171 } 195 }
172 196
173 void CursorManager::UnlockCursor() { 197 void CursorManager::UnlockCursor() {
174 cursor_lock_count_--; 198 cursor_lock_count_--;
175 DCHECK_GE(cursor_lock_count_, 0); 199 DCHECK_GE(cursor_lock_count_, 0);
176 if (cursor_lock_count_ > 0) 200 if (cursor_lock_count_ > 0)
177 return; 201 return;
178 202
179 if (GetCurrentCursor() != state_on_unlock_->cursor()) { 203 if (GetCursor() != state_on_unlock_->cursor()) {
180 delegate_->SetCursor(state_on_unlock_->cursor(), this); 204 delegate_->SetCursor(state_on_unlock_->cursor(), this);
181 } 205 }
182 if (IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) { 206 if (IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) {
183 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(), 207 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(),
184 this); 208 this);
185 } 209 }
186 if (IsCursorVisible() != state_on_unlock_->visible()) { 210 if (IsCursorVisible() != state_on_unlock_->visible()) {
187 delegate_->SetVisibility(state_on_unlock_->visible(), 211 delegate_->SetVisibility(state_on_unlock_->visible(),
188 this); 212 this);
189 } 213 }
190 } 214 }
191 215
192 bool CursorManager::IsCursorLocked() const { 216 bool CursorManager::IsCursorLocked() const {
193 return cursor_lock_count_ > 0; 217 return cursor_lock_count_ > 0;
194 } 218 }
195 219
196 void CursorManager::AddObserver( 220 void CursorManager::AddObserver(
197 aura::client::CursorClientObserver* observer) { 221 aura::client::CursorClientObserver* observer) {
198 observers_.AddObserver(observer); 222 observers_.AddObserver(observer);
199 } 223 }
200 224
201 void CursorManager::RemoveObserver( 225 void CursorManager::RemoveObserver(
202 aura::client::CursorClientObserver* observer) { 226 aura::client::CursorClientObserver* observer) {
203 observers_.RemoveObserver(observer); 227 observers_.RemoveObserver(observer);
204 } 228 }
205 229
206 gfx::NativeCursor CursorManager::GetCurrentCursor() const {
207 return current_state_->cursor();
208 }
209
210 bool CursorManager::GetCurrentVisibility() const {
211 return current_state_->visible();
212 }
213
214 bool CursorManager::GetMouseEventsEnabled() const {
215 return current_state_->mouse_events_enabled();
216 }
217
218 void CursorManager::CommitCursor(gfx::NativeCursor cursor) { 230 void CursorManager::CommitCursor(gfx::NativeCursor cursor) {
219 current_state_->set_cursor(cursor); 231 current_state_->set_cursor(cursor);
220 } 232 }
221 233
222 void CursorManager::CommitVisibility(bool visible) { 234 void CursorManager::CommitVisibility(bool visible) {
235 // TODO(tdanderson): Find a better place for this so we don't end up
236 // notifying the observers more than necessary.
223 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, 237 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
224 OnCursorVisibilityChanged(visible)); 238 OnCursorVisibilityChanged(visible));
225 current_state_->SetVisible(visible); 239 current_state_->SetVisible(visible);
226 } 240 }
227 241
228 void CursorManager::CommitScale(float scale) { 242 void CursorManager::CommitScale(float scale) {
229 current_state_->set_scale(scale); 243 current_state_->set_scale(scale);
230 } 244 }
231 245
232 void CursorManager::CommitCursorSet(ui::CursorSetType cursor_set) { 246 void CursorManager::CommitCursorSet(ui::CursorSetType cursor_set) {
233 current_state_->set_cursor_set(cursor_set); 247 current_state_->set_cursor_set(cursor_set);
234 } 248 }
235 249
236 void CursorManager::CommitMouseEventsEnabled(bool enabled) { 250 void CursorManager::CommitMouseEventsEnabled(bool enabled) {
237 current_state_->SetMouseEventsEnabled(enabled); 251 current_state_->SetMouseEventsEnabled(enabled);
238 } 252 }
239 253
240 } // namespace corewm 254 } // namespace corewm
241 } // namespace views 255 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698