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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/wm/ash_native_cursor_manager.h"
6
7 #include "ash/shell.h"
8 #include "ash/wm/image_cursors.h"
9 #include "base/logging.h"
10 #include "ui/aura/env.h"
11 #include "ui/aura/root_window.h"
12 #include "ui/base/cursor/cursor.h"
13
14 namespace {
15
16 // The coordinate of the cursor used when the mouse events are disabled.
17 const int kDisabledCursorLocationX = -10000;
18 const int kDisabledCursorLocationY = -10000;
19
20 void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) {
21 ash::Shell::RootWindowList root_windows =
22 ash::Shell::GetInstance()->GetAllRootWindows();
23 for (ash::Shell::RootWindowList::iterator iter = root_windows.begin();
24 iter != root_windows.end(); ++iter)
25 (*iter)->SetCursor(cursor);
26 }
27
28 void NotifyCursorVisibilityChange(bool visible) {
29 ash::Shell::RootWindowList root_windows =
30 ash::Shell::GetInstance()->GetAllRootWindows();
31 for (ash::Shell::RootWindowList::iterator iter = root_windows.begin();
32 iter != root_windows.end(); ++iter)
33 (*iter)->OnCursorVisibilityChanged(visible);
34 }
35
36 void NotifyMouseEventsEnableStateChange(bool enabled) {
37 ash::Shell::RootWindowList root_windows =
38 ash::Shell::GetInstance()->GetAllRootWindows();
39 for (ash::Shell::RootWindowList::iterator iter = root_windows.begin();
40 iter != root_windows.end(); ++iter)
41 (*iter)->OnMouseEventsEnableStateChanged(enabled);
42 }
43
44 } // namespace
45
46 namespace ash {
47
48 AshNativeCursorManager::AshNativeCursorManager()
49 : image_cursors_(new ImageCursors) {
50 }
51
52 AshNativeCursorManager::~AshNativeCursorManager() {
53 }
54
55 void AshNativeCursorManager::SetDeviceScaleFactor(
56 float device_scale_factor,
57 views::corewm::NativeCursorManagerDelegate* delegate) {
58 if (image_cursors_->SetDeviceScaleFactor(device_scale_factor))
59 SetCursor(delegate->GetCurrentCursor(), delegate);
60 }
61
62 void AshNativeCursorManager::SetCursor(
63 gfx::NativeCursor cursor,
64 views::corewm::NativeCursorManagerDelegate* delegate) {
65 gfx::NativeCursor new_cursor = cursor;
66 image_cursors_->SetPlatformCursor(&new_cursor);
67 new_cursor.set_device_scale_factor(image_cursors_->GetDeviceScaleFactor());
68
69 delegate->CommitCursor(new_cursor);
70
71 if (delegate->GetCurrentVisibility())
72 SetCursorOnAllRootWindows(new_cursor);
73 }
74
75 void AshNativeCursorManager::SetVisibility(
76 bool visible,
77 views::corewm::NativeCursorManagerDelegate* delegate) {
78 delegate->CommitVisibility(visible);
79
80 if (visible) {
81 SetCursor(delegate->GetCurrentCursor(), delegate);
82 } else {
83 gfx::NativeCursor invisible_cursor(ui::kCursorNone);
84 image_cursors_->SetPlatformCursor(&invisible_cursor);
85 SetCursorOnAllRootWindows(invisible_cursor);
86 }
87
88 NotifyCursorVisibilityChange(visible);
89 }
90
91 void AshNativeCursorManager::SetMouseEventsEnabled(
92 bool enabled,
93 views::corewm::NativeCursorManagerDelegate* delegate) {
94 delegate->CommitMouseEventsEnabled(enabled);
95
96 if (enabled) {
97 aura::Env::GetInstance()->set_last_mouse_location(
98 disabled_cursor_location_);
99 } else {
100 disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location();
101 aura::Env::GetInstance()->set_last_mouse_location(
102 gfx::Point(kDisabledCursorLocationX, kDisabledCursorLocationY));
103 }
104
105 SetVisibility(delegate->GetCurrentVisibility(), delegate);
106 NotifyMouseEventsEnableStateChange(enabled);
107 }
108
109 } // namespace ash
OLDNEW
« 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