Chromium Code Reviews| Index: chrome/browser/ui/ash/event_rewriter.h |
| diff --git a/chrome/browser/ui/ash/event_rewriter.h b/chrome/browser/ui/ash/event_rewriter.h |
| index f35276df188009a5ecdf3480343aa082ec014695..1b1fc0e30c8bf7543669981f950cc4246a44e2eb 100644 |
| --- a/chrome/browser/ui/ash/event_rewriter.h |
| +++ b/chrome/browser/ui/ash/event_rewriter.h |
| @@ -11,6 +11,7 @@ |
| #include "ash/event_rewriter_delegate.h" |
| #include "base/basictypes.h" |
| #include "base/compiler_specific.h" |
| +#include "base/hash_tables.h" |
| #include "ui/aura/root_window_observer.h" |
| #include "ui/base/keycodes/keyboard_codes.h" |
| @@ -42,6 +43,7 @@ class EventRewriter : public ash::EventRewriterDelegate, |
| enum DeviceType { |
| kDeviceUnknown = 0, |
| kDeviceAppleKeyboard, |
| + kDeviceChromeOSKeyboard, |
| }; |
| EventRewriter(); |
| @@ -66,6 +68,9 @@ class EventRewriter : public ash::EventRewriterDelegate, |
| void set_xkeyboard_for_testing(chromeos::input_method::XKeyboard* xkeyboard) { |
| xkeyboard_ = xkeyboard; |
| } |
| + void set_force_chromeos_keyboard_for_testing(bool chromeos_keyboard) { |
| + force_chromeos_keyboard_for_testing_ = chromeos_keyboard; |
| + } |
| #endif |
| // Gets DeviceType from the |device_name|. |
| @@ -88,10 +93,53 @@ class EventRewriter : public ash::EventRewriterDelegate, |
| virtual void DeviceRemoved(int device_id) OVERRIDE; |
| virtual void DeviceKeyPressedOrReleased(int device_id) OVERRIDE; |
| + bool EventSourceIsChromeOSKeyboard() const; |
| + |
| // Updates |*_xkeycode_| in response to a keyboard map change. |
| void RefreshKeycodes(); |
| // Converts an X key symbol like XK_Control_L to a key code. |
| unsigned char NativeKeySymToNativeKeycode(unsigned long keysym); |
| + |
| + // We don't want to include Xlib.h here since it has polluting macros, so |
| + // define these locally. |
| + typedef unsigned long KeySym; |
|
Daniel Erat
2012/11/29 04:54:23
this approach seems fine to me, although i'd proba
danakj
2012/11/30 03:07:40
Ah, okay. I was worried about "already defined" co
danakj
2012/11/30 03:49:13
Actually, it did cause compiler errors, so I moved
|
| + typedef unsigned char KeyCode; |
| + |
| + struct KeyboardRemapping { |
| + KeySym input_keysym; |
| + unsigned int input_mods; |
| + unsigned int input_native_mods; |
| + KeySym output_keysym; |
| + ui::KeyboardCode output_keycode; |
| + }; |
| + |
| + // Given a set of KeyboardRemapping structs, it finds a matching struct |
| + // if possible, and returns the remapped event values. |
|
Daniel Erat
2012/11/29 04:54:23
nit: s/returns/updates/, also add "Returns true if
danakj
2012/11/30 03:07:40
Done.
|
| + bool RewriteWithKeyboardRemappingsByKeySym( |
| + const KeyboardRemapping* remappings, |
| + size_t num_remappings, |
| + KeySym keysym, |
| + unsigned int native_mods, |
| + unsigned int mods, |
| + KeySym* remapped_native_keysym, |
| + unsigned int* remapped_native_mods, |
| + ui::KeyboardCode* remapped_keycode, |
| + unsigned int* remapped_mods); |
| + |
| + // Given a set of KeyboardRemapping structs, it finds a matching struct |
| + // if possible, and returns the remapped event values. This function converts |
| + // the KeySym in the KeyboardRemapping struct into the KeyCode before matching |
| + // to allow any KeyCode on the same physical key as the given KeySym to match. |
| + bool RewriteWithKeyboardRemappingsByKeyCode( |
| + const KeyboardRemapping* remappings, |
| + size_t num_remappings, |
| + KeyCode keycode, |
| + unsigned int native_mods, |
| + unsigned int mods, |
| + KeySym* remapped_native_keysym, |
| + unsigned int* remapped_native_mods, |
| + ui::KeyboardCode* remapped_keycode, |
| + unsigned int* remapped_mods); |
| #endif |
| // Rewrites the |event| by applying all RewriteXXX functions as needed. |
| @@ -125,6 +173,11 @@ class EventRewriter : public ash::EventRewriterDelegate, |
| // Returns true when the |event| is rewritten. |
| bool RewriteBackspaceAndArrowKeys(ui::KeyEvent* event); |
| + // When the Search key acts as a function key, it remaps Search+1 |
| + // through Search+= to F1 through F12. Returns true when the |event| is |
| + // rewritten. |
| + bool RewriteFunctionKeys(ui::KeyEvent* event); |
| + |
| // Rewrites the located |event|. |
| void RewriteLocatedEvent(ui::LocatedEvent* event); |
| @@ -153,32 +206,10 @@ class EventRewriter : public ash::EventRewriterDelegate, |
| int last_device_id_; |
| #if defined(OS_CHROMEOS) |
| - // X keycodes corresponding to various keysyms. |
| - unsigned int control_l_xkeycode_; |
| - unsigned int control_r_xkeycode_; |
| - unsigned int alt_l_xkeycode_; |
| - unsigned int alt_r_xkeycode_; |
| - unsigned int meta_l_xkeycode_; |
| - unsigned int meta_r_xkeycode_; |
| - unsigned int windows_l_xkeycode_; |
| - unsigned int caps_lock_xkeycode_; |
| - unsigned int void_symbol_xkeycode_; |
| - unsigned int delete_xkeycode_; |
| - unsigned int home_xkeycode_; |
| - unsigned int end_xkeycode_; |
| - unsigned int prior_xkeycode_; |
| - unsigned int next_xkeycode_; |
| - unsigned int kp_0_xkeycode_; |
| - unsigned int kp_1_xkeycode_; |
| - unsigned int kp_2_xkeycode_; |
| - unsigned int kp_3_xkeycode_; |
| - unsigned int kp_4_xkeycode_; |
| - unsigned int kp_5_xkeycode_; |
| - unsigned int kp_6_xkeycode_; |
| - unsigned int kp_7_xkeycode_; |
| - unsigned int kp_8_xkeycode_; |
| - unsigned int kp_9_xkeycode_; |
| - unsigned int kp_decimal_xkeycode_; |
| + bool force_chromeos_keyboard_for_testing_; |
| + |
| + // A mapping from X11 KeySym keys to KeyCode values. |
| + base::hash_map<unsigned long, unsigned long> keysym_to_keycode_map_; |
| chromeos::input_method::XKeyboard* xkeyboard_; // for testing. |
| #endif |