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 "chrome/browser/chromeos/events/event_rewriter.h" | 5 #include "ui/chromeos/events/event_rewriter.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/common/wm/window_state.h" | |
| 12 #include "ash/sticky_keys/sticky_keys_controller.h" | |
| 13 #include "ash/wm/window_util.h" | |
| 14 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 15 #include "base/logging.h" | 12 #include "base/logging.h" |
| 16 #include "base/macros.h" | 13 #include "base/macros.h" |
| 17 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
| 18 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 19 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
| 20 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | |
| 21 #include "chrome/browser/extensions/extension_commands_global_registry.h" | |
| 22 #include "chrome/browser/profiles/profile_manager.h" | |
| 23 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | |
| 24 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | |
| 25 #include "chrome/common/pref_names.h" | |
| 26 #include "chromeos/chromeos_switches.h" | 17 #include "chromeos/chromeos_switches.h" |
| 27 #include "components/prefs/pref_service.h" | |
| 28 #include "components/user_manager/user_manager.h" | |
| 29 #include "ui/base/ime/chromeos/ime_keyboard.h" | 18 #include "ui/base/ime/chromeos/ime_keyboard.h" |
| 30 #include "ui/base/ime/chromeos/input_method_manager.h" | 19 #include "ui/base/ime/chromeos/input_method_manager.h" |
| 20 #include "ui/chromeos/pref_names.h" | |
| 31 #include "ui/events/devices/input_device_manager.h" | 21 #include "ui/events/devices/input_device_manager.h" |
| 32 #include "ui/events/event.h" | 22 #include "ui/events/event.h" |
| 33 #include "ui/events/event_utils.h" | 23 #include "ui/events/event_utils.h" |
| 34 #include "ui/events/keycodes/dom/dom_code.h" | 24 #include "ui/events/keycodes/dom/dom_code.h" |
| 35 #include "ui/events/keycodes/dom/dom_key.h" | 25 #include "ui/events/keycodes/dom/dom_key.h" |
| 36 #include "ui/events/keycodes/dom/keycode_converter.h" | 26 #include "ui/events/keycodes/dom/keycode_converter.h" |
| 37 #include "ui/events/keycodes/keyboard_code_conversion.h" | 27 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 38 #include "ui/wm/core/window_util.h" | 28 #include "ui/wm/core/window_util.h" |
| 39 | 29 |
| 40 #if defined(USE_X11) | 30 #if defined(USE_X11) |
| 31 #include <X11/Xlib.h> | |
| 41 #include <X11/extensions/XInput2.h> | 32 #include <X11/extensions/XInput2.h> |
| 42 #include <X11/Xlib.h> | |
| 43 | 33 |
| 44 // Get rid of macros from Xlib.h that conflicts with other parts of the code. | 34 // Get rid of macros from Xlib.h that conflicts with other parts of the code. |
| 45 #undef RootWindow | 35 #undef RootWindow |
| 46 #undef Status | 36 #undef Status |
| 47 | 37 |
| 48 #include "ui/base/x/x11_util.h" | 38 #include "ui/base/x/x11_util.h" |
| 49 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 39 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| 50 #endif | 40 #endif |
|
sadrul
2017/03/03 15:11:41
We should get rid of the USE_X11 code, since it's
Peng
2017/03/03 16:07:05
Sure. I will do it in a separate CL.
| |
| 51 | 41 |
| 42 namespace ui { | |
| 52 namespace chromeos { | 43 namespace chromeos { |
| 53 | 44 |
| 54 namespace { | 45 namespace { |
| 55 | 46 |
| 56 // Hotrod controller vendor/product ids. | 47 // Hotrod controller vendor/product ids. |
| 57 const int kHotrodRemoteVendorId = 0x0471; | 48 const int kHotrodRemoteVendorId = 0x0471; |
| 58 const int kHotrodRemoteProductId = 0x21cc; | 49 const int kHotrodRemoteProductId = 0x21cc; |
| 59 const int kUnknownVendorId = -1; | 50 const int kUnknownVendorId = -1; |
| 60 const int kUnknownProductId = -1; | 51 const int kUnknownProductId = -1; |
| 61 | 52 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 77 // it likewise uses |GetRemappedKey()| to find the properties of the | 68 // it likewise uses |GetRemappedKey()| to find the properties of the |
| 78 // user preference target key, and replaces the flag accordingly. | 69 // user preference target key, and replaces the flag accordingly. |
| 79 const struct ModifierRemapping { | 70 const struct ModifierRemapping { |
| 80 int flag; | 71 int flag; |
| 81 int remap_to; | 72 int remap_to; |
| 82 const char* pref_name; | 73 const char* pref_name; |
| 83 EventRewriter::MutableKeyState result; | 74 EventRewriter::MutableKeyState result; |
| 84 } kModifierRemappings[] = { | 75 } kModifierRemappings[] = { |
| 85 {// kModifierRemappingCtrl references this entry by index. | 76 {// kModifierRemappingCtrl references this entry by index. |
| 86 ui::EF_CONTROL_DOWN, | 77 ui::EF_CONTROL_DOWN, |
| 87 input_method::kControlKey, | 78 ::chromeos::input_method::kControlKey, |
| 88 prefs::kLanguageRemapControlKeyTo, | 79 prefs::kLanguageRemapControlKeyTo, |
| 89 {ui::EF_CONTROL_DOWN, ui::DomCode::CONTROL_LEFT, ui::DomKey::CONTROL, | 80 {ui::EF_CONTROL_DOWN, ui::DomCode::CONTROL_LEFT, ui::DomKey::CONTROL, |
| 90 ui::VKEY_CONTROL}}, | 81 ui::VKEY_CONTROL}}, |
| 91 {// kModifierRemappingNeoMod3 references this entry by index. | 82 {// kModifierRemappingNeoMod3 references this entry by index. |
| 92 ui::EF_MOD3_DOWN | ui::EF_ALTGR_DOWN, | 83 ui::EF_MOD3_DOWN | ui::EF_ALTGR_DOWN, |
| 93 input_method::kNumModifierKeys, | 84 ::chromeos::input_method::kNumModifierKeys, |
| 94 nullptr, | 85 nullptr, |
| 95 {ui::EF_MOD3_DOWN | ui::EF_ALTGR_DOWN, ui::DomCode::CAPS_LOCK, | 86 {ui::EF_MOD3_DOWN | ui::EF_ALTGR_DOWN, ui::DomCode::CAPS_LOCK, |
| 96 ui::DomKey::ALT_GRAPH, ui::VKEY_ALTGR}}, | 87 ui::DomKey::ALT_GRAPH, ui::VKEY_ALTGR}}, |
| 97 {ui::EF_COMMAND_DOWN, | 88 {ui::EF_COMMAND_DOWN, |
| 98 input_method::kSearchKey, | 89 ::chromeos::input_method::kSearchKey, |
| 99 prefs::kLanguageRemapSearchKeyTo, | 90 prefs::kLanguageRemapSearchKeyTo, |
| 100 {ui::EF_COMMAND_DOWN, ui::DomCode::META_LEFT, ui::DomKey::META, | 91 {ui::EF_COMMAND_DOWN, ui::DomCode::META_LEFT, ui::DomKey::META, |
| 101 ui::VKEY_LWIN}}, | 92 ui::VKEY_LWIN}}, |
| 102 {ui::EF_ALT_DOWN, | 93 {ui::EF_ALT_DOWN, |
| 103 input_method::kAltKey, | 94 ::chromeos::input_method::kAltKey, |
| 104 prefs::kLanguageRemapAltKeyTo, | 95 prefs::kLanguageRemapAltKeyTo, |
| 105 {ui::EF_ALT_DOWN, ui::DomCode::ALT_LEFT, ui::DomKey::ALT, ui::VKEY_MENU}}, | 96 {ui::EF_ALT_DOWN, ui::DomCode::ALT_LEFT, ui::DomKey::ALT, ui::VKEY_MENU}}, |
| 106 {ui::EF_NONE, | 97 {ui::EF_NONE, |
| 107 input_method::kVoidKey, | 98 ::chromeos::input_method::kVoidKey, |
| 108 nullptr, | 99 nullptr, |
| 109 {ui::EF_NONE, ui::DomCode::NONE, ui::DomKey::NONE, ui::VKEY_UNKNOWN}}, | 100 {ui::EF_NONE, ui::DomCode::NONE, ui::DomKey::NONE, ui::VKEY_UNKNOWN}}, |
| 110 {ui::EF_MOD3_DOWN, | 101 {ui::EF_MOD3_DOWN, |
| 111 input_method::kCapsLockKey, | 102 ::chromeos::input_method::kCapsLockKey, |
| 112 prefs::kLanguageRemapCapsLockKeyTo, | 103 prefs::kLanguageRemapCapsLockKeyTo, |
| 113 {ui::EF_MOD3_DOWN, ui::DomCode::CAPS_LOCK, ui::DomKey::CAPS_LOCK, | 104 {ui::EF_MOD3_DOWN, ui::DomCode::CAPS_LOCK, ui::DomKey::CAPS_LOCK, |
| 114 ui::VKEY_CAPITAL}}, | 105 ui::VKEY_CAPITAL}}, |
| 115 {ui::EF_NONE, | 106 {ui::EF_NONE, |
| 116 input_method::kEscapeKey, | 107 ::chromeos::input_method::kEscapeKey, |
| 117 prefs::kLanguageRemapEscapeKeyTo, | 108 prefs::kLanguageRemapEscapeKeyTo, |
| 118 {ui::EF_NONE, ui::DomCode::ESCAPE, ui::DomKey::ESCAPE, ui::VKEY_ESCAPE}}, | 109 {ui::EF_NONE, ui::DomCode::ESCAPE, ui::DomKey::ESCAPE, ui::VKEY_ESCAPE}}, |
| 119 {ui::EF_NONE, | 110 {ui::EF_NONE, |
| 120 input_method::kBackspaceKey, | 111 ::chromeos::input_method::kBackspaceKey, |
| 121 prefs::kLanguageRemapBackspaceKeyTo, | 112 prefs::kLanguageRemapBackspaceKeyTo, |
| 122 {ui::EF_NONE, ui::DomCode::BACKSPACE, ui::DomKey::BACKSPACE, | 113 {ui::EF_NONE, ui::DomCode::BACKSPACE, ui::DomKey::BACKSPACE, |
| 123 ui::VKEY_BACK}}, | 114 ui::VKEY_BACK}}, |
| 124 {ui::EF_NONE, | 115 {ui::EF_NONE, |
| 125 input_method::kNumModifierKeys, | 116 ::chromeos::input_method::kNumModifierKeys, |
| 126 prefs::kLanguageRemapDiamondKeyTo, | 117 prefs::kLanguageRemapDiamondKeyTo, |
| 127 {ui::EF_NONE, ui::DomCode::F15, ui::DomKey::F15, ui::VKEY_F15}}}; | 118 {ui::EF_NONE, ui::DomCode::F15, ui::DomKey::F15, ui::VKEY_F15}}}; |
| 128 | 119 |
| 129 const ModifierRemapping* kModifierRemappingCtrl = &kModifierRemappings[0]; | 120 const ModifierRemapping* kModifierRemappingCtrl = &kModifierRemappings[0]; |
| 130 const ModifierRemapping* kModifierRemappingNeoMod3 = &kModifierRemappings[1]; | 121 const ModifierRemapping* kModifierRemappingNeoMod3 = &kModifierRemappings[1]; |
| 131 | 122 |
| 132 // Gets a remapped key for |pref_name| key. For example, to find out which | 123 // Gets a remapped key for |pref_name| key. For example, to find out which |
| 133 // key Search is currently remapped to, call the function with | 124 // key Search is currently remapped to, call the function with |
| 134 // prefs::kLanguageRemapSearchKeyTo. | 125 // prefs::kLanguageRemapSearchKeyTo. |
| 135 const ModifierRemapping* GetRemappedKey(const std::string& pref_name, | 126 const ModifierRemapping* GetRemappedKey(const std::string& pref_name, |
| 136 const PrefService& pref_service) { | 127 EventRewriter::Delegate* delegate) { |
| 128 if (!delegate) | |
| 129 return nullptr; | |
| 130 | |
| 137 int value = -1; | 131 int value = -1; |
| 138 // If we're at the login screen, try to get the pref from the global prefs | 132 if (!delegate->GetKeyboardRemappedPrefValue(pref_name, &value)) |
| 139 // dictionary. | 133 return nullptr; |
| 140 if (!LoginDisplayHost::default_host() || | |
| 141 !LoginDisplayHost::default_host() | |
| 142 ->GetOobeUI() | |
| 143 ->signin_screen_handler() | |
| 144 ->GetKeyboardRemappedPrefValue(pref_name, &value)) { | |
| 145 if (!pref_service.FindPreference(pref_name)) | |
| 146 return nullptr; | |
| 147 value = pref_service.GetInteger(pref_name); | |
| 148 } | |
| 149 | 134 |
| 150 for (size_t i = 0; i < arraysize(kModifierRemappings); ++i) { | 135 for (size_t i = 0; i < arraysize(kModifierRemappings); ++i) { |
| 151 if (value == kModifierRemappings[i].remap_to) | 136 if (value == kModifierRemappings[i].remap_to) |
| 152 return &kModifierRemappings[i]; | 137 return &kModifierRemappings[i]; |
| 153 } | 138 } |
| 154 return nullptr; | 139 return nullptr; |
| 155 } | 140 } |
| 156 | 141 |
| 157 bool HasDiamondKey() { | 142 bool HasDiamondKey() { |
| 158 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 143 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 159 chromeos::switches::kHasChromeOSDiamondKey); | 144 ::chromeos::switches::kHasChromeOSDiamondKey); |
| 160 } | 145 } |
| 161 | 146 |
| 162 bool IsISOLevel5ShiftUsedByCurrentInputMethod() { | 147 bool IsISOLevel5ShiftUsedByCurrentInputMethod() { |
| 163 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, | 148 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, |
| 164 // it's not possible to make both features work. For now, we don't remap | 149 // it's not possible to make both features work. For now, we don't remap |
| 165 // Mod3Mask when Neo2 is in use. | 150 // Mod3Mask when Neo2 is in use. |
| 166 // TODO(yusukes): Remove the restriction. | 151 // TODO(yusukes): Remove the restriction. |
| 167 input_method::InputMethodManager* manager = | 152 ::chromeos::input_method::InputMethodManager* manager = |
| 168 input_method::InputMethodManager::Get(); | 153 ::chromeos::input_method::InputMethodManager::Get(); |
| 169 return manager->IsISOLevel5ShiftUsedByCurrentInputMethod(); | 154 return manager->IsISOLevel5ShiftUsedByCurrentInputMethod(); |
| 170 } | 155 } |
| 171 | 156 |
| 172 bool IsExtensionCommandRegistered(ui::KeyboardCode key_code, int flags) { | |
| 173 // Some keyboard events for ChromeOS get rewritten, such as: | |
| 174 // Search+Shift+Left gets converted to Shift+Home (BeginDocument). | |
| 175 // This doesn't make sense if the user has assigned that shortcut | |
| 176 // to an extension. Because: | |
| 177 // 1) The extension would, upon seeing a request for Ctrl+Shift+Home have | |
| 178 // to register for Shift+Home, instead. | |
| 179 // 2) The conversion is unnecessary, because Shift+Home (BeginDocument) isn't | |
| 180 // going to be executed. | |
| 181 // Therefore, we skip converting the accelerator if an extension has | |
| 182 // registered for this shortcut. | |
| 183 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 184 if (!profile || !extensions::ExtensionCommandsGlobalRegistry::Get(profile)) | |
| 185 return false; | |
| 186 | |
| 187 int modifiers = flags & (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | | |
| 188 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN); | |
| 189 ui::Accelerator accelerator(key_code, modifiers); | |
| 190 return extensions::ExtensionCommandsGlobalRegistry::Get(profile) | |
| 191 ->IsRegistered(accelerator); | |
| 192 } | |
| 193 | |
| 194 EventRewriter::DeviceType GetDeviceType(const std::string& device_name, | 157 EventRewriter::DeviceType GetDeviceType(const std::string& device_name, |
| 195 int vendor_id, | 158 int vendor_id, |
| 196 int product_id) { | 159 int product_id) { |
| 197 if (vendor_id == kHotrodRemoteVendorId && | 160 if (vendor_id == kHotrodRemoteVendorId && |
| 198 product_id == kHotrodRemoteProductId) { | 161 product_id == kHotrodRemoteProductId) { |
| 199 return EventRewriter::kDeviceHotrodRemote; | 162 return EventRewriter::kDeviceHotrodRemote; |
| 200 } | 163 } |
| 201 | 164 |
| 202 if (base::LowerCaseEqualsASCII(device_name, "virtual core keyboard")) | 165 if (base::LowerCaseEqualsASCII(device_name, "virtual core keyboard")) |
| 203 return EventRewriter::kDeviceVirtualCoreKeyboard; | 166 return EventRewriter::kDeviceVirtualCoreKeyboard; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 299 case ui::DomCode::META_RIGHT: | 262 case ui::DomCode::META_RIGHT: |
| 300 return right ? ui::DomCode::META_RIGHT : ui::DomCode::META_LEFT; | 263 return right ? ui::DomCode::META_RIGHT : ui::DomCode::META_LEFT; |
| 301 default: | 264 default: |
| 302 break; | 265 break; |
| 303 } | 266 } |
| 304 return code; | 267 return code; |
| 305 } | 268 } |
| 306 | 269 |
| 307 } // namespace | 270 } // namespace |
| 308 | 271 |
| 309 EventRewriter::EventRewriter(ash::StickyKeysController* sticky_keys_controller) | 272 EventRewriter::EventRewriter(Delegate* delegate, |
| 273 StickyKeysController* sticky_keys_controller) | |
| 310 : last_keyboard_device_id_(ui::ED_UNKNOWN_DEVICE), | 274 : last_keyboard_device_id_(ui::ED_UNKNOWN_DEVICE), |
| 311 ime_keyboard_for_testing_(NULL), | 275 ime_keyboard_for_testing_(NULL), |
| 312 pref_service_for_testing_(NULL), | 276 delegate_(delegate), |
| 313 sticky_keys_controller_(sticky_keys_controller), | 277 sticky_keys_controller_(sticky_keys_controller), |
| 314 pressed_modifier_latches_(ui::EF_NONE), | 278 pressed_modifier_latches_(ui::EF_NONE), |
| 315 latched_modifier_latches_(ui::EF_NONE), | 279 latched_modifier_latches_(ui::EF_NONE), |
| 316 used_modifier_latches_(ui::EF_NONE) {} | 280 used_modifier_latches_(ui::EF_NONE) {} |
| 317 | 281 |
| 318 EventRewriter::~EventRewriter() {} | 282 EventRewriter::~EventRewriter() {} |
| 319 | 283 |
| 320 EventRewriter::DeviceType EventRewriter::KeyboardDeviceAddedForTesting( | 284 EventRewriter::DeviceType EventRewriter::KeyboardDeviceAddedForTesting( |
| 321 int device_id, | 285 int device_id, |
| 322 const std::string& device_name) { | 286 const std::string& device_name) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 | 361 |
| 398 // Ignore virtual Xorg keyboard (magic that generates key repeat | 362 // Ignore virtual Xorg keyboard (magic that generates key repeat |
| 399 // events). Pretend that the previous real keyboard is the one that is still | 363 // events). Pretend that the previous real keyboard is the one that is still |
| 400 // in use. | 364 // in use. |
| 401 if (type == kDeviceVirtualCoreKeyboard) | 365 if (type == kDeviceVirtualCoreKeyboard) |
| 402 return; | 366 return; |
| 403 | 367 |
| 404 last_keyboard_device_id_ = device_id; | 368 last_keyboard_device_id_ = device_id; |
| 405 } | 369 } |
| 406 | 370 |
| 407 const PrefService* EventRewriter::GetPrefService() const { | |
| 408 if (pref_service_for_testing_) | |
| 409 return pref_service_for_testing_; | |
| 410 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 411 return profile ? profile->GetPrefs() : NULL; | |
| 412 } | |
| 413 | |
| 414 bool EventRewriter::IsAppleKeyboard() const { | 371 bool EventRewriter::IsAppleKeyboard() const { |
| 415 return IsLastKeyboardOfType(kDeviceAppleKeyboard); | 372 return IsLastKeyboardOfType(kDeviceAppleKeyboard); |
| 416 } | 373 } |
| 417 | 374 |
| 418 bool EventRewriter::IsHotrodRemote() const { | 375 bool EventRewriter::IsHotrodRemote() const { |
| 419 return IsLastKeyboardOfType(kDeviceHotrodRemote); | 376 return IsLastKeyboardOfType(kDeviceHotrodRemote); |
| 420 } | 377 } |
| 421 | 378 |
| 422 bool EventRewriter::IsLastKeyboardOfType(DeviceType device_type) const { | 379 bool EventRewriter::IsLastKeyboardOfType(DeviceType device_type) const { |
| 423 if (last_keyboard_device_id_ == ui::ED_UNKNOWN_DEVICE) | 380 if (last_keyboard_device_id_ == ui::ED_UNKNOWN_DEVICE) |
| 424 return false; | 381 return false; |
| 425 | 382 |
| 426 // Check which device generated |event|. | 383 // Check which device generated |event|. |
| 427 std::map<int, DeviceType>::const_iterator iter = | 384 std::map<int, DeviceType>::const_iterator iter = |
| 428 device_id_to_type_.find(last_keyboard_device_id_); | 385 device_id_to_type_.find(last_keyboard_device_id_); |
| 429 if (iter == device_id_to_type_.end()) { | 386 if (iter == device_id_to_type_.end()) { |
| 430 LOG(ERROR) << "Device ID " << last_keyboard_device_id_ << " is unknown."; | 387 LOG(ERROR) << "Device ID " << last_keyboard_device_id_ << " is unknown."; |
| 431 return false; | 388 return false; |
| 432 } | 389 } |
| 433 | 390 |
| 434 const DeviceType type = iter->second; | 391 const DeviceType type = iter->second; |
| 435 return type == device_type; | 392 return type == device_type; |
| 436 } | 393 } |
| 437 | 394 |
| 438 bool EventRewriter::TopRowKeysAreFunctionKeys(const ui::KeyEvent& event) const { | 395 int EventRewriter::GetRemappedModifierMasks(const ui::Event& event, |
| 439 const PrefService* prefs = GetPrefService(); | |
| 440 return prefs && prefs->FindPreference(prefs::kLanguageSendFunctionKeys) && | |
| 441 prefs->GetBoolean(prefs::kLanguageSendFunctionKeys); | |
| 442 } | |
| 443 | |
| 444 int EventRewriter::GetRemappedModifierMasks(const PrefService& pref_service, | |
| 445 const ui::Event& event, | |
| 446 int original_flags) const { | 396 int original_flags) const { |
| 447 int unmodified_flags = original_flags; | 397 int unmodified_flags = original_flags; |
| 448 int rewritten_flags = pressed_modifier_latches_ | latched_modifier_latches_; | 398 int rewritten_flags = pressed_modifier_latches_ | latched_modifier_latches_; |
| 449 for (size_t i = 0; unmodified_flags && (i < arraysize(kModifierRemappings)); | 399 for (size_t i = 0; unmodified_flags && (i < arraysize(kModifierRemappings)); |
| 450 ++i) { | 400 ++i) { |
| 451 const ModifierRemapping* remapped_key = NULL; | 401 const ModifierRemapping* remapped_key = NULL; |
| 452 if (!(unmodified_flags & kModifierRemappings[i].flag)) | 402 if (!(unmodified_flags & kModifierRemappings[i].flag)) |
| 453 continue; | 403 continue; |
| 454 switch (kModifierRemappings[i].flag) { | 404 switch (kModifierRemappings[i].flag) { |
| 455 case ui::EF_COMMAND_DOWN: | 405 case ui::EF_COMMAND_DOWN: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 474 if ((original_flags & ui::EF_ALTGR_DOWN) && | 424 if ((original_flags & ui::EF_ALTGR_DOWN) && |
| 475 IsISOLevel5ShiftUsedByCurrentInputMethod()) { | 425 IsISOLevel5ShiftUsedByCurrentInputMethod()) { |
| 476 remapped_key = kModifierRemappingNeoMod3; | 426 remapped_key = kModifierRemappingNeoMod3; |
| 477 } | 427 } |
| 478 break; | 428 break; |
| 479 default: | 429 default: |
| 480 break; | 430 break; |
| 481 } | 431 } |
| 482 if (!remapped_key && kModifierRemappings[i].pref_name) { | 432 if (!remapped_key && kModifierRemappings[i].pref_name) { |
| 483 remapped_key = | 433 remapped_key = |
| 484 GetRemappedKey(kModifierRemappings[i].pref_name, pref_service); | 434 GetRemappedKey(kModifierRemappings[i].pref_name, delegate_); |
| 485 } | 435 } |
| 486 if (remapped_key) { | 436 if (remapped_key) { |
| 487 unmodified_flags &= ~kModifierRemappings[i].flag; | 437 unmodified_flags &= ~kModifierRemappings[i].flag; |
| 488 rewritten_flags |= remapped_key->flag; | 438 rewritten_flags |= remapped_key->flag; |
| 489 } | 439 } |
| 490 } | 440 } |
| 491 return rewritten_flags | unmodified_flags; | 441 return rewritten_flags | unmodified_flags; |
| 492 } | 442 } |
| 493 | 443 |
| 494 ui::EventRewriteStatus EventRewriter::RewriteKeyEvent( | 444 ui::EventRewriteStatus EventRewriter::RewriteKeyEvent( |
| 495 const ui::KeyEvent& key_event, | 445 const ui::KeyEvent& key_event, |
| 496 std::unique_ptr<ui::Event>* rewritten_event) { | 446 std::unique_ptr<ui::Event>* rewritten_event) { |
| 497 if (IsExtensionCommandRegistered(key_event.key_code(), key_event.flags())) | 447 if (delegate_ && delegate_->IsExtensionCommandRegistered(key_event.key_code(), |
| 448 key_event.flags())) | |
| 498 return ui::EVENT_REWRITE_CONTINUE; | 449 return ui::EVENT_REWRITE_CONTINUE; |
| 499 if (key_event.source_device_id() != ui::ED_UNKNOWN_DEVICE) | 450 if (key_event.source_device_id() != ui::ED_UNKNOWN_DEVICE) |
| 500 DeviceKeyPressedOrReleased(key_event.source_device_id()); | 451 DeviceKeyPressedOrReleased(key_event.source_device_id()); |
| 501 | 452 |
| 502 // Drop repeated keys from Hotrod remote. | 453 // Drop repeated keys from Hotrod remote. |
| 503 if ((key_event.flags() & ui::EF_IS_REPEAT) && | 454 if ((key_event.flags() & ui::EF_IS_REPEAT) && |
| 504 (key_event.type() == ui::ET_KEY_PRESSED) && IsHotrodRemote() && | 455 (key_event.type() == ui::ET_KEY_PRESSED) && IsHotrodRemote() && |
| 505 key_event.key_code() != ui::VKEY_BACK) { | 456 key_event.key_code() != ui::VKEY_BACK) { |
| 506 return ui::EVENT_REWRITE_DISCARD; | 457 return ui::EVENT_REWRITE_DISCARD; |
| 507 } | 458 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 521 } | 472 } |
| 522 | 473 |
| 523 ui::EventRewriteStatus status = ui::EVENT_REWRITE_CONTINUE; | 474 ui::EventRewriteStatus status = ui::EVENT_REWRITE_CONTINUE; |
| 524 bool is_sticky_key_extension_command = false; | 475 bool is_sticky_key_extension_command = false; |
| 525 if (sticky_keys_controller_) { | 476 if (sticky_keys_controller_) { |
| 526 status = sticky_keys_controller_->RewriteKeyEvent(key_event, state.key_code, | 477 status = sticky_keys_controller_->RewriteKeyEvent(key_event, state.key_code, |
| 527 &state.flags); | 478 &state.flags); |
| 528 if (status == ui::EVENT_REWRITE_DISCARD) | 479 if (status == ui::EVENT_REWRITE_DISCARD) |
| 529 return ui::EVENT_REWRITE_DISCARD; | 480 return ui::EVENT_REWRITE_DISCARD; |
| 530 is_sticky_key_extension_command = | 481 is_sticky_key_extension_command = |
| 531 IsExtensionCommandRegistered(state.key_code, state.flags); | 482 delegate_ && |
| 483 delegate_->IsExtensionCommandRegistered(state.key_code, state.flags); | |
| 532 } | 484 } |
| 533 | 485 |
| 534 // If flags have changed, this may change the interpretation of the key, | 486 // If flags have changed, this may change the interpretation of the key, |
| 535 // so reapply layout. | 487 // so reapply layout. |
| 536 if (state.flags != key_event.flags()) | 488 if (state.flags != key_event.flags()) |
| 537 SetMeaningForLayout(key_event.type(), &state); | 489 SetMeaningForLayout(key_event.type(), &state); |
| 538 | 490 |
| 539 // If sticky key rewrites the event, and it matches an extension command, do | 491 // If sticky key rewrites the event, and it matches an extension command, do |
| 540 // not further rewrite the event since it won't match the extension command | 492 // not further rewrite the event since it won't match the extension command |
| 541 // thereafter. | 493 // thereafter. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 ui::UpdateX11EventForFlags(rewritten_scroll_event); | 610 ui::UpdateX11EventForFlags(rewritten_scroll_event); |
| 659 #endif | 611 #endif |
| 660 return status; | 612 return status; |
| 661 } | 613 } |
| 662 | 614 |
| 663 bool EventRewriter::RewriteModifierKeys(const ui::KeyEvent& key_event, | 615 bool EventRewriter::RewriteModifierKeys(const ui::KeyEvent& key_event, |
| 664 MutableKeyState* state) { | 616 MutableKeyState* state) { |
| 665 DCHECK(key_event.type() == ui::ET_KEY_PRESSED || | 617 DCHECK(key_event.type() == ui::ET_KEY_PRESSED || |
| 666 key_event.type() == ui::ET_KEY_RELEASED); | 618 key_event.type() == ui::ET_KEY_RELEASED); |
| 667 | 619 |
| 668 // Do nothing if we have just logged in as guest but have not restarted chrome | 620 if (!delegate_ || !delegate_->RewriteModifierKeys()) |
| 669 // process yet (so we are still on the login screen). In this situations we | |
| 670 // have no user profile so can not do anything useful. | |
| 671 // Note that currently, unlike other accounts, when user logs in as guest, we | |
| 672 // restart chrome process. In future this is to be changed. | |
| 673 // TODO(glotov): remove the following condition when we do not restart chrome | |
| 674 // when user logs in as guest. | |
| 675 // TODO(kpschoedel): check whether this is still necessary. | |
| 676 if (user_manager::UserManager::Get()->IsLoggedInAsGuest() && | |
| 677 LoginDisplayHost::default_host()) | |
| 678 return false; | |
| 679 | |
| 680 const PrefService* pref_service = GetPrefService(); | |
| 681 if (!pref_service) | |
| 682 return false; | 621 return false; |
| 683 | 622 |
| 684 // Preserve a copy of the original before rewriting |state| based on | 623 // Preserve a copy of the original before rewriting |state| based on |
| 685 // user preferences, device configuration, and certain IME properties. | 624 // user preferences, device configuration, and certain IME properties. |
| 686 MutableKeyState incoming = *state; | 625 MutableKeyState incoming = *state; |
| 687 state->flags = ui::EF_NONE; | 626 state->flags = ui::EF_NONE; |
| 688 int characteristic_flag = ui::EF_NONE; | 627 int characteristic_flag = ui::EF_NONE; |
| 689 bool exact_event = false; | 628 bool exact_event = false; |
| 690 | 629 |
| 691 // First, remap the key code. | 630 // First, remap the key code. |
| 692 const ModifierRemapping* remapped_key = NULL; | 631 const ModifierRemapping* remapped_key = NULL; |
| 693 // Remapping based on DomKey. | 632 // Remapping based on DomKey. |
| 694 switch (incoming.key) { | 633 switch (incoming.key) { |
| 695 // On Chrome OS, F15 (XF86XK_Launch6) with NumLock (Mod2Mask) is sent | 634 // On Chrome OS, F15 (XF86XK_Launch6) with NumLock (Mod2Mask) is sent |
| 696 // when Diamond key is pressed. | 635 // when Diamond key is pressed. |
| 697 case ui::DomKey::F15: | 636 case ui::DomKey::F15: |
| 698 // When diamond key is not available, the configuration UI for Diamond | 637 // When diamond key is not available, the configuration UI for Diamond |
| 699 // key is not shown. Therefore, ignore the kLanguageRemapDiamondKeyTo | 638 // key is not shown. Therefore, ignore the kLanguageRemapDiamondKeyTo |
| 700 // syncable pref. | 639 // syncable pref. |
| 701 if (HasDiamondKey()) | 640 if (HasDiamondKey()) |
| 702 remapped_key = | 641 remapped_key = |
| 703 GetRemappedKey(prefs::kLanguageRemapDiamondKeyTo, *pref_service); | 642 GetRemappedKey(prefs::kLanguageRemapDiamondKeyTo, delegate_); |
| 704 // Default behavior of F15 is Control, even if --has-chromeos-diamond-key | 643 // Default behavior of F15 is Control, even if --has-chromeos-diamond-key |
| 705 // is absent, according to unit test comments. | 644 // is absent, according to unit test comments. |
| 706 if (!remapped_key) { | 645 if (!remapped_key) { |
| 707 DCHECK_EQ(ui::VKEY_CONTROL, kModifierRemappingCtrl->result.key_code); | 646 DCHECK_EQ(ui::VKEY_CONTROL, kModifierRemappingCtrl->result.key_code); |
| 708 remapped_key = kModifierRemappingCtrl; | 647 remapped_key = kModifierRemappingCtrl; |
| 709 } | 648 } |
| 710 break; | 649 break; |
| 711 case ui::DomKey::ALT_GRAPH: | 650 case ui::DomKey::ALT_GRAPH: |
| 712 // The Neo2 codes modifiers such that CapsLock appears as VKEY_ALTGR, | 651 // The Neo2 codes modifiers such that CapsLock appears as VKEY_ALTGR, |
| 713 // but AltGraph (right Alt) also appears as VKEY_ALTGR in Neo2, | 652 // but AltGraph (right Alt) also appears as VKEY_ALTGR in Neo2, |
| 714 // as it does in other layouts. Neo2's "Mod3" is represented in | 653 // as it does in other layouts. Neo2's "Mod3" is represented in |
| 715 // EventFlags by a combination of AltGr+Mod3, while its "Mod4" is | 654 // EventFlags by a combination of AltGr+Mod3, while its "Mod4" is |
| 716 // AltGr alone. | 655 // AltGr alone. |
| 717 if (IsISOLevel5ShiftUsedByCurrentInputMethod()) { | 656 if (IsISOLevel5ShiftUsedByCurrentInputMethod()) { |
| 718 if (incoming.code == ui::DomCode::CAPS_LOCK) { | 657 if (incoming.code == ui::DomCode::CAPS_LOCK) { |
| 719 characteristic_flag = ui::EF_ALTGR_DOWN | ui::EF_MOD3_DOWN; | 658 characteristic_flag = ui::EF_ALTGR_DOWN | ui::EF_MOD3_DOWN; |
| 720 remapped_key = | 659 remapped_key = |
| 721 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); | 660 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, delegate_); |
| 722 } else { | 661 } else { |
| 723 characteristic_flag = ui::EF_ALTGR_DOWN; | 662 characteristic_flag = ui::EF_ALTGR_DOWN; |
| 724 remapped_key = | 663 remapped_key = |
| 725 GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, *pref_service); | 664 GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, delegate_); |
| 726 } | 665 } |
| 727 } | 666 } |
| 728 if (remapped_key && remapped_key->result.key_code == ui::VKEY_CAPITAL) | 667 if (remapped_key && remapped_key->result.key_code == ui::VKEY_CAPITAL) |
| 729 remapped_key = kModifierRemappingNeoMod3; | 668 remapped_key = kModifierRemappingNeoMod3; |
| 730 break; | 669 break; |
| 731 #if !defined(USE_X11) | 670 #if !defined(USE_X11) |
| 732 case ui::DomKey::ALT_GRAPH_LATCH: | 671 case ui::DomKey::ALT_GRAPH_LATCH: |
| 733 if (key_event.type() == ui::ET_KEY_PRESSED) { | 672 if (key_event.type() == ui::ET_KEY_PRESSED) { |
| 734 pressed_modifier_latches_ |= ui::EF_ALTGR_DOWN; | 673 pressed_modifier_latches_ |= ui::EF_ALTGR_DOWN; |
| 735 } else { | 674 } else { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 756 // Remapping based on DomCode. | 695 // Remapping based on DomCode. |
| 757 switch (incoming.code) { | 696 switch (incoming.code) { |
| 758 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock | 697 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock |
| 759 // is pressed (with one exception: when | 698 // is pressed (with one exception: when |
| 760 // IsISOLevel5ShiftUsedByCurrentInputMethod() is true, the key generates | 699 // IsISOLevel5ShiftUsedByCurrentInputMethod() is true, the key generates |
| 761 // XK_ISO_Level3_Shift with Mod3Mask, not XF86XK_Launch7). | 700 // XK_ISO_Level3_Shift with Mod3Mask, not XF86XK_Launch7). |
| 762 case ui::DomCode::F16: | 701 case ui::DomCode::F16: |
| 763 case ui::DomCode::CAPS_LOCK: | 702 case ui::DomCode::CAPS_LOCK: |
| 764 characteristic_flag = ui::EF_CAPS_LOCK_ON; | 703 characteristic_flag = ui::EF_CAPS_LOCK_ON; |
| 765 remapped_key = | 704 remapped_key = |
| 766 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); | 705 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, delegate_); |
| 767 break; | 706 break; |
| 768 case ui::DomCode::META_LEFT: | 707 case ui::DomCode::META_LEFT: |
| 769 case ui::DomCode::META_RIGHT: | 708 case ui::DomCode::META_RIGHT: |
| 770 characteristic_flag = ui::EF_COMMAND_DOWN; | 709 characteristic_flag = ui::EF_COMMAND_DOWN; |
| 771 // Rewrite Command-L/R key presses on an Apple keyboard to Control. | 710 // Rewrite Command-L/R key presses on an Apple keyboard to Control. |
| 772 if (IsAppleKeyboard()) { | 711 if (IsAppleKeyboard()) { |
| 773 DCHECK_EQ(ui::VKEY_CONTROL, kModifierRemappingCtrl->result.key_code); | 712 DCHECK_EQ(ui::VKEY_CONTROL, kModifierRemappingCtrl->result.key_code); |
| 774 remapped_key = kModifierRemappingCtrl; | 713 remapped_key = kModifierRemappingCtrl; |
| 775 } else { | 714 } else { |
| 776 remapped_key = | 715 remapped_key = |
| 777 GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, *pref_service); | 716 GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, delegate_); |
| 778 } | 717 } |
| 779 // Default behavior is Super key, hence don't remap the event if the pref | 718 // Default behavior is Super key, hence don't remap the event if the pref |
| 780 // is unavailable. | 719 // is unavailable. |
| 781 break; | 720 break; |
| 782 case ui::DomCode::CONTROL_LEFT: | 721 case ui::DomCode::CONTROL_LEFT: |
| 783 case ui::DomCode::CONTROL_RIGHT: | 722 case ui::DomCode::CONTROL_RIGHT: |
| 784 characteristic_flag = ui::EF_CONTROL_DOWN; | 723 characteristic_flag = ui::EF_CONTROL_DOWN; |
| 785 remapped_key = | 724 remapped_key = |
| 786 GetRemappedKey(prefs::kLanguageRemapControlKeyTo, *pref_service); | 725 GetRemappedKey(prefs::kLanguageRemapControlKeyTo, delegate_); |
| 787 break; | 726 break; |
| 788 case ui::DomCode::ALT_LEFT: | 727 case ui::DomCode::ALT_LEFT: |
| 789 case ui::DomCode::ALT_RIGHT: | 728 case ui::DomCode::ALT_RIGHT: |
| 790 // ALT key | 729 // ALT key |
| 791 characteristic_flag = ui::EF_ALT_DOWN; | 730 characteristic_flag = ui::EF_ALT_DOWN; |
| 792 remapped_key = | 731 remapped_key = GetRemappedKey(prefs::kLanguageRemapAltKeyTo, delegate_); |
| 793 GetRemappedKey(prefs::kLanguageRemapAltKeyTo, *pref_service); | |
| 794 break; | 732 break; |
| 795 case ui::DomCode::ESCAPE: | 733 case ui::DomCode::ESCAPE: |
| 796 remapped_key = | 734 remapped_key = |
| 797 GetRemappedKey(prefs::kLanguageRemapEscapeKeyTo, *pref_service); | 735 GetRemappedKey(prefs::kLanguageRemapEscapeKeyTo, delegate_); |
| 798 break; | 736 break; |
| 799 case ui::DomCode::BACKSPACE: | 737 case ui::DomCode::BACKSPACE: |
| 800 remapped_key = | 738 remapped_key = |
| 801 GetRemappedKey(prefs::kLanguageRemapBackspaceKeyTo, *pref_service); | 739 GetRemappedKey(prefs::kLanguageRemapBackspaceKeyTo, delegate_); |
| 802 break; | 740 break; |
| 803 default: | 741 default: |
| 804 break; | 742 break; |
| 805 } | 743 } |
| 806 | 744 |
| 807 if (remapped_key) { | 745 if (remapped_key) { |
| 808 state->key_code = remapped_key->result.key_code; | 746 state->key_code = remapped_key->result.key_code; |
| 809 state->code = remapped_key->result.code; | 747 state->code = remapped_key->result.code; |
| 810 state->key = remapped_key->result.key; | 748 state->key = remapped_key->result.key; |
| 811 incoming.flags |= characteristic_flag; | 749 incoming.flags |= characteristic_flag; |
| 812 characteristic_flag = remapped_key->flag; | 750 characteristic_flag = remapped_key->flag; |
| 813 if (remapped_key->remap_to == input_method::kCapsLockKey) | 751 if (remapped_key->remap_to == ::chromeos::input_method::kCapsLockKey) |
| 814 characteristic_flag |= ui::EF_CAPS_LOCK_ON; | 752 characteristic_flag |= ui::EF_CAPS_LOCK_ON; |
| 815 state->code = RelocateModifier( | 753 state->code = RelocateModifier( |
| 816 state->code, ui::KeycodeConverter::DomCodeToLocation(incoming.code)); | 754 state->code, ui::KeycodeConverter::DomCodeToLocation(incoming.code)); |
| 817 } | 755 } |
| 818 | 756 |
| 819 // Next, remap modifier bits. | 757 // Next, remap modifier bits. |
| 820 state->flags |= | 758 state->flags |= GetRemappedModifierMasks(key_event, incoming.flags); |
| 821 GetRemappedModifierMasks(*pref_service, key_event, incoming.flags); | |
| 822 | 759 |
| 823 // If the DomKey is not a modifier before remapping but is after, set the | 760 // If the DomKey is not a modifier before remapping but is after, set the |
| 824 // modifier latches for the later non-modifier key's modifier states. | 761 // modifier latches for the later non-modifier key's modifier states. |
| 825 bool non_modifier_to_modifier = | 762 bool non_modifier_to_modifier = |
| 826 !ui::KeycodeConverter::IsDomKeyForModifier(incoming.key) && | 763 !ui::KeycodeConverter::IsDomKeyForModifier(incoming.key) && |
| 827 ui::KeycodeConverter::IsDomKeyForModifier(state->key); | 764 ui::KeycodeConverter::IsDomKeyForModifier(state->key); |
| 828 if (key_event.type() == ui::ET_KEY_PRESSED) { | 765 if (key_event.type() == ui::ET_KEY_PRESSED) { |
| 829 state->flags |= characteristic_flag; | 766 state->flags |= characteristic_flag; |
| 830 if (non_modifier_to_modifier) | 767 if (non_modifier_to_modifier) |
| 831 pressed_modifier_latches_ |= characteristic_flag; | 768 pressed_modifier_latches_ |= characteristic_flag; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 844 if (state->key_code == ui::VKEY_CAPITAL | 781 if (state->key_code == ui::VKEY_CAPITAL |
| 845 // ... except on linux Chrome OS, where InputMethodChromeOS handles it. | 782 // ... except on linux Chrome OS, where InputMethodChromeOS handles it. |
| 846 && (base::SysInfo::IsRunningOnChromeOS() || ime_keyboard_for_testing_) | 783 && (base::SysInfo::IsRunningOnChromeOS() || ime_keyboard_for_testing_) |
| 847 #if defined(USE_X11) | 784 #if defined(USE_X11) |
| 848 // ... but for X11, do nothing if the original key is ui::VKEY_CAPITAL | 785 // ... but for X11, do nothing if the original key is ui::VKEY_CAPITAL |
| 849 // (i.e. a Caps Lock key on an external keyboard is pressed) since X | 786 // (i.e. a Caps Lock key on an external keyboard is pressed) since X |
| 850 // handles that itself. | 787 // handles that itself. |
| 851 && incoming.key_code != ui::VKEY_CAPITAL | 788 && incoming.key_code != ui::VKEY_CAPITAL |
| 852 #endif | 789 #endif |
| 853 ) { | 790 ) { |
| 854 chromeos::input_method::ImeKeyboard* ime_keyboard = | 791 ::chromeos::input_method::ImeKeyboard* ime_keyboard = |
| 855 ime_keyboard_for_testing_ | 792 ime_keyboard_for_testing_ |
| 856 ? ime_keyboard_for_testing_ | 793 ? ime_keyboard_for_testing_ |
| 857 : chromeos::input_method::InputMethodManager::Get() | 794 : ::chromeos::input_method::InputMethodManager::Get() |
| 858 ->GetImeKeyboard(); | 795 ->GetImeKeyboard(); |
| 859 ime_keyboard->SetCapsLockEnabled(!ime_keyboard->CapsLockIsEnabled()); | 796 ime_keyboard->SetCapsLockEnabled(!ime_keyboard->CapsLockIsEnabled()); |
| 860 } | 797 } |
| 861 } | 798 } |
| 862 return exact_event; | 799 return exact_event; |
| 863 } | 800 } |
| 864 | 801 |
| 865 void EventRewriter::RewriteNumPadKeys(const ui::KeyEvent& key_event, | 802 void EventRewriter::RewriteNumPadKeys(const ui::KeyEvent& key_event, |
| 866 MutableKeyState* state) { | 803 MutableKeyState* state) { |
| 867 DCHECK(key_event.type() == ui::ET_KEY_PRESSED || | 804 DCHECK(key_event.type() == ui::ET_KEY_PRESSED || |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1003 | 940 |
| 1004 void EventRewriter::RewriteFunctionKeys(const ui::KeyEvent& key_event, | 941 void EventRewriter::RewriteFunctionKeys(const ui::KeyEvent& key_event, |
| 1005 MutableKeyState* state) { | 942 MutableKeyState* state) { |
| 1006 CHECK(key_event.type() == ui::ET_KEY_PRESSED || | 943 CHECK(key_event.type() == ui::ET_KEY_PRESSED || |
| 1007 key_event.type() == ui::ET_KEY_RELEASED); | 944 key_event.type() == ui::ET_KEY_RELEASED); |
| 1008 | 945 |
| 1009 if ((state->key_code >= ui::VKEY_F1) && (state->key_code <= ui::VKEY_F12)) { | 946 if ((state->key_code >= ui::VKEY_F1) && (state->key_code <= ui::VKEY_F12)) { |
| 1010 // By default the top row (F1-F12) keys are system keys for back, forward, | 947 // By default the top row (F1-F12) keys are system keys for back, forward, |
| 1011 // brightness, volume, etc. However, windows for v2 apps can optionally | 948 // brightness, volume, etc. However, windows for v2 apps can optionally |
| 1012 // request raw function keys for these keys. | 949 // request raw function keys for these keys. |
| 1013 bool top_row_keys_are_function_keys = TopRowKeysAreFunctionKeys(key_event); | 950 const bool top_row_keys_are_function_keys = |
| 1014 bool search_is_pressed = (state->flags & ui::EF_COMMAND_DOWN) != 0; | 951 delegate_ && delegate_->TopRowKeysAreFunctionKeys(); |
| 952 const bool search_is_pressed = (state->flags & ui::EF_COMMAND_DOWN) != 0; | |
| 1015 | 953 |
| 1016 // Search? Top Row Result | 954 // Search? Top Row Result |
| 1017 // ------- -------- ------ | 955 // ------- -------- ------ |
| 1018 // No Fn Unchanged | 956 // No Fn Unchanged |
| 1019 // No System Fn -> System | 957 // No System Fn -> System |
| 1020 // Yes Fn Fn -> System | 958 // Yes Fn Fn -> System |
| 1021 // Yes System Search+Fn -> Fn | 959 // Yes System Search+Fn -> Fn |
| 1022 if (top_row_keys_are_function_keys == search_is_pressed) { | 960 if (top_row_keys_are_function_keys == search_is_pressed) { |
| 1023 // Rewrite the F1-F12 keys on a Chromebook keyboard to system keys. | 961 // Rewrite the F1-F12 keys on a Chromebook keyboard to system keys. |
| 1024 static const KeyboardRemapping kFkeysToSystemKeys[] = { | 962 static const KeyboardRemapping kFkeysToSystemKeys[] = { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1103 if (state->code == map.input_dom_code) { | 1041 if (state->code == map.input_dom_code) { |
| 1104 state->flags &= ~ui::EF_COMMAND_DOWN; | 1042 state->flags &= ~ui::EF_COMMAND_DOWN; |
| 1105 ApplyRemapping(map.result, state); | 1043 ApplyRemapping(map.result, state); |
| 1106 return; | 1044 return; |
| 1107 } | 1045 } |
| 1108 } | 1046 } |
| 1109 } | 1047 } |
| 1110 } | 1048 } |
| 1111 | 1049 |
| 1112 void EventRewriter::RewriteLocatedEvent(const ui::Event& event, int* flags) { | 1050 void EventRewriter::RewriteLocatedEvent(const ui::Event& event, int* flags) { |
| 1113 const PrefService* pref_service = GetPrefService(); | 1051 if (!delegate_) |
| 1114 if (!pref_service) | |
| 1115 return; | 1052 return; |
| 1116 *flags = GetRemappedModifierMasks(*pref_service, event, *flags); | 1053 *flags = GetRemappedModifierMasks(event, *flags); |
| 1117 } | 1054 } |
| 1118 | 1055 |
| 1119 int EventRewriter::RewriteModifierClick(const ui::MouseEvent& mouse_event, | 1056 int EventRewriter::RewriteModifierClick(const ui::MouseEvent& mouse_event, |
| 1120 int* flags) { | 1057 int* flags) { |
| 1121 // Remap Alt+Button1 to Button3. | 1058 // Remap Alt+Button1 to Button3. |
| 1122 const int kAltLeftButton = (ui::EF_ALT_DOWN | ui::EF_LEFT_MOUSE_BUTTON); | 1059 const int kAltLeftButton = (ui::EF_ALT_DOWN | ui::EF_LEFT_MOUSE_BUTTON); |
| 1123 if (((*flags & kAltLeftButton) == kAltLeftButton) && | 1060 if (((*flags & kAltLeftButton) == kAltLeftButton) && |
| 1124 ((mouse_event.type() == ui::ET_MOUSE_PRESSED) || | 1061 ((mouse_event.type() == ui::ET_MOUSE_PRESSED) || |
| 1125 pressed_device_ids_.count(mouse_event.source_device_id()))) { | 1062 pressed_device_ids_.count(mouse_event.source_device_id()))) { |
| 1126 *flags &= ~kAltLeftButton; | 1063 *flags &= ~kAltLeftButton; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1167 for (const auto& keyboard : keyboard_devices) { | 1104 for (const auto& keyboard : keyboard_devices) { |
| 1168 if (keyboard.id == device_id) { | 1105 if (keyboard.id == device_id) { |
| 1169 return KeyboardDeviceAddedInternal( | 1106 return KeyboardDeviceAddedInternal( |
| 1170 keyboard.id, keyboard.name, keyboard.vendor_id, keyboard.product_id); | 1107 keyboard.id, keyboard.name, keyboard.vendor_id, keyboard.product_id); |
| 1171 } | 1108 } |
| 1172 } | 1109 } |
| 1173 return kDeviceUnknown; | 1110 return kDeviceUnknown; |
| 1174 } | 1111 } |
| 1175 | 1112 |
| 1176 } // namespace chromeos | 1113 } // namespace chromeos |
| 1114 } // namespace ui | |
| OLD | NEW |