Chromium Code Reviews| 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 |
| 37 // TODO(rsadam@): Remove when autovirtual keyboard flag is on by default. | |
| 20 void VirtualKeyboardController::OnMaximizeModeStarted() { | 38 void VirtualKeyboardController::OnMaximizeModeStarted() { |
| 21 keyboard::SetTouchKeyboardEnabled(true); | 39 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 22 Shell::GetInstance()->CreateKeyboard(); | 40 keyboard::switches::kAutoVirtualKeyboard)) { |
| 41 SetKeyboardEnabled(true); | |
| 42 } | |
| 23 } | 43 } |
| 24 | 44 |
| 25 void VirtualKeyboardController::OnMaximizeModeEnded() { | 45 void VirtualKeyboardController::OnMaximizeModeEnded() { |
| 26 keyboard::SetTouchKeyboardEnabled(false); | 46 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 27 if (!keyboard::IsKeyboardEnabled()) | 47 keyboard::switches::kAutoVirtualKeyboard)) { |
| 28 Shell::GetInstance()->DeactivateKeyboard(); | 48 SetKeyboardEnabled(false); |
| 49 } | |
| 50 } | |
| 51 | |
| 52 // Determines the active input devices. | |
| 53 void VirtualKeyboardController::UpdateDevices() { | |
| 54 ui::DeviceDataManager* device_data_manager = | |
| 55 ui::DeviceDataManager::GetInstance(); | |
| 56 | |
| 57 // Checks for internal touchscreens. | |
| 58 std::vector<ui::TouchscreenDevice> screens = | |
| 59 device_data_manager->touchscreen_devices(); | |
| 60 has_touchscreen_ = screens.size() > 0; | |
| 61 | |
| 62 // Checks for keyboards. | |
| 63 has_external_keyboard_ = false; | |
| 64 has_internal_keyboard_ = false; | |
| 65 std::vector<ui::KeyboardDevice> keyboards = | |
| 66 device_data_manager->keyboard_devices(); | |
| 67 std::vector<ui::KeyboardDevice>::const_iterator iter; | |
| 68 for (iter = keyboards.begin(); iter != keyboards.end(); ++iter) { | |
| 69 ui::InputDeviceType type = (*iter).type; | |
| 70 if (type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL) | |
| 71 has_internal_keyboard_ = true; | |
| 72 if (type == ui::InputDeviceType::INPUT_DEVICE_EXTERNAL) | |
| 73 has_external_keyboard_ = true; | |
| 74 } | |
| 75 // Update keyboard state. | |
| 76 Update(); | |
| 77 } | |
| 78 | |
| 79 // Creates/Destroys the virtual keyboard as necessary. | |
| 80 void VirtualKeyboardController::SetKeyboardEnabled(bool enabled) { | |
| 81 keyboard::SetTouchKeyboardEnabled(enabled); | |
| 82 if (enabled) { | |
| 83 Shell::GetInstance()->CreateKeyboard(); | |
| 84 } else { | |
| 85 if (!keyboard::IsKeyboardEnabled()) | |
| 86 Shell::GetInstance()->DeactivateKeyboard(); | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 // Updates the keyboard state. | |
|
flackr
2014/10/27 15:33:12
Move function comments to .h file.
rsadam
2014/10/27 15:51:18
Done.
| |
| 91 void VirtualKeyboardController::Update() { | |
|
flackr
2014/10/27 15:33:12
Maybe call this UpdateKeyboardEnabled to different
rsadam
2014/10/27 15:51:18
Done.
| |
| 92 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 93 keyboard::switches::kAutoVirtualKeyboard)) { | |
| 94 SetKeyboardEnabled(Shell::GetInstance() | |
| 95 ->maximize_mode_controller() | |
| 96 ->IsMaximizeModeWindowManagerEnabled()); | |
|
flackr
2014/10/27 15:20:38
This would have already been done by OnMaximizeMod
rsadam
2014/10/27 15:51:18
Since we delayed when this is created, we might mi
| |
| 97 return; | |
| 98 } | |
| 99 // TODO(rsadam@): Add UI to re-enable suppressed keyboard. | |
| 100 SetKeyboardEnabled(!has_internal_keyboard_ && has_touchscreen_ && | |
| 101 !has_external_keyboard_); | |
| 102 } | |
| 103 | |
| 104 void VirtualKeyboardController::OnTouchscreenDeviceConfigurationChanged() { | |
| 105 UpdateDevices(); | |
| 106 } | |
| 107 | |
| 108 void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() { | |
| 109 UpdateDevices(); | |
| 29 } | 110 } |
| 30 | 111 |
| 31 } // namespace ash | 112 } // namespace ash |
| OLD | NEW |