summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshuchen <shuchen@chromium.org>2015-11-19 17:00:12 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-20 01:01:07 +0000
commit57a7c3e44caa988c3eb3186f40e63f4ac7037185 (patch)
tree3f5967989085385eb3a2f59509a8392312b63c52
parent045fda4cf9669c3eaeff905d3d6b3d2f8a878f01 (diff)
downloadchromium_src-57a7c3e44caa988c3eb3186f40e63f4ac7037185.zip
chromium_src-57a7c3e44caa988c3eb3186f40e63f4ac7037185.tar.gz
chromium_src-57a7c3e44caa988c3eb3186f40e63f4ac7037185.tar.bz2
Uses DomCode instead of DomKey to determine the rewrite of the modifier keys.
This is to make sure the remapping can take affect even the XKB layout remaps certain modifier keys. e.g. Colemak keyboard remap CAPS (scancode) to Backspace. BUG=215923 TEST=Search key accelerators (e.g. Search+L to lock screen) can work with Colemak keyboard. Review URL: https://codereview.chromium.org/1456163003 Cr-Commit-Position: refs/heads/master@{#360701}
-rw-r--r--chrome/browser/chromeos/events/event_rewriter.cc102
1 files changed, 56 insertions, 46 deletions
diff --git a/chrome/browser/chromeos/events/event_rewriter.cc b/chrome/browser/chromeos/events/event_rewriter.cc
index 7f6bf10..d1621b9c 100644
--- a/chrome/browser/chromeos/events/event_rewriter.cc
+++ b/chrome/browser/chromeos/events/event_rewriter.cc
@@ -673,10 +673,58 @@ bool EventRewriter::RewriteModifierKeys(const ui::KeyEvent& key_event,
// First, remap the key code.
const ModifierRemapping* remapped_key = NULL;
+ // Remapping based on DomKey.
switch (incoming.key) {
+ case ui::DomKey::ALT_GRAPH:
+ // The Neo2 codes modifiers such that CapsLock appears as VKEY_ALTGR,
+ // but AltGraph (right Alt) also appears as VKEY_ALTGR in Neo2,
+ // as it does in other layouts. Neo2's "Mod3" is represented in
+ // EventFlags by a combination of AltGr+Mod3, while its "Mod4" is
+ // AltGr alone.
+ if (IsISOLevel5ShiftUsedByCurrentInputMethod()) {
+ if (incoming.code == ui::DomCode::CAPS_LOCK) {
+ characteristic_flag = ui::EF_ALTGR_DOWN | ui::EF_MOD3_DOWN;
+ remapped_key =
+ GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service);
+ } else {
+ characteristic_flag = ui::EF_ALTGR_DOWN;
+ remapped_key =
+ GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, *pref_service);
+ }
+ }
+ if (remapped_key && remapped_key->result.key_code == ui::VKEY_CAPITAL)
+ remapped_key = kModifierRemappingNeoMod3;
+ break;
+#if !defined(USE_X11)
+ case ui::DomKey::ALT_GRAPH_LATCH:
+ if (key_event.type() == ui::ET_KEY_PRESSED) {
+ pressed_modifier_latches_ |= ui::EF_ALTGR_DOWN;
+ } else {
+ pressed_modifier_latches_ &= ~ui::EF_ALTGR_DOWN;
+ if (used_modifier_latches_ & ui::EF_ALTGR_DOWN)
+ used_modifier_latches_ &= ~ui::EF_ALTGR_DOWN;
+ else
+ latched_modifier_latches_ |= ui::EF_ALTGR_DOWN;
+ }
+ // Rewrite to AltGraph. When this key is used like a regular modifier,
+ // the web-exposed result looks like a use of the regular modifier.
+ // When it's used as a latch, the web-exposed result is a vacuous
+ // modifier press-and-release, which should be harmless, but preserves
+ // the event for applications using the |code| (e.g. remoting).
+ state->key = ui::DomKey::ALT_GRAPH;
+ state->key_code = ui::VKEY_ALTGR;
+ exact_event = true;
+ break;
+#endif
+ default:
+ break;
+ }
+
+ // Remapping based on DomCode.
+ switch (incoming.code) {
// On Chrome OS, F15 (XF86XK_Launch6) with NumLock (Mod2Mask) is sent
// when Diamond key is pressed.
- case ui::DomKey::F15:
+ case ui::DomCode::F15:
// When diamond key is not available, the configuration UI for Diamond
// key is not shown. Therefore, ignore the kLanguageRemapDiamondKeyTo
// syncable pref.
@@ -703,12 +751,13 @@ bool EventRewriter::RewriteModifierKeys(const ui::KeyEvent& key_event,
// is pressed (with one exception: when
// IsISOLevel5ShiftUsedByCurrentInputMethod() is true, the key generates
// XK_ISO_Level3_Shift with Mod3Mask, not XF86XK_Launch7).
- case ui::DomKey::F16:
+ case ui::DomCode::F16:
characteristic_flag = ui::EF_CAPS_LOCK_DOWN;
remapped_key =
GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service);
break;
- case ui::DomKey::OS:
+ case ui::DomCode::OS_LEFT:
+ case ui::DomCode::OS_RIGHT:
characteristic_flag = ui::EF_COMMAND_DOWN;
// Rewrite Command-L/R key presses on an Apple keyboard to Control.
if (IsAppleKeyboard()) {
@@ -721,58 +770,19 @@ bool EventRewriter::RewriteModifierKeys(const ui::KeyEvent& key_event,
// Default behavior is Super key, hence don't remap the event if the pref
// is unavailable.
break;
- case ui::DomKey::CONTROL:
+ case ui::DomCode::CONTROL_LEFT:
+ case ui::DomCode::CONTROL_RIGHT:
characteristic_flag = ui::EF_CONTROL_DOWN;
remapped_key =
GetRemappedKey(prefs::kLanguageRemapControlKeyTo, *pref_service);
break;
- case ui::DomKey::ALT:
+ case ui::DomCode::ALT_LEFT:
+ case ui::DomCode::ALT_RIGHT:
// ALT key
characteristic_flag = ui::EF_ALT_DOWN;
remapped_key =
GetRemappedKey(prefs::kLanguageRemapAltKeyTo, *pref_service);
break;
- case ui::DomKey::ALT_GRAPH:
- // The Neo2 codes modifiers such that CapsLock appears as VKEY_ALTGR,
- // but AltGraph (right Alt) also appears as VKEY_ALTGR in Neo2,
- // as it does in other layouts. Neo2's "Mod3" is represented in
- // EventFlags by a combination of AltGr+Mod3, while its "Mod4" is
- // AltGr alone.
- if (IsISOLevel5ShiftUsedByCurrentInputMethod()) {
- if (incoming.code == ui::DomCode::CAPS_LOCK) {
- characteristic_flag = ui::EF_ALTGR_DOWN | ui::EF_MOD3_DOWN;
- remapped_key =
- GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service);
- } else {
- characteristic_flag = ui::EF_ALTGR_DOWN;
- remapped_key =
- GetRemappedKey(prefs::kLanguageRemapSearchKeyTo, *pref_service);
- }
- }
- if (remapped_key && remapped_key->result.key_code == ui::VKEY_CAPITAL)
- remapped_key = kModifierRemappingNeoMod3;
- break;
-#if !defined(USE_X11)
- case ui::DomKey::ALT_GRAPH_LATCH:
- if (key_event.type() == ui::ET_KEY_PRESSED) {
- pressed_modifier_latches_ |= ui::EF_ALTGR_DOWN;
- } else {
- pressed_modifier_latches_ &= ~ui::EF_ALTGR_DOWN;
- if (used_modifier_latches_ & ui::EF_ALTGR_DOWN)
- used_modifier_latches_ &= ~ui::EF_ALTGR_DOWN;
- else
- latched_modifier_latches_ |= ui::EF_ALTGR_DOWN;
- }
- // Rewrite to AltGraph. When this key is used like a regular modifier,
- // the web-exposed result looks like a use of the regular modifier.
- // When it's used as a latch, the web-exposed result is a vacuous
- // modifier press-and-release, which should be harmless, but preserves
- // the event for applications using the |code| (e.g. remoting).
- state->key = ui::DomKey::ALT_GRAPH;
- state->key_code = ui::VKEY_ALTGR;
- exact_event = true;
- break;
-#endif
default:
break;
}