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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: ash/virtual_keyboard_controller.cc
diff --git a/ash/virtual_keyboard_controller.cc b/ash/virtual_keyboard_controller.cc
index 6bd535a2d45b0d629f22c9f087cfadf104dcb892..d66120d7030c5f944bef04705fa8c8cbba94bab7 100644
--- a/ash/virtual_keyboard_controller.cc
+++ b/ash/virtual_keyboard_controller.cc
@@ -4,28 +4,109 @@
#include "ash/virtual_keyboard_controller.h"
+#include <vector>
+
#include "ash/shell.h"
+#include "ash/wm/maximize_mode/maximize_mode_controller.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) {
Shell::GetInstance()->AddShellObserver(this);
+ ui::DeviceDataManager::GetInstance()->AddObserver(this);
+ UpdateDevices();
}
VirtualKeyboardController::~VirtualKeyboardController() {
Shell::GetInstance()->RemoveShellObserver(this);
+ ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
}
+// TODO(rsadam@): Remove when autovirtual keyboard flag is on by default.
void VirtualKeyboardController::OnMaximizeModeStarted() {
- keyboard::SetTouchKeyboardEnabled(true);
- Shell::GetInstance()->CreateKeyboard();
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ keyboard::switches::kAutoVirtualKeyboard)) {
+ SetKeyboardEnabled(true);
+ }
}
void VirtualKeyboardController::OnMaximizeModeEnded() {
- keyboard::SetTouchKeyboardEnabled(false);
- if (!keyboard::IsKeyboardEnabled())
- Shell::GetInstance()->DeactivateKeyboard();
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ keyboard::switches::kAutoVirtualKeyboard)) {
+ SetKeyboardEnabled(false);
+ }
+}
+
+// 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;
+ }
+ // Update keyboard state.
+ Update();
+}
+
+// Creates/Destroys the virtual keyboard as necessary.
+void VirtualKeyboardController::SetKeyboardEnabled(bool enabled) {
+ keyboard::SetTouchKeyboardEnabled(enabled);
+ if (enabled) {
+ Shell::GetInstance()->CreateKeyboard();
+ } else {
+ if (!keyboard::IsKeyboardEnabled())
+ Shell::GetInstance()->DeactivateKeyboard();
+ }
+}
+
+// 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.
+void VirtualKeyboardController::Update() {
flackr 2014/10/27 15:33:12 Maybe call this UpdateKeyboardEnabled to different
rsadam 2014/10/27 15:51:18 Done.
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ keyboard::switches::kAutoVirtualKeyboard)) {
+ SetKeyboardEnabled(Shell::GetInstance()
+ ->maximize_mode_controller()
+ ->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
+ return;
+ }
+ // TODO(rsadam@): Add UI to re-enable suppressed keyboard.
+ SetKeyboardEnabled(!has_internal_keyboard_ && has_touchscreen_ &&
+ !has_external_keyboard_);
+}
+
+void VirtualKeyboardController::OnTouchscreenDeviceConfigurationChanged() {
+ UpdateDevices();
+}
+
+void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() {
+ UpdateDevices();
}
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698