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 "chrome/browser/chromeos/events/event_rewriter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/sticky_keys/sticky_keys_controller.h" | 9 #include "ash/sticky_keys/sticky_keys_controller.h" |
10 #include "ash/wm/window_state.h" | 10 #include "ash/wm/window_state.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 bool IsISOLevel5ShiftUsedByCurrentInputMethod() { | 98 bool IsISOLevel5ShiftUsedByCurrentInputMethod() { |
99 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, | 99 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, |
100 // it's not possible to make both features work. For now, we don't remap | 100 // it's not possible to make both features work. For now, we don't remap |
101 // Mod3Mask when Neo2 is in use. | 101 // Mod3Mask when Neo2 is in use. |
102 // TODO(yusukes): Remove the restriction. | 102 // TODO(yusukes): Remove the restriction. |
103 input_method::InputMethodManager* manager = | 103 input_method::InputMethodManager* manager = |
104 input_method::InputMethodManager::Get(); | 104 input_method::InputMethodManager::Get(); |
105 return manager->IsISOLevel5ShiftUsedByCurrentInputMethod(); | 105 return manager->IsISOLevel5ShiftUsedByCurrentInputMethod(); |
106 } | 106 } |
107 | 107 |
108 bool IsExtensionCommandRegistered(const ui::KeyEvent& key_event) { | 108 bool IsExtensionCommandRegistered(ui::KeyboardCode key_code, int flags) { |
109 // Some keyboard events for ChromeOS get rewritten, such as: | 109 // Some keyboard events for ChromeOS get rewritten, such as: |
110 // Search+Shift+Left gets converted to Shift+Home (BeginDocument). | 110 // Search+Shift+Left gets converted to Shift+Home (BeginDocument). |
111 // This doesn't make sense if the user has assigned that shortcut | 111 // This doesn't make sense if the user has assigned that shortcut |
112 // to an extension. Because: | 112 // to an extension. Because: |
113 // 1) The extension would, upon seeing a request for Ctrl+Shift+Home have | 113 // 1) The extension would, upon seeing a request for Ctrl+Shift+Home have |
114 // to register for Shift+Home, instead. | 114 // to register for Shift+Home, instead. |
115 // 2) The conversion is unnecessary, because Shift+Home (BeginDocument) isn't | 115 // 2) The conversion is unnecessary, because Shift+Home (BeginDocument) isn't |
116 // going to be executed. | 116 // going to be executed. |
117 // Therefore, we skip converting the accelerator if an extension has | 117 // Therefore, we skip converting the accelerator if an extension has |
118 // registered for this shortcut. | 118 // registered for this shortcut. |
119 Profile* profile = ProfileManager::GetActiveUserProfile(); | 119 Profile* profile = ProfileManager::GetActiveUserProfile(); |
120 if (!profile || !extensions::ExtensionCommandsGlobalRegistry::Get(profile)) | 120 if (!profile || !extensions::ExtensionCommandsGlobalRegistry::Get(profile)) |
121 return false; | 121 return false; |
122 | 122 |
123 int modifiers = key_event.flags() & (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | | 123 int modifiers = flags & (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | |
124 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN); | 124 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN); |
125 ui::Accelerator accelerator(key_event.key_code(), modifiers); | 125 ui::Accelerator accelerator(key_code, modifiers); |
126 return extensions::ExtensionCommandsGlobalRegistry::Get(profile) | 126 return extensions::ExtensionCommandsGlobalRegistry::Get(profile) |
127 ->IsRegistered(accelerator); | 127 ->IsRegistered(accelerator); |
128 } | 128 } |
129 | 129 |
130 EventRewriter::DeviceType GetDeviceType(const std::string& device_name) { | 130 EventRewriter::DeviceType GetDeviceType(const std::string& device_name) { |
131 std::vector<std::string> tokens; | 131 std::vector<std::string> tokens; |
132 Tokenize(device_name, " .", &tokens); | 132 Tokenize(device_name, " .", &tokens); |
133 | 133 |
134 // If the |device_name| contains the two words, "apple" and "keyboard", treat | 134 // If the |device_name| contains the two words, "apple" and "keyboard", treat |
135 // it as an Apple keyboard. | 135 // it as an Apple keyboard. |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 remapped_state->key_code = map.output_key_code; | 376 remapped_state->key_code = map.output_key_code; |
377 remapped_state->flags = (input.flags & ~map.input_flags) | map.output_flags; | 377 remapped_state->flags = (input.flags & ~map.input_flags) | map.output_flags; |
378 return true; | 378 return true; |
379 } | 379 } |
380 return false; | 380 return false; |
381 } | 381 } |
382 | 382 |
383 ui::EventRewriteStatus EventRewriter::RewriteKeyEvent( | 383 ui::EventRewriteStatus EventRewriter::RewriteKeyEvent( |
384 const ui::KeyEvent& key_event, | 384 const ui::KeyEvent& key_event, |
385 scoped_ptr<ui::Event>* rewritten_event) { | 385 scoped_ptr<ui::Event>* rewritten_event) { |
386 if (IsExtensionCommandRegistered(key_event)) | 386 if (IsExtensionCommandRegistered(key_event.key_code(), key_event.flags())) |
387 return ui::EVENT_REWRITE_CONTINUE; | 387 return ui::EVENT_REWRITE_CONTINUE; |
388 if (key_event.source_device_id() != ui::ED_UNKNOWN_DEVICE) | 388 if (key_event.source_device_id() != ui::ED_UNKNOWN_DEVICE) |
389 DeviceKeyPressedOrReleased(key_event.source_device_id()); | 389 DeviceKeyPressedOrReleased(key_event.source_device_id()); |
390 MutableKeyState state = {key_event.flags(), key_event.key_code()}; | 390 MutableKeyState state = {key_event.flags(), key_event.key_code()}; |
391 // Do not rewrite an event sent by ui_controls::SendKeyPress(). See | 391 // Do not rewrite an event sent by ui_controls::SendKeyPress(). See |
392 // crbug.com/136465. | 392 // crbug.com/136465. |
393 if (!(key_event.flags() & ui::EF_FINAL)) { | 393 if (!(key_event.flags() & ui::EF_FINAL)) { |
394 RewriteModifierKeys(key_event, &state); | 394 RewriteModifierKeys(key_event, &state); |
395 RewriteNumPadKeys(key_event, &state); | 395 RewriteNumPadKeys(key_event, &state); |
396 } | 396 } |
397 ui::EventRewriteStatus status = ui::EVENT_REWRITE_CONTINUE; | 397 ui::EventRewriteStatus status = ui::EVENT_REWRITE_CONTINUE; |
398 bool is_sticky_key_extension_command = false; | |
398 if (sticky_keys_controller_) { | 399 if (sticky_keys_controller_) { |
399 status = sticky_keys_controller_->RewriteKeyEvent( | 400 status = sticky_keys_controller_->RewriteKeyEvent( |
400 key_event, state.key_code, &state.flags); | 401 key_event, state.key_code, &state.flags); |
402 is_sticky_key_extension_command = | |
403 IsExtensionCommandRegistered(state.key_code, state.flags); | |
Finnur
2014/09/24 10:48:41
This block should probably be below line 405.
David Tseng
2014/09/24 16:24:28
Done.
| |
401 if (status == ui::EVENT_REWRITE_DISCARD) | 404 if (status == ui::EVENT_REWRITE_DISCARD) |
402 return ui::EVENT_REWRITE_DISCARD; | 405 return ui::EVENT_REWRITE_DISCARD; |
403 } | 406 } |
407 // Only rewrite keys involving the search modifier if it has no extensions | |
408 // binding the command. | |
Finnur
2014/09/24 10:48:41
This comment seems a little out of place here. Why
David Tseng
2014/09/24 16:24:28
Was fixated on Search for the fix; rephrased to be
| |
409 if (!is_sticky_key_extension_command) { | |
404 if (!(key_event.flags() & ui::EF_FINAL)) { | 410 if (!(key_event.flags() & ui::EF_FINAL)) { |
Finnur
2014/09/24 10:48:41
The indentation here is now wrong, but we anyway p
David Tseng
2014/09/24 16:24:28
Done.
| |
405 RewriteExtendedKeys(key_event, &state); | 411 RewriteExtendedKeys(key_event, &state); |
406 RewriteFunctionKeys(key_event, &state); | 412 RewriteFunctionKeys(key_event, &state); |
407 } | 413 } |
414 } | |
408 if ((key_event.flags() == state.flags) && | 415 if ((key_event.flags() == state.flags) && |
409 (key_event.key_code() == state.key_code) && | 416 (key_event.key_code() == state.key_code) && |
410 #if defined(USE_X11) | 417 #if defined(USE_X11) |
411 // TODO(kpschoedel): This test is present because several consumers of | 418 // TODO(kpschoedel): This test is present because several consumers of |
412 // key events depend on having a native core X11 event, so we rewrite | 419 // key events depend on having a native core X11 event, so we rewrite |
413 // all XI2 key events (GenericEvent) into corresponding core X11 key | 420 // all XI2 key events (GenericEvent) into corresponding core X11 key |
414 // events. Remove this when event consumers no longer care about | 421 // events. Remove this when event consumers no longer care about |
415 // native X11 event details (crbug.com/380349). | 422 // native X11 event details (crbug.com/380349). |
416 (!key_event.HasNativeEvent() || | 423 (!key_event.HasNativeEvent() || |
417 (key_event.native_event()->type != GenericEvent)) && | 424 (key_event.native_event()->type != GenericEvent)) && |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
886 KeyboardDeviceAddedInternal(device_info[i].deviceid, device_info[i].name); | 893 KeyboardDeviceAddedInternal(device_info[i].deviceid, device_info[i].name); |
887 } | 894 } |
888 | 895 |
889 XIFreeDeviceInfo(device_info); | 896 XIFreeDeviceInfo(device_info); |
890 #else | 897 #else |
891 KeyboardDeviceAddedInternal(device_id, "keyboard"); | 898 KeyboardDeviceAddedInternal(device_id, "keyboard"); |
892 #endif | 899 #endif |
893 } | 900 } |
894 | 901 |
895 } // namespace chromeos | 902 } // namespace chromeos |
OLD | NEW |