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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/corewm/cursor_manager.cc
diff --git a/ui/views/corewm/cursor_manager.cc b/ui/views/corewm/cursor_manager.cc
index 97a19ba93c3c9560876de35e4ee529b58c98654f..f7b971edfc434b6e5408085e8dc6324534b4adde 100644
--- a/ui/views/corewm/cursor_manager.cc
+++ b/ui/views/corewm/cursor_manager.cc
@@ -28,6 +28,15 @@ class CursorState {
visible_on_mouse_events_enabled_(true) {
}
+ 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.
+ cursor_ = ui::kCursorNone;
+ visible_ = true;
+ scale_ = 1.f;
+ cursor_set_ = ui::CURSOR_SET_NORMAL;
+ mouse_events_enabled_ = true;
+ visible_on_mouse_events_enabled_ = true;
+ }
+
gfx::NativeCursor cursor() const { return cursor_; }
void set_cursor(gfx::NativeCursor cursor) { cursor_ = cursor; }
@@ -78,24 +87,39 @@ class CursorState {
} // namespace internal
+int CursorManager::cursor_lock_count_ = 0;
+scoped_ptr<internal::CursorState> CursorManager::current_state_(
+ new internal::CursorState);
+scoped_ptr<internal::CursorState> CursorManager::state_on_unlock_(
+ new internal::CursorState);
+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.
+
CursorManager::CursorManager(scoped_ptr<NativeCursorManager> delegate)
- : delegate_(delegate.Pass()),
- cursor_lock_count_(0),
- current_state_(new internal::CursorState),
- state_on_unlock_(new internal::CursorState) {
+ : delegate_(delegate.Pass()) {
}
CursorManager::~CursorManager() {
}
+void CursorManager::ResetState() {
+ CursorManager::cursor_lock_count_ = 0;
+ CursorManager::current_state_->ResetState();
+ CursorManager::state_on_unlock_->ResetState();
+ CursorManager::observers_.Clear();
+}
+
void CursorManager::SetCursor(gfx::NativeCursor cursor) {
state_on_unlock_->set_cursor(cursor);
if (cursor_lock_count_ == 0 &&
- GetCurrentCursor() != state_on_unlock_->cursor()) {
+ GetCursor() != state_on_unlock_->cursor()) {
delegate_->SetCursor(state_on_unlock_->cursor(), this);
}
}
+gfx::NativeCursor CursorManager::GetCursor() const {
+ return current_state_->cursor();
+}
+
void CursorManager::ShowCursor() {
state_on_unlock_->SetVisible(true);
if (cursor_lock_count_ == 0 &&
@@ -122,21 +146,21 @@ bool CursorManager::IsCursorVisible() const {
void CursorManager::SetScale(float scale) {
state_on_unlock_->set_scale(scale);
- if (GetCurrentScale() != state_on_unlock_->scale())
+ if (GetScale() != state_on_unlock_->scale())
delegate_->SetScale(state_on_unlock_->scale(), this);
}
+float CursorManager::GetScale() const {
+ return current_state_->scale();
+}
+
void CursorManager::SetCursorSet(ui::CursorSetType cursor_set) {
state_on_unlock_->set_cursor_set(cursor_set);
- if (GetCurrentCursorSet() != state_on_unlock_->cursor_set())
+ if (GetCursorSet() != state_on_unlock_->cursor_set())
delegate_->SetCursorSet(state_on_unlock_->cursor_set(), this);
}
-float CursorManager::GetCurrentScale() const {
- return current_state_->scale();
-}
-
-ui::CursorSetType CursorManager::GetCurrentCursorSet() const {
+ui::CursorSetType CursorManager::GetCursorSet() const {
return current_state_->cursor_set();
}
@@ -176,7 +200,7 @@ void CursorManager::UnlockCursor() {
if (cursor_lock_count_ > 0)
return;
- if (GetCurrentCursor() != state_on_unlock_->cursor()) {
+ if (GetCursor() != state_on_unlock_->cursor()) {
delegate_->SetCursor(state_on_unlock_->cursor(), this);
}
if (IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) {
@@ -203,23 +227,13 @@ void CursorManager::RemoveObserver(
observers_.RemoveObserver(observer);
}
-gfx::NativeCursor CursorManager::GetCurrentCursor() const {
- return current_state_->cursor();
-}
-
-bool CursorManager::GetCurrentVisibility() const {
- return current_state_->visible();
-}
-
-bool CursorManager::GetMouseEventsEnabled() const {
- return current_state_->mouse_events_enabled();
-}
-
void CursorManager::CommitCursor(gfx::NativeCursor cursor) {
current_state_->set_cursor(cursor);
}
void CursorManager::CommitVisibility(bool visible) {
+ // TODO(tdanderson): Find a better place for this so we don't end up
+ // notifying the observers more than necessary.
FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
OnCursorVisibilityChanged(visible));
current_state_->SetVisible(visible);

Powered by Google App Engine
This is Rietveld 408576698