OLD | NEW |
---|---|
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 internal touchscreens. | |
56 std::vector<ui::TouchscreenDevice> screens = | |
sky
2014/10/27 20:28:33
nit: remove this local and move to has_touchscreen
rsadam
2014/10/28 15:07:29
Done.
| |
57 device_data_manager->touchscreen_devices(); | |
58 has_touchscreen_ = screens.size() > 0; | |
59 | |
60 // Checks for keyboards. | |
61 has_external_keyboard_ = false; | |
62 has_internal_keyboard_ = false; | |
63 std::vector<ui::KeyboardDevice> keyboards = | |
64 device_data_manager->keyboard_devices(); | |
65 std::vector<ui::KeyboardDevice>::const_iterator iter; | |
sky
2014/10/27 20:28:33
nit: move into for loop.
nit2: use auto to make mo
rsadam
2014/10/28 15:07:29
Done.
| |
66 for (iter = keyboards.begin(); iter != keyboards.end(); ++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 |
OLD | NEW |