OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/ash_native_cursor_manager.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 "base/logging.h" |
11 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
12 #include "ui/aura/window_event_dispatcher.h" | 12 #include "ui/aura/window_event_dispatcher.h" |
13 #include "ui/aura/window_tree_host.h" | 13 #include "ui/aura/window_tree_host.h" |
14 #include "ui/base/cursor/cursor.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 | 17 |
18 namespace ash { | 18 namespace ash { |
19 namespace { | 19 namespace { |
20 | 20 |
21 void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) { | 21 void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) { |
22 aura::Window::Windows root_windows = | 22 aura::Window::Windows root_windows = |
23 Shell::GetInstance()->GetAllRootWindows(); | 23 Shell::GetInstance()->GetAllRootWindows(); |
24 for (aura::Window::Windows::iterator iter = root_windows.begin(); | 24 for (aura::Window::Windows::iterator iter = root_windows.begin(); |
25 iter != root_windows.end(); ++iter) | 25 iter != root_windows.end(); ++iter) |
26 (*iter)->GetHost()->SetCursor(cursor); | 26 (*iter)->GetHost()->SetCursor(cursor); |
27 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
28 Shell::GetInstance() | 28 Shell::GetInstance() |
29 ->window_tree_host_manager() | 29 ->window_tree_host_manager() |
(...skipping 21 matching lines...) Expand all Loading... |
51 Shell::GetInstance()->GetAllRootWindows(); | 51 Shell::GetInstance()->GetAllRootWindows(); |
52 for (aura::Window::Windows::iterator iter = root_windows.begin(); | 52 for (aura::Window::Windows::iterator iter = root_windows.begin(); |
53 iter != root_windows.end(); ++iter) | 53 iter != root_windows.end(); ++iter) |
54 (*iter)->GetHost()->dispatcher()->OnMouseEventsEnableStateChanged(enabled); | 54 (*iter)->GetHost()->dispatcher()->OnMouseEventsEnableStateChanged(enabled); |
55 // Mirror window never process events. | 55 // Mirror window never process events. |
56 } | 56 } |
57 | 57 |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 AshNativeCursorManager::AshNativeCursorManager() | 60 AshNativeCursorManager::AshNativeCursorManager() |
61 : native_cursor_enabled_(true), | 61 : native_cursor_enabled_(true), image_cursors_(new ui::ImageCursors) {} |
62 image_cursors_(new ui::ImageCursors) { | |
63 } | |
64 | 62 |
65 AshNativeCursorManager::~AshNativeCursorManager() { | 63 AshNativeCursorManager::~AshNativeCursorManager() {} |
66 } | |
67 | |
68 | 64 |
69 void AshNativeCursorManager::SetNativeCursorEnabled(bool enabled) { | 65 void AshNativeCursorManager::SetNativeCursorEnabled(bool enabled) { |
70 native_cursor_enabled_ = enabled; | 66 native_cursor_enabled_ = enabled; |
71 | 67 |
72 ::wm::CursorManager* cursor_manager = | 68 ::wm::CursorManager* cursor_manager = Shell::GetInstance()->cursor_manager(); |
73 Shell::GetInstance()->cursor_manager(); | |
74 SetCursor(cursor_manager->GetCursor(), cursor_manager); | 69 SetCursor(cursor_manager->GetCursor(), cursor_manager); |
75 } | 70 } |
76 | 71 |
77 void AshNativeCursorManager::SetDisplay( | 72 void AshNativeCursorManager::SetDisplay( |
78 const display::Display& display, | 73 const display::Display& display, |
79 ::wm::NativeCursorManagerDelegate* delegate) { | 74 ::wm::NativeCursorManagerDelegate* delegate) { |
80 DCHECK(display.is_valid()); | 75 DCHECK(display.is_valid()); |
81 // Use the platform's device scale factor instead of the display's, which | 76 // Use the platform's device scale factor instead of the display's, which |
82 // might have been adjusted for the UI scale. | 77 // might have been adjusted for the UI scale. |
83 const float original_scale = Shell::GetInstance()->display_manager()-> | 78 const float original_scale = Shell::GetInstance() |
84 GetDisplayInfo(display.id()).device_scale_factor(); | 79 ->display_manager() |
| 80 ->GetDisplayInfo(display.id()) |
| 81 .device_scale_factor(); |
85 #if defined(OS_CHROMEOS) | 82 #if defined(OS_CHROMEOS) |
86 // And use the nearest resource scale factor. | 83 // And use the nearest resource scale factor. |
87 const float cursor_scale = ui::GetScaleForScaleFactor( | 84 const float cursor_scale = |
88 ui::GetSupportedScaleFactor(original_scale)); | 85 ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(original_scale)); |
89 #else | 86 #else |
90 // TODO(oshima): crbug.com/143619 | 87 // TODO(oshima): crbug.com/143619 |
91 const float cursor_scale = original_scale; | 88 const float cursor_scale = original_scale; |
92 #endif | 89 #endif |
93 if (image_cursors_->SetDisplay(display, cursor_scale)) | 90 if (image_cursors_->SetDisplay(display, cursor_scale)) |
94 SetCursor(delegate->GetCursor(), delegate); | 91 SetCursor(delegate->GetCursor(), delegate); |
95 #if defined(OS_CHROMEOS) | 92 #if defined(OS_CHROMEOS) |
96 Shell::GetInstance() | 93 Shell::GetInstance() |
97 ->window_tree_host_manager() | 94 ->window_tree_host_manager() |
98 ->cursor_window_controller() | 95 ->cursor_window_controller() |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 disabled_cursor_location_); | 165 disabled_cursor_location_); |
169 } else { | 166 } else { |
170 disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location(); | 167 disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location(); |
171 } | 168 } |
172 | 169 |
173 SetVisibility(delegate->IsCursorVisible(), delegate); | 170 SetVisibility(delegate->IsCursorVisible(), delegate); |
174 NotifyMouseEventsEnableStateChange(enabled); | 171 NotifyMouseEventsEnableStateChange(enabled); |
175 } | 172 } |
176 | 173 |
177 } // namespace ash | 174 } // namespace ash |
OLD | NEW |