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

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

Issue 336403005: Use XInput2 events for keyboard events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add TODO regarding XI2-to-core rewriting. Created 6 years, 6 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 #ifndef CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_H_
6 #define CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_H_ 6 #define CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "ui/events/event.h" 15 #include "ui/events/event.h"
16 #include "ui/events/event_rewriter.h" 16 #include "ui/events/event_rewriter.h"
17 17
18 #if defined(USE_X11)
19 #include "chrome/browser/chromeos/device_hierarchy_observer.h"
20 #include "ui/events/platform/platform_event_observer.h"
21 typedef union _XEvent XEvent;
22 #endif
23
24 class PrefService; 18 class PrefService;
25 19
26 namespace ash { 20 namespace ash {
27 class StickyKeysController; 21 class StickyKeysController;
28 } 22 }
29 23
30 namespace chromeos { 24 namespace chromeos {
31 namespace input_method { 25 namespace input_method {
32 class ImeKeyboard; 26 class ImeKeyboard;
33 } 27 }
34 28
35 // EventRewriter makes various changes to keyboard-related events, 29 // EventRewriter makes various changes to keyboard-related events,
36 // including KeyEvents and some other events with keyboard modifier flags: 30 // including KeyEvents and some other events with keyboard modifier flags:
37 // - maps modifiers keys (Control, Alt, Search, Caps, Diamond) according 31 // - maps modifiers keys (Control, Alt, Search, Caps, Diamond) according
38 // to user preferences; 32 // to user preferences;
39 // - maps Command to Control on Apple keyboards; 33 // - maps Command to Control on Apple keyboards;
40 // - converts numeric pad editing keys to their numeric forms; 34 // - converts numeric pad editing keys to their numeric forms;
41 // - converts top-row function keys to special keys where necessary; 35 // - converts top-row function keys to special keys where necessary;
42 // - handles various key combinations like Search+Backspace -> Delete 36 // - handles various key combinations like Search+Backspace -> Delete
43 // and Search+number to Fnumber; 37 // and Search+number to Fnumber;
44 // - handles key/pointer combinations like Alt+Button1 -> Button3. 38 // - handles key/pointer combinations like Alt+Button1 -> Button3.
45 class EventRewriter 39 class EventRewriter : public ui::EventRewriter {
46 :
47 #if defined(USE_X11)
48 public DeviceHierarchyObserver,
49 public ui::PlatformEventObserver,
50 #endif
51 public ui::EventRewriter {
52 public: 40 public:
53 enum DeviceType { 41 enum DeviceType {
54 kDeviceUnknown = 0, 42 kDeviceUnknown = 0,
55 kDeviceAppleKeyboard, 43 kDeviceAppleKeyboard,
56 }; 44 };
57 45
58 // Does not take ownership of the |sticky_keys_controller|, which may also 46 // Does not take ownership of the |sticky_keys_controller|, which may also
59 // be NULL (for testing without ash), in which case sticky key operations 47 // be NULL (for testing without ash), in which case sticky key operations
60 // don't happen. 48 // don't happen.
61 explicit EventRewriter(ash::StickyKeysController* sticky_keys_controller); 49 explicit EventRewriter(ash::StickyKeysController* sticky_keys_controller);
62 virtual ~EventRewriter(); 50 virtual ~EventRewriter();
63 51
64 // Calls DeviceAddedInternal. 52 // Calls KeyboardDeviceAddedInternal.
65 DeviceType DeviceAddedForTesting(int device_id, 53 DeviceType KeyboardDeviceAddedForTesting(int device_id,
66 const std::string& device_name); 54 const std::string& device_name);
67 55
68 // Calls RewriteLocatedEvent(). 56 // Calls RewriteMouseEvent().
69 void RewriteLocatedEventForTesting(const ui::Event& event, int* flags); 57 void RewriteMouseButtonEventForTesting(
58 const ui::MouseEvent& event,
59 scoped_ptr<ui::Event>* rewritten_event);
70 60
71 #if defined(USE_X11)
72 const std::map<int, DeviceType>& device_id_to_type_for_testing() const { 61 const std::map<int, DeviceType>& device_id_to_type_for_testing() const {
73 return device_id_to_type_; 62 return device_id_to_type_;
74 } 63 }
75 #endif 64 void set_last_keyboard_device_id_for_testing(int device_id) {
76 65 last_keyboard_device_id_ = device_id;
77 void set_last_device_id_for_testing(int device_id) {
78 last_device_id_ = device_id;
79 } 66 }
80 void set_pref_service_for_testing(const PrefService* pref_service) { 67 void set_pref_service_for_testing(const PrefService* pref_service) {
81 pref_service_for_testing_ = pref_service; 68 pref_service_for_testing_ = pref_service;
82 } 69 }
83 void set_ime_keyboard_for_testing( 70 void set_ime_keyboard_for_testing(
84 chromeos::input_method::ImeKeyboard* ime_keyboard) { 71 chromeos::input_method::ImeKeyboard* ime_keyboard) {
85 ime_keyboard_for_testing_ = ime_keyboard; 72 ime_keyboard_for_testing_ = ime_keyboard;
86 } 73 }
87 74
88 // EventRewriter overrides: 75 // EventRewriter overrides:
89 virtual ui::EventRewriteStatus RewriteEvent( 76 virtual ui::EventRewriteStatus RewriteEvent(
90 const ui::Event& event, 77 const ui::Event& event,
91 scoped_ptr<ui::Event>* rewritten_event) OVERRIDE; 78 scoped_ptr<ui::Event>* rewritten_event) OVERRIDE;
92 virtual ui::EventRewriteStatus NextDispatchEvent( 79 virtual ui::EventRewriteStatus NextDispatchEvent(
93 const ui::Event& last_event, 80 const ui::Event& last_event,
94 scoped_ptr<ui::Event>* new_event) OVERRIDE; 81 scoped_ptr<ui::Event>* new_event) OVERRIDE;
95 82
96 #if defined(USE_X11) 83 // Generate a new key event from an event and replacement key code and flags.
97 // ui::PlatformEventObserver: 84 static void RewrittenKeyEvent(const ui::KeyEvent& key_event,
Daniel Erat 2014/06/25 17:13:24 did you mean to name this RewriteKeyEvent()? an ea
kpschoedel 2014/06/25 19:59:48 This is the function that constructs a new key eve
Daniel Erat 2014/06/25 20:06:13 great, thanks! (i mostly just wanted there to be a
98 virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE; 85 ui::KeyboardCode key_code,
99 virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE; 86 int flags,
100 87 scoped_ptr<ui::Event>* rewritten_event);
101 // DeviceHierarchyObserver:
102 virtual void DeviceHierarchyChanged() OVERRIDE;
103 virtual void DeviceAdded(int device_id) OVERRIDE;
104 virtual void DeviceRemoved(int device_id) OVERRIDE;
105 #endif
106 88
107 private: 89 private:
108 // Things that keyboard-related rewriter phases can change about an Event. 90 // Things that keyboard-related rewriter phases can change about an Event.
109 struct MutableKeyState { 91 struct MutableKeyState {
110 int flags; 92 int flags;
111 ui::KeyboardCode key_code; 93 ui::KeyboardCode key_code;
112 }; 94 };
113 95
114 // Tables of direct remappings for |RewriteWithKeyboardRemappingsByKeyCode()|. 96 // Tables of direct remappings for |RewriteWithKeyboardRemappingsByKeyCode()|.
115 struct KeyboardRemapping { 97 struct KeyboardRemapping {
116 ui::KeyboardCode input_key_code; 98 ui::KeyboardCode input_key_code;
117 int input_flags; 99 int input_flags;
118 ui::KeyboardCode output_key_code; 100 ui::KeyboardCode output_key_code;
119 int output_flags; 101 int output_flags;
120 }; 102 };
121 103
122 #if defined(USE_X11)
123 void DeviceKeyPressedOrReleased(int device_id); 104 void DeviceKeyPressedOrReleased(int device_id);
124 #endif
125 105
126 // Returns the PrefService that should be used. 106 // Returns the PrefService that should be used.
127 const PrefService* GetPrefService() const; 107 const PrefService* GetPrefService() const;
128 108
109 // Adds a device to |device_id_to_type_|.
110 void KeyboardDeviceAdded(int device_id);
111
129 // Checks the type of the |device_name|, and inserts a new entry to 112 // Checks the type of the |device_name|, and inserts a new entry to
130 // |device_id_to_type_|. 113 // |device_id_to_type_|.
131 DeviceType DeviceAddedInternal(int device_id, const std::string& device_name); 114 DeviceType KeyboardDeviceAddedInternal(int device_id,
115 const std::string& device_name);
132 116
133 // Returns true if |last_device_id_| is Apple's. 117 // Returns true if |last_keyboard_device_id_| is Apple's.
134 bool IsAppleKeyboard() const; 118 bool IsAppleKeyboard() const;
135 119
136 // Returns true if the target for |event| would prefer to receive raw function 120 // Returns true if the target for |event| would prefer to receive raw function
137 // keys instead of having them rewritten into back, forward, brightness, 121 // keys instead of having them rewritten into back, forward, brightness,
138 // volume, etc. or if the user has specified that they desire top-row keys to 122 // volume, etc. or if the user has specified that they desire top-row keys to
139 // be treated as function keys globally. 123 // be treated as function keys globally.
140 bool TopRowKeysAreFunctionKeys(const ui::KeyEvent& event) const; 124 bool TopRowKeysAreFunctionKeys(const ui::KeyEvent& event) const;
141 125
142 // Given modifier flags |original_flags|, returns the remapped modifiers 126 // Given modifier flags |original_flags|, returns the remapped modifiers
143 // according to user preferences and/or event properties. 127 // according to user preferences and/or event properties.
(...skipping 27 matching lines...) Expand all
171 const ui::ScrollEvent& scroll_event, 155 const ui::ScrollEvent& scroll_event,
172 scoped_ptr<ui::Event>* rewritten_event); 156 scoped_ptr<ui::Event>* rewritten_event);
173 157
174 // Rewriter phases. These can inspect the original |event|, but operate using 158 // Rewriter phases. These can inspect the original |event|, but operate using
175 // the current |state|, which may have been modified by previous phases. 159 // the current |state|, which may have been modified by previous phases.
176 void RewriteModifierKeys(const ui::KeyEvent& event, MutableKeyState* state); 160 void RewriteModifierKeys(const ui::KeyEvent& event, MutableKeyState* state);
177 void RewriteNumPadKeys(const ui::KeyEvent& event, MutableKeyState* state); 161 void RewriteNumPadKeys(const ui::KeyEvent& event, MutableKeyState* state);
178 void RewriteExtendedKeys(const ui::KeyEvent& event, MutableKeyState* state); 162 void RewriteExtendedKeys(const ui::KeyEvent& event, MutableKeyState* state);
179 void RewriteFunctionKeys(const ui::KeyEvent& event, MutableKeyState* state); 163 void RewriteFunctionKeys(const ui::KeyEvent& event, MutableKeyState* state);
180 void RewriteLocatedEvent(const ui::Event& event, int* flags); 164 void RewriteLocatedEvent(const ui::Event& event, int* flags);
165 int RewriteModifierClick(const ui::MouseEvent& event, int* flags);
181 166
182 // A set of device IDs whose press event has been rewritten. 167 // A set of device IDs whose press event has been rewritten.
168 // This is to ensure that press and release events are rewritten consistently.
183 std::set<int> pressed_device_ids_; 169 std::set<int> pressed_device_ids_;
184 170
185 std::map<int, DeviceType> device_id_to_type_; 171 std::map<int, DeviceType> device_id_to_type_;
Daniel Erat 2014/06/25 17:13:24 nit: add a blank line below this one
kpschoedel 2014/06/25 19:59:48 Done.
186 int last_device_id_; 172 // The |source_device_id()| of the most recent keyboard event,
173 // used to interpret modifiers on pointer events.
174 int last_keyboard_device_id_;
187 175
188 chromeos::input_method::ImeKeyboard* ime_keyboard_for_testing_; 176 chromeos::input_method::ImeKeyboard* ime_keyboard_for_testing_;
189 const PrefService* pref_service_for_testing_; 177 const PrefService* pref_service_for_testing_;
190 178
191 // The sticky keys controller is not owned here; 179 // The sticky keys controller is not owned here;
192 // at time of writing it is a singleton in ash::Shell> 180 // at time of writing it is a singleton in ash::Shell>
193 ash::StickyKeysController* sticky_keys_controller_; 181 ash::StickyKeysController* sticky_keys_controller_;
194 182
195 DISALLOW_COPY_AND_ASSIGN(EventRewriter); 183 DISALLOW_COPY_AND_ASSIGN(EventRewriter);
196 }; 184 };
197 185
198 } // namespace chromeos 186 } // namespace chromeos
199 187
200 #endif // CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_H_ 188 #endif // CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/events/event_rewriter.cc » ('j') | chrome/browser/chromeos/events/event_rewriter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698