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