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

Side by Side Diff: ash/wm/native_cursor_manager_ash_mus.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
« no previous file with comments | « ash/wm/native_cursor_manager_ash_mus.h ('k') | ash/wm/native_cursor_manager_ash_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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/ash_native_cursor_manager.h" 5 #include "ash/wm/native_cursor_manager_ash_mus.h"
6 6
7 #include "ash/display/cursor_window_controller.h" 7 #include "ash/display/cursor_window_controller.h"
8 #include "ash/display/window_tree_host_manager.h" 8 #include "ash/display/window_tree_host_manager.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "base/logging.h" 10 #include "ash/shell_port.h"
11 #include "ui/aura/env.h" 11 #include "ui/aura/env.h"
12 #include "ui/aura/mus/window_port_mus.h"
12 #include "ui/aura/window_event_dispatcher.h" 13 #include "ui/aura/window_event_dispatcher.h"
13 #include "ui/aura/window_tree_host.h" 14 #include "ui/aura/window_tree_host.h"
14 #include "ui/base/cursor/cursor.h"
15 #include "ui/base/cursor/image_cursors.h" 15 #include "ui/base/cursor/image_cursors.h"
16 #include "ui/base/layout.h" 16 #include "ui/base/layout.h"
17 #include "ui/wm/core/cursor_manager.h"
18
19 #if defined(USE_OZONE)
20 #include "ui/base/cursor/ozone/cursor_data_factory_ozone.h"
21 #endif
17 22
18 namespace ash { 23 namespace ash {
19 namespace { 24 namespace {
20 25
26 // We want to forward these things to the window tree client.
27
21 void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) { 28 void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) {
22 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); 29 ui::CursorData mojo_cursor;
23 for (aura::Window::Windows::iterator iter = root_windows.begin(); 30 if (cursor.platform()) {
24 iter != root_windows.end(); ++iter) 31 #if defined(USE_OZONE)
25 (*iter)->GetHost()->SetCursor(cursor); 32 mojo_cursor = ui::CursorDataFactoryOzone::GetCursorData(cursor.platform());
33 #else
34 NOTIMPLEMENTED()
35 << "Can't pass native platform cursors on non-ozone platforms";
36 mojo_cursor = ui::CursorData(ui::CursorType::kPointer);
37 #endif
38 } else {
39 mojo_cursor = ui::CursorData(cursor.native_type());
40 }
41
42 // As the window manager, tell mus to use |mojo_cursor| everywhere. We do
43 // this instead of trying to set per-window because otherwise we run into the
44 // event targeting issue.
45 ShellPort::Get()->SetGlobalOverrideCursor(mojo_cursor);
26 46
27 Shell::Get() 47 Shell::Get()
28 ->window_tree_host_manager() 48 ->window_tree_host_manager()
29 ->cursor_window_controller() 49 ->cursor_window_controller()
30 ->SetCursor(cursor); 50 ->SetCursor(cursor);
31 } 51 }
32 52
33 void NotifyCursorVisibilityChange(bool visible) { 53 void NotifyCursorVisibilityChange(bool visible) {
54 // Communicate the cursor visibility state to the mus server.
55 if (visible)
56 ShellPort::Get()->ShowCursor();
57 else
58 ShellPort::Get()->HideCursor();
59
60 // Communicate the cursor visibility change to our local root window objects.
34 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); 61 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
35 for (aura::Window::Windows::iterator iter = root_windows.begin(); 62 for (aura::Window::Windows::iterator iter = root_windows.begin();
36 iter != root_windows.end(); ++iter) 63 iter != root_windows.end(); ++iter)
37 (*iter)->GetHost()->OnCursorVisibilityChanged(visible); 64 (*iter)->GetHost()->OnCursorVisibilityChanged(visible);
38 65
39 Shell::Get() 66 Shell::Get()
40 ->window_tree_host_manager() 67 ->window_tree_host_manager()
41 ->cursor_window_controller() 68 ->cursor_window_controller()
42 ->SetVisibility(visible); 69 ->SetVisibility(visible);
43 } 70 }
44 71
45 void NotifyMouseEventsEnableStateChange(bool enabled) { 72 void NotifyMouseEventsEnableStateChange(bool enabled) {
46 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); 73 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows();
47 for (aura::Window::Windows::iterator iter = root_windows.begin(); 74 for (aura::Window::Windows::iterator iter = root_windows.begin();
48 iter != root_windows.end(); ++iter) 75 iter != root_windows.end(); ++iter)
49 (*iter)->GetHost()->dispatcher()->OnMouseEventsEnableStateChanged(enabled); 76 (*iter)->GetHost()->dispatcher()->OnMouseEventsEnableStateChanged(enabled);
50 // Mirror window never process events. 77 // Mirror window never process events.
51 } 78 }
52 79
53 } // namespace 80 } // namespace
54 81
55 AshNativeCursorManager::AshNativeCursorManager() 82 NativeCursorManagerAshMus::NativeCursorManagerAshMus() {
56 : native_cursor_enabled_(true), image_cursors_(new ui::ImageCursors) {} 83 #if defined(USE_OZONE)
84 // If we're in a mus client, we aren't going to have all of ozone initialized
85 // even though we're in an ozone build. All the hard coded USE_OZONE ifdefs
86 // that handle cursor code expect that there will be a CursorFactoryOzone
87 // instance. Partially initialize the ozone cursor internals here, like we
88 // partially initialize other ozone subsystems in
89 // ChromeBrowserMainExtraPartsViews.
90 cursor_factory_ozone_ = base::MakeUnique<ui::CursorDataFactoryOzone>();
91 image_cursors_ = base::MakeUnique<ui::ImageCursors>();
92 #endif
93 }
57 94
58 AshNativeCursorManager::~AshNativeCursorManager() {} 95 NativeCursorManagerAshMus::~NativeCursorManagerAshMus() = default;
59 96
60 void AshNativeCursorManager::SetNativeCursorEnabled(bool enabled) { 97 void NativeCursorManagerAshMus::SetNativeCursorEnabled(bool enabled) {
61 native_cursor_enabled_ = enabled; 98 native_cursor_enabled_ = enabled;
62 99
63 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager(); 100 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager();
64 SetCursor(cursor_manager->GetCursor(), cursor_manager); 101 SetCursor(cursor_manager->GetCursor(), cursor_manager);
65 } 102 }
66 103
67 void AshNativeCursorManager::SetDisplay( 104 float NativeCursorManagerAshMus::GetScale() const {
105 return image_cursors_->GetScale();
106 }
107
108 display::Display::Rotation NativeCursorManagerAshMus::GetRotation() const {
109 return image_cursors_->GetRotation();
110 }
111
112 void NativeCursorManagerAshMus::SetDisplay(
68 const display::Display& display, 113 const display::Display& display,
69 ::wm::NativeCursorManagerDelegate* delegate) { 114 ::wm::NativeCursorManagerDelegate* delegate) {
70 DCHECK(display.is_valid()); 115 DCHECK(display.is_valid());
71 // Use the platform's device scale factor instead of the display's, which 116 // Use the platform's device scale factor instead of the display's, which
72 // might have been adjusted for the UI scale. 117 // might have been adjusted for the UI scale.
73 const float original_scale = Shell::Get() 118 const float original_scale = Shell::Get()
74 ->display_manager() 119 ->display_manager()
75 ->GetDisplayInfo(display.id()) 120 ->GetDisplayInfo(display.id())
76 .device_scale_factor(); 121 .device_scale_factor();
77 // And use the nearest resource scale factor. 122 // And use the nearest resource scale factor.
78 const float cursor_scale = 123 const float cursor_scale =
79 ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(original_scale)); 124 ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(original_scale));
80 125
81 if (image_cursors_->SetDisplay(display, cursor_scale)) 126 if (image_cursors_->SetDisplay(display, cursor_scale))
82 SetCursor(delegate->GetCursor(), delegate); 127 SetCursor(delegate->GetCursor(), delegate);
83 128
84 Shell::Get() 129 Shell::Get()
85 ->window_tree_host_manager() 130 ->window_tree_host_manager()
86 ->cursor_window_controller() 131 ->cursor_window_controller()
87 ->SetDisplay(display); 132 ->SetDisplay(display);
88 } 133 }
89 134
90 void AshNativeCursorManager::SetCursor( 135 void NativeCursorManagerAshMus::SetCursor(
91 gfx::NativeCursor cursor, 136 gfx::NativeCursor cursor,
92 ::wm::NativeCursorManagerDelegate* delegate) { 137 ::wm::NativeCursorManagerDelegate* delegate) {
93 if (native_cursor_enabled_) { 138 if (image_cursors_) {
94 image_cursors_->SetPlatformCursor(&cursor); 139 if (native_cursor_enabled_) {
95 } else { 140 image_cursors_->SetPlatformCursor(&cursor);
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 { 141 } else {
103 cursor.SetPlatformCursor(invisible_cursor.platform()); 142 gfx::NativeCursor invisible_cursor(ui::CursorType::kNone);
143 image_cursors_->SetPlatformCursor(&invisible_cursor);
144 if (cursor == ui::CursorType::kCustom) {
145 // Fall back to the default pointer cursor for now. (crbug.com/476078)
146 // TODO(oshima): support custom cursor.
147 cursor = ui::CursorType::kPointer;
148 } else {
149 cursor.SetPlatformCursor(invisible_cursor.platform());
150 }
104 } 151 }
105 } 152 }
106 cursor.set_device_scale_factor(image_cursors_->GetScale()); 153 cursor.set_device_scale_factor(image_cursors_->GetScale());
107 154
108 delegate->CommitCursor(cursor); 155 delegate->CommitCursor(cursor);
109 156
110 if (delegate->IsCursorVisible()) 157 if (delegate->IsCursorVisible())
111 SetCursorOnAllRootWindows(cursor); 158 SetCursorOnAllRootWindows(cursor);
112 } 159 }
113 160
114 void AshNativeCursorManager::SetCursorSet( 161 void NativeCursorManagerAshMus::SetVisibility(
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, 162 bool visible,
132 ::wm::NativeCursorManagerDelegate* delegate) { 163 ::wm::NativeCursorManagerDelegate* delegate) {
133 delegate->CommitVisibility(visible); 164 delegate->CommitVisibility(visible);
134 165
135 if (visible) { 166 if (visible) {
136 SetCursor(delegate->GetCursor(), delegate); 167 SetCursor(delegate->GetCursor(), delegate);
137 } else { 168 } else {
138 gfx::NativeCursor invisible_cursor(ui::CursorType::kNone); 169 gfx::NativeCursor invisible_cursor(ui::CursorType::kNone);
139 image_cursors_->SetPlatformCursor(&invisible_cursor); 170 image_cursors_->SetPlatformCursor(&invisible_cursor);
140 SetCursorOnAllRootWindows(invisible_cursor); 171 SetCursorOnAllRootWindows(invisible_cursor);
141 } 172 }
142 173
143 NotifyCursorVisibilityChange(visible); 174 NotifyCursorVisibilityChange(visible);
144 } 175 }
145 176
146 void AshNativeCursorManager::SetMouseEventsEnabled( 177 void NativeCursorManagerAshMus::SetCursorSet(
178 ui::CursorSetType cursor_set,
179 ::wm::NativeCursorManagerDelegate* delegate) {
180 // We can't just hand this off to ImageCursors like we do in the classic ash
181 // case. We need to collaborate with the mus server to fully implement this.
182 NOTIMPLEMENTED();
183 }
184
185 void NativeCursorManagerAshMus::SetMouseEventsEnabled(
147 bool enabled, 186 bool enabled,
148 ::wm::NativeCursorManagerDelegate* delegate) { 187 ::wm::NativeCursorManagerDelegate* delegate) {
149 delegate->CommitMouseEventsEnabled(enabled); 188 delegate->CommitMouseEventsEnabled(enabled);
150 189
151 if (enabled) { 190 if (enabled) {
152 aura::Env::GetInstance()->set_last_mouse_location( 191 aura::Env::GetInstance()->set_last_mouse_location(
153 disabled_cursor_location_); 192 disabled_cursor_location_);
154 } else { 193 } else {
155 disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location(); 194 disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location();
156 } 195 }
157 196
158 SetVisibility(delegate->IsCursorVisible(), delegate); 197 SetVisibility(delegate->IsCursorVisible(), delegate);
198
159 NotifyMouseEventsEnableStateChange(enabled); 199 NotifyMouseEventsEnableStateChange(enabled);
160 } 200 }
161 201
162 } // namespace ash 202 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/native_cursor_manager_ash_mus.h ('k') | ash/wm/native_cursor_manager_ash_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698