blob: 1ebc72bfc7196f67fa71b3bda4523b0aafae1960 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/cursor_manager.h"
#include "ash/wm/cursor_delegate.h"
#include "base/logging.h"
#include "ui/aura/env.h"
namespace ash {
CursorManager::CursorManager()
: delegate_(NULL),
cursor_lock_count_(0),
did_cursor_change_(false),
cursor_to_set_on_unlock_(0),
cursor_visible_(true) {
}
CursorManager::~CursorManager() {
}
void CursorManager::LockCursor() {
cursor_lock_count_++;
}
void CursorManager::UnlockCursor() {
cursor_lock_count_--;
DCHECK_GE(cursor_lock_count_, 0);
if (cursor_lock_count_ == 0) {
if (did_cursor_change_) {
did_cursor_change_ = false;
if (delegate_)
delegate_->SetCursor(cursor_to_set_on_unlock_);
}
did_cursor_change_ = false;
cursor_to_set_on_unlock_ = gfx::kNullCursor;
}
}
void CursorManager::SetCursor(gfx::NativeCursor cursor) {
if (cursor_lock_count_ == 0) {
if (delegate_)
delegate_->SetCursor(cursor);
} else {
cursor_to_set_on_unlock_ = cursor;
did_cursor_change_ = true;
}
}
void CursorManager::ShowCursor(bool show) {
cursor_visible_ = show;
if (delegate_)
delegate_->ShowCursor(show);
}
bool CursorManager::IsCursorVisible() const {
return cursor_visible_;
}
} // namespace ash