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

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: Address review comments (sadrul) 3 Created 6 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/events/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 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 original key event and the replacement
97 // ui::PlatformEventObserver: 84 // key code and flags determined by a key rewriter.
98 virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE; 85 static void BuildRewrittenKeyEvent(const ui::KeyEvent& key_event,
99 virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE; 86 ui::KeyboardCode key_code,
100 87 int flags,
101 // DeviceHierarchyObserver: 88 scoped_ptr<ui::Event>* rewritten_event);
102 virtual void DeviceHierarchyChanged() OVERRIDE;
103 virtual void DeviceAdded(int device_id) OVERRIDE;
104 virtual void DeviceRemoved(int device_id) OVERRIDE;
105 #endif
106 89
107 private: 90 private:
108 // Things that keyboard-related rewriter phases can change about an Event. 91 // Things that keyboard-related rewriter phases can change about an Event.
109 struct MutableKeyState { 92 struct MutableKeyState {
110 int flags; 93 int flags;
111 ui::KeyboardCode key_code; 94 ui::KeyboardCode key_code;
112 }; 95 };
113 96
114 // Tables of direct remappings for |RewriteWithKeyboardRemappingsByKeyCode()|. 97 // Tables of direct remappings for |RewriteWithKeyboardRemappingsByKeyCode()|.
115 struct KeyboardRemapping { 98 struct KeyboardRemapping {
116 ui::KeyboardCode input_key_code; 99 ui::KeyboardCode input_key_code;
117 int input_flags; 100 int input_flags;
118 ui::KeyboardCode output_key_code; 101 ui::KeyboardCode output_key_code;
119 int output_flags; 102 int output_flags;
120 }; 103 };
121 104
122 #if defined(USE_X11)
123 void DeviceKeyPressedOrReleased(int device_id); 105 void DeviceKeyPressedOrReleased(int device_id);
124 #endif
125 106
126 // Returns the PrefService that should be used. 107 // Returns the PrefService that should be used.
127 const PrefService* GetPrefService() const; 108 const PrefService* GetPrefService() const;
128 109
110 // Adds a device to |device_id_to_type_|.
111 void KeyboardDeviceAdded(int device_id);
112
129 // Checks the type of the |device_name|, and inserts a new entry to 113 // Checks the type of the |device_name|, and inserts a new entry to
130 // |device_id_to_type_|. 114 // |device_id_to_type_|.
131 DeviceType DeviceAddedInternal(int device_id, const std::string& device_name); 115 DeviceType KeyboardDeviceAddedInternal(int device_id,
116 const std::string& device_name);
132 117
133 // Returns true if |last_device_id_| is Apple's. 118 // Returns true if |last_keyboard_device_id_| is Apple's.
134 bool IsAppleKeyboard() const; 119 bool IsAppleKeyboard() const;
135 120
136 // Returns true if the target for |event| would prefer to receive raw function 121 // Returns true if the target for |event| would prefer to receive raw function
137 // keys instead of having them rewritten into back, forward, brightness, 122 // 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 123 // volume, etc. or if the user has specified that they desire top-row keys to
139 // be treated as function keys globally. 124 // be treated as function keys globally.
140 bool TopRowKeysAreFunctionKeys(const ui::KeyEvent& event) const; 125 bool TopRowKeysAreFunctionKeys(const ui::KeyEvent& event) const;
141 126
142 // Given modifier flags |original_flags|, returns the remapped modifiers 127 // Given modifier flags |original_flags|, returns the remapped modifiers
143 // according to user preferences and/or event properties. 128 // according to user preferences and/or event properties.
(...skipping 27 matching lines...) Expand all
171 const ui::ScrollEvent& scroll_event, 156 const ui::ScrollEvent& scroll_event,
172 scoped_ptr<ui::Event>* rewritten_event); 157 scoped_ptr<ui::Event>* rewritten_event);
173 158
174 // Rewriter phases. These can inspect the original |event|, but operate using 159 // Rewriter phases. These can inspect the original |event|, but operate using
175 // the current |state|, which may have been modified by previous phases. 160 // the current |state|, which may have been modified by previous phases.
176 void RewriteModifierKeys(const ui::KeyEvent& event, MutableKeyState* state); 161 void RewriteModifierKeys(const ui::KeyEvent& event, MutableKeyState* state);
177 void RewriteNumPadKeys(const ui::KeyEvent& event, MutableKeyState* state); 162 void RewriteNumPadKeys(const ui::KeyEvent& event, MutableKeyState* state);
178 void RewriteExtendedKeys(const ui::KeyEvent& event, MutableKeyState* state); 163 void RewriteExtendedKeys(const ui::KeyEvent& event, MutableKeyState* state);
179 void RewriteFunctionKeys(const ui::KeyEvent& event, MutableKeyState* state); 164 void RewriteFunctionKeys(const ui::KeyEvent& event, MutableKeyState* state);
180 void RewriteLocatedEvent(const ui::Event& event, int* flags); 165 void RewriteLocatedEvent(const ui::Event& event, int* flags);
166 int RewriteModifierClick(const ui::MouseEvent& event, int* flags);
181 167
182 // A set of device IDs whose press event has been rewritten. 168 // A set of device IDs whose press event has been rewritten.
169 // This is to ensure that press and release events are rewritten consistently.
183 std::set<int> pressed_device_ids_; 170 std::set<int> pressed_device_ids_;
184 171
185 std::map<int, DeviceType> device_id_to_type_; 172 std::map<int, DeviceType> device_id_to_type_;
186 int last_device_id_; 173
174 // The |source_device_id()| of the most recent keyboard event,
175 // used to interpret modifiers on pointer events.
176 int last_keyboard_device_id_;
187 177
188 chromeos::input_method::ImeKeyboard* ime_keyboard_for_testing_; 178 chromeos::input_method::ImeKeyboard* ime_keyboard_for_testing_;
189 const PrefService* pref_service_for_testing_; 179 const PrefService* pref_service_for_testing_;
190 180
191 // The sticky keys controller is not owned here; 181 // The sticky keys controller is not owned here;
192 // at time of writing it is a singleton in ash::Shell> 182 // at time of writing it is a singleton in ash::Shell>
193 ash::StickyKeysController* sticky_keys_controller_; 183 ash::StickyKeysController* sticky_keys_controller_;
194 184
195 DISALLOW_COPY_AND_ASSIGN(EventRewriter); 185 DISALLOW_COPY_AND_ASSIGN(EventRewriter);
196 }; 186 };
197 187
198 } // namespace chromeos 188 } // namespace chromeos
199 189
200 #endif // CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_H_ 190 #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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698