| 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 "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/wm/core/native_cursor_manager.h" | 9 #include "ui/wm/core/native_cursor_manager.h" |
| 10 #include "ui/wm/core/native_cursor_manager_delegate.h" | 10 #include "ui/wm/core/native_cursor_manager_delegate.h" |
| 11 | 11 |
| 12 namespace wm { | 12 namespace wm { |
| 13 | 13 |
| 14 namespace internal { | 14 namespace internal { |
| 15 | 15 |
| 16 // Represents the cursor state which is composed of cursor type, visibility, and | 16 // Represents the cursor state which is composed of cursor type, visibility, and |
| 17 // mouse events enable state. When mouse events are disabled, the cursor is | 17 // mouse events enable state. When mouse events are disabled, the cursor is |
| 18 // always invisible. | 18 // always invisible. |
| 19 class CursorState { | 19 class CursorState { |
| 20 public: | 20 public: |
| 21 CursorState() | 21 CursorState() |
| 22 : cursor_(ui::kCursorNone), | 22 : cursor_(ui::kCursorNone), |
| 23 visible_(true), | 23 visible_(true), |
| 24 scale_(1.f), |
| 24 cursor_set_(ui::CURSOR_SET_NORMAL), | 25 cursor_set_(ui::CURSOR_SET_NORMAL), |
| 25 mouse_events_enabled_(true), | 26 mouse_events_enabled_(true), |
| 26 visible_on_mouse_events_enabled_(true) { | 27 visible_on_mouse_events_enabled_(true) { |
| 27 } | 28 } |
| 28 | 29 |
| 29 gfx::NativeCursor cursor() const { return cursor_; } | 30 gfx::NativeCursor cursor() const { return cursor_; } |
| 30 void set_cursor(gfx::NativeCursor cursor) { cursor_ = cursor; } | 31 void set_cursor(gfx::NativeCursor cursor) { cursor_ = cursor; } |
| 31 | 32 |
| 32 bool visible() const { return visible_; } | 33 bool visible() const { return visible_; } |
| 33 void SetVisible(bool visible) { | 34 void SetVisible(bool visible) { |
| 34 if (mouse_events_enabled_) | 35 if (mouse_events_enabled_) |
| 35 visible_ = visible; | 36 visible_ = visible; |
| 36 // Ignores the call when mouse events disabled. | 37 // Ignores the call when mouse events disabled. |
| 37 } | 38 } |
| 38 | 39 |
| 40 float scale() const { return scale_; } |
| 41 void set_scale(float scale) { |
| 42 scale_ = scale; |
| 43 } |
| 44 |
| 39 ui::CursorSetType cursor_set() const { return cursor_set_; } | 45 ui::CursorSetType cursor_set() const { return cursor_set_; } |
| 40 void set_cursor_set(ui::CursorSetType cursor_set) { | 46 void set_cursor_set(ui::CursorSetType cursor_set) { |
| 41 cursor_set_ = cursor_set; | 47 cursor_set_ = cursor_set; |
| 42 } | 48 } |
| 43 | 49 |
| 44 bool mouse_events_enabled() const { return mouse_events_enabled_; } | 50 bool mouse_events_enabled() const { return mouse_events_enabled_; } |
| 45 void SetMouseEventsEnabled(bool enabled) { | 51 void SetMouseEventsEnabled(bool enabled) { |
| 46 if (mouse_events_enabled_ == enabled) | 52 if (mouse_events_enabled_ == enabled) |
| 47 return; | 53 return; |
| 48 mouse_events_enabled_ = enabled; | 54 mouse_events_enabled_ = enabled; |
| 49 | 55 |
| 50 // Restores the visibility when mouse events are enabled. | 56 // Restores the visibility when mouse events are enabled. |
| 51 if (enabled) { | 57 if (enabled) { |
| 52 visible_ = visible_on_mouse_events_enabled_; | 58 visible_ = visible_on_mouse_events_enabled_; |
| 53 } else { | 59 } else { |
| 54 visible_on_mouse_events_enabled_ = visible_; | 60 visible_on_mouse_events_enabled_ = visible_; |
| 55 visible_ = false; | 61 visible_ = false; |
| 56 } | 62 } |
| 57 } | 63 } |
| 58 | 64 |
| 59 private: | 65 private: |
| 60 gfx::NativeCursor cursor_; | 66 gfx::NativeCursor cursor_; |
| 61 bool visible_; | 67 bool visible_; |
| 68 float scale_; |
| 62 ui::CursorSetType cursor_set_; | 69 ui::CursorSetType cursor_set_; |
| 63 bool mouse_events_enabled_; | 70 bool mouse_events_enabled_; |
| 64 | 71 |
| 65 // The visibility to set when mouse events are enabled. | 72 // The visibility to set when mouse events are enabled. |
| 66 bool visible_on_mouse_events_enabled_; | 73 bool visible_on_mouse_events_enabled_; |
| 67 | 74 |
| 68 DISALLOW_COPY_AND_ASSIGN(CursorState); | 75 DISALLOW_COPY_AND_ASSIGN(CursorState); |
| 69 }; | 76 }; |
| 70 | 77 |
| 71 } // namespace internal | 78 } // namespace internal |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 delegate_->SetVisibility(state_on_unlock_->visible(), this); | 116 delegate_->SetVisibility(state_on_unlock_->visible(), this); |
| 110 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, | 117 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, |
| 111 OnCursorVisibilityChanged(false)); | 118 OnCursorVisibilityChanged(false)); |
| 112 } | 119 } |
| 113 } | 120 } |
| 114 | 121 |
| 115 bool CursorManager::IsCursorVisible() const { | 122 bool CursorManager::IsCursorVisible() const { |
| 116 return current_state_->visible(); | 123 return current_state_->visible(); |
| 117 } | 124 } |
| 118 | 125 |
| 126 void CursorManager::SetScale(float scale) { |
| 127 state_on_unlock_->set_scale(scale); |
| 128 if (GetScale() != state_on_unlock_->scale()) |
| 129 delegate_->SetScale(state_on_unlock_->scale(), this); |
| 130 } |
| 131 |
| 132 float CursorManager::GetScale() const { |
| 133 return current_state_->scale(); |
| 134 } |
| 135 |
| 119 void CursorManager::SetCursorSet(ui::CursorSetType cursor_set) { | 136 void CursorManager::SetCursorSet(ui::CursorSetType cursor_set) { |
| 120 state_on_unlock_->set_cursor_set(cursor_set); | 137 state_on_unlock_->set_cursor_set(cursor_set); |
| 121 if (GetCursorSet() != state_on_unlock_->cursor_set()) | 138 if (GetCursorSet() != state_on_unlock_->cursor_set()) |
| 122 delegate_->SetCursorSet(state_on_unlock_->cursor_set(), this); | 139 delegate_->SetCursorSet(state_on_unlock_->cursor_set(), this); |
| 123 } | 140 } |
| 124 | 141 |
| 125 ui::CursorSetType CursorManager::GetCursorSet() const { | 142 ui::CursorSetType CursorManager::GetCursorSet() const { |
| 126 return current_state_->cursor_set(); | 143 return current_state_->cursor_set(); |
| 127 } | 144 } |
| 128 | 145 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 216 } |
| 200 | 217 |
| 201 void CursorManager::CommitVisibility(bool visible) { | 218 void CursorManager::CommitVisibility(bool visible) { |
| 202 // TODO(tdanderson): Find a better place for this so we don't | 219 // TODO(tdanderson): Find a better place for this so we don't |
| 203 // notify the observers more than is necessary. | 220 // notify the observers more than is necessary. |
| 204 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, | 221 FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_, |
| 205 OnCursorVisibilityChanged(visible)); | 222 OnCursorVisibilityChanged(visible)); |
| 206 current_state_->SetVisible(visible); | 223 current_state_->SetVisible(visible); |
| 207 } | 224 } |
| 208 | 225 |
| 226 void CursorManager::CommitScale(float scale) { |
| 227 current_state_->set_scale(scale); |
| 228 } |
| 229 |
| 209 void CursorManager::CommitCursorSet(ui::CursorSetType cursor_set) { | 230 void CursorManager::CommitCursorSet(ui::CursorSetType cursor_set) { |
| 210 current_state_->set_cursor_set(cursor_set); | 231 current_state_->set_cursor_set(cursor_set); |
| 211 } | 232 } |
| 212 | 233 |
| 213 void CursorManager::CommitMouseEventsEnabled(bool enabled) { | 234 void CursorManager::CommitMouseEventsEnabled(bool enabled) { |
| 214 current_state_->SetMouseEventsEnabled(enabled); | 235 current_state_->SetMouseEventsEnabled(enabled); |
| 215 } | 236 } |
| 216 | 237 |
| 217 } // namespace wm | 238 } // namespace wm |
| OLD | NEW |