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

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: static const 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
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 kDeviceChromeOSKeyboard,
45 }; 47 };
46 48
47 EventRewriter(); 49 EventRewriter();
48 virtual ~EventRewriter(); 50 virtual ~EventRewriter();
49 51
50 // Calls DeviceAddedInternal. 52 // Calls DeviceAddedInternal.
51 DeviceType DeviceAddedForTesting(int device_id, 53 DeviceType DeviceAddedForTesting(int device_id,
52 const std::string& device_name); 54 const std::string& device_name);
53 // Calls Rewrite. 55 // Calls Rewrite.
54 void RewriteForTesting(ui::KeyEvent* event); 56 void RewriteForTesting(ui::KeyEvent* event);
55 57
56 const std::map<int, DeviceType>& device_id_to_type_for_testing() const { 58 const std::map<int, DeviceType>& device_id_to_type_for_testing() const {
57 return device_id_to_type_; 59 return device_id_to_type_;
58 } 60 }
59 void set_last_device_id_for_testing(int device_id) { 61 void set_last_device_id_for_testing(int device_id) {
60 last_device_id_ = device_id; 62 last_device_id_ = device_id;
61 } 63 }
62 void set_pref_service_for_testing(const PrefService* pref_service) { 64 void set_pref_service_for_testing(const PrefService* pref_service) {
63 pref_service_ = pref_service; 65 pref_service_ = pref_service;
64 } 66 }
65 #if defined(OS_CHROMEOS) 67 #if defined(OS_CHROMEOS)
66 void set_xkeyboard_for_testing(chromeos::input_method::XKeyboard* xkeyboard) { 68 void set_xkeyboard_for_testing(chromeos::input_method::XKeyboard* xkeyboard) {
67 xkeyboard_ = xkeyboard; 69 xkeyboard_ = xkeyboard;
68 } 70 }
71 void set_force_chromeos_keyboard_for_testing(bool chromeos_keyboard) {
72 force_chromeos_keyboard_for_testing_ = chromeos_keyboard;
73 }
69 #endif 74 #endif
70 75
71 // Gets DeviceType from the |device_name|. 76 // Gets DeviceType from the |device_name|.
72 static DeviceType GetDeviceType(const std::string& device_name); 77 static DeviceType GetDeviceType(const std::string& device_name);
73 78
74 private: 79 private:
75 // ash::EventRewriterDelegate overrides: 80 // ash::EventRewriterDelegate overrides:
76 virtual ash::EventRewriterDelegate::Action RewriteOrFilterKeyEvent( 81 virtual ash::EventRewriterDelegate::Action RewriteOrFilterKeyEvent(
77 ui::KeyEvent* event) OVERRIDE; 82 ui::KeyEvent* event) OVERRIDE;
78 virtual ash::EventRewriterDelegate::Action RewriteOrFilterLocatedEvent( 83 virtual ash::EventRewriterDelegate::Action RewriteOrFilterLocatedEvent(
79 ui::LocatedEvent* event) OVERRIDE; 84 ui::LocatedEvent* event) OVERRIDE;
80 85
81 // aura::RootWindowObserver overrides: 86 // aura::RootWindowObserver overrides:
82 virtual void OnKeyboardMappingChanged(const aura::RootWindow* root) OVERRIDE; 87 virtual void OnKeyboardMappingChanged(const aura::RootWindow* root) OVERRIDE;
83 88
84 #if defined(OS_CHROMEOS) 89 #if defined(OS_CHROMEOS)
85 // chromeos::DeviceHierarchyObserver overrides: 90 // chromeos::DeviceHierarchyObserver overrides:
86 virtual void DeviceHierarchyChanged() OVERRIDE {} 91 virtual void DeviceHierarchyChanged() OVERRIDE {}
87 virtual void DeviceAdded(int device_id) OVERRIDE; 92 virtual void DeviceAdded(int device_id) OVERRIDE;
88 virtual void DeviceRemoved(int device_id) OVERRIDE; 93 virtual void DeviceRemoved(int device_id) OVERRIDE;
89 virtual void DeviceKeyPressedOrReleased(int device_id) OVERRIDE; 94 virtual void DeviceKeyPressedOrReleased(int device_id) OVERRIDE;
90 95
96 bool EventSourceIsChromeOSKeyboard() const;
97
91 // Updates |*_xkeycode_| in response to a keyboard map change. 98 // Updates |*_xkeycode_| in response to a keyboard map change.
92 void RefreshKeycodes(); 99 void RefreshKeycodes();
93 // Converts an X key symbol like XK_Control_L to a key code. 100 // Converts an X key symbol like XK_Control_L to a key code.
94 unsigned char NativeKeySymToNativeKeycode(unsigned long keysym); 101 unsigned char NativeKeySymToNativeKeycode(unsigned long keysym);
95 #endif 102 #endif
96 103
97 // Rewrites the |event| by applying all RewriteXXX functions as needed. 104 // Rewrites the |event| by applying all RewriteXXX functions as needed.
98 void Rewrite(ui::KeyEvent* event); 105 void Rewrite(ui::KeyEvent* event);
99 106
100 // Rewrites a modifier key press/release following the current user 107 // Rewrites a modifier key press/release following the current user
(...skipping 17 matching lines...) Expand all
118 // * Ctrl+Alt+Down -> End 125 // * Ctrl+Alt+Down -> End
119 // When the Search key acts as a function key, it instead maps: 126 // When the Search key acts as a function key, it instead maps:
120 // * Search+Backspace -> Delete 127 // * Search+Backspace -> Delete
121 // * Search+Up -> Prior (aka PageUp) 128 // * Search+Up -> Prior (aka PageUp)
122 // * Search+Down -> Next (aka PageDown) 129 // * Search+Down -> Next (aka PageDown)
123 // * Search+Left -> Home 130 // * Search+Left -> Home
124 // * Search+right -> End 131 // * Search+right -> End
125 // Returns true when the |event| is rewritten. 132 // Returns true when the |event| is rewritten.
126 bool RewriteBackspaceAndArrowKeys(ui::KeyEvent* event); 133 bool RewriteBackspaceAndArrowKeys(ui::KeyEvent* event);
127 134
135 // When the Search key acts as a function key, it remaps Search+1
136 // through Search+= to F1 through F12. Returns true when the |event| is
137 // rewritten.
138 bool RewriteFunctionKeys(ui::KeyEvent* event);
139
128 // Rewrites the located |event|. 140 // Rewrites the located |event|.
129 void RewriteLocatedEvent(ui::LocatedEvent* event); 141 void RewriteLocatedEvent(ui::LocatedEvent* event);
130 142
131 // Overwrites |event| with the keycodes and flags. 143 // Overwrites |event| with the keycodes and flags.
132 void OverwriteEvent(ui::KeyEvent* event, 144 void OverwriteEvent(ui::KeyEvent* event,
133 unsigned int new_native_keycode, 145 unsigned int new_native_keycode,
134 unsigned int new_native_state, 146 unsigned int new_native_state,
135 ui::KeyboardCode new_keycode, 147 ui::KeyboardCode new_keycode,
136 int new_flags); 148 int new_flags);
137 149
138 // Checks the type of the |device_name|, and inserts a new entry to 150 // Checks the type of the |device_name|, and inserts a new entry to
139 // |device_id_to_type_|. 151 // |device_id_to_type_|.
140 DeviceType DeviceAddedInternal(int device_id, const std::string& device_name); 152 DeviceType DeviceAddedInternal(int device_id, const std::string& device_name);
141 153
142 // Returns true if |last_device_id_| is Apple's. 154 // Returns true if |last_device_id_| is Apple's.
143 bool IsAppleKeyboard() const; 155 bool IsAppleKeyboard() const;
144 156
145 // Remaps |original_flags| to |remapped_flags| and |original_native_modifiers| 157 // Remaps |original_flags| to |remapped_flags| and |original_native_modifiers|
146 // to |remapped_native_modifiers| following the current user prefs. 158 // to |remapped_native_modifiers| following the current user prefs.
147 void GetRemappedModifierMasks(int original_flags, 159 void GetRemappedModifierMasks(int original_flags,
148 unsigned int original_native_modifiers, 160 unsigned int original_native_modifiers,
149 int* remapped_flags, 161 int* remapped_flags,
150 unsigned int* remapped_native_modifiers) const; 162 unsigned int* remapped_native_modifiers) const;
151 163
152 std::map<int, DeviceType> device_id_to_type_; 164 std::map<int, DeviceType> device_id_to_type_;
153 int last_device_id_; 165 int last_device_id_;
154 166
155 #if defined(OS_CHROMEOS) 167 #if defined(OS_CHROMEOS)
156 // X keycodes corresponding to various keysyms. 168 bool force_chromeos_keyboard_for_testing_;
157 unsigned int control_l_xkeycode_; 169
158 unsigned int control_r_xkeycode_; 170 // A mapping from X11 KeySym keys to KeyCode values.
159 unsigned int alt_l_xkeycode_; 171 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 172
183 chromeos::input_method::XKeyboard* xkeyboard_; // for testing. 173 chromeos::input_method::XKeyboard* xkeyboard_; // for testing.
184 #endif 174 #endif
185 175
186 const PrefService* pref_service_; // for testing. 176 const PrefService* pref_service_; // for testing.
187 177
188 DISALLOW_COPY_AND_ASSIGN(EventRewriter); 178 DISALLOW_COPY_AND_ASSIGN(EventRewriter);
189 }; 179 };
190 180
191 #endif // CHROME_BROWSER_UI_ASH_EVENT_REWRITER_H_ 181 #endif // CHROME_BROWSER_UI_ASH_EVENT_REWRITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698