OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/virtual_keyboard_controller.h" | 5 #include "ash/virtual_keyboard_controller.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
| 9 #include "ash/common/keyboard/keyboard_ui.h" |
9 #include "ash/common/system/tray/system_tray_notifier.h" | 10 #include "ash/common/system/tray/system_tray_notifier.h" |
10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
11 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
| 13 #include "ash/common/wm_window.h" |
| 14 #include "ash/root_window_controller.h" |
12 #include "ash/shell.h" | 15 #include "ash/shell.h" |
13 #include "base/command_line.h" | 16 #include "base/command_line.h" |
14 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "ui/display/display.h" |
| 19 #include "ui/display/screen.h" |
15 #include "ui/events/devices/input_device.h" | 20 #include "ui/events/devices/input_device.h" |
16 #include "ui/events/devices/input_device_manager.h" | 21 #include "ui/events/devices/input_device_manager.h" |
17 #include "ui/events/devices/touchscreen_device.h" | 22 #include "ui/events/devices/touchscreen_device.h" |
| 23 #include "ui/keyboard/keyboard_controller.h" |
18 #include "ui/keyboard/keyboard_switches.h" | 24 #include "ui/keyboard/keyboard_switches.h" |
19 #include "ui/keyboard/keyboard_util.h" | 25 #include "ui/keyboard/keyboard_util.h" |
20 | 26 |
21 namespace ash { | 27 namespace ash { |
22 namespace { | 28 namespace { |
23 | 29 |
24 // Checks whether smart deployment is enabled. | 30 // Checks whether smart deployment is enabled. |
25 bool IsSmartVirtualKeyboardEnabled() { | 31 bool IsSmartVirtualKeyboardEnabled() { |
26 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 32 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
27 keyboard::switches::kEnableVirtualKeyboard)) { | 33 keyboard::switches::kEnableVirtualKeyboard)) { |
28 return false; | 34 return false; |
29 } | 35 } |
30 return keyboard::IsSmartDeployEnabled(); | 36 return keyboard::IsSmartDeployEnabled(); |
31 } | 37 } |
32 | 38 |
| 39 void MoveKeyboardToDisplayInternal(const int64_t display_id) { |
| 40 // Remove the keyboard from curent root window controller |
| 41 WmShell::Get()->keyboard_ui()->Hide(); |
| 42 RootWindowController::ForWindow( |
| 43 keyboard::KeyboardController::GetInstance()->GetContainerWindow()) |
| 44 ->DeactivateKeyboard(keyboard::KeyboardController::GetInstance()); |
| 45 |
| 46 for (RootWindowController* controller : |
| 47 Shell::GetInstance()->GetAllRootWindowControllers()) { |
| 48 if (display::Screen::GetScreen() |
| 49 ->GetDisplayNearestWindow(controller->GetRootWindow()) |
| 50 .id() == display_id) { |
| 51 controller->ActivateKeyboard(keyboard::KeyboardController::GetInstance()); |
| 52 break; |
| 53 } |
| 54 } |
| 55 } |
| 56 |
| 57 void MoveKeyboardToFirstTouchableDisplay() { |
| 58 // Move the keyboard to the first display with touch capability. |
| 59 for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) { |
| 60 if (display.touch_support() == |
| 61 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE) { |
| 62 MoveKeyboardToDisplayInternal(display.id()); |
| 63 return; |
| 64 } |
| 65 } |
| 66 } |
| 67 |
33 } // namespace | 68 } // namespace |
34 | 69 |
35 VirtualKeyboardController::VirtualKeyboardController() | 70 VirtualKeyboardController::VirtualKeyboardController() |
36 : has_external_keyboard_(false), | 71 : has_external_keyboard_(false), |
37 has_internal_keyboard_(false), | 72 has_internal_keyboard_(false), |
38 has_touchscreen_(false), | 73 has_touchscreen_(false), |
39 ignore_external_keyboard_(false) { | 74 ignore_external_keyboard_(false) { |
40 WmShell::Get()->AddShellObserver(this); | 75 WmShell::Get()->AddShellObserver(this); |
41 ui::InputDeviceManager::GetInstance()->AddObserver(this); | 76 ui::InputDeviceManager::GetInstance()->AddObserver(this); |
42 UpdateDevices(); | 77 UpdateDevices(); |
(...skipping 26 matching lines...) Expand all Loading... |
69 | 104 |
70 void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() { | 105 void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() { |
71 UpdateDevices(); | 106 UpdateDevices(); |
72 } | 107 } |
73 | 108 |
74 void VirtualKeyboardController::ToggleIgnoreExternalKeyboard() { | 109 void VirtualKeyboardController::ToggleIgnoreExternalKeyboard() { |
75 ignore_external_keyboard_ = !ignore_external_keyboard_; | 110 ignore_external_keyboard_ = !ignore_external_keyboard_; |
76 UpdateKeyboardEnabled(); | 111 UpdateKeyboardEnabled(); |
77 } | 112 } |
78 | 113 |
| 114 void VirtualKeyboardController::MoveKeyboardToDisplay(int64_t display_id) { |
| 115 DCHECK(keyboard::KeyboardController::GetInstance() != nullptr); |
| 116 DCHECK(display_id != display::kInvalidDisplayId); |
| 117 |
| 118 aura::Window* container = |
| 119 keyboard::KeyboardController::GetInstance()->GetContainerWindow(); |
| 120 DCHECK(container != nullptr); |
| 121 const display::Screen* screen = display::Screen::GetScreen(); |
| 122 const display::Display current_display = |
| 123 screen->GetDisplayNearestWindow(container); |
| 124 |
| 125 if (display_id != current_display.id()) |
| 126 MoveKeyboardToDisplayInternal(display_id); |
| 127 } |
| 128 |
| 129 void VirtualKeyboardController::MoveKeyboardToTouchableDisplay() { |
| 130 DCHECK(keyboard::KeyboardController::GetInstance() != nullptr); |
| 131 |
| 132 aura::Window* container = |
| 133 keyboard::KeyboardController::GetInstance()->GetContainerWindow(); |
| 134 DCHECK(container != nullptr); |
| 135 |
| 136 const display::Screen* screen = display::Screen::GetScreen(); |
| 137 const display::Display current_display = |
| 138 screen->GetDisplayNearestWindow(container); |
| 139 |
| 140 if (WmShell::Get()->GetFocusedWindow() != nullptr) { |
| 141 // Move the virtual keyboard to the focused display if that display has |
| 142 // touch capability or keyboard is locked |
| 143 const display::Display focused_display = |
| 144 WmShell::Get()->GetFocusedWindow()->GetDisplayNearestWindow(); |
| 145 if (current_display.id() != focused_display.id() && |
| 146 focused_display.id() != display::kInvalidDisplayId && |
| 147 focused_display.touch_support() == |
| 148 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE) { |
| 149 MoveKeyboardToDisplayInternal(focused_display.id()); |
| 150 return; |
| 151 } |
| 152 } |
| 153 |
| 154 if (current_display.touch_support() != |
| 155 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE) { |
| 156 // The keyboard is currently on the display without touch capability. |
| 157 MoveKeyboardToFirstTouchableDisplay(); |
| 158 } |
| 159 } |
| 160 |
79 void VirtualKeyboardController::UpdateDevices() { | 161 void VirtualKeyboardController::UpdateDevices() { |
80 ui::InputDeviceManager* device_data_manager = | 162 ui::InputDeviceManager* device_data_manager = |
81 ui::InputDeviceManager::GetInstance(); | 163 ui::InputDeviceManager::GetInstance(); |
82 | 164 |
83 // Checks for touchscreens. | 165 // Checks for touchscreens. |
84 has_touchscreen_ = device_data_manager->GetTouchscreenDevices().size() > 0; | 166 has_touchscreen_ = device_data_manager->GetTouchscreenDevices().size() > 0; |
85 | 167 |
86 // Checks for keyboards. | 168 // Checks for keyboards. |
87 has_external_keyboard_ = false; | 169 has_external_keyboard_ = false; |
88 has_internal_keyboard_ = false; | 170 has_internal_keyboard_ = false; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 if (is_enabled == was_enabled) | 210 if (is_enabled == was_enabled) |
129 return; | 211 return; |
130 if (is_enabled) { | 212 if (is_enabled) { |
131 Shell::GetInstance()->CreateKeyboard(); | 213 Shell::GetInstance()->CreateKeyboard(); |
132 } else { | 214 } else { |
133 Shell::GetInstance()->DeactivateKeyboard(); | 215 Shell::GetInstance()->DeactivateKeyboard(); |
134 } | 216 } |
135 } | 217 } |
136 | 218 |
137 } // namespace ash | 219 } // namespace ash |
OLD | NEW |