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

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: Created 6 years, 2 months 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>
8
7 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "base/command_line.h"
11 #include "base/strings/string_util.h"
12 #include "ui/events/device_data_manager.h"
13 #include "ui/events/input_device.h"
14 #include "ui/events/keyboard_device.h"
15 #include "ui/events/touchscreen_device.h"
16 #include "ui/gfx/x/x11_types.h"
17 #include "ui/keyboard/keyboard_switches.h"
8 #include "ui/keyboard/keyboard_util.h" 18 #include "ui/keyboard/keyboard_util.h"
9 19
10 namespace ash { 20 namespace ash {
11 21
12 VirtualKeyboardController::VirtualKeyboardController() { 22 VirtualKeyboardController::VirtualKeyboardController()
13 Shell::GetInstance()->AddShellObserver(this); 23 : has_external_keyboard_(false),
24 has_internal_keyboard_(false),
25 has_touchscreen_(false) {
26 ui::DeviceDataManager::GetInstance()->AddObserver(this);
27 UpdateDevices();
28 // Do not actually create the keyboard object since Ash environment may not be
29 // ready yet.
30 keyboard::SetTouchKeyboardEnabled(ShouldShowKeyboard());
14 } 31 }
15 32
16 VirtualKeyboardController::~VirtualKeyboardController() { 33 VirtualKeyboardController::~VirtualKeyboardController() {
17 Shell::GetInstance()->RemoveShellObserver(this); 34 ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
18 } 35 }
19 36
20 void VirtualKeyboardController::OnMaximizeModeStarted() { 37 // Determines the active input devices.
21 keyboard::SetTouchKeyboardEnabled(true); 38 void VirtualKeyboardController::UpdateDevices() {
22 Shell::GetInstance()->CreateKeyboard(); 39 ui::DeviceDataManager* device_data_manager =
40 ui::DeviceDataManager::GetInstance();
41
42 // Checks for internal touchscreens.
43 std::vector<ui::TouchscreenDevice> screens =
44 device_data_manager->touchscreen_devices();
45 has_touchscreen_ = screens.size() > 0;
46
47 // Checks for keyboards.
48 has_external_keyboard_ = false;
49 has_internal_keyboard_ = false;
50 std::vector<ui::KeyboardDevice> keyboards =
51 device_data_manager->keyboard_devices();
52 std::vector<ui::KeyboardDevice>::const_iterator iter;
53 for (iter = keyboards.begin(); iter != keyboards.end(); ++iter) {
54 ui::InputDeviceType type = (*iter).type;
55 if (type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL)
56 has_internal_keyboard_ = true;
57 if (type == ui::InputDeviceType::INPUT_DEVICE_EXTERNAL)
58 has_external_keyboard_ = true;
59 }
23 } 60 }
24 61
25 void VirtualKeyboardController::OnMaximizeModeEnded() { 62 // Updates the virtual keyboard state.
26 keyboard::SetTouchKeyboardEnabled(false); 63 void VirtualKeyboardController::SetKeyboardEnabled(bool enabled) {
27 if (!keyboard::IsKeyboardEnabled()) 64 keyboard::SetTouchKeyboardEnabled(enabled);
28 Shell::GetInstance()->DeactivateKeyboard(); 65 if (enabled) {
66 Shell::GetInstance()->CreateKeyboard();
67 } else {
68 if (!keyboard::IsKeyboardEnabled())
69 Shell::GetInstance()->DeactivateKeyboard();
70 }
71 }
72
73 // Whether the keyboard should be shown.
74 bool VirtualKeyboardController::ShouldShowKeyboard() {
75 // If flag to autodetect is not set, we will always deploy the keyboard on
76 // maximize mode, and always dismiss it otherwise.
77 if (!CommandLine::ForCurrentProcess()->HasSwitch(
78 keyboard::switches::kAutoVirtualKeyboard)) {
79 return !has_internal_keyboard_;
80 }
81 // TODO(rsadam@): Add logic for a repressed keyboard. For now just enable the
82 // keyboard.
83 return !has_internal_keyboard_ && has_touchscreen_;
84 }
85
86 void VirtualKeyboardController::OnTouchscreenDeviceConfigurationChanged() {
87 UpdateDevices();
88 SetKeyboardEnabled(ShouldShowKeyboard());
89 }
90
91 void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() {
92 UpdateDevices();
93 SetKeyboardEnabled(ShouldShowKeyboard());
29 } 94 }
30 95
31 } // namespace ash 96 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698