| OLD | NEW |
| 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" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 bool mouse_events_enabled_; | 66 bool mouse_events_enabled_; |
| 67 | 67 |
| 68 // The visibility to set when mouse events are enabled. | 68 // The visibility to set when mouse events are enabled. |
| 69 bool visible_on_mouse_events_enabled_; | 69 bool visible_on_mouse_events_enabled_; |
| 70 | 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(CursorState); | 71 DISALLOW_COPY_AND_ASSIGN(CursorState); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 } // namespace internal | 74 } // namespace internal |
| 75 | 75 |
| 76 bool CursorManager::last_cursor_visibility_state_ = true; |
| 77 |
| 76 CursorManager::CursorManager(scoped_ptr<NativeCursorManager> delegate) | 78 CursorManager::CursorManager(scoped_ptr<NativeCursorManager> delegate) |
| 77 : delegate_(std::move(delegate)), | 79 : delegate_(std::move(delegate)), |
| 78 cursor_lock_count_(0), | 80 cursor_lock_count_(0), |
| 79 current_state_(new internal::CursorState), | 81 current_state_(new internal::CursorState), |
| 80 state_on_unlock_(new internal::CursorState) {} | 82 state_on_unlock_(new internal::CursorState) { |
| 83 // Restore the last cursor visibility state. |
| 84 current_state_->SetVisible(last_cursor_visibility_state_); |
| 85 } |
| 81 | 86 |
| 82 CursorManager::~CursorManager() { | 87 CursorManager::~CursorManager() { |
| 83 } | 88 } |
| 84 | 89 |
| 85 void CursorManager::SetCursor(gfx::NativeCursor cursor) { | 90 void CursorManager::SetCursor(gfx::NativeCursor cursor) { |
| 86 state_on_unlock_->set_cursor(cursor); | 91 state_on_unlock_->set_cursor(cursor); |
| 87 if (cursor_lock_count_ == 0 && | 92 if (cursor_lock_count_ == 0 && |
| 88 GetCursor() != state_on_unlock_->cursor()) { | 93 GetCursor() != state_on_unlock_->cursor()) { |
| 89 delegate_->SetCursor(state_on_unlock_->cursor(), this); | 94 delegate_->SetCursor(state_on_unlock_->cursor(), this); |
| 90 } | 95 } |
| 91 } | 96 } |
| 92 | 97 |
| 93 gfx::NativeCursor CursorManager::GetCursor() const { | 98 gfx::NativeCursor CursorManager::GetCursor() const { |
| 94 return current_state_->cursor(); | 99 return current_state_->cursor(); |
| 95 } | 100 } |
| 96 | 101 |
| 97 void CursorManager::ShowCursor() { | 102 void CursorManager::ShowCursor() { |
| 103 last_cursor_visibility_state_ = true; |
| 98 state_on_unlock_->SetVisible(true); | 104 state_on_unlock_->SetVisible(true); |
| 99 if (cursor_lock_count_ == 0 && | 105 if (cursor_lock_count_ == 0 && |
| 100 IsCursorVisible() != state_on_unlock_->visible()) { | 106 IsCursorVisible() != state_on_unlock_->visible()) { |
| 101 delegate_->SetVisibility(state_on_unlock_->visible(), this); | 107 delegate_->SetVisibility(state_on_unlock_->visible(), this); |
| 102 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, | 108 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, |
| 103 OnCursorVisibilityChanged(true)); | 109 OnCursorVisibilityChanged(true)); |
| 104 } | 110 } |
| 105 } | 111 } |
| 106 | 112 |
| 107 void CursorManager::HideCursor() { | 113 void CursorManager::HideCursor() { |
| 114 last_cursor_visibility_state_ = false; |
| 108 state_on_unlock_->SetVisible(false); | 115 state_on_unlock_->SetVisible(false); |
| 109 if (cursor_lock_count_ == 0 && | 116 if (cursor_lock_count_ == 0 && |
| 110 IsCursorVisible() != state_on_unlock_->visible()) { | 117 IsCursorVisible() != state_on_unlock_->visible()) { |
| 111 delegate_->SetVisibility(state_on_unlock_->visible(), this); | 118 delegate_->SetVisibility(state_on_unlock_->visible(), this); |
| 112 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, | 119 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, |
| 113 OnCursorVisibilityChanged(false)); | 120 OnCursorVisibilityChanged(false)); |
| 114 } | 121 } |
| 115 } | 122 } |
| 116 | 123 |
| 117 bool CursorManager::IsCursorVisible() const { | 124 bool CursorManager::IsCursorVisible() const { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 217 |
| 211 void CursorManager::CommitCursorSet(ui::CursorSetType cursor_set) { | 218 void CursorManager::CommitCursorSet(ui::CursorSetType cursor_set) { |
| 212 current_state_->set_cursor_set(cursor_set); | 219 current_state_->set_cursor_set(cursor_set); |
| 213 } | 220 } |
| 214 | 221 |
| 215 void CursorManager::CommitMouseEventsEnabled(bool enabled) { | 222 void CursorManager::CommitMouseEventsEnabled(bool enabled) { |
| 216 current_state_->SetMouseEventsEnabled(enabled); | 223 current_state_->SetMouseEventsEnabled(enabled); |
| 217 } | 224 } |
| 218 | 225 |
| 219 } // namespace wm | 226 } // namespace wm |
| OLD | NEW |