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

Side by Side Diff: chrome/browser/ui/ash/event_rewriter.h

Issue 11417144: Use rewriting to make ChromeOS keyboard F<number> keys produce extended keycodes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: forlanding3 Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/ash/chrome_shell_delegate.cc ('k') | chrome/browser/ui/ash/event_rewriter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef CHROME_BROWSER_UI_ASH_EVENT_REWRITER_H_ 5 #ifndef CHROME_BROWSER_UI_ASH_EVENT_REWRITER_H_
6 #define CHROME_BROWSER_UI_ASH_EVENT_REWRITER_H_ 6 #define CHROME_BROWSER_UI_ASH_EVENT_REWRITER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "ash/event_rewriter_delegate.h" 11 #include "ash/event_rewriter_delegate.h"
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/hash_tables.h"
14 #include "ui/aura/root_window_observer.h" 15 #include "ui/aura/root_window_observer.h"
15 #include "ui/base/keycodes/keyboard_codes.h" 16 #include "ui/base/keycodes/keyboard_codes.h"
16 17
17 #if defined(OS_CHROMEOS) 18 #if defined(OS_CHROMEOS)
18 #include "chrome/browser/chromeos/device_hierarchy_observer.h" 19 #include "chrome/browser/chromeos/device_hierarchy_observer.h"
19 #endif 20 #endif
20 21
21 class PrefService; 22 class PrefService;
22 23
23 namespace aura { 24 namespace aura {
(...skipping 11 matching lines...) Expand all
35 class EventRewriter : public ash::EventRewriterDelegate, 36 class EventRewriter : public ash::EventRewriterDelegate,
36 public aura::RootWindowObserver 37 public aura::RootWindowObserver
37 #if defined(OS_CHROMEOS) 38 #if defined(OS_CHROMEOS)
38 , public chromeos::DeviceHierarchyObserver 39 , public chromeos::DeviceHierarchyObserver
39 #endif 40 #endif
40 { 41 {
41 public: 42 public:
42 enum DeviceType { 43 enum DeviceType {
43 kDeviceUnknown = 0, 44 kDeviceUnknown = 0,
44 kDeviceAppleKeyboard, 45 kDeviceAppleKeyboard,
46 #if defined(OS_CHROMEOS)
47 kDeviceChromeOSKeyboard,
48 #endif
45 }; 49 };
46 50
47 EventRewriter(); 51 EventRewriter();
48 virtual ~EventRewriter(); 52 virtual ~EventRewriter();
49 53
50 // Calls DeviceAddedInternal. 54 // Calls DeviceAddedInternal.
51 DeviceType DeviceAddedForTesting(int device_id, 55 DeviceType DeviceAddedForTesting(int device_id,
52 const std::string& device_name); 56 const std::string& device_name);
53 // Calls Rewrite. 57 // Calls Rewrite.
54 void RewriteForTesting(ui::KeyEvent* event); 58 void RewriteForTesting(ui::KeyEvent* event);
55 59
56 const std::map<int, DeviceType>& device_id_to_type_for_testing() const { 60 const std::map<int, DeviceType>& device_id_to_type_for_testing() const {
57 return device_id_to_type_; 61 return device_id_to_type_;
58 } 62 }
59 void set_last_device_id_for_testing(int device_id) { 63 void set_last_device_id_for_testing(int device_id) {
60 last_device_id_ = device_id; 64 last_device_id_ = device_id;
61 } 65 }
62 void set_pref_service_for_testing(const PrefService* pref_service) { 66 void set_pref_service_for_testing(const PrefService* pref_service) {
63 pref_service_ = pref_service; 67 pref_service_ = pref_service;
64 } 68 }
65 #if defined(OS_CHROMEOS) 69 #if defined(OS_CHROMEOS)
66 void set_xkeyboard_for_testing(chromeos::input_method::XKeyboard* xkeyboard) { 70 void set_xkeyboard_for_testing(chromeos::input_method::XKeyboard* xkeyboard) {
67 xkeyboard_ = xkeyboard; 71 xkeyboard_ = xkeyboard;
68 } 72 }
73 void set_force_chromeos_keyboard_for_testing(bool chromeos_keyboard) {
74 force_chromeos_keyboard_for_testing_ = chromeos_keyboard;
75 }
69 #endif 76 #endif
70 77
71 // Gets DeviceType from the |device_name|. 78 // Gets DeviceType from the |device_name|.
72 static DeviceType GetDeviceType(const std::string& device_name); 79 static DeviceType GetDeviceType(const std::string& device_name);
73 80
74 private: 81 private:
75 // ash::EventRewriterDelegate overrides: 82 // ash::EventRewriterDelegate overrides:
76 virtual ash::EventRewriterDelegate::Action RewriteOrFilterKeyEvent( 83 virtual ash::EventRewriterDelegate::Action RewriteOrFilterKeyEvent(
77 ui::KeyEvent* event) OVERRIDE; 84 ui::KeyEvent* event) OVERRIDE;
78 virtual ash::EventRewriterDelegate::Action RewriteOrFilterLocatedEvent( 85 virtual ash::EventRewriterDelegate::Action RewriteOrFilterLocatedEvent(
79 ui::LocatedEvent* event) OVERRIDE; 86 ui::LocatedEvent* event) OVERRIDE;
80 87
81 // aura::RootWindowObserver overrides: 88 // aura::RootWindowObserver overrides:
82 virtual void OnKeyboardMappingChanged(const aura::RootWindow* root) OVERRIDE; 89 virtual void OnKeyboardMappingChanged(const aura::RootWindow* root) OVERRIDE;
83 90
84 #if defined(OS_CHROMEOS) 91 #if defined(OS_CHROMEOS)
85 // chromeos::DeviceHierarchyObserver overrides: 92 // chromeos::DeviceHierarchyObserver overrides:
86 virtual void DeviceHierarchyChanged() OVERRIDE {} 93 virtual void DeviceHierarchyChanged() OVERRIDE {}
87 virtual void DeviceAdded(int device_id) OVERRIDE; 94 virtual void DeviceAdded(int device_id) OVERRIDE;
88 virtual void DeviceRemoved(int device_id) OVERRIDE; 95 virtual void DeviceRemoved(int device_id) OVERRIDE;
89 virtual void DeviceKeyPressedOrReleased(int device_id) OVERRIDE; 96 virtual void DeviceKeyPressedOrReleased(int device_id) OVERRIDE;
90 97
98 bool EventSourceIsChromeOSKeyboard() const;
99
100 // We don't want to include Xlib.h here since it has polluting macros, so
101 // define these locally.
102 typedef unsigned long KeySym;
103 typedef unsigned char KeyCode;
104
91 // Updates |*_xkeycode_| in response to a keyboard map change. 105 // Updates |*_xkeycode_| in response to a keyboard map change.
92 void RefreshKeycodes(); 106 void RefreshKeycodes();
93 // Converts an X key symbol like XK_Control_L to a key code. 107 // Converts an X key symbol like XK_Control_L to a key code.
94 unsigned char NativeKeySymToNativeKeycode(unsigned long keysym); 108 unsigned char NativeKeySymToNativeKeycode(KeySym keysym);
109
110 struct KeyboardRemapping {
111 KeySym input_keysym;
112 unsigned int input_mods;
113 unsigned int input_native_mods;
114 KeySym output_keysym;
115 ui::KeyboardCode output_keycode;
116 };
117
118 // Given a set of KeyboardRemapping structs, it finds a matching struct
119 // if possible, and updates the remapped event values. Returns true if a
120 // remapping was found and remapped values were updated.
121 bool RewriteWithKeyboardRemappingsByKeySym(
122 const KeyboardRemapping* remappings,
123 size_t num_remappings,
124 KeySym keysym,
125 unsigned int native_mods,
126 unsigned int mods,
127 KeySym* remapped_native_keysym,
128 unsigned int* remapped_native_mods,
129 ui::KeyboardCode* remapped_keycode,
130 unsigned int* remapped_mods);
131
132 // Given a set of KeyboardRemapping structs, it finds a matching struct
133 // if possible, and updates the remapped event values. This function converts
134 // the KeySym in the KeyboardRemapping struct into the KeyCode before matching
135 // to allow any KeyCode on the same physical key as the given KeySym to match.
136 // Returns true if a remapping was found and remapped values were updated.
137 bool RewriteWithKeyboardRemappingsByKeyCode(
138 const KeyboardRemapping* remappings,
139 size_t num_remappings,
140 KeyCode keycode,
141 unsigned int native_mods,
142 unsigned int mods,
143 KeySym* remapped_native_keysym,
144 unsigned int* remapped_native_mods,
145 ui::KeyboardCode* remapped_keycode,
146 unsigned int* remapped_mods);
95 #endif 147 #endif
96 148
97 // Rewrites the |event| by applying all RewriteXXX functions as needed. 149 // Rewrites the |event| by applying all RewriteXXX functions as needed.
98 void Rewrite(ui::KeyEvent* event); 150 void Rewrite(ui::KeyEvent* event);
99 151
100 // Rewrites a modifier key press/release following the current user 152 // Rewrites a modifier key press/release following the current user
101 // preferences. 153 // preferences.
102 bool RewriteModifiers(ui::KeyEvent* event); 154 bool RewriteModifiers(ui::KeyEvent* event);
103 155
104 // Rewrites Fn key press/release to Control. In some cases, Fn key is not 156 // Rewrites Fn key press/release to Control. In some cases, Fn key is not
(...skipping 13 matching lines...) Expand all
118 // * Ctrl+Alt+Down -> End 170 // * Ctrl+Alt+Down -> End
119 // When the Search key acts as a function key, it instead maps: 171 // When the Search key acts as a function key, it instead maps:
120 // * Search+Backspace -> Delete 172 // * Search+Backspace -> Delete
121 // * Search+Up -> Prior (aka PageUp) 173 // * Search+Up -> Prior (aka PageUp)
122 // * Search+Down -> Next (aka PageDown) 174 // * Search+Down -> Next (aka PageDown)
123 // * Search+Left -> Home 175 // * Search+Left -> Home
124 // * Search+right -> End 176 // * Search+right -> End
125 // Returns true when the |event| is rewritten. 177 // Returns true when the |event| is rewritten.
126 bool RewriteBackspaceAndArrowKeys(ui::KeyEvent* event); 178 bool RewriteBackspaceAndArrowKeys(ui::KeyEvent* event);
127 179
180 // When the Search key acts as a function key, it remaps Search+1
181 // through Search+= to F1 through F12. Returns true when the |event| is
182 // rewritten.
183 bool RewriteFunctionKeys(ui::KeyEvent* event);
184
128 // Rewrites the located |event|. 185 // Rewrites the located |event|.
129 void RewriteLocatedEvent(ui::LocatedEvent* event); 186 void RewriteLocatedEvent(ui::LocatedEvent* event);
130 187
131 // Overwrites |event| with the keycodes and flags. 188 // Overwrites |event| with the keycodes and flags.
132 void OverwriteEvent(ui::KeyEvent* event, 189 void OverwriteEvent(ui::KeyEvent* event,
133 unsigned int new_native_keycode, 190 unsigned int new_native_keycode,
134 unsigned int new_native_state, 191 unsigned int new_native_state,
135 ui::KeyboardCode new_keycode, 192 ui::KeyboardCode new_keycode,
136 int new_flags); 193 int new_flags);
137 194
138 // Checks the type of the |device_name|, and inserts a new entry to 195 // Checks the type of the |device_name|, and inserts a new entry to
139 // |device_id_to_type_|. 196 // |device_id_to_type_|.
140 DeviceType DeviceAddedInternal(int device_id, const std::string& device_name); 197 DeviceType DeviceAddedInternal(int device_id, const std::string& device_name);
141 198
142 // Returns true if |last_device_id_| is Apple's. 199 // Returns true if |last_device_id_| is Apple's.
143 bool IsAppleKeyboard() const; 200 bool IsAppleKeyboard() const;
144 201
145 // Remaps |original_flags| to |remapped_flags| and |original_native_modifiers| 202 // Remaps |original_flags| to |remapped_flags| and |original_native_modifiers|
146 // to |remapped_native_modifiers| following the current user prefs. 203 // to |remapped_native_modifiers| following the current user prefs.
147 void GetRemappedModifierMasks(int original_flags, 204 void GetRemappedModifierMasks(int original_flags,
148 unsigned int original_native_modifiers, 205 unsigned int original_native_modifiers,
149 int* remapped_flags, 206 int* remapped_flags,
150 unsigned int* remapped_native_modifiers) const; 207 unsigned int* remapped_native_modifiers) const;
151 208
152 std::map<int, DeviceType> device_id_to_type_; 209 std::map<int, DeviceType> device_id_to_type_;
153 int last_device_id_; 210 int last_device_id_;
154 211
155 #if defined(OS_CHROMEOS) 212 #if defined(OS_CHROMEOS)
156 // X keycodes corresponding to various keysyms. 213 bool force_chromeos_keyboard_for_testing_;
157 unsigned int control_l_xkeycode_; 214
158 unsigned int control_r_xkeycode_; 215 // A mapping from X11 KeySym keys to KeyCode values.
159 unsigned int alt_l_xkeycode_; 216 base::hash_map<unsigned long, unsigned long> keysym_to_keycode_map_;
160 unsigned int alt_r_xkeycode_;
161 unsigned int meta_l_xkeycode_;
162 unsigned int meta_r_xkeycode_;
163 unsigned int windows_l_xkeycode_;
164 unsigned int caps_lock_xkeycode_;
165 unsigned int void_symbol_xkeycode_;
166 unsigned int delete_xkeycode_;
167 unsigned int home_xkeycode_;
168 unsigned int end_xkeycode_;
169 unsigned int prior_xkeycode_;
170 unsigned int next_xkeycode_;
171 unsigned int kp_0_xkeycode_;
172 unsigned int kp_1_xkeycode_;
173 unsigned int kp_2_xkeycode_;
174 unsigned int kp_3_xkeycode_;
175 unsigned int kp_4_xkeycode_;
176 unsigned int kp_5_xkeycode_;
177 unsigned int kp_6_xkeycode_;
178 unsigned int kp_7_xkeycode_;
179 unsigned int kp_8_xkeycode_;
180 unsigned int kp_9_xkeycode_;
181 unsigned int kp_decimal_xkeycode_;
182 217
183 chromeos::input_method::XKeyboard* xkeyboard_; // for testing. 218 chromeos::input_method::XKeyboard* xkeyboard_; // for testing.
184 #endif 219 #endif
185 220
186 const PrefService* pref_service_; // for testing. 221 const PrefService* pref_service_; // for testing.
187 222
188 DISALLOW_COPY_AND_ASSIGN(EventRewriter); 223 DISALLOW_COPY_AND_ASSIGN(EventRewriter);
189 }; 224 };
190 225
191 #endif // CHROME_BROWSER_UI_ASH_EVENT_REWRITER_H_ 226 #endif // CHROME_BROWSER_UI_ASH_EVENT_REWRITER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/chrome_shell_delegate.cc ('k') | chrome/browser/ui/ash/event_rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698