Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Unified Diff: ui/views/corewm/cursor_controller.cc

Issue 12263050: Rework ash::CursorManager into a corewm object, to share code with desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/corewm/cursor_controller.cc
diff --git a/ui/views/corewm/cursor_controller.cc b/ui/views/corewm/cursor_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4cc857f04fa8267e6ad6e0c92b8fb2b7feefe148
--- /dev/null
+++ b/ui/views/corewm/cursor_controller.cc
@@ -0,0 +1,156 @@
+// Copyright (c) 2013 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 "ui/views/corewm/cursor_controller.h"
+
+#include "base/logging.h"
+
+namespace views {
+namespace corewm {
+
+namespace internal {
+
+// Represents the cursor state which is composed of cursor type, visibility, and
+// mouse events enable state. When mouse events are disabled, the cursor is
+// always invisible.
+class CursorState {
+ public:
+ CursorState()
+ : cursor_(ui::kCursorNone),
+ visible_(true),
+ mouse_events_enabled_(true),
+ visible_on_mouse_events_enabled_(true) {
+ }
+
+ gfx::NativeCursor cursor() const { return cursor_; }
+ void set_cursor(gfx::NativeCursor cursor) { cursor_ = cursor; }
+
+ bool visible() const { return visible_; }
+ void SetVisible(bool visible) {
+ if (mouse_events_enabled_)
+ visible_ = visible;
+ // Ignores the call when mouse events disabled.
+ }
+
+ bool mouse_events_enabled() const { return mouse_events_enabled_; }
+ void SetMouseEventsEnabled(bool enabled) {
+ if (mouse_events_enabled_ == enabled)
+ return;
+ mouse_events_enabled_ = enabled;
+
+ // Restores the visibility when mouse events are enabled.
+ if (enabled) {
+ visible_ = visible_on_mouse_events_enabled_;
+ } else {
+ visible_on_mouse_events_enabled_ = visible_;
+ visible_ = false;
+ }
+ }
+
+ private:
+ gfx::NativeCursor cursor_;
+ bool visible_;
+ bool mouse_events_enabled_;
+
+ // The visibility to set when mouse events are enabled.
+ bool visible_on_mouse_events_enabled_;
+
+ DISALLOW_COPY_AND_ASSIGN(CursorState);
+};
+
+} // namespace internal
+
+CursorController::CursorController()
+ : cursor_lock_count_(0),
+ current_state_(new internal::CursorState),
+ state_on_unlock_(new internal::CursorState) {
+}
+
+CursorController::~CursorController() {
+}
+
+void CursorController::SetCursor(gfx::NativeCursor cursor) {
+ state_on_unlock_->set_cursor(cursor);
+ if (cursor_lock_count_ == 0 &&
+ GetCurrentCursor() != state_on_unlock_->cursor()) {
+ SetCursorInternal(state_on_unlock_->cursor());
+ }
+}
+
+void CursorController::ShowCursor() {
+ state_on_unlock_->SetVisible(true);
+ if (cursor_lock_count_ == 0 &&
+ IsCursorVisible() != state_on_unlock_->visible()) {
+ SetCursorVisibility(state_on_unlock_->visible());
+ }
+}
+
+void CursorController::HideCursor() {
+ state_on_unlock_->SetVisible(false);
+ if (cursor_lock_count_ == 0 &&
+ IsCursorVisible() != state_on_unlock_->visible()) {
+ SetCursorVisibility(state_on_unlock_->visible());
+ }
+}
+
+bool CursorController::IsCursorVisible() const {
+ return current_state_->visible();
+}
+
+void CursorController::EnableMouseEvents() {
+ state_on_unlock_->SetMouseEventsEnabled(true);
+ if (cursor_lock_count_ == 0 &&
+ IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) {
+ SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled());
+ }
+}
+
+void CursorController::DisableMouseEvents() {
+ state_on_unlock_->SetMouseEventsEnabled(false);
+ if (cursor_lock_count_ == 0 &&
+ IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled()) {
+ SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled());
+ }
+}
+
+bool CursorController::IsMouseEventsEnabled() const {
+ return current_state_->mouse_events_enabled();
+}
+
+void CursorController::LockCursor() {
+ cursor_lock_count_++;
+}
+
+void CursorController::UnlockCursor() {
+ cursor_lock_count_--;
+ DCHECK_GE(cursor_lock_count_, 0);
+ if (cursor_lock_count_ > 0)
+ return;
+
+ if (GetCurrentCursor() != state_on_unlock_->cursor())
+ SetCursorInternal(state_on_unlock_->cursor());
+ if (IsMouseEventsEnabled() != state_on_unlock_->mouse_events_enabled())
+ SetMouseEventsEnabled(state_on_unlock_->mouse_events_enabled());
+ if (IsCursorVisible() != state_on_unlock_->visible())
+ SetCursorVisibility(state_on_unlock_->visible());
+}
+
+gfx::NativeCursor CursorController::GetCurrentCursor() const {
+ return current_state_->cursor();
+}
+
+void CursorController::SetCursorInternal(gfx::NativeCursor cursor) {
+ current_state_->set_cursor(cursor);
+}
+
+void CursorController::SetCursorVisibility(bool visible) {
+ current_state_->SetVisible(visible);
+}
+
+void CursorController::SetMouseEventsEnabled(bool enabled) {
+ current_state_->SetMouseEventsEnabled(enabled);
+}
+
+} // namespace corewm
+} // namespace views

Powered by Google App Engine
This is Rietveld 408576698