| 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..a573740d52695696b8346787ab15d87558c01b7d 100644
|
| --- a/ui/views/corewm/cursor_manager.cc
|
| +++ b/ui/views/corewm/cursor_manager.cc
|
| @@ -78,11 +78,16 @@ class CursorState {
|
|
|
| } // namespace internal
|
|
|
| +int CursorManager::cursor_lock_count_ = 0;
|
| +internal::CursorState* CursorManager::current_state_ =
|
| + new internal::CursorState;
|
| +internal::CursorState* CursorManager::state_on_unlock_ =
|
| + new internal::CursorState;
|
| +CursorManager::CursorObservers* CursorManager::observers_ =
|
| + new ObserverList<aura::client::CursorClientObserver>;
|
| +
|
| 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() {
|
| @@ -91,17 +96,21 @@ CursorManager::~CursorManager() {
|
| 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 &&
|
| IsCursorVisible() != state_on_unlock_->visible()) {
|
| delegate_->SetVisibility(state_on_unlock_->visible(), this);
|
| - FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
|
| + FOR_EACH_OBSERVER(aura::client::CursorClientObserver, *observers_,
|
| OnCursorVisibilityChanged(true));
|
| }
|
| }
|
| @@ -111,7 +120,7 @@ void CursorManager::HideCursor() {
|
| if (cursor_lock_count_ == 0 &&
|
| IsCursorVisible() != state_on_unlock_->visible()) {
|
| delegate_->SetVisibility(state_on_unlock_->visible(), this);
|
| - FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
|
| + FOR_EACH_OBSERVER(aura::client::CursorClientObserver, *observers_,
|
| OnCursorVisibilityChanged(false));
|
| }
|
| }
|
| @@ -122,21 +131,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 +185,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()) {
|
| @@ -195,24 +204,12 @@ bool CursorManager::IsCursorLocked() const {
|
|
|
| void CursorManager::AddObserver(
|
| aura::client::CursorClientObserver* observer) {
|
| - observers_.AddObserver(observer);
|
| + observers_->AddObserver(observer);
|
| }
|
|
|
| void CursorManager::RemoveObserver(
|
| aura::client::CursorClientObserver* observer) {
|
| - 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();
|
| + observers_->RemoveObserver(observer);
|
| }
|
|
|
| void CursorManager::CommitCursor(gfx::NativeCursor cursor) {
|
| @@ -220,7 +217,9 @@ void CursorManager::CommitCursor(gfx::NativeCursor cursor) {
|
| }
|
|
|
| void CursorManager::CommitVisibility(bool visible) {
|
| - FOR_EACH_OBSERVER(aura::client::CursorClientObserver, observers_,
|
| + // 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);
|
| }
|
| @@ -237,5 +236,12 @@ void CursorManager::CommitMouseEventsEnabled(bool enabled) {
|
| current_state_->SetMouseEventsEnabled(enabled);
|
| }
|
|
|
| +void CursorManager::TestApi::ResetState() {
|
| + cursor_manager_->cursor_lock_count_ = 0;
|
| + cursor_manager_->current_state_ = new internal::CursorState;
|
| + cursor_manager_->state_on_unlock_ = new internal::CursorState;
|
| + cursor_manager_->observers_->Clear();
|
| +}
|
| +
|
| } // namespace corewm
|
| } // namespace views
|
|
|