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

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

Issue 255033003: Convert sticky keys to a chromeos::EventRewriter phase. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@x354034-er
Patch Set: distinguish between MouseEvent and MouseWheelEvent 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) 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 // 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
60 // don't happen.
61 explicit EventRewriter(ash::StickyKeysController* sticky_keys_controller);
55 virtual ~EventRewriter(); 62 virtual ~EventRewriter();
56 63
57 // Calls DeviceAddedInternal. 64 // Calls DeviceAddedInternal.
58 DeviceType DeviceAddedForTesting(int device_id, 65 DeviceType DeviceAddedForTesting(int device_id,
59 const std::string& device_name); 66 const std::string& device_name);
60 67
61 // Calls RewriteLocatedEvent(). 68 // Calls RewriteLocatedEvent().
62 void RewriteLocatedEventForTesting(const ui::Event& event, int* flags); 69 void RewriteLocatedEventForTesting(const ui::Event& event, int* flags);
63 70
64 #if defined(USE_X11) 71 #if defined(USE_X11)
(...skipping 26 matching lines...) Expand all
91 virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE; 98 virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE;
92 virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE; 99 virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE;
93 100
94 // DeviceHierarchyObserver: 101 // DeviceHierarchyObserver:
95 virtual void DeviceHierarchyChanged() OVERRIDE; 102 virtual void DeviceHierarchyChanged() OVERRIDE;
96 virtual void DeviceAdded(int device_id) OVERRIDE; 103 virtual void DeviceAdded(int device_id) OVERRIDE;
97 virtual void DeviceRemoved(int device_id) OVERRIDE; 104 virtual void DeviceRemoved(int device_id) OVERRIDE;
98 #endif 105 #endif
99 106
100 private: 107 private:
101 // Things that internal rewriter phases can change about an Event. 108 // Things that keyboard-related rewriter phases can change about an Event.
102 struct MutableKeyState { 109 struct MutableKeyState {
103 int flags; 110 int flags;
104 ui::KeyboardCode key_code; 111 ui::KeyboardCode key_code;
105 }; 112 };
106 113
107 // Tables of direct remappings for |RewriteWithKeyboardRemappingsByKeyCode()|. 114 // Tables of direct remappings for |RewriteWithKeyboardRemappingsByKeyCode()|.
108 struct KeyboardRemapping { 115 struct KeyboardRemapping {
109 ui::KeyboardCode input_key_code; 116 ui::KeyboardCode input_key_code;
110 int input_flags; 117 int input_flags;
111 ui::KeyboardCode output_key_code; 118 ui::KeyboardCode output_key_code;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 bool RewriteWithKeyboardRemappingsByKeyCode( 151 bool RewriteWithKeyboardRemappingsByKeyCode(
145 const KeyboardRemapping* remappings, 152 const KeyboardRemapping* remappings,
146 size_t num_remappings, 153 size_t num_remappings,
147 const MutableKeyState& input, 154 const MutableKeyState& input,
148 MutableKeyState* remapped_state); 155 MutableKeyState* remapped_state);
149 156
150 // Rewrite a particular kind of event. 157 // Rewrite a particular kind of event.
151 ui::EventRewriteStatus RewriteKeyEvent( 158 ui::EventRewriteStatus RewriteKeyEvent(
152 const ui::KeyEvent& key_event, 159 const ui::KeyEvent& key_event,
153 scoped_ptr<ui::Event>* rewritten_event); 160 scoped_ptr<ui::Event>* rewritten_event);
154 ui::EventRewriteStatus RewriteMouseEvent( 161 ui::EventRewriteStatus RewriteMouseButtonEvent(
155 const ui::MouseEvent& mouse_event, 162 const ui::MouseEvent& mouse_event,
156 scoped_ptr<ui::Event>* rewritten_event); 163 scoped_ptr<ui::Event>* rewritten_event);
164 ui::EventRewriteStatus RewriteMouseWheelEvent(
165 const ui::MouseWheelEvent& mouse_event,
166 scoped_ptr<ui::Event>* rewritten_event);
157 ui::EventRewriteStatus RewriteTouchEvent( 167 ui::EventRewriteStatus RewriteTouchEvent(
158 const ui::TouchEvent& touch_event, 168 const ui::TouchEvent& touch_event,
159 scoped_ptr<ui::Event>* rewritten_event); 169 scoped_ptr<ui::Event>* rewritten_event);
170 ui::EventRewriteStatus RewriteScrollEvent(
171 const ui::ScrollEvent& scroll_event,
172 scoped_ptr<ui::Event>* rewritten_event);
160 173
161 // Rewriter phases. These can inspect the original |event|, but operate using 174 // Rewriter phases. These can inspect the original |event|, but operate using
162 // the current |state|, which may have been modified by previous phases. 175 // the current |state|, which may have been modified by previous phases.
163 void RewriteModifierKeys(const ui::KeyEvent& event, MutableKeyState* state); 176 void RewriteModifierKeys(const ui::KeyEvent& event, MutableKeyState* state);
164 void RewriteNumPadKeys(const ui::KeyEvent& event, MutableKeyState* state); 177 void RewriteNumPadKeys(const ui::KeyEvent& event, MutableKeyState* state);
165 void RewriteExtendedKeys(const ui::KeyEvent& event, MutableKeyState* state); 178 void RewriteExtendedKeys(const ui::KeyEvent& event, MutableKeyState* state);
166 void RewriteFunctionKeys(const ui::KeyEvent& event, MutableKeyState* state); 179 void RewriteFunctionKeys(const ui::KeyEvent& event, MutableKeyState* state);
167 void RewriteLocatedEvent(const ui::Event& event, int* flags); 180 void RewriteLocatedEvent(const ui::Event& event, int* flags);
168 181
169 // A set of device IDs whose press event has been rewritten. 182 // A set of device IDs whose press event has been rewritten.
170 std::set<int> pressed_device_ids_; 183 std::set<int> pressed_device_ids_;
171 184
172 std::map<int, DeviceType> device_id_to_type_; 185 std::map<int, DeviceType> device_id_to_type_;
173 int last_device_id_; 186 int last_device_id_;
174 187
175 chromeos::input_method::ImeKeyboard* ime_keyboard_for_testing_; 188 chromeos::input_method::ImeKeyboard* ime_keyboard_for_testing_;
176 const PrefService* pref_service_for_testing_; 189 const PrefService* pref_service_for_testing_;
177 190
191 // The sticky keys controller is not owned here;
192 // at time of writing it is a singleton in ash::Shell>
193 ash::StickyKeysController* sticky_keys_controller_;
194
178 DISALLOW_COPY_AND_ASSIGN(EventRewriter); 195 DISALLOW_COPY_AND_ASSIGN(EventRewriter);
179 }; 196 };
180 197
181 } // namespace chromeos 198 } // namespace chromeos
182 199
183 #endif // CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_H_ 200 #endif // CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/chrome_browser_main_chromeos.cc ('k') | chrome/browser/chromeos/events/event_rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698