| 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> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 10 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "ui/events/devices/device_data_manager.h" | 13 #include "ui/events/devices/device_data_manager.h" |
| 14 #include "ui/events/devices/input_device.h" | 14 #include "ui/events/devices/input_device.h" |
| 15 #include "ui/events/devices/keyboard_device.h" | 15 #include "ui/events/devices/keyboard_device.h" |
| 16 #include "ui/events/devices/touchscreen_device.h" | 16 #include "ui/events/devices/touchscreen_device.h" |
| 17 #include "ui/gfx/x/x11_types.h" | 17 #include "ui/gfx/x/x11_types.h" |
| 18 #include "ui/keyboard/keyboard_switches.h" | 18 #include "ui/keyboard/keyboard_switches.h" |
| 19 #include "ui/keyboard/keyboard_util.h" | 19 #include "ui/keyboard/keyboard_util.h" |
| 20 | 20 |
| 21 namespace ash { | 21 namespace ash { |
| 22 namespace { |
| 23 |
| 24 // Checks whether smart deployment is enabled. |
| 25 bool IsSmartVirtualKeyboardEnabled() { |
| 26 return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 27 keyboard::switches::kDisableSmartVirtualKeyboard); |
| 28 } |
| 29 |
| 30 } // namespace |
| 22 | 31 |
| 23 VirtualKeyboardController::VirtualKeyboardController() | 32 VirtualKeyboardController::VirtualKeyboardController() |
| 24 : has_external_keyboard_(false), | 33 : has_external_keyboard_(false), |
| 25 has_internal_keyboard_(false), | 34 has_internal_keyboard_(false), |
| 26 has_touchscreen_(false), | 35 has_touchscreen_(false), |
| 27 ignore_external_keyboard_(false) { | 36 ignore_external_keyboard_(false) { |
| 28 Shell::GetInstance()->AddShellObserver(this); | 37 Shell::GetInstance()->AddShellObserver(this); |
| 29 ui::DeviceDataManager::GetInstance()->AddObserver(this); | 38 ui::DeviceDataManager::GetInstance()->AddObserver(this); |
| 30 UpdateDevices(); | 39 UpdateDevices(); |
| 31 } | 40 } |
| 32 | 41 |
| 33 VirtualKeyboardController::~VirtualKeyboardController() { | 42 VirtualKeyboardController::~VirtualKeyboardController() { |
| 34 Shell::GetInstance()->RemoveShellObserver(this); | 43 Shell::GetInstance()->RemoveShellObserver(this); |
| 35 ui::DeviceDataManager::GetInstance()->RemoveObserver(this); | 44 ui::DeviceDataManager::GetInstance()->RemoveObserver(this); |
| 36 } | 45 } |
| 37 | 46 |
| 38 void VirtualKeyboardController::OnMaximizeModeStarted() { | 47 void VirtualKeyboardController::OnMaximizeModeStarted() { |
| 39 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 48 if (!IsSmartVirtualKeyboardEnabled()) |
| 40 keyboard::switches::kAutoVirtualKeyboard)) { | |
| 41 SetKeyboardEnabled(true); | 49 SetKeyboardEnabled(true); |
| 42 } | |
| 43 } | 50 } |
| 44 | 51 |
| 45 void VirtualKeyboardController::OnMaximizeModeEnded() { | 52 void VirtualKeyboardController::OnMaximizeModeEnded() { |
| 46 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 53 if (!IsSmartVirtualKeyboardEnabled()) |
| 47 keyboard::switches::kAutoVirtualKeyboard)) { | |
| 48 SetKeyboardEnabled(false); | 54 SetKeyboardEnabled(false); |
| 49 } | |
| 50 } | 55 } |
| 51 | 56 |
| 52 void VirtualKeyboardController::OnTouchscreenDeviceConfigurationChanged() { | 57 void VirtualKeyboardController::OnTouchscreenDeviceConfigurationChanged() { |
| 53 UpdateDevices(); | 58 UpdateDevices(); |
| 54 } | 59 } |
| 55 | 60 |
| 56 void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() { | 61 void VirtualKeyboardController::OnKeyboardDeviceConfigurationChanged() { |
| 57 UpdateDevices(); | 62 UpdateDevices(); |
| 58 } | 63 } |
| 59 | 64 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 80 if (type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL) | 85 if (type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL) |
| 81 has_internal_keyboard_ = true; | 86 has_internal_keyboard_ = true; |
| 82 if (type == ui::InputDeviceType::INPUT_DEVICE_EXTERNAL) | 87 if (type == ui::InputDeviceType::INPUT_DEVICE_EXTERNAL) |
| 83 has_external_keyboard_ = true; | 88 has_external_keyboard_ = true; |
| 84 } | 89 } |
| 85 // Update keyboard state. | 90 // Update keyboard state. |
| 86 UpdateKeyboardEnabled(); | 91 UpdateKeyboardEnabled(); |
| 87 } | 92 } |
| 88 | 93 |
| 89 void VirtualKeyboardController::UpdateKeyboardEnabled() { | 94 void VirtualKeyboardController::UpdateKeyboardEnabled() { |
| 90 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 95 if (!IsSmartVirtualKeyboardEnabled()) { |
| 91 keyboard::switches::kAutoVirtualKeyboard)) { | |
| 92 SetKeyboardEnabled(Shell::GetInstance() | 96 SetKeyboardEnabled(Shell::GetInstance() |
| 93 ->maximize_mode_controller() | 97 ->maximize_mode_controller() |
| 94 ->IsMaximizeModeWindowManagerEnabled()); | 98 ->IsMaximizeModeWindowManagerEnabled()); |
| 95 return; | 99 return; |
| 96 } | 100 } |
| 97 SetKeyboardEnabled(!has_internal_keyboard_ && has_touchscreen_ && | 101 SetKeyboardEnabled(!has_internal_keyboard_ && has_touchscreen_ && |
| 98 (!has_external_keyboard_ || ignore_external_keyboard_)); | 102 (!has_external_keyboard_ || ignore_external_keyboard_)); |
| 99 ash::Shell::GetInstance() | 103 ash::Shell::GetInstance() |
| 100 ->system_tray_notifier() | 104 ->system_tray_notifier() |
| 101 ->NotifyVirtualKeyboardSuppressionChanged(!has_internal_keyboard_ && | 105 ->NotifyVirtualKeyboardSuppressionChanged(!has_internal_keyboard_ && |
| 102 has_touchscreen_ && | 106 has_touchscreen_ && |
| 103 has_external_keyboard_); | 107 has_external_keyboard_); |
| 104 } | 108 } |
| 105 | 109 |
| 106 void VirtualKeyboardController::SetKeyboardEnabled(bool enabled) { | 110 void VirtualKeyboardController::SetKeyboardEnabled(bool enabled) { |
| 107 keyboard::SetTouchKeyboardEnabled(enabled); | 111 keyboard::SetTouchKeyboardEnabled(enabled); |
| 108 if (enabled) { | 112 if (enabled) { |
| 109 Shell::GetInstance()->CreateKeyboard(); | 113 Shell::GetInstance()->CreateKeyboard(); |
| 110 } else { | 114 } else { |
| 111 if (!keyboard::IsKeyboardEnabled()) | 115 if (!keyboard::IsKeyboardEnabled()) |
| 112 Shell::GetInstance()->DeactivateKeyboard(); | 116 Shell::GetInstance()->DeactivateKeyboard(); |
| 113 } | 117 } |
| 114 } | 118 } |
| 115 | 119 |
| 116 } // namespace ash | 120 } // namespace ash |
| OLD | NEW |