| Index: ash/virtual_keyboard_controller.cc
|
| diff --git a/ash/virtual_keyboard_controller.cc b/ash/virtual_keyboard_controller.cc
|
| index 6bd535a2d45b0d629f22c9f087cfadf104dcb892..abfa2ee371e73d979dfc92d3c97e3913b8a6b0c9 100644
|
| --- a/ash/virtual_keyboard_controller.cc
|
| +++ b/ash/virtual_keyboard_controller.cc
|
| @@ -4,28 +4,93 @@
|
|
|
| #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() {
|
| - Shell::GetInstance()->AddShellObserver(this);
|
| +VirtualKeyboardController::VirtualKeyboardController()
|
| + : has_external_keyboard_(false),
|
| + has_internal_keyboard_(false),
|
| + has_touchscreen_(false) {
|
| + ui::DeviceDataManager::GetInstance()->AddObserver(this);
|
| + UpdateDevices();
|
| + // Do not actually create the keyboard object since Ash environment may not be
|
| + // ready yet.
|
| + keyboard::SetTouchKeyboardEnabled(ShouldShowKeyboard());
|
| }
|
|
|
| VirtualKeyboardController::~VirtualKeyboardController() {
|
| - Shell::GetInstance()->RemoveShellObserver(this);
|
| + ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
|
| +}
|
| +
|
| +// Determines the active input devices.
|
| +void VirtualKeyboardController::UpdateDevices() {
|
| + ui::DeviceDataManager* device_data_manager =
|
| + ui::DeviceDataManager::GetInstance();
|
| +
|
| + // Checks for internal touchscreens.
|
| + std::vector<ui::TouchscreenDevice> screens =
|
| + device_data_manager->touchscreen_devices();
|
| + has_touchscreen_ = screens.size() > 0;
|
| +
|
| + // 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::INPUT_DEVICE_INTERNAL)
|
| + has_internal_keyboard_ = true;
|
| + if (type == ui::InputDeviceType::INPUT_DEVICE_EXTERNAL)
|
| + has_external_keyboard_ = true;
|
| + }
|
| +}
|
| +
|
| +// Updates the virtual keyboard state.
|
| +void VirtualKeyboardController::SetKeyboardEnabled(bool enabled) {
|
| + keyboard::SetTouchKeyboardEnabled(enabled);
|
| + if (enabled) {
|
| + Shell::GetInstance()->CreateKeyboard();
|
| + } else {
|
| + if (!keyboard::IsKeyboardEnabled())
|
| + Shell::GetInstance()->DeactivateKeyboard();
|
| + }
|
| +}
|
| +
|
| +// Whether the keyboard should be shown.
|
| +bool VirtualKeyboardController::ShouldShowKeyboard() {
|
| + // 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)) {
|
| + return !has_internal_keyboard_;
|
| + }
|
| + // TODO(rsadam@): Add logic for a repressed keyboard. For now just enable the
|
| + // keyboard.
|
| + return !has_internal_keyboard_ && has_touchscreen_;
|
| }
|
|
|
| -void VirtualKeyboardController::OnMaximizeModeStarted() {
|
| - keyboard::SetTouchKeyboardEnabled(true);
|
| - Shell::GetInstance()->CreateKeyboard();
|
| +void VirtualKeyboardController::OnTouchscreenDeviceConfigurationChanged() {
|
| + UpdateDevices();
|
| + SetKeyboardEnabled(ShouldShowKeyboard());
|
| }
|
|
|
| -void VirtualKeyboardController::OnMaximizeModeEnded() {
|
| - keyboard::SetTouchKeyboardEnabled(false);
|
| - if (!keyboard::IsKeyboardEnabled())
|
| - Shell::GetInstance()->DeactivateKeyboard();
|
| +void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() {
|
| + UpdateDevices();
|
| + SetKeyboardEnabled(ShouldShowKeyboard());
|
| }
|
|
|
| } // namespace ash
|
|
|