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

Unified Diff: ash/wm/ash_native_cursor_manager.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: Rebase to ToT 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
« no previous file with comments | « ash/wm/ash_native_cursor_manager.h ('k') | ash/wm/ash_native_cursor_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/wm/ash_native_cursor_manager.cc
diff --git a/ash/wm/ash_native_cursor_manager.cc b/ash/wm/ash_native_cursor_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..94a08bf85b0bb3de9be5173dd40f165aee86eed5
--- /dev/null
+++ b/ash/wm/ash_native_cursor_manager.cc
@@ -0,0 +1,109 @@
+// 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/ash_native_cursor_manager.h"
+
+#include "ash/shell.h"
+#include "ash/wm/image_cursors.h"
+#include "base/logging.h"
+#include "ui/aura/env.h"
+#include "ui/aura/root_window.h"
+#include "ui/base/cursor/cursor.h"
+
+namespace {
+
+// The coordinate of the cursor used when the mouse events are disabled.
+const int kDisabledCursorLocationX = -10000;
+const int kDisabledCursorLocationY = -10000;
+
+void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) {
+ ash::Shell::RootWindowList root_windows =
+ ash::Shell::GetInstance()->GetAllRootWindows();
+ for (ash::Shell::RootWindowList::iterator iter = root_windows.begin();
+ iter != root_windows.end(); ++iter)
+ (*iter)->SetCursor(cursor);
+}
+
+void NotifyCursorVisibilityChange(bool visible) {
+ ash::Shell::RootWindowList root_windows =
+ ash::Shell::GetInstance()->GetAllRootWindows();
+ for (ash::Shell::RootWindowList::iterator iter = root_windows.begin();
+ iter != root_windows.end(); ++iter)
+ (*iter)->OnCursorVisibilityChanged(visible);
+}
+
+void NotifyMouseEventsEnableStateChange(bool enabled) {
+ ash::Shell::RootWindowList root_windows =
+ ash::Shell::GetInstance()->GetAllRootWindows();
+ for (ash::Shell::RootWindowList::iterator iter = root_windows.begin();
+ iter != root_windows.end(); ++iter)
+ (*iter)->OnMouseEventsEnableStateChanged(enabled);
+}
+
+} // namespace
+
+namespace ash {
+
+AshNativeCursorManager::AshNativeCursorManager()
+ : image_cursors_(new ImageCursors) {
+}
+
+AshNativeCursorManager::~AshNativeCursorManager() {
+}
+
+void AshNativeCursorManager::SetDeviceScaleFactor(
+ float device_scale_factor,
+ views::corewm::NativeCursorManagerDelegate* delegate) {
+ if (image_cursors_->SetDeviceScaleFactor(device_scale_factor))
+ SetCursor(delegate->GetCurrentCursor(), delegate);
+}
+
+void AshNativeCursorManager::SetCursor(
+ gfx::NativeCursor cursor,
+ views::corewm::NativeCursorManagerDelegate* delegate) {
+ gfx::NativeCursor new_cursor = cursor;
+ image_cursors_->SetPlatformCursor(&new_cursor);
+ new_cursor.set_device_scale_factor(image_cursors_->GetDeviceScaleFactor());
+
+ delegate->CommitCursor(new_cursor);
+
+ if (delegate->GetCurrentVisibility())
+ SetCursorOnAllRootWindows(new_cursor);
+}
+
+void AshNativeCursorManager::SetVisibility(
+ bool visible,
+ views::corewm::NativeCursorManagerDelegate* delegate) {
+ delegate->CommitVisibility(visible);
+
+ if (visible) {
+ SetCursor(delegate->GetCurrentCursor(), delegate);
+ } else {
+ gfx::NativeCursor invisible_cursor(ui::kCursorNone);
+ image_cursors_->SetPlatformCursor(&invisible_cursor);
+ SetCursorOnAllRootWindows(invisible_cursor);
+ }
+
+ NotifyCursorVisibilityChange(visible);
+}
+
+void AshNativeCursorManager::SetMouseEventsEnabled(
+ bool enabled,
+ views::corewm::NativeCursorManagerDelegate* delegate) {
+ delegate->CommitMouseEventsEnabled(enabled);
+
+ if (enabled) {
+ aura::Env::GetInstance()->set_last_mouse_location(
+ disabled_cursor_location_);
+ } else {
+ disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location();
+ aura::Env::GetInstance()->set_last_mouse_location(
+ gfx::Point(kDisabledCursorLocationX, kDisabledCursorLocationY));
+ }
+
+ SetVisibility(delegate->GetCurrentVisibility(), delegate);
+ NotifyMouseEventsEnableStateChange(enabled);
+}
+
+} // namespace ash
« no previous file with comments | « ash/wm/ash_native_cursor_manager.h ('k') | ash/wm/ash_native_cursor_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698