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

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

Issue 286103004: Blocked volume up/down events that originated from remapped function keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Wrapped AllowsVolumeControl test in #ifdef (USE_X11) Created 6 years, 7 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
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 <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
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
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;
633 630 } else if ((incoming.flags & ui::EF_COMMAND_DOWN)) {
634 if (!rewritten && (incoming.flags & ui::EF_COMMAND_DOWN)) {
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698