| OLD | NEW |
| 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_classic.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" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 45 void NotifyMouseEventsEnableStateChange(bool enabled) { | 45 void NotifyMouseEventsEnableStateChange(bool enabled) { |
| 46 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); | 46 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); |
| 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 NativeCursorManagerAshClassic::NativeCursorManagerAshClassic() |
| 56 : native_cursor_enabled_(true), image_cursors_(new ui::ImageCursors) {} | 56 : native_cursor_enabled_(true), image_cursors_(new ui::ImageCursors) {} |
| 57 | 57 |
| 58 AshNativeCursorManager::~AshNativeCursorManager() {} | 58 NativeCursorManagerAshClassic::~NativeCursorManagerAshClassic() {} |
| 59 | 59 |
| 60 void AshNativeCursorManager::SetNativeCursorEnabled(bool enabled) { | 60 void NativeCursorManagerAshClassic::SetNativeCursorEnabled(bool enabled) { |
| 61 native_cursor_enabled_ = enabled; | 61 native_cursor_enabled_ = enabled; |
| 62 | 62 |
| 63 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager(); | 63 ::wm::CursorManager* cursor_manager = Shell::Get()->cursor_manager(); |
| 64 SetCursor(cursor_manager->GetCursor(), cursor_manager); | 64 SetCursor(cursor_manager->GetCursor(), cursor_manager); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void AshNativeCursorManager::SetDisplay( | 67 float NativeCursorManagerAshClassic::GetScale() const { |
| 68 return image_cursors_->GetScale(); |
| 69 } |
| 70 |
| 71 display::Display::Rotation NativeCursorManagerAshClassic::GetRotation() const { |
| 72 return image_cursors_->GetRotation(); |
| 73 } |
| 74 |
| 75 void NativeCursorManagerAshClassic::SetDisplay( |
| 68 const display::Display& display, | 76 const display::Display& display, |
| 69 ::wm::NativeCursorManagerDelegate* delegate) { | 77 ::wm::NativeCursorManagerDelegate* delegate) { |
| 70 DCHECK(display.is_valid()); | 78 DCHECK(display.is_valid()); |
| 71 // Use the platform's device scale factor instead of the display's, which | 79 // Use the platform's device scale factor instead of the display's, which |
| 72 // might have been adjusted for the UI scale. | 80 // might have been adjusted for the UI scale. |
| 73 const float original_scale = Shell::Get() | 81 const float original_scale = Shell::Get() |
| 74 ->display_manager() | 82 ->display_manager() |
| 75 ->GetDisplayInfo(display.id()) | 83 ->GetDisplayInfo(display.id()) |
| 76 .device_scale_factor(); | 84 .device_scale_factor(); |
| 77 // And use the nearest resource scale factor. | 85 // And use the nearest resource scale factor. |
| 78 const float cursor_scale = | 86 const float cursor_scale = |
| 79 ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(original_scale)); | 87 ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(original_scale)); |
| 80 | 88 |
| 81 if (image_cursors_->SetDisplay(display, cursor_scale)) | 89 if (image_cursors_->SetDisplay(display, cursor_scale)) |
| 82 SetCursor(delegate->GetCursor(), delegate); | 90 SetCursor(delegate->GetCursor(), delegate); |
| 83 | 91 |
| 84 Shell::Get() | 92 Shell::Get() |
| 85 ->window_tree_host_manager() | 93 ->window_tree_host_manager() |
| 86 ->cursor_window_controller() | 94 ->cursor_window_controller() |
| 87 ->SetDisplay(display); | 95 ->SetDisplay(display); |
| 88 } | 96 } |
| 89 | 97 |
| 90 void AshNativeCursorManager::SetCursor( | 98 void NativeCursorManagerAshClassic::SetCursor( |
| 91 gfx::NativeCursor cursor, | 99 gfx::NativeCursor cursor, |
| 92 ::wm::NativeCursorManagerDelegate* delegate) { | 100 ::wm::NativeCursorManagerDelegate* delegate) { |
| 93 if (native_cursor_enabled_) { | 101 if (native_cursor_enabled_) { |
| 94 image_cursors_->SetPlatformCursor(&cursor); | 102 image_cursors_->SetPlatformCursor(&cursor); |
| 95 } else { | 103 } else { |
| 96 gfx::NativeCursor invisible_cursor(ui::CursorType::kNone); | 104 gfx::NativeCursor invisible_cursor(ui::CursorType::kNone); |
| 97 image_cursors_->SetPlatformCursor(&invisible_cursor); | 105 image_cursors_->SetPlatformCursor(&invisible_cursor); |
| 98 if (cursor == ui::CursorType::kCustom) { | 106 if (cursor == ui::CursorType::kCustom) { |
| 99 // Fall back to the default pointer cursor for now. (crbug.com/476078) | 107 // Fall back to the default pointer cursor for now. (crbug.com/476078) |
| 100 // TODO(oshima): support custom cursor. | 108 // TODO(oshima): support custom cursor. |
| 101 cursor = ui::CursorType::kPointer; | 109 cursor = ui::CursorType::kPointer; |
| 102 } else { | 110 } else { |
| 103 cursor.SetPlatformCursor(invisible_cursor.platform()); | 111 cursor.SetPlatformCursor(invisible_cursor.platform()); |
| 104 } | 112 } |
| 105 } | 113 } |
| 106 cursor.set_device_scale_factor(image_cursors_->GetScale()); | 114 cursor.set_device_scale_factor(image_cursors_->GetScale()); |
| 107 | 115 |
| 108 delegate->CommitCursor(cursor); | 116 delegate->CommitCursor(cursor); |
| 109 | 117 |
| 110 if (delegate->IsCursorVisible()) | 118 if (delegate->IsCursorVisible()) |
| 111 SetCursorOnAllRootWindows(cursor); | 119 SetCursorOnAllRootWindows(cursor); |
| 112 } | 120 } |
| 113 | 121 |
| 114 void AshNativeCursorManager::SetCursorSet( | 122 void NativeCursorManagerAshClassic::SetCursorSet( |
| 115 ui::CursorSetType cursor_set, | 123 ui::CursorSetType cursor_set, |
| 116 ::wm::NativeCursorManagerDelegate* delegate) { | 124 ::wm::NativeCursorManagerDelegate* delegate) { |
| 117 image_cursors_->SetCursorSet(cursor_set); | 125 image_cursors_->SetCursorSet(cursor_set); |
| 118 delegate->CommitCursorSet(cursor_set); | 126 delegate->CommitCursorSet(cursor_set); |
| 119 | 127 |
| 120 // Sets the cursor to reflect the scale change immediately. | 128 // Sets the cursor to reflect the scale change immediately. |
| 121 if (delegate->IsCursorVisible()) | 129 if (delegate->IsCursorVisible()) |
| 122 SetCursor(delegate->GetCursor(), delegate); | 130 SetCursor(delegate->GetCursor(), delegate); |
| 123 | 131 |
| 124 Shell::Get() | 132 Shell::Get() |
| 125 ->window_tree_host_manager() | 133 ->window_tree_host_manager() |
| 126 ->cursor_window_controller() | 134 ->cursor_window_controller() |
| 127 ->SetCursorSet(cursor_set); | 135 ->SetCursorSet(cursor_set); |
| 128 } | 136 } |
| 129 | 137 |
| 130 void AshNativeCursorManager::SetVisibility( | 138 void NativeCursorManagerAshClassic::SetVisibility( |
| 131 bool visible, | 139 bool visible, |
| 132 ::wm::NativeCursorManagerDelegate* delegate) { | 140 ::wm::NativeCursorManagerDelegate* delegate) { |
| 133 delegate->CommitVisibility(visible); | 141 delegate->CommitVisibility(visible); |
| 134 | 142 |
| 135 if (visible) { | 143 if (visible) { |
| 136 SetCursor(delegate->GetCursor(), delegate); | 144 SetCursor(delegate->GetCursor(), delegate); |
| 137 } else { | 145 } else { |
| 138 gfx::NativeCursor invisible_cursor(ui::CursorType::kNone); | 146 gfx::NativeCursor invisible_cursor(ui::CursorType::kNone); |
| 139 image_cursors_->SetPlatformCursor(&invisible_cursor); | 147 image_cursors_->SetPlatformCursor(&invisible_cursor); |
| 140 SetCursorOnAllRootWindows(invisible_cursor); | 148 SetCursorOnAllRootWindows(invisible_cursor); |
| 141 } | 149 } |
| 142 | 150 |
| 143 NotifyCursorVisibilityChange(visible); | 151 NotifyCursorVisibilityChange(visible); |
| 144 } | 152 } |
| 145 | 153 |
| 146 void AshNativeCursorManager::SetMouseEventsEnabled( | 154 void NativeCursorManagerAshClassic::SetMouseEventsEnabled( |
| 147 bool enabled, | 155 bool enabled, |
| 148 ::wm::NativeCursorManagerDelegate* delegate) { | 156 ::wm::NativeCursorManagerDelegate* delegate) { |
| 149 delegate->CommitMouseEventsEnabled(enabled); | 157 delegate->CommitMouseEventsEnabled(enabled); |
| 150 | 158 |
| 151 if (enabled) { | 159 if (enabled) { |
| 152 aura::Env::GetInstance()->set_last_mouse_location( | 160 aura::Env::GetInstance()->set_last_mouse_location( |
| 153 disabled_cursor_location_); | 161 disabled_cursor_location_); |
| 154 } else { | 162 } else { |
| 155 disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location(); | 163 disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location(); |
| 156 } | 164 } |
| 157 | 165 |
| 158 SetVisibility(delegate->IsCursorVisible(), delegate); | 166 SetVisibility(delegate->IsCursorVisible(), delegate); |
| 159 NotifyMouseEventsEnableStateChange(enabled); | 167 NotifyMouseEventsEnableStateChange(enabled); |
| 160 } | 168 } |
| 161 | 169 |
| 162 } // namespace ash | 170 } // namespace ash |
| OLD | NEW |