| 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/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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 current_state_(new internal::CursorState), | 84 current_state_(new internal::CursorState), |
| 85 state_on_unlock_(new internal::CursorState) { | 85 state_on_unlock_(new internal::CursorState) { |
| 86 } | 86 } |
| 87 | 87 |
| 88 CursorManager::~CursorManager() { | 88 CursorManager::~CursorManager() { |
| 89 } | 89 } |
| 90 | 90 |
| 91 void CursorManager::SetCursor(gfx::NativeCursor cursor) { | 91 void CursorManager::SetCursor(gfx::NativeCursor cursor) { |
| 92 state_on_unlock_->set_cursor(cursor); | 92 state_on_unlock_->set_cursor(cursor); |
| 93 if (cursor_lock_count_ == 0 && | 93 if (cursor_lock_count_ == 0 && |
| 94 GetCurrentCursor() != state_on_unlock_->cursor()) { | 94 GetCursor() != state_on_unlock_->cursor()) { |
| 95 delegate_->SetCursor(state_on_unlock_->cursor(), this); | 95 delegate_->SetCursor(state_on_unlock_->cursor(), this); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 gfx::NativeCursor CursorManager::GetCursor() const { |
| 100 return current_state_->cursor(); |
| 101 } |
| 102 |
| 99 void CursorManager::ShowCursor() { | 103 void CursorManager::ShowCursor() { |
| 100 state_on_unlock_->SetVisible(true); | 104 state_on_unlock_->SetVisible(true); |
| 101 if (cursor_lock_count_ == 0 && | 105 if (cursor_lock_count_ == 0 && |
| 102 IsCursorVisible() != state_on_unlock_->visible()) { | 106 IsCursorVisible() != state_on_unlock_->visible()) { |
| 103 delegate_->SetVisibility(state_on_unlock_->visible(), this); | 107 delegate_->SetVisibility(state_on_unlock_->visible(), this); |
| 104 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, | 108 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, |
| 105 OnCursorVisibilityChanged(true)); | 109 OnCursorVisibilityChanged(true)); |
| 106 } | 110 } |
| 107 } | 111 } |
| 108 | 112 |
| 109 void CursorManager::HideCursor() { | 113 void CursorManager::HideCursor() { |
| 110 state_on_unlock_->SetVisible(false); | 114 state_on_unlock_->SetVisible(false); |
| 111 if (cursor_lock_count_ == 0 && | 115 if (cursor_lock_count_ == 0 && |
| 112 IsCursorVisible() != state_on_unlock_->visible()) { | 116 IsCursorVisible() != state_on_unlock_->visible()) { |
| 113 delegate_->SetVisibility(state_on_unlock_->visible(), this); | 117 delegate_->SetVisibility(state_on_unlock_->visible(), this); |
| 114 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, | 118 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, |
| 115 OnCursorVisibilityChanged(false)); | 119 OnCursorVisibilityChanged(false)); |
| 116 } | 120 } |
| 117 } | 121 } |
| 118 | 122 |
| 119 bool CursorManager::IsCursorVisible() const { | 123 bool CursorManager::IsCursorVisible() const { |
| 120 return current_state_->visible(); | 124 return current_state_->visible(); |
| 121 } | 125 } |
| 122 | 126 |
| 123 void CursorManager::SetScale(float scale) { | 127 void CursorManager::SetScale(float scale) { |
| 124 state_on_unlock_->set_scale(scale); | 128 state_on_unlock_->set_scale(scale); |
| 125 if (GetCurrentScale() != state_on_unlock_->scale()) | 129 if (GetScale() != state_on_unlock_->scale()) |
| 126 delegate_->SetScale(state_on_unlock_->scale(), this); | 130 delegate_->SetScale(state_on_unlock_->scale(), this); |
| 127 } | 131 } |
| 128 | 132 |
| 133 float CursorManager::GetScale() const { |
| 134 return current_state_->scale(); |
| 135 } |
| 136 |
| 129 void CursorManager::SetCursorSet(ui::CursorSetType cursor_set) { | 137 void CursorManager::SetCursorSet(ui::CursorSetType cursor_set) { |
| 130 state_on_unlock_->set_cursor_set(cursor_set); | 138 state_on_unlock_->set_cursor_set(cursor_set); |
| 131 if (GetCurrentCursorSet() != state_on_unlock_->cursor_set()) | 139 if (GetCursorSet() != state_on_unlock_->cursor_set()) |
| 132 delegate_->SetCursorSet(state_on_unlock_->cursor_set(), this); | 140 delegate_->SetCursorSet(state_on_unlock_->cursor_set(), this); |
| 133 } | 141 } |
| 134 | 142 |
| 135 float CursorManager::GetCurrentScale() const { | 143 ui::CursorSetType CursorManager::GetCursorSet() const { |
| 136 return current_state_->scale(); | |
| 137 } | |
| 138 | |
| 139 ui::CursorSetType CursorManager::GetCurrentCursorSet() const { | |
| 140 return current_state_->cursor_set(); | 144 return current_state_->cursor_set(); |
| 141 } | 145 } |
| 142 | 146 |
| 143 void CursorManager::EnableMouseEvents() { | 147 void CursorManager::EnableMouseEvents() { |
| 144 state_on_unlock_->SetMouseEventsEnabled(true); | 148 state_on_unlock_->SetMouseEventsEnabled(true); |
| 145 if (cursor_lock_count_ == 0 && | 149 if (cursor_lock_count_ == 0 && |
| 146 IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) { | 150 IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) { |
| 147 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(), | 151 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(), |
| 148 this); | 152 this); |
| 149 } | 153 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 169 void CursorManager::LockCursor() { | 173 void CursorManager::LockCursor() { |
| 170 cursor_lock_count_++; | 174 cursor_lock_count_++; |
| 171 } | 175 } |
| 172 | 176 |
| 173 void CursorManager::UnlockCursor() { | 177 void CursorManager::UnlockCursor() { |
| 174 cursor_lock_count_--; | 178 cursor_lock_count_--; |
| 175 DCHECK_GE(cursor_lock_count_, 0); | 179 DCHECK_GE(cursor_lock_count_, 0); |
| 176 if (cursor_lock_count_ > 0) | 180 if (cursor_lock_count_ > 0) |
| 177 return; | 181 return; |
| 178 | 182 |
| 179 if (GetCurrentCursor() != state_on_unlock_->cursor()) { | 183 if (GetCursor() != state_on_unlock_->cursor()) { |
| 180 delegate_->SetCursor(state_on_unlock_->cursor(), this); | 184 delegate_->SetCursor(state_on_unlock_->cursor(), this); |
| 181 } | 185 } |
| 182 if (IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) { | 186 if (IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) { |
| 183 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(), | 187 delegate_->SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled(), |
| 184 this); | 188 this); |
| 185 } | 189 } |
| 186 if (IsCursorVisible() != state_on_unlock_->visible()) { | 190 if (IsCursorVisible() != state_on_unlock_->visible()) { |
| 187 delegate_->SetVisibility(state_on_unlock_->visible(), | 191 delegate_->SetVisibility(state_on_unlock_->visible(), |
| 188 this); | 192 this); |
| 189 } | 193 } |
| 190 } | 194 } |
| 191 | 195 |
| 192 bool CursorManager::IsCursorLocked() const { | 196 bool CursorManager::IsCursorLocked() const { |
| 193 return cursor_lock_count_ > 0; | 197 return cursor_lock_count_ > 0; |
| 194 } | 198 } |
| 195 | 199 |
| 196 void CursorManager::AddObserver( | 200 void CursorManager::AddObserver( |
| 197 aura::client::CursorClientObserver* observer) { | 201 aura::client::CursorClientObserver* observer) { |
| 198 observers_.AddObserver(observer); | 202 observers_.AddObserver(observer); |
| 199 } | 203 } |
| 200 | 204 |
| 201 void CursorManager::RemoveObserver( | 205 void CursorManager::RemoveObserver( |
| 202 aura::client::CursorClientObserver* observer) { | 206 aura::client::CursorClientObserver* observer) { |
| 203 observers_.RemoveObserver(observer); | 207 observers_.RemoveObserver(observer); |
| 204 } | 208 } |
| 205 | 209 |
| 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) { | 210 void CursorManager::CommitCursor(gfx::NativeCursor cursor) { |
| 219 current_state_->set_cursor(cursor); | 211 current_state_->set_cursor(cursor); |
| 220 } | 212 } |
| 221 | 213 |
| 222 void CursorManager::CommitVisibility(bool visible) { | 214 void CursorManager::CommitVisibility(bool visible) { |
| 215 // TODO(tdanderson): Find a better place for this so we don't |
| 216 // notify the observers more than is necessary. |
| 223 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, | 217 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, |
| 224 OnCursorVisibilityChanged(visible)); | 218 OnCursorVisibilityChanged(visible)); |
| 225 current_state_->SetVisible(visible); | 219 current_state_->SetVisible(visible); |
| 226 } | 220 } |
| 227 | 221 |
| 228 void CursorManager::CommitScale(float scale) { | 222 void CursorManager::CommitScale(float scale) { |
| 229 current_state_->set_scale(scale); | 223 current_state_->set_scale(scale); |
| 230 } | 224 } |
| 231 | 225 |
| 232 void CursorManager::CommitCursorSet(ui::CursorSetType cursor_set) { | 226 void CursorManager::CommitCursorSet(ui::CursorSetType cursor_set) { |
| 233 current_state_->set_cursor_set(cursor_set); | 227 current_state_->set_cursor_set(cursor_set); |
| 234 } | 228 } |
| 235 | 229 |
| 236 void CursorManager::CommitMouseEventsEnabled(bool enabled) { | 230 void CursorManager::CommitMouseEventsEnabled(bool enabled) { |
| 237 current_state_->SetMouseEventsEnabled(enabled); | 231 current_state_->SetMouseEventsEnabled(enabled); |
| 238 } | 232 } |
| 239 | 233 |
| 240 } // namespace corewm | 234 } // namespace corewm |
| 241 } // namespace views | 235 } // namespace views |
| OLD | NEW |