Index: ash/virtual_keyboard_controller.cc |
diff --git a/ash/virtual_keyboard_controller.cc b/ash/virtual_keyboard_controller.cc |
index 6bd535a2d45b0d629f22c9f087cfadf104dcb892..33750dd2184ef8b16eab95b0ff6fd42357180441 100644 |
--- a/ash/virtual_keyboard_controller.cc |
+++ b/ash/virtual_keyboard_controller.cc |
@@ -4,28 +4,113 @@ |
#include "ash/virtual_keyboard_controller.h" |
+#include <vector> |
+ |
#include "ash/shell.h" |
+#include "base/command_line.h" |
+#include "base/strings/string_util.h" |
+#include "ui/events/device_data_manager.h" |
+#include "ui/events/input_device.h" |
+#include "ui/events/keyboard_device.h" |
+#include "ui/events/touchscreen_device.h" |
+#include "ui/gfx/x/x11_types.h" |
+#include "ui/keyboard/keyboard_switches.h" |
#include "ui/keyboard/keyboard_util.h" |
namespace ash { |
-VirtualKeyboardController::VirtualKeyboardController() { |
+VirtualKeyboardController::VirtualKeyboardController() |
+ : has_external_keyboard_(false), |
+ has_internal_keyboard_(false), |
+ has_touchscreen_(false), |
+ maximized_(false) { |
Shell::GetInstance()->AddShellObserver(this); |
+ ui::DeviceDataManager::GetInstance()->AddObserver(this); |
+ UpdateDevices(); |
} |
VirtualKeyboardController::~VirtualKeyboardController() { |
Shell::GetInstance()->RemoveShellObserver(this); |
+ ui::DeviceDataManager::GetInstance()->RemoveObserver(this); |
} |
void VirtualKeyboardController::OnMaximizeModeStarted() { |
- keyboard::SetTouchKeyboardEnabled(true); |
- Shell::GetInstance()->CreateKeyboard(); |
+ maximized_ = true; |
+ Update(); |
} |
void VirtualKeyboardController::OnMaximizeModeEnded() { |
- keyboard::SetTouchKeyboardEnabled(false); |
- if (!keyboard::IsKeyboardEnabled()) |
- Shell::GetInstance()->DeactivateKeyboard(); |
+ maximized_ = false; |
+ Update(); |
+} |
+ |
+// 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.
|
+// external keyboards and internal keyboards. |
+void VirtualKeyboardController::UpdateDevices() { |
+ ui::DeviceDataManager* device_data_manager = |
+ ui::DeviceDataManager::GetInstance(); |
+ |
+ // Checks for internal touchscreens. |
+ has_touchscreen_ = false; |
+ std::vector<ui::TouchscreenDevice> screens = |
+ device_data_manager->touchscreen_devices(); |
+ std::vector<ui::TouchscreenDevice>::const_iterator screen_iter; |
+ for (screen_iter = screens.begin(); |
+ screen_iter != screens.end(); ++screen_iter) { |
+ 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.
|
+ has_touchscreen_ = true; |
+ } |
+ |
+ // Checks for keyboards. |
+ has_external_keyboard_ = false; |
+ has_internal_keyboard_ = false; |
+ std::vector<ui::KeyboardDevice> keyboards = |
+ device_data_manager->keyboard_devices(); |
+ std::vector<ui::KeyboardDevice>::const_iterator iter; |
+ for (iter = keyboards.begin(); |
+ iter != keyboards.end(); ++iter) { |
+ ui::InputDeviceType type = (*iter).type; |
+ if (type == ui::InputDeviceType::INTERNAL) |
+ has_internal_keyboard_ = true; |
+ if (type == ui::InputDeviceType::EXTERNAL) |
+ has_external_keyboard_ = true; |
+ } |
+ |
+ // Updates keyboard state. |
+ Update(); |
+} |
+ |
+ |
+// Updates the keyboard state. |
+void VirtualKeyboardController::Update() { |
+ // If flag to autodetect is not set, we will always deploy the keyboard on |
+ // maximize mode, and always dismiss it otherwise. |
+ if (!CommandLine::ForCurrentProcess()->HasSwitch( |
+ keyboard::switches::kAutoVirtualKeyboard)) { |
flackr
2014/10/04 01:02:54
SetTouchKeyboardEnabled(maximized_) and early retu
rsadam
2014/10/23 20:10:52
Done.
|
+ has_touchscreen_ = true; |
+ has_internal_keyboard_= true; |
+ } |
+ |
+ // If the device does not have a touchscreen, or the device has an internal |
+ // keyboard and is not in TouchView mode, disable the keyboard. |
+ if ((has_internal_keyboard_ && !maximized_) |
+ || !has_touchscreen_) { |
+ 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.
|
+ if (!keyboard::IsKeyboardEnabled()) |
+ Shell::GetInstance()->DeactivateKeyboard(); |
+ } else { |
+ // TODO(rsadam@): Add logic for a repressed keyboard. For now just enable. |
+ keyboard::SetTouchKeyboardEnabled(true); |
+ Shell::GetInstance()->CreateKeyboard(); |
+ } |
+} |
+ |
+void VirtualKeyboardController::OnTouchscreenDeviceConfigurationChanged() { |
+ UpdateDevices(); |
+} |
+ |
+void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() { |
+ UpdateDevices(); |
} |
} // namespace ash |