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

Side by Side Diff: ash/virtual_keyboard_controller.cc

Issue 613343005: Automatic deployment of the virtual keyboard. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix typo. Created 6 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
« no previous file with comments | « ash/virtual_keyboard_controller.h ('k') | ash/virtual_keyboard_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
8
7 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
11 #include "base/command_line.h"
12 #include "base/strings/string_util.h"
13 #include "ui/events/device_data_manager.h"
14 #include "ui/events/input_device.h"
15 #include "ui/events/keyboard_device.h"
16 #include "ui/events/touchscreen_device.h"
17 #include "ui/gfx/x/x11_types.h"
18 #include "ui/keyboard/keyboard_switches.h"
8 #include "ui/keyboard/keyboard_util.h" 19 #include "ui/keyboard/keyboard_util.h"
9 20
10 namespace ash { 21 namespace ash {
11 22
12 VirtualKeyboardController::VirtualKeyboardController() { 23 VirtualKeyboardController::VirtualKeyboardController()
24 : has_external_keyboard_(false),
25 has_internal_keyboard_(false),
26 has_touchscreen_(false) {
13 Shell::GetInstance()->AddShellObserver(this); 27 Shell::GetInstance()->AddShellObserver(this);
28 ui::DeviceDataManager::GetInstance()->AddObserver(this);
29 UpdateDevices();
14 } 30 }
15 31
16 VirtualKeyboardController::~VirtualKeyboardController() { 32 VirtualKeyboardController::~VirtualKeyboardController() {
17 Shell::GetInstance()->RemoveShellObserver(this); 33 Shell::GetInstance()->RemoveShellObserver(this);
34 ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
18 } 35 }
19 36
20 void VirtualKeyboardController::OnMaximizeModeStarted() { 37 void VirtualKeyboardController::OnMaximizeModeStarted() {
21 keyboard::SetTouchKeyboardEnabled(true); 38 if (!CommandLine::ForCurrentProcess()->HasSwitch(
22 Shell::GetInstance()->CreateKeyboard(); 39 keyboard::switches::kAutoVirtualKeyboard)) {
40 SetKeyboardEnabled(true);
41 }
23 } 42 }
24 43
25 void VirtualKeyboardController::OnMaximizeModeEnded() { 44 void VirtualKeyboardController::OnMaximizeModeEnded() {
26 keyboard::SetTouchKeyboardEnabled(false); 45 if (!CommandLine::ForCurrentProcess()->HasSwitch(
27 if (!keyboard::IsKeyboardEnabled()) 46 keyboard::switches::kAutoVirtualKeyboard)) {
28 Shell::GetInstance()->DeactivateKeyboard(); 47 SetKeyboardEnabled(false);
48 }
49 }
50
51 void VirtualKeyboardController::UpdateDevices() {
52 ui::DeviceDataManager* device_data_manager =
53 ui::DeviceDataManager::GetInstance();
54
55 // Checks for touchscreens.
56 has_touchscreen_ = device_data_manager->touchscreen_devices().size() > 0;
57
58 // Checks for keyboards.
59 has_external_keyboard_ = false;
60 has_internal_keyboard_ = false;
61 std::vector<ui::KeyboardDevice> keyboards =
62 device_data_manager->keyboard_devices();
63 for (auto iter = keyboards.begin();
64 iter != keyboards.end() ||
65 (has_internal_keyboard_ && has_external_keyboard_);
66 ++iter) {
67 ui::InputDeviceType type = (*iter).type;
68 if (type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL)
69 has_internal_keyboard_ = true;
70 if (type == ui::InputDeviceType::INPUT_DEVICE_EXTERNAL)
71 has_external_keyboard_ = true;
72 }
73 // Update keyboard state.
74 UpdateKeyboardEnabled();
75 }
76
77 void VirtualKeyboardController::SetKeyboardEnabled(bool enabled) {
78 keyboard::SetTouchKeyboardEnabled(enabled);
79 if (enabled) {
80 Shell::GetInstance()->CreateKeyboard();
81 } else {
82 if (!keyboard::IsKeyboardEnabled())
83 Shell::GetInstance()->DeactivateKeyboard();
84 }
85 }
86
87 void VirtualKeyboardController::UpdateKeyboardEnabled() {
88 if (!CommandLine::ForCurrentProcess()->HasSwitch(
89 keyboard::switches::kAutoVirtualKeyboard)) {
90 SetKeyboardEnabled(Shell::GetInstance()
91 ->maximize_mode_controller()
92 ->IsMaximizeModeWindowManagerEnabled());
93 return;
94 }
95 // TODO(rsadam@): Add UI to re-enable suppressed keyboard.
96 SetKeyboardEnabled(!has_internal_keyboard_ && has_touchscreen_ &&
97 !has_external_keyboard_);
98 }
99
100 void VirtualKeyboardController::OnTouchscreenDeviceConfigurationChanged() {
101 UpdateDevices();
102 }
103
104 void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() {
105 UpdateDevices();
29 } 106 }
30 107
31 } // namespace ash 108 } // namespace ash
OLDNEW
« no previous file with comments | « ash/virtual_keyboard_controller.h ('k') | ash/virtual_keyboard_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698