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

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: comments addressed 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
« no previous file with comments | « ui/views/corewm/cursor_manager.h ('k') | ui/views/corewm/cursor_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 bool mouse_events_enabled_; 71 bool mouse_events_enabled_;
72 72
73 // The visibility to set when mouse events are enabled. 73 // The visibility to set when mouse events are enabled.
74 bool visible_on_mouse_events_enabled_; 74 bool visible_on_mouse_events_enabled_;
75 75
76 DISALLOW_COPY_AND_ASSIGN(CursorState); 76 DISALLOW_COPY_AND_ASSIGN(CursorState);
77 }; 77 };
78 78
79 } // namespace internal 79 } // namespace internal
80 80
81 int CursorManager::cursor_lock_count_ = 0;
82 internal::CursorState* CursorManager::current_state_ =
83 new internal::CursorState;
84 internal::CursorState* CursorManager::state_on_unlock_ =
85 new internal::CursorState;
86 CursorManager::CursorObservers* CursorManager::observers_ =
87 new ObserverList<aura::client::CursorClientObserver>;
88
81 CursorManager::CursorManager(scoped_ptr<NativeCursorManager> delegate) 89 CursorManager::CursorManager(scoped_ptr<NativeCursorManager> delegate)
82 : delegate_(delegate.Pass()), 90 : delegate_(delegate.Pass()) {
83 cursor_lock_count_(0),
84 current_state_(new internal::CursorState),
85 state_on_unlock_(new internal::CursorState) {
86 } 91 }
87 92
88 CursorManager::~CursorManager() { 93 CursorManager::~CursorManager() {
89 } 94 }
90 95
91 void CursorManager::SetCursor(gfx::NativeCursor cursor) { 96 void CursorManager::SetCursor(gfx::NativeCursor cursor) {
92 state_on_unlock_->set_cursor(cursor); 97 state_on_unlock_->set_cursor(cursor);
93 if (cursor_lock_count_ == 0 && 98 if (cursor_lock_count_ == 0 &&
94 GetCurrentCursor() != state_on_unlock_->cursor()) { 99 GetCursor() != state_on_unlock_->cursor()) {
95 delegate_->SetCursor(state_on_unlock_->cursor(), this); 100 delegate_->SetCursor(state_on_unlock_->cursor(), this);
96 } 101 }
97 } 102 }
98 103
104 gfx::NativeCursor CursorManager::GetCursor() const {
105 return current_state_->cursor();
106 }
107
99 void CursorManager::ShowCursor() { 108 void CursorManager::ShowCursor() {
100 state_on_unlock_->SetVisible(true); 109 state_on_unlock_->SetVisible(true);
101 if (cursor_lock_count_ == 0 && 110 if (cursor_lock_count_ == 0 &&
102 IsCursorVisible() != state_on_unlock_->visible()) { 111 IsCursorVisible() != state_on_unlock_->visible()) {
103 delegate_->SetVisibility(state_on_unlock_->visible(), this); 112 delegate_->SetVisibility(state_on_unlock_->visible(), this);
104 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, 113 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, *observers_,
105 OnCursorVisibilityChanged(true)); 114 OnCursorVisibilityChanged(true));
106 } 115 }
107 } 116 }
108 117
109 void CursorManager::HideCursor() { 118 void CursorManager::HideCursor() {
110 state_on_unlock_->SetVisible(false); 119 state_on_unlock_->SetVisible(false);
111 if (cursor_lock_count_ == 0 && 120 if (cursor_lock_count_ == 0 &&
112 IsCursorVisible() != state_on_unlock_->visible()) { 121 IsCursorVisible() != state_on_unlock_->visible()) {
113 delegate_->SetVisibility(state_on_unlock_->visible(), this); 122 delegate_->SetVisibility(state_on_unlock_->visible(), this);
114 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, 123 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, *observers_,
115 OnCursorVisibilityChanged(false)); 124 OnCursorVisibilityChanged(false));
116 } 125 }
117 } 126 }
118 127
119 bool CursorManager::IsCursorVisible() const { 128 bool CursorManager::IsCursorVisible() const {
120 return current_state_->visible(); 129 return current_state_->visible();
121 } 130 }
122 131
123 void CursorManager::SetScale(float scale) { 132 void CursorManager::SetScale(float scale) {
124 state_on_unlock_->set_scale(scale); 133 state_on_unlock_->set_scale(scale);
125 if (GetCurrentScale() != state_on_unlock_->scale()) 134 if (GetScale() != state_on_unlock_->scale())
126 delegate_->SetScale(state_on_unlock_->scale(), this); 135 delegate_->SetScale(state_on_unlock_->scale(), this);
127 } 136 }
128 137
138 float CursorManager::GetScale() const {
139 return current_state_->scale();
140 }
141
129 void CursorManager::SetCursorSet(ui::CursorSetType cursor_set) { 142 void CursorManager::SetCursorSet(ui::CursorSetType cursor_set) {
130 state_on_unlock_->set_cursor_set(cursor_set); 143 state_on_unlock_->set_cursor_set(cursor_set);
131 if (GetCurrentCursorSet() != state_on_unlock_->cursor_set()) 144 if (GetCursorSet() != state_on_unlock_->cursor_set())
132 delegate_->SetCursorSet(state_on_unlock_->cursor_set(), this); 145 delegate_->SetCursorSet(state_on_unlock_->cursor_set(), this);
133 } 146 }
134 147
135 float CursorManager::GetCurrentScale() const { 148 ui::CursorSetType CursorManager::GetCursorSet() const {
136 return current_state_->scale();
137 }
138
139 ui::CursorSetType CursorManager::GetCurrentCursorSet() const {
140 return current_state_->cursor_set(); 149 return current_state_->cursor_set();
141 } 150 }
142 151
143 void CursorManager::EnableMouseEvents() { 152 void CursorManager::EnableMouseEvents() {
144 state_on_unlock_->SetMouseEventsEnabled(true); 153 state_on_unlock_->SetMouseEventsEnabled(true);
145 if (cursor_lock_count_ == 0 && 154 if (cursor_lock_count_ == 0 &&
146 IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) { 155 IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) {
147 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(), 156 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(),
148 this); 157 this);
149 } 158 }
(...skipping 19 matching lines...) Expand all
169 void CursorManager::LockCursor() { 178 void CursorManager::LockCursor() {
170 cursor_lock_count_++; 179 cursor_lock_count_++;
171 } 180 }
172 181
173 void CursorManager::UnlockCursor() { 182 void CursorManager::UnlockCursor() {
174 cursor_lock_count_--; 183 cursor_lock_count_--;
175 DCHECK_GE(cursor_lock_count_, 0); 184 DCHECK_GE(cursor_lock_count_, 0);
176 if (cursor_lock_count_ > 0) 185 if (cursor_lock_count_ > 0)
177 return; 186 return;
178 187
179 if (GetCurrentCursor() != state_on_unlock_->cursor()) { 188 if (GetCursor() != state_on_unlock_->cursor()) {
180 delegate_->SetCursor(state_on_unlock_->cursor(), this); 189 delegate_->SetCursor(state_on_unlock_->cursor(), this);
181 } 190 }
182 if (IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) { 191 if (IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) {
183 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(), 192 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(),
184 this); 193 this);
185 } 194 }
186 if (IsCursorVisible() != state_on_unlock_->visible()) { 195 if (IsCursorVisible() != state_on_unlock_->visible()) {
187 delegate_->SetVisibility(state_on_unlock_->visible(), 196 delegate_->SetVisibility(state_on_unlock_->visible(),
188 this); 197 this);
189 } 198 }
190 } 199 }
191 200
192 bool CursorManager::IsCursorLocked() const { 201 bool CursorManager::IsCursorLocked() const {
193 return cursor_lock_count_ > 0; 202 return cursor_lock_count_ > 0;
194 } 203 }
195 204
196 void CursorManager::AddObserver( 205 void CursorManager::AddObserver(
197 aura::client::CursorClientObserver* observer) { 206 aura::client::CursorClientObserver* observer) {
198 observers_.AddObserver(observer); 207 observers_->AddObserver(observer);
199 } 208 }
200 209
201 void CursorManager::RemoveObserver( 210 void CursorManager::RemoveObserver(
202 aura::client::CursorClientObserver* observer) { 211 aura::client::CursorClientObserver* observer) {
203 observers_.RemoveObserver(observer); 212 observers_->RemoveObserver(observer);
204 }
205
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 } 213 }
217 214
218 void CursorManager::CommitCursor(gfx::NativeCursor cursor) { 215 void CursorManager::CommitCursor(gfx::NativeCursor cursor) {
219 current_state_->set_cursor(cursor); 216 current_state_->set_cursor(cursor);
220 } 217 }
221 218
222 void CursorManager::CommitVisibility(bool visible) { 219 void CursorManager::CommitVisibility(bool visible) {
223 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, 220 // TODO(tdanderson): Find a better place for this so we don't end up
221 // notifying the observers more than necessary.
222 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, *observers_,
224 OnCursorVisibilityChanged(visible)); 223 OnCursorVisibilityChanged(visible));
225 current_state_->SetVisible(visible); 224 current_state_->SetVisible(visible);
226 } 225 }
227 226
228 void CursorManager::CommitScale(float scale) { 227 void CursorManager::CommitScale(float scale) {
229 current_state_->set_scale(scale); 228 current_state_->set_scale(scale);
230 } 229 }
231 230
232 void CursorManager::CommitCursorSet(ui::CursorSetType cursor_set) { 231 void CursorManager::CommitCursorSet(ui::CursorSetType cursor_set) {
233 current_state_->set_cursor_set(cursor_set); 232 current_state_->set_cursor_set(cursor_set);
234 } 233 }
235 234
236 void CursorManager::CommitMouseEventsEnabled(bool enabled) { 235 void CursorManager::CommitMouseEventsEnabled(bool enabled) {
237 current_state_->SetMouseEventsEnabled(enabled); 236 current_state_->SetMouseEventsEnabled(enabled);
238 } 237 }
239 238
239 void CursorManager::TestApi::ResetState() {
240 cursor_manager_->cursor_lock_count_ = 0;
241 cursor_manager_->current_state_ = new internal::CursorState;
242 cursor_manager_->state_on_unlock_ = new internal::CursorState;
243 cursor_manager_->observers_->Clear();
244 }
245
240 } // namespace corewm 246 } // namespace corewm
241 } // namespace views 247 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/corewm/cursor_manager.h ('k') | ui/views/corewm/cursor_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698