OLD | NEW |
---|---|
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) | 18 #if defined(USE_X11) |
19 #include "chrome/browser/chromeos/device_hierarchy_observer.h" | 19 #include "chrome/browser/chromeos/device_hierarchy_observer.h" |
20 #include "ui/events/platform/platform_event_observer.h" | 20 #include "ui/events/platform/platform_event_observer.h" |
21 typedef union _XEvent XEvent; | 21 typedef union _XEvent XEvent; |
22 #endif | 22 #endif |
23 | 23 |
24 class PrefService; | 24 class PrefService; |
25 | 25 |
26 namespace ash { | |
27 class StickyKeysController; | |
28 } | |
29 | |
26 namespace chromeos { | 30 namespace chromeos { |
27 namespace input_method { | 31 namespace input_method { |
28 class ImeKeyboard; | 32 class ImeKeyboard; |
29 } | 33 } |
30 | 34 |
31 // EventRewriter makes various changes to keyboard-related events, | 35 // EventRewriter makes various changes to keyboard-related events, |
32 // including KeyEvents and some other events with keyboard modifier flags: | 36 // including KeyEvents and some other events with keyboard modifier flags: |
33 // - maps modifiers keys (Control, Alt, Search, Caps, Diamond) according | 37 // - maps modifiers keys (Control, Alt, Search, Caps, Diamond) according |
34 // to user preferences; | 38 // to user preferences; |
35 // - maps Command to Control on Apple keyboards; | 39 // - maps Command to Control on Apple keyboards; |
36 // - converts numeric pad editing keys to their numeric forms; | 40 // - converts numeric pad editing keys to their numeric forms; |
37 // - converts top-row function keys to special keys where necessary; | 41 // - converts top-row function keys to special keys where necessary; |
38 // - handles various key combinations like Search+Backspace -> Delete | 42 // - handles various key combinations like Search+Backspace -> Delete |
39 // and Search+number to Fnumber; | 43 // and Search+number to Fnumber; |
40 // - handles key/pointer combinations like Alt+Button1 -> Button3. | 44 // - handles key/pointer combinations like Alt+Button1 -> Button3. |
41 class EventRewriter | 45 class EventRewriter |
42 : | 46 : |
43 #if defined(USE_X11) | 47 #if defined(USE_X11) |
44 public DeviceHierarchyObserver, | 48 public DeviceHierarchyObserver, |
45 public ui::PlatformEventObserver, | 49 public ui::PlatformEventObserver, |
46 #endif | 50 #endif |
47 public ui::EventRewriter { | 51 public ui::EventRewriter { |
48 public: | 52 public: |
49 enum DeviceType { | 53 enum DeviceType { |
50 kDeviceUnknown = 0, | 54 kDeviceUnknown = 0, |
51 kDeviceAppleKeyboard, | 55 kDeviceAppleKeyboard, |
52 }; | 56 }; |
53 | 57 |
54 EventRewriter(); | 58 EventRewriter(ash::StickyKeysController* sticky_keys_controller); |
Daniel Erat
2014/06/05 23:16:10
add 'explicit' and a comment describing whether ow
kpschoedel
2014/06/06 17:53:23
Done.
Ideally this will be temporary and I can mo
| |
55 virtual ~EventRewriter(); | 59 virtual ~EventRewriter(); |
56 | 60 |
57 // Calls DeviceAddedInternal. | 61 // Calls DeviceAddedInternal. |
58 DeviceType DeviceAddedForTesting(int device_id, | 62 DeviceType DeviceAddedForTesting(int device_id, |
59 const std::string& device_name); | 63 const std::string& device_name); |
60 | 64 |
61 // Calls RewriteLocatedEvent(). | 65 // Calls RewriteLocatedEvent(). |
62 void RewriteLocatedEventForTesting(const ui::Event& event, int* flags); | 66 void RewriteLocatedEventForTesting(const ui::Event& event, int* flags); |
63 | 67 |
64 #if defined(USE_X11) | 68 #if defined(USE_X11) |
(...skipping 26 matching lines...) Expand all Loading... | |
91 virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE; | 95 virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE; |
92 virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE; | 96 virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE; |
93 | 97 |
94 // DeviceHierarchyObserver: | 98 // DeviceHierarchyObserver: |
95 virtual void DeviceHierarchyChanged() OVERRIDE; | 99 virtual void DeviceHierarchyChanged() OVERRIDE; |
96 virtual void DeviceAdded(int device_id) OVERRIDE; | 100 virtual void DeviceAdded(int device_id) OVERRIDE; |
97 virtual void DeviceRemoved(int device_id) OVERRIDE; | 101 virtual void DeviceRemoved(int device_id) OVERRIDE; |
98 #endif | 102 #endif |
99 | 103 |
100 private: | 104 private: |
101 // Things that internal rewriter phases can change about an Event. | 105 // Things that keyboard-related rewriter phases can change about an Event. |
102 struct MutableKeyState { | 106 struct MutableKeyState { |
103 int flags; | 107 int flags; |
104 ui::KeyboardCode key_code; | 108 ui::KeyboardCode key_code; |
105 }; | 109 }; |
106 | 110 |
107 // Tables of direct remappings for |RewriteWithKeyboardRemappingsByKeyCode()|. | 111 // Tables of direct remappings for |RewriteWithKeyboardRemappingsByKeyCode()|. |
108 struct KeyboardRemapping { | 112 struct KeyboardRemapping { |
109 ui::KeyboardCode input_key_code; | 113 ui::KeyboardCode input_key_code; |
110 int input_flags; | 114 int input_flags; |
111 ui::KeyboardCode output_key_code; | 115 ui::KeyboardCode output_key_code; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 // Rewrite a particular kind of event. | 154 // Rewrite a particular kind of event. |
151 ui::EventRewriteStatus RewriteKeyEvent( | 155 ui::EventRewriteStatus RewriteKeyEvent( |
152 const ui::KeyEvent& key_event, | 156 const ui::KeyEvent& key_event, |
153 scoped_ptr<ui::Event>* rewritten_event); | 157 scoped_ptr<ui::Event>* rewritten_event); |
154 ui::EventRewriteStatus RewriteMouseEvent( | 158 ui::EventRewriteStatus RewriteMouseEvent( |
155 const ui::MouseEvent& mouse_event, | 159 const ui::MouseEvent& mouse_event, |
156 scoped_ptr<ui::Event>* rewritten_event); | 160 scoped_ptr<ui::Event>* rewritten_event); |
157 ui::EventRewriteStatus RewriteTouchEvent( | 161 ui::EventRewriteStatus RewriteTouchEvent( |
158 const ui::TouchEvent& touch_event, | 162 const ui::TouchEvent& touch_event, |
159 scoped_ptr<ui::Event>* rewritten_event); | 163 scoped_ptr<ui::Event>* rewritten_event); |
164 ui::EventRewriteStatus RewriteScrollEvent( | |
165 const ui::ScrollEvent& scroll_event, | |
166 scoped_ptr<ui::Event>* rewritten_event); | |
160 | 167 |
161 // Rewriter phases. These can inspect the original |event|, but operate using | 168 // Rewriter phases. These can inspect the original |event|, but operate using |
162 // the current |state|, which may have been modified by previous phases. | 169 // the current |state|, which may have been modified by previous phases. |
163 void RewriteModifierKeys(const ui::KeyEvent& event, MutableKeyState* state); | 170 void RewriteModifierKeys(const ui::KeyEvent& event, MutableKeyState* state); |
164 void RewriteNumPadKeys(const ui::KeyEvent& event, MutableKeyState* state); | 171 void RewriteNumPadKeys(const ui::KeyEvent& event, MutableKeyState* state); |
165 void RewriteExtendedKeys(const ui::KeyEvent& event, MutableKeyState* state); | 172 void RewriteExtendedKeys(const ui::KeyEvent& event, MutableKeyState* state); |
166 void RewriteFunctionKeys(const ui::KeyEvent& event, MutableKeyState* state); | 173 void RewriteFunctionKeys(const ui::KeyEvent& event, MutableKeyState* state); |
167 void RewriteLocatedEvent(const ui::Event& event, int* flags); | 174 void RewriteLocatedEvent(const ui::Event& event, int* flags); |
168 | 175 |
169 // A set of device IDs whose press event has been rewritten. | 176 // A set of device IDs whose press event has been rewritten. |
170 std::set<int> pressed_device_ids_; | 177 std::set<int> pressed_device_ids_; |
171 | 178 |
172 std::map<int, DeviceType> device_id_to_type_; | 179 std::map<int, DeviceType> device_id_to_type_; |
173 int last_device_id_; | 180 int last_device_id_; |
174 | 181 |
175 chromeos::input_method::ImeKeyboard* ime_keyboard_for_testing_; | 182 chromeos::input_method::ImeKeyboard* ime_keyboard_for_testing_; |
176 const PrefService* pref_service_for_testing_; | 183 const PrefService* pref_service_for_testing_; |
177 | 184 |
185 ash::StickyKeysController* sticky_keys_controller_; | |
Daniel Erat
2014/06/05 23:16:10
nit: add a comment describing ownership of this po
kpschoedel
2014/06/06 17:53:23
Done.
| |
186 | |
178 DISALLOW_COPY_AND_ASSIGN(EventRewriter); | 187 DISALLOW_COPY_AND_ASSIGN(EventRewriter); |
179 }; | 188 }; |
180 | 189 |
181 } // namespace chromeos | 190 } // namespace chromeos |
182 | 191 |
183 #endif // CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_H_ | 192 #endif // CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_H_ |
OLD | NEW |