Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Side by Side Diff: ash/virtual_keyboard_controller.cc

Issue 2445293002: Make the virtual keyboard show up on the display with input focus. (Closed)
Patch Set: rebase & update Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 MoveKeyboardToDisplay(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
33 } // namespace 57 } // namespace
34 58
35 VirtualKeyboardController::VirtualKeyboardController() 59 VirtualKeyboardController::VirtualKeyboardController()
36 : has_external_keyboard_(false), 60 : has_external_keyboard_(false),
37 has_internal_keyboard_(false), 61 has_internal_keyboard_(false),
38 has_touchscreen_(false), 62 has_touchscreen_(false),
39 ignore_external_keyboard_(false) { 63 ignore_external_keyboard_(false) {
40 WmShell::Get()->AddShellObserver(this); 64 WmShell::Get()->AddShellObserver(this);
41 ui::InputDeviceManager::GetInstance()->AddObserver(this); 65 ui::InputDeviceManager::GetInstance()->AddObserver(this);
42 UpdateDevices(); 66 UpdateDevices();
(...skipping 26 matching lines...) Expand all
69 93
70 void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() { 94 void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() {
71 UpdateDevices(); 95 UpdateDevices();
72 } 96 }
73 97
74 void VirtualKeyboardController::ToggleIgnoreExternalKeyboard() { 98 void VirtualKeyboardController::ToggleIgnoreExternalKeyboard() {
75 ignore_external_keyboard_ = !ignore_external_keyboard_; 99 ignore_external_keyboard_ = !ignore_external_keyboard_;
76 UpdateKeyboardEnabled(); 100 UpdateKeyboardEnabled();
77 } 101 }
78 102
103 void VirtualKeyboardController::MoveKeyboardToFirstTouchableDisplay() const {
104 // Move the keyboard to the first display with touch capability.
105 for (RootWindowController* controller :
106 Shell::GetInstance()->GetAllRootWindowControllers()) {
107 display::Display display =
108 display::Screen::GetScreen()->GetDisplayNearestWindow(
109 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
110 if (display.touch_support() ==
111 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE) {
112 MoveKeyboardToDisplay(display.id());
113 return;
114 }
115 }
116 }
117
118 void VirtualKeyboardController::MoveKeyboardToAnotherDisplayIfNeeded(
119 int64_t display_id) {
120 DCHECK(keyboard::KeyboardController::GetInstance() != nullptr);
121
122 aura::Window* container =
123 keyboard::KeyboardController::GetInstance()->GetContainerWindow();
124 DCHECK(container != nullptr);
125
126 const display::Screen* screen = display::Screen::GetScreen();
127 const display::Display current_display =
128 screen->GetDisplayNearestWindow(container);
129
130 if (display_id != display::Display::kInvalidDisplayID) {
131 // Destination is specified. If the keyboard shows on different display,
132 // move it to that display.
133 if (display_id != current_display.id())
134 MoveKeyboardToDisplay(display_id);
135 return;
136 }
137
138 if (WmShell::Get()->GetFocusedWindow() != nullptr) {
139 // Move the virtual keyboard to the focused display if that display has
140 // touch capability or keyboard is locked
141 const display::Display focused_display =
142 WmShell::Get()->GetFocusedWindow()->GetDisplayNearestWindow();
143 if (current_display.id() != focused_display.id() &&
144 focused_display.id() != display::Display::kInvalidDisplayID &&
145 focused_display.touch_support() ==
146 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE) {
147 MoveKeyboardToDisplay(focused_display.id());
148 return;
149 }
150 }
151
152 if (current_display.touch_support() !=
153 display::Display::TouchSupport::TOUCH_SUPPORT_AVAILABLE) {
154 // The keyboard is currently on the display without touch capability.
155 MoveKeyboardToFirstTouchableDisplay();
156 }
157 }
158
79 void VirtualKeyboardController::UpdateDevices() { 159 void VirtualKeyboardController::UpdateDevices() {
80 ui::InputDeviceManager* device_data_manager = 160 ui::InputDeviceManager* device_data_manager =
81 ui::InputDeviceManager::GetInstance(); 161 ui::InputDeviceManager::GetInstance();
82 162
83 // Checks for touchscreens. 163 // Checks for touchscreens.
84 has_touchscreen_ = device_data_manager->GetTouchscreenDevices().size() > 0; 164 has_touchscreen_ = device_data_manager->GetTouchscreenDevices().size() > 0;
85 165
86 // Checks for keyboards. 166 // Checks for keyboards.
87 has_external_keyboard_ = false; 167 has_external_keyboard_ = false;
88 has_internal_keyboard_ = false; 168 has_internal_keyboard_ = false;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if (is_enabled == was_enabled) 208 if (is_enabled == was_enabled)
129 return; 209 return;
130 if (is_enabled) { 210 if (is_enabled) {
131 Shell::GetInstance()->CreateKeyboard(); 211 Shell::GetInstance()->CreateKeyboard();
132 } else { 212 } else {
133 Shell::GetInstance()->DeactivateKeyboard(); 213 Shell::GetInstance()->DeactivateKeyboard();
134 } 214 }
135 } 215 }
136 216
137 } // namespace ash 217 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698