OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/ash/event_rewriter.h" | 5 #include "chrome/browser/ui/ash/event_rewriter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 break; | 114 break; |
115 } | 115 } |
116 return false; | 116 return false; |
117 } | 117 } |
118 | 118 |
119 bool HasChromeOSKeyboard() { | 119 bool HasChromeOSKeyboard() { |
120 return CommandLine::ForCurrentProcess()->HasSwitch( | 120 return CommandLine::ForCurrentProcess()->HasSwitch( |
121 switches::kHasChromeOSKeyboard); | 121 switches::kHasChromeOSKeyboard); |
122 } | 122 } |
123 | 123 |
| 124 bool EventSourceIsChromebookKeyboard(ui::KeyEvent* /* event */) { |
| 125 // TODO(danakj): Determine if the event came from a Chromebook internal |
| 126 // keyboard. |
| 127 return true; |
| 128 } |
| 129 |
124 bool IsMod3UsedByCurrentInputMethod() { | 130 bool IsMod3UsedByCurrentInputMethod() { |
125 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, | 131 // Since both German Neo2 XKB layout and Caps Lock depend on Mod3Mask, |
126 // it's not possible to make both features work. For now, we don't remap | 132 // it's not possible to make both features work. For now, we don't remap |
127 // Mod3Mask when Neo2 is in use. | 133 // Mod3Mask when Neo2 is in use. |
128 // TODO(yusukes): Remove the restriction. | 134 // TODO(yusukes): Remove the restriction. |
129 return InputMethodManager::GetInstance()->GetCurrentInputMethod().id() == | 135 return InputMethodManager::GetInstance()->GetCurrentInputMethod().id() == |
130 kNeo2LayoutId; | 136 kNeo2LayoutId; |
131 } | 137 } |
132 #endif | 138 #endif |
133 | 139 |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 } | 637 } |
632 #else | 638 #else |
633 // TODO(yusukes): Support Ash on other platforms if needed. | 639 // TODO(yusukes): Support Ash on other platforms if needed. |
634 #endif | 640 #endif |
635 return rewritten; | 641 return rewritten; |
636 } | 642 } |
637 | 643 |
638 bool EventRewriter::RewriteBackspaceAndArrowKeys(ui::KeyEvent* event) { | 644 bool EventRewriter::RewriteBackspaceAndArrowKeys(ui::KeyEvent* event) { |
639 bool rewritten = false; | 645 bool rewritten = false; |
640 #if defined(OS_CHROMEOS) | 646 #if defined(OS_CHROMEOS) |
| 647 // On a Chromebook keyboard, modifier keys can be used to access extended |
| 648 // keyboard shortcuts. On other keyboards, keys such as delete and page up are |
| 649 // already available, so we do not need to rewrite anything here. |
| 650 if (!EventSourceIsChromebookKeyboard(event)) |
| 651 return rewritten; |
| 652 |
| 653 const PrefService* pref_service = |
| 654 pref_service_ ? pref_service_ : GetPrefService(); |
| 655 bool chromebook_function_key = CommandLine::ForCurrentProcess()->HasSwitch( |
| 656 switches::kEnableChromebookFunctionKey); |
| 657 |
| 658 bool search_as_function_key = chromebook_function_key && pref_service && |
| 659 pref_service->GetBoolean(prefs::kLanguageSearchKeyActsAsFunctionKey); |
| 660 |
641 XEvent* xev = event->native_event(); | 661 XEvent* xev = event->native_event(); |
642 XKeyEvent* xkey = &(xev->xkey); | 662 XKeyEvent* xkey = &(xev->xkey); |
| 663 const KeySym keysym = XLookupKeysym(xkey, 0); |
643 | 664 |
644 const KeySym keysym = XLookupKeysym(xkey, 0); | 665 if (!search_as_function_key) { |
645 if (keysym == XK_BackSpace && (xkey->state & Mod1Mask)) { | 666 if (keysym == XK_BackSpace && (xkey->state & Mod1Mask)) { |
646 // Remap Alt+Backspace to Delete. | 667 // Without Search as Function key: Remap Alt+Backspace to Delete. |
647 OverwriteEvent(event, delete_xkeycode_, xkey->state & ~Mod1Mask, | 668 OverwriteEvent(event, delete_xkeycode_, xkey->state & ~Mod1Mask, |
648 ui::VKEY_DELETE, event->flags() & ~ui::EF_ALT_DOWN); | 669 ui::VKEY_DELETE, event->flags() & ~ui::EF_ALT_DOWN); |
649 rewritten = true; | 670 rewritten = true; |
650 } else if (keysym == XK_Up && | 671 } else if (keysym == XK_Up && |
651 (xkey->state & ControlMask) && (xkey->state & Mod1Mask)) { | 672 (xkey->state & ControlMask) && (xkey->state & Mod1Mask)) { |
652 // Remap Ctrl+Alt+Up to Home. | 673 // Without Search as Function key: Remap Ctrl+Alt+Up to Home. |
653 OverwriteEvent(event, | 674 OverwriteEvent(event, |
654 home_xkeycode_, | 675 home_xkeycode_, |
655 xkey->state & ~(Mod1Mask | ControlMask), | 676 xkey->state & ~(Mod1Mask | ControlMask), |
656 ui::VKEY_HOME, | 677 ui::VKEY_HOME, |
657 event->flags() & ~(ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN)); | 678 event->flags() & ~(ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN)); |
658 rewritten = true; | 679 rewritten = true; |
659 } else if (keysym == XK_Up && (xkey->state & Mod1Mask)) { | 680 } else if (keysym == XK_Up && (xkey->state & Mod1Mask)) { |
660 // Remap Alt+Up to Prior (aka PageUp). | 681 // Without Search as Function key: Remap Alt+Up to Prior (aka PageUp). |
661 OverwriteEvent(event, prior_xkeycode_, xkey->state & ~Mod1Mask, | 682 OverwriteEvent(event, prior_xkeycode_, xkey->state & ~Mod1Mask, |
662 ui::VKEY_PRIOR, event->flags() & ~ui::EF_ALT_DOWN); | 683 ui::VKEY_PRIOR, event->flags() & ~ui::EF_ALT_DOWN); |
663 rewritten = true; | 684 rewritten = true; |
664 } else if (keysym == XK_Down && | 685 } else if (keysym == XK_Down && |
665 (xkey->state & ControlMask) && (xkey->state & Mod1Mask)) { | 686 (xkey->state & ControlMask) && (xkey->state & Mod1Mask)) { |
666 // Remap Ctrl+Alt+Down to End. | 687 // Without Search as Function key: Remap Ctrl+Alt+Down to End. |
667 OverwriteEvent(event, | 688 OverwriteEvent(event, |
668 end_xkeycode_, | 689 end_xkeycode_, |
669 xkey->state & ~(Mod1Mask | ControlMask), | 690 xkey->state & ~(Mod1Mask | ControlMask), |
670 ui::VKEY_END, | 691 ui::VKEY_END, |
671 event->flags() & ~(ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN)); | 692 event->flags() & ~(ui::EF_ALT_DOWN | ui::EF_CONTROL_DOWN)); |
672 rewritten = true; | 693 rewritten = true; |
673 } else if (keysym == XK_Down && (xkey->state & Mod1Mask)) { | 694 } else if (keysym == XK_Down && (xkey->state & Mod1Mask)) { |
674 // Remap Alt+Down to Next (aka PageDown). | 695 // Without Search as Function key: Remap Alt+Down to Next (aka PageDown). |
675 OverwriteEvent(event, next_xkeycode_, xkey->state & ~Mod1Mask, | 696 OverwriteEvent(event, next_xkeycode_, xkey->state & ~Mod1Mask, |
676 ui::VKEY_NEXT, event->flags() & ~ui::EF_ALT_DOWN); | 697 ui::VKEY_NEXT, event->flags() & ~ui::EF_ALT_DOWN); |
677 rewritten = true; | 698 rewritten = true; |
| 699 } |
| 700 } else { |
| 701 if (keysym == XK_BackSpace && (xkey->state & Mod4Mask)) { |
| 702 // With Search as Function key: Remap Search+Backspace to Delete. |
| 703 OverwriteEvent(event, delete_xkeycode_, xkey->state & ~Mod4Mask, |
| 704 ui::VKEY_DELETE, event->flags()); |
| 705 rewritten = true; |
| 706 } else if (keysym == XK_Left && (xkey->state & Mod4Mask)) { |
| 707 // With Search as Function key: Remap Search+Left to Home. |
| 708 OverwriteEvent(event, home_xkeycode_, xkey->state & ~Mod4Mask, |
| 709 ui::VKEY_HOME, event->flags()); |
| 710 rewritten = true; |
| 711 } else if (keysym == XK_Up && (xkey->state & Mod4Mask)) { |
| 712 // With Search as Function key: Remap Search+Up to Prior (aka PageUp). |
| 713 OverwriteEvent(event, prior_xkeycode_, xkey->state & ~Mod4Mask, |
| 714 ui::VKEY_PRIOR, event->flags()); |
| 715 rewritten = true; |
| 716 } else if (keysym == XK_Right && (xkey->state & Mod4Mask)) { |
| 717 // With Search as Function key: Remap Search+Right to End. |
| 718 OverwriteEvent(event, end_xkeycode_, xkey->state & ~Mod4Mask, |
| 719 ui::VKEY_END, event->flags()); |
| 720 rewritten = true; |
| 721 } else if (keysym == XK_Down && (xkey->state & Mod4Mask)) { |
| 722 // With Search as Function key: Remap Search+Down to Next (aka PageDown). |
| 723 OverwriteEvent(event, next_xkeycode_, xkey->state & ~Mod4Mask, |
| 724 ui::VKEY_NEXT, event->flags()); |
| 725 rewritten = true; |
| 726 } |
678 } | 727 } |
679 #else | 728 #else |
680 // TODO(yusukes): Support Ash on other platforms if needed. | 729 // TODO(yusukes): Support Ash on other platforms if needed. |
681 #endif | 730 #endif |
682 return rewritten; | 731 return rewritten; |
683 } | 732 } |
684 | 733 |
685 void EventRewriter::RewriteLocatedEvent(ui::LocatedEvent* event) { | 734 void EventRewriter::RewriteLocatedEvent(ui::LocatedEvent* event) { |
686 #if defined(OS_CHROMEOS) | 735 #if defined(OS_CHROMEOS) |
687 if (event->flags() & ui::EF_IS_SYNTHESIZED) | 736 if (event->flags() & ui::EF_IS_SYNTHESIZED) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 const DeviceType type = EventRewriter::GetDeviceType(device_name); | 799 const DeviceType type = EventRewriter::GetDeviceType(device_name); |
751 if (type == kDeviceAppleKeyboard) { | 800 if (type == kDeviceAppleKeyboard) { |
752 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " | 801 VLOG(1) << "Apple keyboard '" << device_name << "' connected: " |
753 << "id=" << device_id; | 802 << "id=" << device_id; |
754 } | 803 } |
755 // Always overwrite the existing device_id since the X server may reuse a | 804 // Always overwrite the existing device_id since the X server may reuse a |
756 // device id for an unattached device. | 805 // device id for an unattached device. |
757 device_id_to_type_[device_id] = type; | 806 device_id_to_type_[device_id] = type; |
758 return type; | 807 return type; |
759 } | 808 } |
OLD | NEW |