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

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: Fix typo. 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
« no previous file with comments | « ash/virtual_keyboard_controller.h ('k') | ash/virtual_keyboard_controller_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/virtual_keyboard_controller.cc
diff --git a/ash/virtual_keyboard_controller.cc b/ash/virtual_keyboard_controller.cc
index 6bd535a2d45b0d629f22c9f087cfadf104dcb892..82fb12137ff114b3bb909b8d1acb7118f6e1d30a 100644
--- a/ash/virtual_keyboard_controller.cc
+++ b/ash/virtual_keyboard_controller.cc
@@ -4,28 +4,105 @@
#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);
}
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);
+ }
+}
+
+void VirtualKeyboardController::UpdateDevices() {
+ ui::DeviceDataManager* device_data_manager =
+ ui::DeviceDataManager::GetInstance();
+
+ // Checks for touchscreens.
+ has_touchscreen_ = device_data_manager->touchscreen_devices().size() > 0;
+
+ // Checks for keyboards.
+ has_external_keyboard_ = false;
+ has_internal_keyboard_ = false;
+ std::vector<ui::KeyboardDevice> keyboards =
+ device_data_manager->keyboard_devices();
+ for (auto iter = keyboards.begin();
+ iter != keyboards.end() ||
+ (has_internal_keyboard_ && has_external_keyboard_);
+ ++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.
+ UpdateKeyboardEnabled();
+}
+
+void VirtualKeyboardController::SetKeyboardEnabled(bool enabled) {
+ keyboard::SetTouchKeyboardEnabled(enabled);
+ if (enabled) {
+ Shell::GetInstance()->CreateKeyboard();
+ } else {
+ if (!keyboard::IsKeyboardEnabled())
+ Shell::GetInstance()->DeactivateKeyboard();
+ }
+}
+
+void VirtualKeyboardController::UpdateKeyboardEnabled() {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(
+ keyboard::switches::kAutoVirtualKeyboard)) {
+ SetKeyboardEnabled(Shell::GetInstance()
+ ->maximize_mode_controller()
+ ->IsMaximizeModeWindowManagerEnabled());
+ 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
« no previous file with comments | « ash/virtual_keyboard_controller.h ('k') | ash/virtual_keyboard_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698