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

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

Issue 1120813002: Remove EF_FUNCTION_KEY and EF_NUMPAD_KEY. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments (wez@) Created 5 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/sticky_keys/sticky_keys_controller.h" 9 #include "ash/sticky_keys/sticky_keys_controller.h"
10 #include "ash/wm/window_state.h" 10 #include "ash/wm/window_state.h"
11 #include "ash/wm/window_util.h" 11 #include "ash/wm/window_util.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/sys_info.h" 17 #include "base/sys_info.h"
18 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" 18 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
19 #include "chrome/browser/extensions/extension_commands_global_registry.h" 19 #include "chrome/browser/extensions/extension_commands_global_registry.h"
20 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chromeos/chromeos_switches.h" 22 #include "chromeos/chromeos_switches.h"
23 #include "components/user_manager/user_manager.h" 23 #include "components/user_manager/user_manager.h"
24 #include "ui/base/ime/chromeos/ime_keyboard.h" 24 #include "ui/base/ime/chromeos/ime_keyboard.h"
25 #include "ui/base/ime/chromeos/input_method_manager.h" 25 #include "ui/base/ime/chromeos/input_method_manager.h"
26 #include "ui/events/devices/device_data_manager.h" 26 #include "ui/events/devices/device_data_manager.h"
27 #include "ui/events/event.h" 27 #include "ui/events/event.h"
28 #include "ui/events/event_utils.h" 28 #include "ui/events/event_utils.h"
29 #include "ui/events/keycodes/dom3/dom_code.h"
30 #include "ui/events/keycodes/dom4/keycode_converter.h"
29 #include "ui/events/keycodes/keyboard_code_conversion.h" 31 #include "ui/events/keycodes/keyboard_code_conversion.h"
30 #include "ui/wm/core/window_util.h" 32 #include "ui/wm/core/window_util.h"
31 33
32 #if defined(USE_X11) 34 #if defined(USE_X11)
33 #include <X11/extensions/XInput2.h> 35 #include <X11/extensions/XInput2.h>
34 #include <X11/Xlib.h> 36 #include <X11/Xlib.h>
35 37
36 // Get rid of macros from Xlib.h that conflicts with other parts of the code. 38 // Get rid of macros from Xlib.h that conflicts with other parts of the code.
37 #undef RootWindow 39 #undef RootWindow
38 #undef Status 40 #undef Status
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 numpad_xevent.xkey = xkeyevent.xkey; 282 numpad_xevent.xkey = xkeyevent.xkey;
281 // Remove the shift state before getting key char. 283 // Remove the shift state before getting key char.
282 // Because X11/XKB sometimes returns unexpected key char for 284 // Because X11/XKB sometimes returns unexpected key char for
283 // Shift+NumpadKey. e.g. Shift+Numpad_4 returns 'D', etc. 285 // Shift+NumpadKey. e.g. Shift+Numpad_4 returns 'D', etc.
284 numpad_xevent.xkey.state &= ~ShiftMask; 286 numpad_xevent.xkey.state &= ~ShiftMask;
285 numpad_xevent.xkey.state |= Mod2Mask; // Always set NumLock mask. 287 numpad_xevent.xkey.state |= Mod2Mask; // Always set NumLock mask.
286 if (!(flags & ui::EF_SHIFT_DOWN)) 288 if (!(flags & ui::EF_SHIFT_DOWN))
287 numpad_xevent.xkey.keycode = original_x11_keycode; 289 numpad_xevent.xkey.keycode = original_x11_keycode;
288 rewritten_key_event->set_character( 290 rewritten_key_event->set_character(
289 ui::GetCharacterFromXEvent(&numpad_xevent)); 291 ui::GetCharacterFromXEvent(&numpad_xevent));
292 rewritten_key_event->native_event()->xkey.state |= Mod2Mask;
Wez 2015/05/05 21:23:44 This code is super confusing; does native_event()
kpschoedel 2015/05/05 22:19:07 It is (and I don't actually understand the intent
290 } 293 }
291 } 294 }
292 #endif 295 #endif
293 if (!rewritten_key_event) 296 if (!rewritten_key_event)
294 rewritten_key_event = new ui::KeyEvent(key_event); 297 rewritten_key_event = new ui::KeyEvent(key_event);
295 rewritten_key_event->set_flags(flags); 298 rewritten_key_event->set_flags(flags);
296 rewritten_key_event->set_key_code(key_code); 299 rewritten_key_event->set_key_code(key_code);
297 #if defined(USE_X11) 300 #if defined(USE_X11)
298 ui::UpdateX11EventForFlags(rewritten_key_event); 301 ui::UpdateX11EventForFlags(rewritten_key_event);
299 rewritten_key_event->NormalizeFlags(); 302 rewritten_key_event->NormalizeFlags();
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 : chromeos::input_method::InputMethodManager::Get() 703 : chromeos::input_method::InputMethodManager::Get()
701 ->GetImeKeyboard(); 704 ->GetImeKeyboard();
702 ime_keyboard->SetCapsLockEnabled(!ime_keyboard->CapsLockIsEnabled()); 705 ime_keyboard->SetCapsLockEnabled(!ime_keyboard->CapsLockIsEnabled());
703 } 706 }
704 } 707 }
705 708
706 void EventRewriter::RewriteNumPadKeys(const ui::KeyEvent& key_event, 709 void EventRewriter::RewriteNumPadKeys(const ui::KeyEvent& key_event,
707 MutableKeyState* state) { 710 MutableKeyState* state) {
708 DCHECK(key_event.type() == ui::ET_KEY_PRESSED || 711 DCHECK(key_event.type() == ui::ET_KEY_PRESSED ||
709 key_event.type() == ui::ET_KEY_RELEASED); 712 key_event.type() == ui::ET_KEY_RELEASED);
710 if (!(state->flags & ui::EF_NUMPAD_KEY))
711 return;
712 MutableKeyState incoming = *state; 713 MutableKeyState incoming = *state;
713 714 static const struct NumPadRemapping {
714 static const KeyboardRemapping kNumPadRemappings[] = { 715 ui::DomCode input_dom_code;
715 {ui::VKEY_INSERT, ui::EF_NUMPAD_KEY, ui::VKEY_NUMPAD0, ui::EF_NUMPAD_KEY}, 716 ui::KeyboardCode input_key_code;
716 {ui::VKEY_DELETE, ui::EF_NUMPAD_KEY, ui::VKEY_DECIMAL, ui::EF_NUMPAD_KEY}, 717 ui::KeyboardCode output_key_code;
717 {ui::VKEY_END, ui::EF_NUMPAD_KEY, ui::VKEY_NUMPAD1, ui::EF_NUMPAD_KEY}, 718 } kNumPadRemappings[] = {
718 {ui::VKEY_DOWN, ui::EF_NUMPAD_KEY, ui::VKEY_NUMPAD2, ui::EF_NUMPAD_KEY}, 719 {ui::DomCode::NUMPAD_DECIMAL, ui::VKEY_DELETE, ui::VKEY_DECIMAL},
719 {ui::VKEY_NEXT, ui::EF_NUMPAD_KEY, ui::VKEY_NUMPAD3, ui::EF_NUMPAD_KEY}, 720 {ui::DomCode::NUMPAD0, ui::VKEY_INSERT, ui::VKEY_NUMPAD0},
720 {ui::VKEY_LEFT, ui::EF_NUMPAD_KEY, ui::VKEY_NUMPAD4, ui::EF_NUMPAD_KEY}, 721 {ui::DomCode::NUMPAD1, ui::VKEY_END, ui::VKEY_NUMPAD1},
721 {ui::VKEY_CLEAR, ui::EF_NUMPAD_KEY, ui::VKEY_NUMPAD5, ui::EF_NUMPAD_KEY}, 722 {ui::DomCode::NUMPAD2, ui::VKEY_DOWN, ui::VKEY_NUMPAD2},
722 {ui::VKEY_RIGHT, ui::EF_NUMPAD_KEY, ui::VKEY_NUMPAD6, ui::EF_NUMPAD_KEY}, 723 {ui::DomCode::NUMPAD3, ui::VKEY_NEXT, ui::VKEY_NUMPAD3},
723 {ui::VKEY_HOME, ui::EF_NUMPAD_KEY, ui::VKEY_NUMPAD7, ui::EF_NUMPAD_KEY}, 724 {ui::DomCode::NUMPAD4, ui::VKEY_LEFT, ui::VKEY_NUMPAD4},
724 {ui::VKEY_UP, ui::EF_NUMPAD_KEY, ui::VKEY_NUMPAD8, ui::EF_NUMPAD_KEY}, 725 {ui::DomCode::NUMPAD5, ui::VKEY_CLEAR, ui::VKEY_NUMPAD5},
725 {ui::VKEY_PRIOR, ui::EF_NUMPAD_KEY, ui::VKEY_NUMPAD9, ui::EF_NUMPAD_KEY}, 726 {ui::DomCode::NUMPAD6, ui::VKEY_RIGHT, ui::VKEY_NUMPAD6},
727 {ui::DomCode::NUMPAD7, ui::VKEY_HOME, ui::VKEY_NUMPAD7},
728 {ui::DomCode::NUMPAD8, ui::VKEY_UP, ui::VKEY_NUMPAD8},
729 {ui::DomCode::NUMPAD9, ui::VKEY_PRIOR, ui::VKEY_NUMPAD9},
Wez 2015/05/05 21:23:44 Remind me - we always rewrite num-pad keys to beha
kpschoedel 2015/05/05 22:19:07 Yes. In the future, either when/if I get around to
726 }; 730 };
727 731 for (const auto& map : kNumPadRemappings) {
Wez 2015/05/05 21:23:44 We end up with a lot of these remapping loops; if
kpschoedel 2015/05/05 22:19:08 Yes, I've been considering this as I do the work t
728 RewriteWithKeyboardRemappingsByKeyCode( 732 if ((incoming.key_code == map.input_key_code) &&
729 kNumPadRemappings, arraysize(kNumPadRemappings), incoming, state); 733 (key_event.code() == map.input_dom_code)) {
734 state->key_code = map.output_key_code;
735 break;
736 }
737 }
730 } 738 }
731 739
732 void EventRewriter::RewriteExtendedKeys(const ui::KeyEvent& key_event, 740 void EventRewriter::RewriteExtendedKeys(const ui::KeyEvent& key_event,
733 MutableKeyState* state) { 741 MutableKeyState* state) {
734 DCHECK(key_event.type() == ui::ET_KEY_PRESSED || 742 DCHECK(key_event.type() == ui::ET_KEY_PRESSED ||
735 key_event.type() == ui::ET_KEY_RELEASED); 743 key_event.type() == ui::ET_KEY_RELEASED);
736 744
737 MutableKeyState incoming = *state; 745 MutableKeyState incoming = *state;
738 bool rewritten = false; 746 bool rewritten = false;
739 747
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 for (const auto& keyboard : keyboards) { 948 for (const auto& keyboard : keyboards) {
941 if (keyboard.id == device_id) { 949 if (keyboard.id == device_id) {
942 return KeyboardDeviceAddedInternal( 950 return KeyboardDeviceAddedInternal(
943 keyboard.id, keyboard.name, keyboard.vendor_id, keyboard.product_id); 951 keyboard.id, keyboard.name, keyboard.vendor_id, keyboard.product_id);
944 } 952 }
945 } 953 }
946 return kDeviceUnknown; 954 return kDeviceUnknown;
947 } 955 }
948 956
949 } // namespace chromeos 957 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698