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

Side by Side Diff: ash/wm/ash_native_cursor_manager.cc

Issue 2932563002: Implement cursor changing on Mushrome (Closed)
Patch Set: oshima patch take 2 Created 3 years, 6 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
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/display/cursor_window_controller.h"
8 #include "ash/display/window_tree_host_manager.h"
9 #include "ash/shell.h"
10 #include "base/logging.h"
11 #include "ui/aura/env.h"
12 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/aura/window_tree_host.h"
14 #include "ui/base/cursor/cursor.h"
15 #include "ui/base/cursor/image_cursors.h"
16 #include "ui/base/layout.h"
17
18 namespace ash {
19 namespace {
20
21 void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) {
22 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
23 for (aura::Window::Windows::iterator iter = root_windows.begin();
24 iter != root_windows.end(); ++iter)
25 (*iter)->GetHost()->SetCursor(cursor);
26
27 Shell::Get()
28 ->window_tree_host_manager()
29 ->cursor_window_controller()
30 ->SetCursor(cursor);
31 }
32
33 void NotifyCursorVisibilityChange(bool visible) {
34 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
35 for (aura::Window::Windows::iterator iter = root_windows.begin();
36 iter != root_windows.end(); ++iter)
37 (*iter)->GetHost()->OnCursorVisibilityChanged(visible);
38
39 Shell::Get()
40 ->window_tree_host_manager()
41 ->cursor_window_controller()
42 ->SetVisibility(visible);
43 }
44
45 void NotifyMouseEventsEnableStateChange(bool enabled) {
46 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
47 for (aura::Window::Windows::iterator iter = root_windows.begin();
48 iter != root_windows.end(); ++iter)
49 (*iter)->GetHost()->dispatcher()->OnMouseEventsEnableStateChanged(enabled);
50 // Mirror window never process events.
51 }
52
53 } // namespace
54
55 AshNativeCursorManager::AshNativeCursorManager()
56 : native_cursor_enabled_(true), image_cursors_(new ui::ImageCursors) {}
57
58 AshNativeCursorManager::~AshNativeCursorManager() {}
59
60 void AshNativeCursorManager::SetNativeCursorEnabled(bool enabled) {
61 native_cursor_enabled_ = enabled;
62
63 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
64 SetCursor(cursor_manager->GetCursor(), cursor_manager);
65 }
66
67 void AshNativeCursorManager::SetDisplay(
68 const display::Display& display,
69 ::wm::NativeCursorManagerDelegate* delegate) {
70 DCHECK(display.is_valid());
71 // Use the platform's device scale factor instead of the display's, which
72 // might have been adjusted for the UI scale.
73 const float original_scale = Shell::Get()
74 ->display_manager()
75 ->GetDisplayInfo(display.id())
76 .device_scale_factor();
77 // And use the nearest resource scale factor.
78 const float cursor_scale =
79 ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(original_scale));
80
81 if (image_cursors_->SetDisplay(display, cursor_scale))
82 SetCursor(delegate->GetCursor(), delegate);
83
84 Shell::Get()
85 ->window_tree_host_manager()
86 ->cursor_window_controller()
87 ->SetDisplay(display);
88 }
89
90 void AshNativeCursorManager::SetCursor(
91 gfx::NativeCursor cursor,
92 ::wm::NativeCursorManagerDelegate* delegate) {
93 if (native_cursor_enabled_) {
94 image_cursors_->SetPlatformCursor(&cursor);
95 } else {
96 gfx::NativeCursor invisible_cursor(ui::CursorType::kNone);
97 image_cursors_->SetPlatformCursor(&invisible_cursor);
98 if (cursor == ui::CursorType::kCustom) {
99 // Fall back to the default pointer cursor for now. (crbug.com/476078)
100 // TODO(oshima): support custom cursor.
101 cursor = ui::CursorType::kPointer;
102 } else {
103 cursor.SetPlatformCursor(invisible_cursor.platform());
104 }
105 }
106 cursor.set_device_scale_factor(image_cursors_->GetScale());
107
108 delegate->CommitCursor(cursor);
109
110 if (delegate->IsCursorVisible())
111 SetCursorOnAllRootWindows(cursor);
112 }
113
114 void AshNativeCursorManager::SetCursorSet(
115 ui::CursorSetType cursor_set,
116 ::wm::NativeCursorManagerDelegate* delegate) {
117 image_cursors_->SetCursorSet(cursor_set);
118 delegate->CommitCursorSet(cursor_set);
119
120 // Sets the cursor to reflect the scale change immediately.
121 if (delegate->IsCursorVisible())
122 SetCursor(delegate->GetCursor(), delegate);
123
124 Shell::Get()
125 ->window_tree_host_manager()
126 ->cursor_window_controller()
127 ->SetCursorSet(cursor_set);
128 }
129
130 void AshNativeCursorManager::SetVisibility(
131 bool visible,
132 ::wm::NativeCursorManagerDelegate* delegate) {
133 delegate->CommitVisibility(visible);
134
135 if (visible) {
136 SetCursor(delegate->GetCursor(), delegate);
137 } else {
138 gfx::NativeCursor invisible_cursor(ui::CursorType::kNone);
139 image_cursors_->SetPlatformCursor(&invisible_cursor);
140 SetCursorOnAllRootWindows(invisible_cursor);
141 }
142
143 NotifyCursorVisibilityChange(visible);
144 }
145
146 void AshNativeCursorManager::SetMouseEventsEnabled(
147 bool enabled,
148 ::wm::NativeCursorManagerDelegate* delegate) {
149 delegate->CommitMouseEventsEnabled(enabled);
150
151 if (enabled) {
152 aura::Env::GetInstance()->set_last_mouse_location(
153 disabled_cursor_location_);
154 } else {
155 disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location();
156 }
157
158 SetVisibility(delegate->IsCursorVisible(), delegate);
159 NotifyMouseEventsEnableStateChange(enabled);
160 }
161
162 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/ash_native_cursor_manager.h ('k') | ash/wm/ash_native_cursor_manager_interactive_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698