Chromium Code Reviews| 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/wm/window_state.h" | 9 #include "ash/wm/window_state.h" |
| 10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 580 rewritten = RewriteWithKeyboardRemappingsByKeyCode( | 580 rewritten = RewriteWithKeyboardRemappingsByKeyCode( |
| 581 kNonSearchRemappings, arraysize(kNonSearchRemappings), incoming, state); | 581 kNonSearchRemappings, arraysize(kNonSearchRemappings), incoming, state); |
| 582 } | 582 } |
| 583 } | 583 } |
| 584 | 584 |
| 585 void EventRewriter::RewriteFunctionKeys(const ui::KeyEvent& key_event, | 585 void EventRewriter::RewriteFunctionKeys(const ui::KeyEvent& key_event, |
| 586 MutableKeyState* state) { | 586 MutableKeyState* state) { |
| 587 CHECK(key_event.type() == ui::ET_KEY_PRESSED || | 587 CHECK(key_event.type() == ui::ET_KEY_PRESSED || |
| 588 key_event.type() == ui::ET_KEY_RELEASED); | 588 key_event.type() == ui::ET_KEY_RELEASED); |
| 589 MutableKeyState incoming = *state; | 589 MutableKeyState incoming = *state; |
| 590 bool rewritten = false; | |
| 591 | 590 |
| 592 if ((incoming.key_code >= ui::VKEY_F1) && | 591 if ((incoming.key_code >= ui::VKEY_F1) && |
| 593 (incoming.key_code <= ui::VKEY_F24)) { | 592 (incoming.key_code <= ui::VKEY_F24)) { |
| 594 // By default the top row (F1-F12) keys are system keys for back, forward, | 593 // By default the top row (F1-F12) keys are system keys for back, forward, |
| 595 // brightness, volume, etc. However, windows for v2 apps can optionally | 594 // brightness, volume, etc. However, windows for v2 apps can optionally |
| 596 // request raw function keys for these keys. | 595 // request raw function keys for these keys. |
| 597 bool top_row_keys_are_function_keys = TopRowKeysAreFunctionKeys(key_event); | 596 bool top_row_keys_are_function_keys = TopRowKeysAreFunctionKeys(key_event); |
| 598 bool search_is_pressed = (incoming.flags & ui::EF_COMMAND_DOWN) != 0; | 597 bool search_is_pressed = (incoming.flags & ui::EF_COMMAND_DOWN) != 0; |
| 599 | 598 |
| 600 // Search? Top Row Result | 599 // Search? Top Row Result |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 612 {ui::VKEY_F4, 0, ui::VKEY_MEDIA_LAUNCH_APP2, 0}, | 611 {ui::VKEY_F4, 0, ui::VKEY_MEDIA_LAUNCH_APP2, 0}, |
| 613 {ui::VKEY_F5, 0, ui::VKEY_MEDIA_LAUNCH_APP1, 0}, | 612 {ui::VKEY_F5, 0, ui::VKEY_MEDIA_LAUNCH_APP1, 0}, |
| 614 {ui::VKEY_F6, 0, ui::VKEY_BRIGHTNESS_DOWN, 0}, | 613 {ui::VKEY_F6, 0, ui::VKEY_BRIGHTNESS_DOWN, 0}, |
| 615 {ui::VKEY_F7, 0, ui::VKEY_BRIGHTNESS_UP, 0}, | 614 {ui::VKEY_F7, 0, ui::VKEY_BRIGHTNESS_UP, 0}, |
| 616 {ui::VKEY_F8, 0, ui::VKEY_VOLUME_MUTE, 0}, | 615 {ui::VKEY_F8, 0, ui::VKEY_VOLUME_MUTE, 0}, |
| 617 {ui::VKEY_F9, 0, ui::VKEY_VOLUME_DOWN, 0}, | 616 {ui::VKEY_F9, 0, ui::VKEY_VOLUME_DOWN, 0}, |
| 618 {ui::VKEY_F10, 0, ui::VKEY_VOLUME_UP, 0}, | 617 {ui::VKEY_F10, 0, ui::VKEY_VOLUME_UP, 0}, |
| 619 }; | 618 }; |
| 620 MutableKeyState incoming_without_command = incoming; | 619 MutableKeyState incoming_without_command = incoming; |
| 621 incoming_without_command.flags &= ~ui::EF_COMMAND_DOWN; | 620 incoming_without_command.flags &= ~ui::EF_COMMAND_DOWN; |
| 622 rewritten = | 621 RewriteWithKeyboardRemappingsByKeyCode(kFkeysToSystemKeys, |
| 623 RewriteWithKeyboardRemappingsByKeyCode(kFkeysToSystemKeys, | 622 arraysize(kFkeysToSystemKeys), |
| 624 arraysize(kFkeysToSystemKeys), | 623 incoming_without_command, |
| 625 incoming_without_command, | 624 state); |
| 626 state); | |
| 627 } else if (search_is_pressed) { | 625 } else if (search_is_pressed) { |
| 628 // Allow Search to avoid rewriting F1-F12. | 626 // Allow Search to avoid rewriting F1-F12. |
| 629 state->flags &= ~ui::EF_COMMAND_DOWN; | 627 state->flags &= ~ui::EF_COMMAND_DOWN; |
| 630 rewritten = true; | |
| 631 } | 628 } |
| 632 } | 629 state->flags |= ui::EF_FUNCTION_KEY; |
|
jonross
2014/05/23 18:48:49
Could you add a unittest that checks for this flag
bruthig
2014/05/23 19:50:07
Doesn't the existing/updated TestRewriteFunctionKe
jonross
2014/05/26 13:55:41
It does, I mis-interpreted the large struct/array
| |
| 633 | 630 } else if ((incoming.flags & ui::EF_COMMAND_DOWN)) { |
|
jonross
2014/05/26 13:55:41
Add a bounds check for the keys this cares about:
| |
| 634 if (!rewritten && (incoming.flags & ui::EF_COMMAND_DOWN)) { | |
|
jonross
2014/05/23 18:48:49
We are losing a path here. Is that intentional?
bruthig
2014/05/23 19:50:07
Yes, this if block will only do work if they origi
| |
| 635 // Remap Search+<number> to F<number>. | 631 // Remap Search+<number> to F<number>. |
| 636 // We check the keycode here instead of the keysym, as these keys have | 632 // We check the keycode here instead of the keysym, as these keys have |
| 637 // different keysyms when modifiers are pressed, such as shift. | 633 // different keysyms when modifiers are pressed, such as shift. |
| 638 | 634 |
| 639 // TODO(danakj): On some i18n keyboards, these choices will be bad and we | 635 // TODO(danakj): On some i18n keyboards, these choices will be bad and we |
| 640 // should make layout-specific choices here. For eg. on a french keyboard | 636 // should make layout-specific choices here. For eg. on a french keyboard |
| 641 // "-" and "6" are the same key, so F11 will not be accessible. | 637 // "-" and "6" are the same key, so F11 will not be accessible. |
| 642 static const KeyboardRemapping kNumberKeysToFkeys[] = { | 638 static const KeyboardRemapping kNumberKeysToFkeys[] = { |
| 643 {ui::VKEY_1, ui::EF_COMMAND_DOWN, ui::VKEY_F1, 0}, | 639 {ui::VKEY_1, ui::EF_COMMAND_DOWN, ui::VKEY_F1, 0}, |
| 644 {ui::VKEY_2, ui::EF_COMMAND_DOWN, ui::VKEY_F2, 0}, | 640 {ui::VKEY_2, ui::EF_COMMAND_DOWN, ui::VKEY_F2, 0}, |
| 645 {ui::VKEY_3, ui::EF_COMMAND_DOWN, ui::VKEY_F3, 0}, | 641 {ui::VKEY_3, ui::EF_COMMAND_DOWN, ui::VKEY_F3, 0}, |
| 646 {ui::VKEY_4, ui::EF_COMMAND_DOWN, ui::VKEY_F4, 0}, | 642 {ui::VKEY_4, ui::EF_COMMAND_DOWN, ui::VKEY_F4, 0}, |
| 647 {ui::VKEY_5, ui::EF_COMMAND_DOWN, ui::VKEY_F5, 0}, | 643 {ui::VKEY_5, ui::EF_COMMAND_DOWN, ui::VKEY_F5, 0}, |
| 648 {ui::VKEY_6, ui::EF_COMMAND_DOWN, ui::VKEY_F6, 0}, | 644 {ui::VKEY_6, ui::EF_COMMAND_DOWN, ui::VKEY_F6, 0}, |
| 649 {ui::VKEY_7, ui::EF_COMMAND_DOWN, ui::VKEY_F7, 0}, | 645 {ui::VKEY_7, ui::EF_COMMAND_DOWN, ui::VKEY_F7, 0}, |
| 650 {ui::VKEY_8, ui::EF_COMMAND_DOWN, ui::VKEY_F8, 0}, | 646 {ui::VKEY_8, ui::EF_COMMAND_DOWN, ui::VKEY_F8, 0}, |
| 651 {ui::VKEY_9, ui::EF_COMMAND_DOWN, ui::VKEY_F9, 0}, | 647 {ui::VKEY_9, ui::EF_COMMAND_DOWN, ui::VKEY_F9, 0}, |
| 652 {ui::VKEY_0, ui::EF_COMMAND_DOWN, ui::VKEY_F10, 0}, | 648 {ui::VKEY_0, ui::EF_COMMAND_DOWN, ui::VKEY_F10, 0}, |
| 653 {ui::VKEY_OEM_MINUS, ui::EF_COMMAND_DOWN, ui::VKEY_F11, 0}, | 649 {ui::VKEY_OEM_MINUS, ui::EF_COMMAND_DOWN, ui::VKEY_F11, 0}, |
| 654 {ui::VKEY_OEM_PLUS, ui::EF_COMMAND_DOWN, ui::VKEY_F12, 0}}; | 650 {ui::VKEY_OEM_PLUS, ui::EF_COMMAND_DOWN, ui::VKEY_F12, 0}}; |
| 655 rewritten = RewriteWithKeyboardRemappingsByKeyCode( | 651 RewriteWithKeyboardRemappingsByKeyCode( |
| 656 kNumberKeysToFkeys, arraysize(kNumberKeysToFkeys), incoming, state); | 652 kNumberKeysToFkeys, arraysize(kNumberKeysToFkeys), incoming, state); |
| 657 } | 653 } |
| 658 } | 654 } |
| 659 | 655 |
| 660 void EventRewriter::RewriteLocatedEvent(const ui::Event& event, | 656 void EventRewriter::RewriteLocatedEvent(const ui::Event& event, |
| 661 MutableKeyState* state) { | 657 MutableKeyState* state) { |
| 662 const PrefService* pref_service = GetPrefService(); | 658 const PrefService* pref_service = GetPrefService(); |
| 663 if (!pref_service) | 659 if (!pref_service) |
| 664 return; | 660 return; |
| 665 | 661 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 757 | 753 |
| 758 XIFreeDeviceInfo(device_info); | 754 XIFreeDeviceInfo(device_info); |
| 759 } | 755 } |
| 760 | 756 |
| 761 void EventRewriter::DeviceRemoved(int device_id) { | 757 void EventRewriter::DeviceRemoved(int device_id) { |
| 762 device_id_to_type_.erase(device_id); | 758 device_id_to_type_.erase(device_id); |
| 763 } | 759 } |
| 764 #endif | 760 #endif |
| 765 | 761 |
| 766 } // namespace chromeos | 762 } // namespace chromeos |
| OLD | NEW |