OLD | NEW |
---|---|
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 |
(...skipping 24 matching lines...) Expand all Loading... | |
35 class EventRewriter : public ash::EventRewriterDelegate, | 35 class EventRewriter : public ash::EventRewriterDelegate, |
36 public aura::RootWindowObserver | 36 public aura::RootWindowObserver |
37 #if defined(OS_CHROMEOS) | 37 #if defined(OS_CHROMEOS) |
38 , public chromeos::DeviceHierarchyObserver | 38 , public chromeos::DeviceHierarchyObserver |
39 #endif | 39 #endif |
40 { | 40 { |
41 public: | 41 public: |
42 enum DeviceType { | 42 enum DeviceType { |
43 kDeviceUnknown = 0, | 43 kDeviceUnknown = 0, |
44 kDeviceAppleKeyboard, | 44 kDeviceAppleKeyboard, |
45 kDeviceChromebookKeyboard, | |
45 }; | 46 }; |
46 | 47 |
47 EventRewriter(); | 48 EventRewriter(); |
48 virtual ~EventRewriter(); | 49 virtual ~EventRewriter(); |
49 | 50 |
50 // Calls DeviceAddedInternal. | 51 // Calls DeviceAddedInternal. |
51 DeviceType DeviceAddedForTesting(int device_id, | 52 DeviceType DeviceAddedForTesting(int device_id, |
52 const std::string& device_name); | 53 const std::string& device_name); |
53 // Calls Rewrite. | 54 // Calls Rewrite. |
54 void RewriteForTesting(ui::KeyEvent* event); | 55 void RewriteForTesting(ui::KeyEvent* event); |
55 | 56 |
56 const std::map<int, DeviceType>& device_id_to_type_for_testing() const { | 57 const std::map<int, DeviceType>& device_id_to_type_for_testing() const { |
57 return device_id_to_type_; | 58 return device_id_to_type_; |
58 } | 59 } |
59 void set_last_device_id_for_testing(int device_id) { | 60 void set_last_device_id_for_testing(int device_id) { |
60 last_device_id_ = device_id; | 61 last_device_id_ = device_id; |
61 } | 62 } |
62 void set_pref_service_for_testing(const PrefService* pref_service) { | 63 void set_pref_service_for_testing(const PrefService* pref_service) { |
63 pref_service_ = pref_service; | 64 pref_service_ = pref_service; |
64 } | 65 } |
65 #if defined(OS_CHROMEOS) | 66 #if defined(OS_CHROMEOS) |
66 void set_xkeyboard_for_testing(chromeos::input_method::XKeyboard* xkeyboard) { | 67 void set_xkeyboard_for_testing(chromeos::input_method::XKeyboard* xkeyboard) { |
67 xkeyboard_ = xkeyboard; | 68 xkeyboard_ = xkeyboard; |
68 } | 69 } |
70 void set_force_external_keyboard_for_testing(bool external_keyboard) { | |
71 force_external_keyboard_for_testing_ = external_keyboard; | |
72 } | |
69 #endif | 73 #endif |
70 | 74 |
71 // Gets DeviceType from the |device_name|. | 75 // Gets DeviceType from the |device_name|. |
72 static DeviceType GetDeviceType(const std::string& device_name); | 76 static DeviceType GetDeviceType(const std::string& device_name); |
73 | 77 |
74 private: | 78 private: |
75 // ash::EventRewriterDelegate overrides: | 79 // ash::EventRewriterDelegate overrides: |
76 virtual ash::EventRewriterDelegate::Action RewriteOrFilterKeyEvent( | 80 virtual ash::EventRewriterDelegate::Action RewriteOrFilterKeyEvent( |
77 ui::KeyEvent* event) OVERRIDE; | 81 ui::KeyEvent* event) OVERRIDE; |
78 virtual ash::EventRewriterDelegate::Action RewriteOrFilterLocatedEvent( | 82 virtual ash::EventRewriterDelegate::Action RewriteOrFilterLocatedEvent( |
79 ui::LocatedEvent* event) OVERRIDE; | 83 ui::LocatedEvent* event) OVERRIDE; |
80 | 84 |
81 // aura::RootWindowObserver overrides: | 85 // aura::RootWindowObserver overrides: |
82 virtual void OnKeyboardMappingChanged(const aura::RootWindow* root) OVERRIDE; | 86 virtual void OnKeyboardMappingChanged(const aura::RootWindow* root) OVERRIDE; |
83 | 87 |
84 #if defined(OS_CHROMEOS) | 88 #if defined(OS_CHROMEOS) |
85 // chromeos::DeviceHierarchyObserver overrides: | 89 // chromeos::DeviceHierarchyObserver overrides: |
86 virtual void DeviceHierarchyChanged() OVERRIDE {} | 90 virtual void DeviceHierarchyChanged() OVERRIDE {} |
87 virtual void DeviceAdded(int device_id) OVERRIDE; | 91 virtual void DeviceAdded(int device_id) OVERRIDE; |
88 virtual void DeviceRemoved(int device_id) OVERRIDE; | 92 virtual void DeviceRemoved(int device_id) OVERRIDE; |
89 virtual void DeviceKeyPressedOrReleased(int device_id) OVERRIDE; | 93 virtual void DeviceKeyPressedOrReleased(int device_id) OVERRIDE; |
90 | 94 |
95 bool EventSourceIsChromebookKeyboard(ui::KeyEvent* event); | |
Daniel Erat
2012/11/28 22:23:03
nit: const argument and method
danakj
2012/11/29 01:50:54
Done. The argument ends up unusued anyhow, so I re
| |
96 | |
91 // Updates |*_xkeycode_| in response to a keyboard map change. | 97 // Updates |*_xkeycode_| in response to a keyboard map change. |
92 void RefreshKeycodes(); | 98 void RefreshKeycodes(); |
93 // Converts an X key symbol like XK_Control_L to a key code. | 99 // Converts an X key symbol like XK_Control_L to a key code. |
94 unsigned char NativeKeySymToNativeKeycode(unsigned long keysym); | 100 unsigned char NativeKeySymToNativeKeycode(unsigned long keysym); |
95 #endif | 101 #endif |
96 | 102 |
97 // Rewrites the |event| by applying all RewriteXXX functions as needed. | 103 // Rewrites the |event| by applying all RewriteXXX functions as needed. |
98 void Rewrite(ui::KeyEvent* event); | 104 void Rewrite(ui::KeyEvent* event); |
99 | 105 |
100 // Rewrites a modifier key press/release following the current user | 106 // Rewrites a modifier key press/release following the current user |
(...skipping 17 matching lines...) Expand all Loading... | |
118 // * Ctrl+Alt+Down -> End | 124 // * Ctrl+Alt+Down -> End |
119 // When the Search key acts as a function key, it instead maps: | 125 // When the Search key acts as a function key, it instead maps: |
120 // * Search+Backspace -> Delete | 126 // * Search+Backspace -> Delete |
121 // * Search+Up -> Prior (aka PageUp) | 127 // * Search+Up -> Prior (aka PageUp) |
122 // * Search+Down -> Next (aka PageDown) | 128 // * Search+Down -> Next (aka PageDown) |
123 // * Search+Left -> Home | 129 // * Search+Left -> Home |
124 // * Search+right -> End | 130 // * Search+right -> End |
125 // Returns true when the |event| is rewritten. | 131 // Returns true when the |event| is rewritten. |
126 bool RewriteBackspaceAndArrowKeys(ui::KeyEvent* event); | 132 bool RewriteBackspaceAndArrowKeys(ui::KeyEvent* event); |
127 | 133 |
134 // When the Search key acts as a function key, it remaps Search+1 | |
135 // through Search+= to F1 through F12. Returns true when the |event| is | |
136 // rewritten. | |
137 bool RewriteFunctionKeys(ui::KeyEvent* event); | |
138 | |
128 // Rewrites the located |event|. | 139 // Rewrites the located |event|. |
129 void RewriteLocatedEvent(ui::LocatedEvent* event); | 140 void RewriteLocatedEvent(ui::LocatedEvent* event); |
130 | 141 |
131 // Overwrites |event| with the keycodes and flags. | 142 // Overwrites |event| with the keycodes and flags. |
132 void OverwriteEvent(ui::KeyEvent* event, | 143 void OverwriteEvent(ui::KeyEvent* event, |
133 unsigned int new_native_keycode, | 144 unsigned int new_native_keycode, |
134 unsigned int new_native_state, | 145 unsigned int new_native_state, |
135 ui::KeyboardCode new_keycode, | 146 ui::KeyboardCode new_keycode, |
136 int new_flags); | 147 int new_flags); |
137 | 148 |
138 // Checks the type of the |device_name|, and inserts a new entry to | 149 // Checks the type of the |device_name|, and inserts a new entry to |
139 // |device_id_to_type_|. | 150 // |device_id_to_type_|. |
140 DeviceType DeviceAddedInternal(int device_id, const std::string& device_name); | 151 DeviceType DeviceAddedInternal(int device_id, const std::string& device_name); |
141 | 152 |
142 // Returns true if |last_device_id_| is Apple's. | 153 // Returns true if |last_device_id_| is Apple's. |
143 bool IsAppleKeyboard() const; | 154 bool IsAppleKeyboard() const; |
144 | 155 |
145 // Remaps |original_flags| to |remapped_flags| and |original_native_modifiers| | 156 // Remaps |original_flags| to |remapped_flags| and |original_native_modifiers| |
146 // to |remapped_native_modifiers| following the current user prefs. | 157 // to |remapped_native_modifiers| following the current user prefs. |
147 void GetRemappedModifierMasks(int original_flags, | 158 void GetRemappedModifierMasks(int original_flags, |
148 unsigned int original_native_modifiers, | 159 unsigned int original_native_modifiers, |
149 int* remapped_flags, | 160 int* remapped_flags, |
150 unsigned int* remapped_native_modifiers) const; | 161 unsigned int* remapped_native_modifiers) const; |
151 | 162 |
152 std::map<int, DeviceType> device_id_to_type_; | 163 std::map<int, DeviceType> device_id_to_type_; |
153 int last_device_id_; | 164 int last_device_id_; |
154 | 165 |
155 #if defined(OS_CHROMEOS) | 166 #if defined(OS_CHROMEOS) |
167 bool force_external_keyboard_for_testing_; | |
168 | |
156 // X keycodes corresponding to various keysyms. | 169 // X keycodes corresponding to various keysyms. |
157 unsigned int control_l_xkeycode_; | 170 unsigned int control_l_xkeycode_; |
158 unsigned int control_r_xkeycode_; | 171 unsigned int control_r_xkeycode_; |
159 unsigned int alt_l_xkeycode_; | 172 unsigned int alt_l_xkeycode_; |
160 unsigned int alt_r_xkeycode_; | 173 unsigned int alt_r_xkeycode_; |
161 unsigned int meta_l_xkeycode_; | 174 unsigned int meta_l_xkeycode_; |
162 unsigned int meta_r_xkeycode_; | 175 unsigned int meta_r_xkeycode_; |
163 unsigned int windows_l_xkeycode_; | 176 unsigned int windows_l_xkeycode_; |
164 unsigned int caps_lock_xkeycode_; | 177 unsigned int caps_lock_xkeycode_; |
165 unsigned int void_symbol_xkeycode_; | 178 unsigned int void_symbol_xkeycode_; |
166 unsigned int delete_xkeycode_; | 179 unsigned int delete_xkeycode_; |
167 unsigned int home_xkeycode_; | 180 unsigned int home_xkeycode_; |
168 unsigned int end_xkeycode_; | 181 unsigned int end_xkeycode_; |
169 unsigned int prior_xkeycode_; | 182 unsigned int prior_xkeycode_; |
170 unsigned int next_xkeycode_; | 183 unsigned int next_xkeycode_; |
171 unsigned int kp_0_xkeycode_; | 184 unsigned int kp_0_xkeycode_; |
172 unsigned int kp_1_xkeycode_; | 185 unsigned int kp_1_xkeycode_; |
173 unsigned int kp_2_xkeycode_; | 186 unsigned int kp_2_xkeycode_; |
174 unsigned int kp_3_xkeycode_; | 187 unsigned int kp_3_xkeycode_; |
175 unsigned int kp_4_xkeycode_; | 188 unsigned int kp_4_xkeycode_; |
176 unsigned int kp_5_xkeycode_; | 189 unsigned int kp_5_xkeycode_; |
177 unsigned int kp_6_xkeycode_; | 190 unsigned int kp_6_xkeycode_; |
178 unsigned int kp_7_xkeycode_; | 191 unsigned int kp_7_xkeycode_; |
179 unsigned int kp_8_xkeycode_; | 192 unsigned int kp_8_xkeycode_; |
180 unsigned int kp_9_xkeycode_; | 193 unsigned int kp_9_xkeycode_; |
181 unsigned int kp_decimal_xkeycode_; | 194 unsigned int kp_decimal_xkeycode_; |
195 unsigned int f1_xkeycode_; | |
Daniel Erat
2012/11/28 22:23:03
yikes. can this be switched to a single keysym-to
danakj
2012/11/29 01:50:54
Done.
| |
196 unsigned int f2_xkeycode_; | |
197 unsigned int f3_xkeycode_; | |
198 unsigned int f4_xkeycode_; | |
199 unsigned int f5_xkeycode_; | |
200 unsigned int f6_xkeycode_; | |
201 unsigned int f7_xkeycode_; | |
202 unsigned int f8_xkeycode_; | |
203 unsigned int f9_xkeycode_; | |
204 unsigned int f10_xkeycode_; | |
205 unsigned int f11_xkeycode_; | |
206 unsigned int f12_xkeycode_; | |
207 unsigned int number1_xkeycode_; | |
208 unsigned int number2_xkeycode_; | |
209 unsigned int number3_xkeycode_; | |
210 unsigned int number4_xkeycode_; | |
211 unsigned int number5_xkeycode_; | |
212 unsigned int number6_xkeycode_; | |
213 unsigned int number7_xkeycode_; | |
214 unsigned int number8_xkeycode_; | |
215 unsigned int number9_xkeycode_; | |
216 unsigned int number0_xkeycode_; | |
217 unsigned int minus_xkeycode_; | |
218 unsigned int equal_xkeycode_; | |
219 unsigned int browser_back_xkeycode_; | |
220 unsigned int browser_forward_xkeycode_; | |
221 unsigned int browser_refresh_xkeycode_; | |
222 unsigned int media_launch_app1_xkeycode_; | |
223 unsigned int media_launch_app2_xkeycode_; | |
224 unsigned int brightness_down_xkeycode_; | |
225 unsigned int brightness_up_xkeycode_; | |
226 unsigned int volume_mute_xkeycode_; | |
227 unsigned int volume_down_xkeycode_; | |
228 unsigned int volume_up_xkeycode_; | |
229 unsigned int power_xkeycode_; | |
182 | 230 |
183 chromeos::input_method::XKeyboard* xkeyboard_; // for testing. | 231 chromeos::input_method::XKeyboard* xkeyboard_; // for testing. |
184 #endif | 232 #endif |
185 | 233 |
186 const PrefService* pref_service_; // for testing. | 234 const PrefService* pref_service_; // for testing. |
187 | 235 |
188 DISALLOW_COPY_AND_ASSIGN(EventRewriter); | 236 DISALLOW_COPY_AND_ASSIGN(EventRewriter); |
189 }; | 237 }; |
190 | 238 |
191 #endif // CHROME_BROWSER_UI_ASH_EVENT_REWRITER_H_ | 239 #endif // CHROME_BROWSER_UI_ASH_EVENT_REWRITER_H_ |
OLD | NEW |