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

Side by Side Diff: chrome/browser/chromeos/events/event_rewriter.cc

Issue 187313002: Update StickyKeys overlay to show or hide AltGr depending on the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix rebase Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <X11/extensions/XInput2.h> 7 #include <X11/extensions/XInput2.h>
8 #include <X11/keysym.h> 8 #include <X11/keysym.h>
9 #include <X11/XF86keysym.h> 9 #include <X11/XF86keysym.h>
10 #include <X11/Xlib.h> 10 #include <X11/Xlib.h>
(...skipping 22 matching lines...) Expand all
33 #include "ui/base/x/x11_util.h" 33 #include "ui/base/x/x11_util.h"
34 #include "ui/events/event.h" 34 #include "ui/events/event.h"
35 #include "ui/events/event_utils.h" 35 #include "ui/events/event_utils.h"
36 #include "ui/events/keycodes/keyboard_code_conversion_x.h" 36 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
37 #include "ui/wm/core/window_util.h" 37 #include "ui/wm/core/window_util.h"
38 38
39 namespace { 39 namespace {
40 40
41 const int kBadDeviceId = -1; 41 const int kBadDeviceId = -1;
42 42
43 const char kNeo2LayoutId[] = "xkb:de:neo:ger";
44 const char kCaMultixLayoutId[] = "xkb:ca:multix:fra";
45
46 // A key code and a flag we should use when a key is remapped to |remap_to|. 43 // A key code and a flag we should use when a key is remapped to |remap_to|.
47 const struct ModifierRemapping { 44 const struct ModifierRemapping {
48 int remap_to; 45 int remap_to;
49 int flag; 46 int flag;
50 unsigned int native_modifier; 47 unsigned int native_modifier;
51 ui::KeyboardCode keycode; 48 ui::KeyboardCode keycode;
52 KeySym native_keysyms[4]; // left, right, shift+left, shift+right. 49 KeySym native_keysyms[4]; // left, right, shift+left, shift+right.
53 } kModifierRemappings[] = { 50 } kModifierRemappings[] = {
54 { chromeos::input_method::kSearchKey, 0, Mod4Mask, ui::VKEY_LWIN, 51 { chromeos::input_method::kSearchKey, 0, Mod4Mask, ui::VKEY_LWIN,
55 { XK_Super_L, XK_Super_L, XK_Super_L, XK_Super_L }}, 52 { XK_Super_L, XK_Super_L, XK_Super_L, XK_Super_L }},
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 break; 109 break;
113 } 110 }
114 return false; 111 return false;
115 } 112 }
116 113
117 bool HasDiamondKey() { 114 bool HasDiamondKey() {
118 return CommandLine::ForCurrentProcess()->HasSwitch( 115 return CommandLine::ForCurrentProcess()->HasSwitch(
119 chromeos::switches::kHasChromeOSDiamondKey); 116 chromeos::switches::kHasChromeOSDiamondKey);
120 } 117 }
121 118
122 bool IsMod3UsedByCurrentInputMethod() { 119 bool IsISOLevel5ShiftUsedByCurrentInputMethod() {
123 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, 120 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask,
124 // it's not possible to make both features work. For now, we don't remap 121 // it's not possible to make both features work. For now, we don't remap
125 // Mod3Mask when Neo2 is in use. 122 // Mod3Mask when Neo2 is in use.
126 // TODO(yusukes): Remove the restriction. 123 // TODO(yusukes): Remove the restriction.
127 chromeos::input_method::InputMethodManager* manager = 124 chromeos::input_method::InputMethodManager* manager =
128 chromeos::input_method::InputMethodManager::Get(); 125 chromeos::input_method::InputMethodManager::Get();
129 return manager->GetCurrentInputMethod().id() == kNeo2LayoutId || 126 return manager->IsISOLevel5ShiftUsedByCurrentInputMethod();
130 manager->GetCurrentInputMethod().id() == kCaMultixLayoutId;
131 } 127 }
132 128
133 } // namespace 129 } // namespace
134 130
135 namespace chromeos { 131 namespace chromeos {
136 132
137 EventRewriter::EventRewriter() 133 EventRewriter::EventRewriter()
138 : last_device_id_(kBadDeviceId), 134 : last_device_id_(kBadDeviceId),
139 xkeyboard_for_testing_(NULL), 135 xkeyboard_for_testing_(NULL),
140 keyboard_driven_event_rewriter_(new KeyboardDrivenEventRewriter), 136 keyboard_driven_event_rewriter_(new KeyboardDrivenEventRewriter),
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 const PrefService* pref_service = GetPrefService(); 385 const PrefService* pref_service = GetPrefService();
390 if (!pref_service) 386 if (!pref_service)
391 return; 387 return;
392 388
393 // When a diamond key is not available, a Mod2Mask should not treated as a 389 // When a diamond key is not available, a Mod2Mask should not treated as a
394 // configurable modifier because Mod2Mask may be worked as NumLock mask. 390 // configurable modifier because Mod2Mask may be worked as NumLock mask.
395 // (cf. http://crbug.com/173956) 391 // (cf. http://crbug.com/173956)
396 const bool skip_mod2 = !HasDiamondKey(); 392 const bool skip_mod2 = !HasDiamondKey();
397 // If Mod3 is used by the current input method, don't allow the CapsLock 393 // If Mod3 is used by the current input method, don't allow the CapsLock
398 // pref to remap it, or the keyboard behavior will be broken. 394 // pref to remap it, or the keyboard behavior will be broken.
399 const bool skip_mod3 = IsMod3UsedByCurrentInputMethod(); 395 const bool skip_mod3 = IsISOLevel5ShiftUsedByCurrentInputMethod();
400 396
401 for (size_t i = 0; i < arraysize(kModifierFlagToPrefName); ++i) { 397 for (size_t i = 0; i < arraysize(kModifierFlagToPrefName); ++i) {
402 if ((skip_mod2 && kModifierFlagToPrefName[i].native_modifier == Mod2Mask) || 398 if ((skip_mod2 && kModifierFlagToPrefName[i].native_modifier == Mod2Mask) ||
403 (skip_mod3 && kModifierFlagToPrefName[i].native_modifier == Mod3Mask)) { 399 (skip_mod3 && kModifierFlagToPrefName[i].native_modifier == Mod3Mask)) {
404 continue; 400 continue;
405 } 401 }
406 if (original_native_modifiers & 402 if (original_native_modifiers &
407 kModifierFlagToPrefName[i].native_modifier) { 403 kModifierFlagToPrefName[i].native_modifier) {
408 const ModifierRemapping* remapped_key = 404 const ModifierRemapping* remapped_key =
409 GetRemappedKey(kModifierFlagToPrefName[i].pref_name, *pref_service); 405 GetRemappedKey(kModifierFlagToPrefName[i].pref_name, *pref_service);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 // key is not shown. Therefore, ignore the kLanguageRemapDiamondKeyTo 462 // key is not shown. Therefore, ignore the kLanguageRemapDiamondKeyTo
467 // syncable pref. 463 // syncable pref.
468 if (HasDiamondKey()) 464 if (HasDiamondKey())
469 remapped_key = 465 remapped_key =
470 GetRemappedKey(prefs::kLanguageRemapDiamondKeyTo, *pref_service); 466 GetRemappedKey(prefs::kLanguageRemapDiamondKeyTo, *pref_service);
471 // Default behavior is Ctrl key. 467 // Default behavior is Ctrl key.
472 if (!remapped_key) 468 if (!remapped_key)
473 remapped_key = kModifierRemappingCtrl; 469 remapped_key = kModifierRemappingCtrl;
474 break; 470 break;
475 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock 471 // On Chrome OS, XF86XK_Launch7 (F16) with Mod3Mask is sent when Caps Lock
476 // is pressed (with one exception: when IsMod3UsedByCurrentInputMethod() is 472 // is pressed (with one exception: when
477 // true, the key generates XK_ISO_Level3_Shift with Mod3Mask, not 473 // IsISOLevel5ShiftUsedByCurrentInputMethod() is true, the key generates
478 // XF86XK_Launch7). 474 // XK_ISO_Level3_Shift with Mod3Mask, not XF86XK_Launch7).
479 case XF86XK_Launch7: 475 case XF86XK_Launch7:
480 remapped_key = 476 remapped_key =
481 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service); 477 GetRemappedKey(prefs::kLanguageRemapCapsLockKeyTo, *pref_service);
482 break; 478 break;
483 case XK_Super_L: 479 case XK_Super_L:
484 case XK_Super_R: 480 case XK_Super_R:
485 // Rewrite Command-L/R key presses on an Apple keyboard to Control-L/R. 481 // Rewrite Command-L/R key presses on an Apple keyboard to Control-L/R.
486 if (IsAppleKeyboard()) 482 if (IsAppleKeyboard())
487 remapped_key = kModifierRemappingCtrl; 483 remapped_key = kModifierRemappingCtrl;
488 else 484 else
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " 893 VLOG(1) << "Apple keyboard '" << device_name << "' connected: "
898 << "id=" << device_id; 894 << "id=" << device_id;
899 } 895 }
900 // Always overwrite the existing device_id since the X server may reuse a 896 // Always overwrite the existing device_id since the X server may reuse a
901 // device id for an unattached device. 897 // device id for an unattached device.
902 device_id_to_type_[device_id] = type; 898 device_id_to_type_[device_id] = type;
903 return type; 899 return type;
904 } 900 }
905 901
906 } // namespace chromeos 902 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698