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

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: Add unittests. 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()
23 : has_external_keyboard_(false),
24 has_internal_keyboard_(false),
25 has_touchscreen_(false),
26 maximized_(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 maximized_ = true;
22 Shell::GetInstance()->CreateKeyboard(); 39 Update();
23 } 40 }
24 41
25 void VirtualKeyboardController::OnMaximizeModeEnded() { 42 void VirtualKeyboardController::OnMaximizeModeEnded() {
26 keyboard::SetTouchKeyboardEnabled(false); 43 maximized_ = false;
27 if (!keyboard::IsKeyboardEnabled()) 44 Update();
28 Shell::GetInstance()->DeactivateKeyboard(); 45 }
46
47 // Traverse active devices and record the presence of a touchscreen,
flackr 2014/10/04 01:02:54 nit: Suggest something that implies the subsequent
rsadam 2014/10/23 20:10:52 Done.
48 // external keyboards and internal keyboards.
49 void VirtualKeyboardController::UpdateDevices() {
50 ui::DeviceDataManager* device_data_manager =
51 ui::DeviceDataManager::GetInstance();
52
53 // Checks for internal touchscreens.
54 has_touchscreen_ = false;
55 std::vector<ui::TouchscreenDevice> screens =
56 device_data_manager->touchscreen_devices();
57 std::vector<ui::TouchscreenDevice>::const_iterator screen_iter;
58 for (screen_iter = screens.begin();
59 screen_iter != screens.end(); ++screen_iter) {
60 if ((*screen_iter).type == ui::InputDeviceType::INTERNAL)
flackr 2014/10/04 01:02:54 Why not deploy for an external touchscreen? Isn't
rsadam 2014/10/23 20:10:52 Done.
61 has_touchscreen_ = true;
62 }
63
64 // Checks for keyboards.
65 has_external_keyboard_ = false;
66 has_internal_keyboard_ = false;
67 std::vector<ui::KeyboardDevice> keyboards =
68 device_data_manager->keyboard_devices();
69 std::vector<ui::KeyboardDevice>::const_iterator iter;
70 for (iter = keyboards.begin();
71 iter != keyboards.end(); ++iter) {
72 ui::InputDeviceType type = (*iter).type;
73 if (type == ui::InputDeviceType::INTERNAL)
74 has_internal_keyboard_ = true;
75 if (type == ui::InputDeviceType::EXTERNAL)
76 has_external_keyboard_ = true;
77 }
78
79 // Updates keyboard state.
80 Update();
81 }
82
83
84 // Updates the keyboard state.
85 void VirtualKeyboardController::Update() {
86 // If flag to autodetect is not set, we will always deploy the keyboard on
87 // maximize mode, and always dismiss it otherwise.
88 if (!CommandLine::ForCurrentProcess()->HasSwitch(
89 keyboard::switches::kAutoVirtualKeyboard)) {
flackr 2014/10/04 01:02:54 SetTouchKeyboardEnabled(maximized_) and early retu
rsadam 2014/10/23 20:10:52 Done.
90 has_touchscreen_ = true;
91 has_internal_keyboard_= true;
92 }
93
94 // If the device does not have a touchscreen, or the device has an internal
95 // keyboard and is not in TouchView mode, disable the keyboard.
96 if ((has_internal_keyboard_ && !maximized_)
97 || !has_touchscreen_) {
98 keyboard::SetTouchKeyboardEnabled(false);
flackr 2014/10/04 01:02:54 Can you move these two commands to enable/disable
rsadam 2014/10/23 20:10:52 Done.
99 if (!keyboard::IsKeyboardEnabled())
100 Shell::GetInstance()->DeactivateKeyboard();
101 } else {
102 // TODO(rsadam@): Add logic for a repressed keyboard. For now just enable.
103 keyboard::SetTouchKeyboardEnabled(true);
104 Shell::GetInstance()->CreateKeyboard();
105 }
106 }
107
108 void VirtualKeyboardController::OnTouchscreenDeviceConfigurationChanged() {
109 UpdateDevices();
110 }
111
112 void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() {
113 UpdateDevices();
29 } 114 }
30 115
31 } // namespace ash 116 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698