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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/prefs/public/pref_member.h" | 9 #include "base/prefs/public/pref_member.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 keycode_delete_(XKeysymToKeycode(display_, XK_Delete)), | 110 keycode_delete_(XKeysymToKeycode(display_, XK_Delete)), |
111 keycode_backspace_(XKeysymToKeycode(display_, XK_BackSpace)), | 111 keycode_backspace_(XKeysymToKeycode(display_, XK_BackSpace)), |
112 keycode_up_(XKeysymToKeycode(display_, XK_Up)), | 112 keycode_up_(XKeysymToKeycode(display_, XK_Up)), |
113 keycode_down_(XKeysymToKeycode(display_, XK_Down)), | 113 keycode_down_(XKeysymToKeycode(display_, XK_Down)), |
114 keycode_left_(XKeysymToKeycode(display_, XK_Left)), | 114 keycode_left_(XKeysymToKeycode(display_, XK_Left)), |
115 keycode_right_(XKeysymToKeycode(display_, XK_Right)), | 115 keycode_right_(XKeysymToKeycode(display_, XK_Right)), |
116 keycode_prior_(XKeysymToKeycode(display_, XK_Prior)), | 116 keycode_prior_(XKeysymToKeycode(display_, XK_Prior)), |
117 keycode_next_(XKeysymToKeycode(display_, XK_Next)), | 117 keycode_next_(XKeysymToKeycode(display_, XK_Next)), |
118 keycode_home_(XKeysymToKeycode(display_, XK_Home)), | 118 keycode_home_(XKeysymToKeycode(display_, XK_Home)), |
119 keycode_end_(XKeysymToKeycode(display_, XK_End)), | 119 keycode_end_(XKeysymToKeycode(display_, XK_End)), |
120 keycode_launch6_(XKeysymToKeycode(display_, XF86XK_Launch6)), | |
120 keycode_launch7_(XKeysymToKeycode(display_, XF86XK_Launch7)), | 121 keycode_launch7_(XKeysymToKeycode(display_, XF86XK_Launch7)), |
121 keycode_f1_(XKeysymToKeycode(display_, XK_F1)), | 122 keycode_f1_(XKeysymToKeycode(display_, XK_F1)), |
122 keycode_f2_(XKeysymToKeycode(display_, XK_F2)), | 123 keycode_f2_(XKeysymToKeycode(display_, XK_F2)), |
123 keycode_f3_(XKeysymToKeycode(display_, XK_F3)), | 124 keycode_f3_(XKeysymToKeycode(display_, XK_F3)), |
124 keycode_f4_(XKeysymToKeycode(display_, XK_F4)), | 125 keycode_f4_(XKeysymToKeycode(display_, XK_F4)), |
125 keycode_f5_(XKeysymToKeycode(display_, XK_F5)), | 126 keycode_f5_(XKeysymToKeycode(display_, XK_F5)), |
126 keycode_f6_(XKeysymToKeycode(display_, XK_F6)), | 127 keycode_f6_(XKeysymToKeycode(display_, XK_F6)), |
127 keycode_f7_(XKeysymToKeycode(display_, XK_F7)), | 128 keycode_f7_(XKeysymToKeycode(display_, XK_F7)), |
128 keycode_f8_(XKeysymToKeycode(display_, XK_F8)), | 129 keycode_f8_(XKeysymToKeycode(display_, XK_F8)), |
129 keycode_f9_(XKeysymToKeycode(display_, XK_F9)), | 130 keycode_f9_(XKeysymToKeycode(display_, XK_F9)), |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 const KeyCode keycode_delete_; | 218 const KeyCode keycode_delete_; |
218 const KeyCode keycode_backspace_; | 219 const KeyCode keycode_backspace_; |
219 const KeyCode keycode_up_; | 220 const KeyCode keycode_up_; |
220 const KeyCode keycode_down_; | 221 const KeyCode keycode_down_; |
221 const KeyCode keycode_left_; | 222 const KeyCode keycode_left_; |
222 const KeyCode keycode_right_; | 223 const KeyCode keycode_right_; |
223 const KeyCode keycode_prior_; | 224 const KeyCode keycode_prior_; |
224 const KeyCode keycode_next_; | 225 const KeyCode keycode_next_; |
225 const KeyCode keycode_home_; | 226 const KeyCode keycode_home_; |
226 const KeyCode keycode_end_; | 227 const KeyCode keycode_end_; |
228 const KeyCode keycode_launch6_; // F15 | |
227 const KeyCode keycode_launch7_; // F16 | 229 const KeyCode keycode_launch7_; // F16 |
228 const KeyCode keycode_f1_; | 230 const KeyCode keycode_f1_; |
229 const KeyCode keycode_f2_; | 231 const KeyCode keycode_f2_; |
230 const KeyCode keycode_f3_; | 232 const KeyCode keycode_f3_; |
231 const KeyCode keycode_f4_; | 233 const KeyCode keycode_f4_; |
232 const KeyCode keycode_f5_; | 234 const KeyCode keycode_f5_; |
233 const KeyCode keycode_f6_; | 235 const KeyCode keycode_f6_; |
234 const KeyCode keycode_f7_; | 236 const KeyCode keycode_f7_; |
235 const KeyCode keycode_f8_; | 237 const KeyCode keycode_f8_; |
236 const KeyCode keycode_f9_; | 238 const KeyCode keycode_f9_; |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 Mod1Mask, | 540 Mod1Mask, |
539 KeyPress), | 541 KeyPress), |
540 GetRewrittenEventAsString(&rewriter, | 542 GetRewrittenEventAsString(&rewriter, |
541 ui::VKEY_RWIN, | 543 ui::VKEY_RWIN, |
542 ui::EF_ALT_DOWN, | 544 ui::EF_ALT_DOWN, |
543 ui::ET_KEY_PRESSED, | 545 ui::ET_KEY_PRESSED, |
544 keycode_super_r_, | 546 keycode_super_r_, |
545 Mod1Mask)); | 547 Mod1Mask)); |
546 } | 548 } |
547 | 549 |
548 TEST_F(EventRewriterTest, TestRewriteNumPadKeys) { | 550 TEST_F(EventRewriterTest, TestRewriteNumPadKeys) { |
Yusuke Sato
2013/01/24 20:46:01
could you do the same with --has-diamond-key?
yoshiki
2013/01/25 01:33:10
Done.
| |
549 TestingPrefServiceSyncable prefs; | 551 TestingPrefServiceSyncable prefs; |
550 EventRewriter rewriter; | 552 EventRewriter rewriter; |
551 rewriter.set_pref_service_for_testing(&prefs); | 553 rewriter.set_pref_service_for_testing(&prefs); |
552 | 554 |
553 // XK_KP_Insert (= NumPad 0 without Num Lock), no modifier. | 555 // XK_KP_Insert (= NumPad 0 without Num Lock), no modifier. |
554 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NUMPAD0, | 556 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NUMPAD0, |
555 0, | 557 0, |
556 ui::ET_KEY_PRESSED, | 558 ui::ET_KEY_PRESSED, |
557 keycode_num_pad_0_, | 559 keycode_num_pad_0_, |
558 Mod2Mask, // Num Lock | 560 Mod2Mask, // Num Lock |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
867 KeyPress), | 869 KeyPress), |
868 GetRewrittenEventAsString(&rewriter, | 870 GetRewrittenEventAsString(&rewriter, |
869 ui::VKEY_NUMPAD9, | 871 ui::VKEY_NUMPAD9, |
870 0, | 872 0, |
871 ui::ET_KEY_PRESSED, | 873 ui::ET_KEY_PRESSED, |
872 keycode_num_pad_9_, | 874 keycode_num_pad_9_, |
873 Mod2Mask)); | 875 Mod2Mask)); |
874 } | 876 } |
875 | 877 |
876 // Tests if the rewriter can handle a Command + Num Pad event. | 878 // Tests if the rewriter can handle a Command + Num Pad event. |
877 TEST_F(EventRewriterTest, TestRewriteNumPadKeysOnAppleKeyboard) { | 879 TEST_F(EventRewriterTest, TestRewriteNumPadKeysOnAppleKeyboard) { |
Yusuke Sato
2013/01/24 20:46:01
the same
yoshiki
2013/01/25 01:33:10
Done.
| |
878 TestingPrefServiceSyncable prefs; | 880 TestingPrefServiceSyncable prefs; |
879 EventRewriter rewriter; | 881 EventRewriter rewriter; |
880 rewriter.DeviceAddedForTesting(0, "Apple Keyboard"); | 882 rewriter.DeviceAddedForTesting(0, "Apple Keyboard"); |
881 rewriter.set_last_device_id_for_testing(0); | 883 rewriter.set_last_device_id_for_testing(0); |
882 rewriter.set_pref_service_for_testing(&prefs); | 884 rewriter.set_pref_service_for_testing(&prefs); |
883 | 885 |
884 // XK_KP_End (= NumPad 1 without Num Lock), Win modifier. | 886 // XK_KP_End (= NumPad 1 without Num Lock), Win modifier. |
885 // The result should be "Num Pad 1 with Control + Num Lock modifiers". | 887 // The result should be "Num Pad 1 with Control + Num Lock modifiers". |
886 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NUMPAD1, | 888 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_NUMPAD1, |
887 ui::EF_CONTROL_DOWN, | 889 ui::EF_CONTROL_DOWN, |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1622 ui::VKEY_F16, | 1624 ui::VKEY_F16, |
1623 0, | 1625 0, |
1624 ui::ET_KEY_PRESSED, | 1626 ui::ET_KEY_PRESSED, |
1625 keycode_launch7_, | 1627 keycode_launch7_, |
1626 0U)); | 1628 0U)); |
1627 EXPECT_TRUE(xkeyboard.caps_lock_is_enabled_); | 1629 EXPECT_TRUE(xkeyboard.caps_lock_is_enabled_); |
1628 | 1630 |
1629 *CommandLine::ForCurrentProcess() = original_cl; | 1631 *CommandLine::ForCurrentProcess() = original_cl; |
1630 } | 1632 } |
1631 | 1633 |
1634 TEST_F(EventRewriterTest, DISABLED_TestRewriteDiamondKey) { | |
1635 // TODO(yusukes): Reenable the test once build servers are upgraded. | |
1636 | |
1637 TestingPrefServiceSyncable prefs; | |
1638 chromeos::Preferences::RegisterUserPrefs(&prefs); | |
1639 | |
1640 chromeos::input_method::MockXKeyboard xkeyboard; | |
1641 EventRewriter rewriter; | |
1642 rewriter.set_pref_service_for_testing(&prefs); | |
1643 rewriter.set_xkeyboard_for_testing(&xkeyboard); | |
1644 | |
1645 // F15 should work as Ctrl when --has-chromeos-diamond-key is not specified. | |
1646 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, | |
1647 ui::EF_CONTROL_DOWN, | |
1648 ui::ET_KEY_PRESSED, | |
1649 keycode_control_l_, | |
1650 0U, | |
1651 KeyPress), | |
1652 GetRewrittenEventAsString(&rewriter, | |
1653 ui::VKEY_F15, | |
1654 0, | |
1655 ui::ET_KEY_PRESSED, | |
1656 keycode_launch6_, | |
1657 0U)); | |
1658 } | |
1659 | |
1660 TEST_F(EventRewriterTest, DISABLED_TestRewriteDiamondKeyWithFlag) { | |
1661 // TODO(yusukes): Reenable the test once build servers are upgraded. | |
1662 | |
1663 const CommandLine original_cl(*CommandLine::ForCurrentProcess()); | |
1664 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
1665 switches::kHasChromeOSDiamondKey, ""); | |
1666 | |
1667 TestingPrefServiceSyncable prefs; | |
1668 chromeos::Preferences::RegisterUserPrefs(&prefs); | |
1669 | |
1670 chromeos::input_method::MockXKeyboard xkeyboard; | |
1671 EventRewriter rewriter; | |
1672 rewriter.set_pref_service_for_testing(&prefs); | |
1673 rewriter.set_xkeyboard_for_testing(&xkeyboard); | |
1674 | |
1675 // On default, F15 should work as Control. | |
Yusuke Sato
2013/01/24 20:46:01
By default?
yoshiki
2013/01/25 01:33:10
Done.
| |
1676 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, | |
1677 ui::EF_CONTROL_DOWN, | |
1678 ui::ET_KEY_PRESSED, | |
1679 keycode_control_l_, | |
1680 0U, | |
1681 KeyPress), | |
1682 GetRewrittenEventAsString(&rewriter, | |
1683 ui::VKEY_F15, | |
1684 0, | |
1685 ui::ET_KEY_PRESSED, | |
1686 keycode_launch6_, | |
1687 0U)); | |
1688 | |
1689 IntegerPrefMember diamond; | |
1690 diamond.Init(prefs::kLanguageRemapDiamondKeyTo, &prefs); | |
1691 diamond.SetValue(chromeos::input_method::kVoidKey); | |
1692 | |
1693 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_UNKNOWN, | |
1694 0, | |
1695 ui::ET_KEY_PRESSED, | |
1696 keycode_void_symbol_, | |
1697 0U, | |
1698 KeyPress), | |
1699 GetRewrittenEventAsString(&rewriter, | |
1700 ui::VKEY_F15, | |
1701 0, | |
1702 ui::ET_KEY_PRESSED, | |
1703 keycode_launch6_, | |
1704 0U)); | |
1705 | |
1706 diamond.SetValue(chromeos::input_method::kControlKey); | |
1707 | |
1708 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, | |
1709 ui::EF_CONTROL_DOWN, | |
1710 ui::ET_KEY_PRESSED, | |
1711 keycode_control_l_, | |
1712 0U, | |
1713 KeyPress), | |
1714 GetRewrittenEventAsString(&rewriter, | |
1715 ui::VKEY_F15, | |
1716 0, | |
1717 ui::ET_KEY_PRESSED, | |
1718 keycode_launch6_, | |
1719 0U)); | |
1720 diamond.SetValue(chromeos::input_method::kAltKey); | |
Yusuke Sato
2013/01/24 20:46:01
Can you add a test for remapping to Caps Lock?
yoshiki
2013/01/25 01:33:10
Done.
| |
1721 | |
1722 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_MENU, | |
1723 ui::EF_ALT_DOWN, | |
1724 ui::ET_KEY_PRESSED, | |
1725 keycode_alt_l_, | |
1726 0, | |
1727 KeyPress), | |
1728 GetRewrittenEventAsString(&rewriter, | |
1729 ui::VKEY_F15, | |
1730 0, | |
1731 ui::ET_KEY_PRESSED, | |
1732 keycode_launch6_, | |
1733 0U)); | |
1734 } | |
1735 | |
1632 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) { | 1736 TEST_F(EventRewriterTest, TestRewriteCapsLockToControl) { |
1633 TestingPrefServiceSyncable prefs; | 1737 TestingPrefServiceSyncable prefs; |
1634 chromeos::Preferences::RegisterUserPrefs(&prefs); | 1738 chromeos::Preferences::RegisterUserPrefs(&prefs); |
1635 IntegerPrefMember control; | 1739 IntegerPrefMember control; |
1636 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs); | 1740 control.Init(prefs::kLanguageRemapCapsLockKeyTo, &prefs); |
1637 control.SetValue(chromeos::input_method::kControlKey); | 1741 control.SetValue(chromeos::input_method::kControlKey); |
1638 | 1742 |
1639 EventRewriter rewriter; | 1743 EventRewriter rewriter; |
1640 rewriter.set_pref_service_for_testing(&prefs); | 1744 rewriter.set_pref_service_for_testing(&prefs); |
1641 | 1745 |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2197 // flag in the event is True. | 2301 // flag in the event is True. |
2198 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, | 2302 EXPECT_EQ(GetExpectedResultAsString(ui::VKEY_CONTROL, |
2199 ui::EF_CONTROL_DOWN, | 2303 ui::EF_CONTROL_DOWN, |
2200 ui::ET_KEY_PRESSED, | 2304 ui::ET_KEY_PRESSED, |
2201 keycode_control_l_, | 2305 keycode_control_l_, |
2202 0U, | 2306 0U, |
2203 KeyPress), | 2307 KeyPress), |
2204 rewritten_event); | 2308 rewritten_event); |
2205 } | 2309 } |
2206 #endif // OS_CHROMEOS | 2310 #endif // OS_CHROMEOS |
OLD | NEW |