Chromium Code Reviews| Index: ash/virtual_keyboard_controller.cc |
| diff --git a/ash/virtual_keyboard_controller.cc b/ash/virtual_keyboard_controller.cc |
| index e5904488f6d555b3e852321796c0d96056489742..de55ae095d84566d807b687ca4f69c741d319020 100644 |
| --- a/ash/virtual_keyboard_controller.cc |
| +++ b/ash/virtual_keyboard_controller.cc |
| @@ -6,15 +6,21 @@ |
| #include <vector> |
| +#include "ash/common/keyboard/keyboard_ui.h" |
| #include "ash/common/system/tray/system_tray_notifier.h" |
| #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| #include "ash/common/wm_shell.h" |
| +#include "ash/common/wm_window.h" |
| +#include "ash/root_window_controller.h" |
| #include "ash/shell.h" |
| #include "base/command_line.h" |
| #include "base/strings/string_util.h" |
| +#include "ui/display/display.h" |
| +#include "ui/display/screen.h" |
| #include "ui/events/devices/input_device.h" |
| #include "ui/events/devices/input_device_manager.h" |
| #include "ui/events/devices/touchscreen_device.h" |
| +#include "ui/keyboard/keyboard_controller.h" |
| #include "ui/keyboard/keyboard_switches.h" |
| #include "ui/keyboard/keyboard_util.h" |
| @@ -30,6 +36,24 @@ bool IsSmartVirtualKeyboardEnabled() { |
| return keyboard::IsSmartDeployEnabled(); |
| } |
| +void MoveKeyboardToDisplay(const int64_t display_id) { |
| + // Remove the keyboard from curent root window controller |
| + WmShell::Get()->keyboard_ui()->Hide(); |
| + RootWindowController::ForWindow( |
| + keyboard::KeyboardController::GetInstance()->GetContainerWindow()) |
| + ->DeactivateKeyboard(keyboard::KeyboardController::GetInstance()); |
| + |
| + for (RootWindowController* controller : |
| + Shell::GetInstance()->GetAllRootWindowControllers()) { |
| + if (display::Screen::GetScreen() |
| + ->GetDisplayNearestWindow(controller->GetRootWindow()) |
| + .id() == display_id) { |
| + controller->ActivateKeyboard(keyboard::KeyboardController::GetInstance()); |
| + break; |
| + } |
| + } |
| +} |
| + |
| } // namespace |
| VirtualKeyboardController::VirtualKeyboardController() |
| @@ -76,6 +100,62 @@ void VirtualKeyboardController::ToggleIgnoreExternalKeyboard() { |
| UpdateKeyboardEnabled(); |
| } |
| +void VirtualKeyboardController::MoveKeyboardToFirstTouchableDisplay() const { |
| + // Move the keyboard to the first display with touch capability. |
| + for (RootWindowController* controller : |
| + Shell::GetInstance()->GetAllRootWindowControllers()) { |
| + display::Display display = |
| + display::Screen::GetScreen()->GetDisplayNearestWindow( |
| + controller->GetRootWindow()); |
|
oshima
2016/11/08 17:26:05
can you use
Screen::GetAllDisplays ?
yhanada
2016/11/14 22:48:47
Done. This function is moved into anonymous namesp
|
| + if (display.touch_support() == |
| + display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE) { |
| + MoveKeyboardToDisplay(display.id()); |
| + return; |
| + } |
| + } |
| +} |
| + |
| +void VirtualKeyboardController::MoveKeyboardToAnotherDisplayIfNeeded( |
| + int64_t display_id) { |
| + DCHECK(keyboard::KeyboardController::GetInstance() != nullptr); |
| + |
| + aura::Window* container = |
| + keyboard::KeyboardController::GetInstance()->GetContainerWindow(); |
| + DCHECK(container != nullptr); |
| + |
| + const display::Screen* screen = display::Screen::GetScreen(); |
| + const display::Display current_display = |
| + screen->GetDisplayNearestWindow(container); |
| + |
| + if (display_id != display::Display::kInvalidDisplayID) { |
| + // Destination is specified. If the keyboard shows on different display, |
| + // move it to that display. |
| + if (display_id != current_display.id()) |
| + MoveKeyboardToDisplay(display_id); |
| + return; |
| + } |
| + |
| + if (WmShell::Get()->GetFocusedWindow() != nullptr) { |
| + // Move the virtual keyboard to the focused display if that display has |
| + // touch capability or keyboard is locked |
| + const display::Display focused_display = |
| + WmShell::Get()->GetFocusedWindow()->GetDisplayNearestWindow(); |
| + if (current_display.id() != focused_display.id() && |
| + focused_display.id() != display::Display::kInvalidDisplayID && |
| + focused_display.touch_support() == |
| + display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE) { |
| + MoveKeyboardToDisplay(focused_display.id()); |
| + return; |
| + } |
| + } |
| + |
| + if (current_display.touch_support() != |
| + display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE) { |
| + // The keyboard is currently on the display without touch capability. |
| + MoveKeyboardToFirstTouchableDisplay(); |
| + } |
| +} |
| + |
| void VirtualKeyboardController::UpdateDevices() { |
| ui::InputDeviceManager* device_data_manager = |
| ui::InputDeviceManager::GetInstance(); |