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/display_controller.h" | 8 #include "ash/display/display_controller.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/image_cursors.h" | |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
13 #include "ui/aura/window_event_dispatcher.h" | 12 #include "ui/aura/window_event_dispatcher.h" |
14 #include "ui/aura/window_tree_host.h" | 13 #include "ui/aura/window_tree_host.h" |
15 #include "ui/base/cursor/cursor.h" | 14 #include "ui/base/cursor/cursor.h" |
| 15 #include "ui/base/cursor/image_cursors.h" |
16 | 16 |
17 namespace ash { | 17 namespace ash { |
18 namespace { | 18 namespace { |
19 | 19 |
20 void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) { | 20 void SetCursorOnAllRootWindows(gfx::NativeCursor cursor) { |
21 aura::Window::Windows root_windows = | 21 aura::Window::Windows root_windows = |
22 Shell::GetInstance()->GetAllRootWindows(); | 22 Shell::GetInstance()->GetAllRootWindows(); |
23 for (aura::Window::Windows::iterator iter = root_windows.begin(); | 23 for (aura::Window::Windows::iterator iter = root_windows.begin(); |
24 iter != root_windows.end(); ++iter) | 24 iter != root_windows.end(); ++iter) |
25 (*iter)->GetHost()->SetCursor(cursor); | 25 (*iter)->GetHost()->SetCursor(cursor); |
(...skipping 21 matching lines...) Expand all Loading... |
47 for (aura::Window::Windows::iterator iter = root_windows.begin(); | 47 for (aura::Window::Windows::iterator iter = root_windows.begin(); |
48 iter != root_windows.end(); ++iter) | 48 iter != root_windows.end(); ++iter) |
49 (*iter)->GetHost()->dispatcher()->OnMouseEventsEnableStateChanged(enabled); | 49 (*iter)->GetHost()->dispatcher()->OnMouseEventsEnableStateChanged(enabled); |
50 // Mirror window never process events. | 50 // Mirror window never process events. |
51 } | 51 } |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 AshNativeCursorManager::AshNativeCursorManager() | 55 AshNativeCursorManager::AshNativeCursorManager() |
56 : native_cursor_enabled_(true), | 56 : native_cursor_enabled_(true), |
57 image_cursors_(new ImageCursors) { | 57 image_cursors_(new ui::ImageCursors) { |
58 } | 58 } |
59 | 59 |
60 AshNativeCursorManager::~AshNativeCursorManager() { | 60 AshNativeCursorManager::~AshNativeCursorManager() { |
61 } | 61 } |
62 | 62 |
63 | 63 |
64 void AshNativeCursorManager::SetNativeCursorEnabled(bool enabled) { | 64 void AshNativeCursorManager::SetNativeCursorEnabled(bool enabled) { |
65 native_cursor_enabled_ = enabled; | 65 native_cursor_enabled_ = enabled; |
66 | 66 |
67 ::wm::CursorManager* cursor_manager = | 67 ::wm::CursorManager* cursor_manager = |
68 Shell::GetInstance()->cursor_manager(); | 68 Shell::GetInstance()->cursor_manager(); |
69 SetCursor(cursor_manager->GetCursor(), cursor_manager); | 69 SetCursor(cursor_manager->GetCursor(), cursor_manager); |
70 } | 70 } |
71 | 71 |
72 void AshNativeCursorManager::SetDisplay( | 72 void AshNativeCursorManager::SetDisplay( |
73 const gfx::Display& display, | 73 const gfx::Display& display, |
74 ::wm::NativeCursorManagerDelegate* delegate) { | 74 ::wm::NativeCursorManagerDelegate* delegate) { |
75 if (image_cursors_->SetDisplay(display)) | 75 DCHECK(display.is_valid()); |
| 76 // Use the platform's device scale factor instead of the display's, which |
| 77 // might have been adjusted for the UI scale. |
| 78 const float scale_factor = Shell::GetInstance()->display_manager()-> |
| 79 GetDisplayInfo(display.id()).device_scale_factor(); |
| 80 if (image_cursors_->SetDisplay(display, scale_factor)) |
76 SetCursor(delegate->GetCursor(), delegate); | 81 SetCursor(delegate->GetCursor(), delegate); |
77 #if defined(OS_CHROMEOS) | 82 #if defined(OS_CHROMEOS) |
78 Shell::GetInstance()->display_controller()->cursor_window_controller()-> | 83 Shell::GetInstance()->display_controller()->cursor_window_controller()-> |
79 SetDisplay(display); | 84 SetDisplay(display); |
80 #endif | 85 #endif |
81 } | 86 } |
82 | 87 |
83 void AshNativeCursorManager::SetCursor( | 88 void AshNativeCursorManager::SetCursor( |
84 gfx::NativeCursor cursor, | 89 gfx::NativeCursor cursor, |
85 ::wm::NativeCursorManagerDelegate* delegate) { | 90 ::wm::NativeCursorManagerDelegate* delegate) { |
86 gfx::NativeCursor new_cursor = cursor; | |
87 if (native_cursor_enabled_) { | 91 if (native_cursor_enabled_) { |
88 image_cursors_->SetPlatformCursor(&new_cursor); | 92 image_cursors_->SetPlatformCursor(&cursor); |
89 } else { | 93 } else { |
90 gfx::NativeCursor invisible_cursor(ui::kCursorNone); | 94 gfx::NativeCursor invisible_cursor(ui::kCursorNone); |
91 image_cursors_->SetPlatformCursor(&invisible_cursor); | 95 image_cursors_->SetPlatformCursor(&invisible_cursor); |
92 if (new_cursor == ui::kCursorCustom) { | 96 if (cursor == ui::kCursorCustom) { |
93 new_cursor = invisible_cursor; | 97 cursor = invisible_cursor; |
94 } else { | 98 } else { |
95 new_cursor.SetPlatformCursor(invisible_cursor.platform()); | 99 cursor.SetPlatformCursor(invisible_cursor.platform()); |
96 } | 100 } |
97 } | 101 } |
98 new_cursor.set_device_scale_factor(image_cursors_->GetScale()); | 102 cursor.set_device_scale_factor(image_cursors_->GetScale()); |
99 | 103 |
100 delegate->CommitCursor(new_cursor); | 104 delegate->CommitCursor(cursor); |
101 | 105 |
102 if (delegate->IsCursorVisible()) | 106 if (delegate->IsCursorVisible()) |
103 SetCursorOnAllRootWindows(new_cursor); | 107 SetCursorOnAllRootWindows(cursor); |
104 } | 108 } |
105 | 109 |
106 void AshNativeCursorManager::SetCursorSet( | 110 void AshNativeCursorManager::SetCursorSet( |
107 ui::CursorSetType cursor_set, | 111 ui::CursorSetType cursor_set, |
108 ::wm::NativeCursorManagerDelegate* delegate) { | 112 ::wm::NativeCursorManagerDelegate* delegate) { |
109 image_cursors_->SetCursorSet(cursor_set); | 113 image_cursors_->SetCursorSet(cursor_set); |
110 delegate->CommitCursorSet(cursor_set); | 114 delegate->CommitCursorSet(cursor_set); |
111 | 115 |
112 // Sets the cursor to reflect the scale change immediately. | 116 // Sets the cursor to reflect the scale change immediately. |
113 if (delegate->IsCursorVisible()) | 117 if (delegate->IsCursorVisible()) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 disabled_cursor_location_); | 149 disabled_cursor_location_); |
146 } else { | 150 } else { |
147 disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location(); | 151 disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location(); |
148 } | 152 } |
149 | 153 |
150 SetVisibility(delegate->IsCursorVisible(), delegate); | 154 SetVisibility(delegate->IsCursorVisible(), delegate); |
151 NotifyMouseEventsEnableStateChange(enabled); | 155 NotifyMouseEventsEnableStateChange(enabled); |
152 } | 156 } |
153 | 157 |
154 } // namespace ash | 158 } // namespace ash |
OLD | NEW |