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

Side by Side Diff: trunk/src/ash/sticky_keys/sticky_keys_controller.h

Issue 341923006: Revert 278342 "Convert sticky keys to a chromeos::EventRewriter ..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 | Annotate | Revision Log
« no previous file with comments | « trunk/src/ash/shell.cc ('k') | trunk/src/ash/sticky_keys/sticky_keys_controller.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ 5 #ifndef ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_
6 #define ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ 6 #define ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_
7 7
8 #include "ash/ash_export.h" 8 #include "ash/ash_export.h"
9 #include "ash/sticky_keys/sticky_keys_state.h" 9 #include "ash/sticky_keys/sticky_keys_state.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "ui/events/event_constants.h" 11 #include "ui/events/event_constants.h"
12 #include "ui/events/event_handler.h" 12 #include "ui/events/event_handler.h"
13 #include "ui/events/event_rewriter.h"
14 #include "ui/events/keycodes/keyboard_codes.h"
15 13
16 namespace ui { 14 namespace ui {
17 class Event; 15 class Event;
18 class KeyEvent; 16 class KeyEvent;
19 class MouseEvent; 17 class MouseEvent;
20 } // namespace ui 18 } // namespace ui
21 19
22 namespace aura { 20 namespace aura {
23 class Window; 21 class Window;
24 } // namespace aura 22 } // namespace aura
(...skipping 29 matching lines...) Expand all
54 // 6. Release 1 key : 1 Keyup event with Ctrl modifier. 52 // 6. Release 1 key : 1 Keyup event with Ctrl modifier.
55 // 7. Press 2 key : 2 Keydown event with Ctrl modifier. 53 // 7. Press 2 key : 2 Keydown event with Ctrl modifier.
56 // 8. Release 2 key : 2 Keyup event with Ctrl modifier. 54 // 8. Release 2 key : 2 Keyup event with Ctrl modifier.
57 // 9. Press Ctrl key : No event 55 // 9. Press Ctrl key : No event
58 // 10. Release Ctrl key: Ctrl Keyup 56 // 10. Release Ctrl key: Ctrl Keyup
59 // 57 //
60 // In the case of Chrome OS, StickyKeysController supports Shift,Alt,Ctrl 58 // In the case of Chrome OS, StickyKeysController supports Shift,Alt,Ctrl
61 // modifiers. Each handling or state is performed independently. 59 // modifiers. Each handling or state is performed independently.
62 // 60 //
63 // StickyKeysController is disabled by default. 61 // StickyKeysController is disabled by default.
64 class ASH_EXPORT StickyKeysController { 62 class ASH_EXPORT StickyKeysController : public ui::EventHandler {
65 public: 63 public:
66 StickyKeysController(); 64 StickyKeysController();
67 virtual ~StickyKeysController(); 65 virtual ~StickyKeysController();
68 66
69 // Activate sticky keys to intercept and modify incoming events. 67 // Activate sticky keys to intercept and modify incoming events.
70 void Enable(bool enabled); 68 void Enable(bool enabled);
71 69
72 void SetModifiersEnabled(bool mod3_enabled, bool altgr_enabled); 70 void SetModifiersEnabled(bool mod3_enabled, bool altgr_enabled);
73 71
72 // Overridden from ui::EventHandler:
73 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
74 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
75 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
76
74 // Returns the StickyKeyOverlay used by the controller. Ownership is not 77 // Returns the StickyKeyOverlay used by the controller. Ownership is not
75 // passed. 78 // passed.
76 StickyKeysOverlay* GetOverlayForTest(); 79 StickyKeysOverlay* GetOverlayForTest();
77 80
78 // Handles keyboard event. Returns an |EventRewriteStatus|, and may
79 // modify |flags|:
80 // - Returns ui::EVENT_REWRITE_DISCARD, and leaves |flags| untouched,
81 // if the event is consumed (i.e. a sticky modifier press or release);
82 // - Returns ui::EVENT_REWRITE_REWRITTEN if the event needs to be modified
83 // according to the returned |flags| (i.e. a sticky-modified key);
84 // - Returns ui::EVENT_REWRITE_DISPATCH_ANOTHER if the event needs to be
85 // modified according to the returned |flags|, and there are delayed
86 // modifier-up events now to be retrieved using |NextDispatchEvent()|
87 // (i.e. a sticky-modified key that ends a sticky state);
88 // - Otherwise returns ui::EVENT_REWRITE_CONTINUE and leaves |flags|
89 // unchanged.
90 ui::EventRewriteStatus RewriteKeyEvent(const ui::KeyEvent& event,
91 ui::KeyboardCode key_code,
92 int* flags);
93
94 // Handles mouse event.
95 ui::EventRewriteStatus RewriteMouseEvent(const ui::MouseEvent& event,
96 int* flags);
97
98 // Handles scroll event.
99 ui::EventRewriteStatus RewriteScrollEvent(const ui::ScrollEvent& event,
100 int* flags);
101
102 // Obtains a pending modifier-up event. If the immediately previous
103 // call to |Rewrite...Event()| or |NextDispatchEvent()| returned
104 // ui::EVENT_REWRITE_DISPATCH_ANOTHER, this sets |new_event| and returns:
105 // - ui::EVENT_REWRITE_DISPATCH_ANOTHER if there is at least one more
106 // pending modifier-up event;
107 // - ui::EVENT_REWRITE_REWRITE if this is the last or only modifier-up event;
108 // Otherwise, there is no pending modifier-up event, and this function
109 // returns ui::EVENT_REWRITE_CONTINUE and sets |new_event| to NULL.
110 ui::EventRewriteStatus NextDispatchEvent(scoped_ptr<ui::Event>* new_event);
111
112 private: 81 private:
113 // Handles keyboard event. Returns true if Sticky key consumes keyboard event. 82 // Handles keyboard event. Returns true if Sticky key consumes keyboard event.
114 // Adds to |mod_down_flags| any flag to be added to the key event. 83 bool HandleKeyEvent(ui::KeyEvent* event);
115 // Sets |released| if any modifier is to be released after the key event.
116 bool HandleKeyEvent(const ui::KeyEvent& event,
117 ui::KeyboardCode key_code,
118 int* mod_down_flags,
119 bool* released);
120 84
121 // Handles mouse event. Returns true if Sticky key consumes keyboard event. 85 // Handles mouse event. Returns true if sticky key consumes mouse event.
122 // Sets |released| if any modifier is to be released after the key event. 86 bool HandleMouseEvent(ui::MouseEvent* event);
123 bool HandleMouseEvent(const ui::MouseEvent& event,
124 int* mod_down_flags,
125 bool* released);
126 87
127 // Handles scroll event. Returns true if Sticky key consumes keyboard event. 88 // Handles scroll event. Returns true if sticky key consumes scroll event.
128 // Sets |released| if any modifier is to be released after the key event. 89 bool HandleScrollEvent(ui::ScrollEvent* event);
129 bool HandleScrollEvent(const ui::ScrollEvent& event,
130 int* mod_down_flags,
131 bool* released);
132 90
133 // Updates the overlay UI with the current state of the sticky keys. 91 // Updates the overlay UI with the current state of the sticky keys.
134 void UpdateOverlay(); 92 void UpdateOverlay();
135 93
136 // Whether sticky keys is activated and modifying events. 94 // Whether sticky keys is activated and modifying events.
137 bool enabled_; 95 bool enabled_;
138 96
139 // Whether the current layout has a mod3 key. 97 // Whether the current layout has a mod3 key.
140 bool mod3_enabled_; 98 bool mod3_enabled_;
141 99
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // Other KeyUp/Down | noop | noop | noop | 136 // Other KeyUp/Down | noop | noop | noop |
179 // Mouse Press | noop | noop(#) | noop(#) | 137 // Mouse Press | noop | noop(#) | noop(#) |
180 // Mouse Release | noop | To DISABLED(#) | noop(#) | 138 // Mouse Release | noop | To DISABLED(#) | noop(#) |
181 // Mouse Wheel | noop | To DISABLED(#) | noop(#) | 139 // Mouse Wheel | noop | To DISABLED(#) | noop(#) |
182 // Other Mouse Event| noop | noop | noop | 140 // Other Mouse Event| noop | noop | noop |
183 // 141 //
184 // Here, (*) means key event will be consumed by StickyKeys, and (#) means event 142 // Here, (*) means key event will be consumed by StickyKeys, and (#) means event
185 // is modified. 143 // is modified.
186 class ASH_EXPORT StickyKeysHandler { 144 class ASH_EXPORT StickyKeysHandler {
187 public: 145 public:
188 explicit StickyKeysHandler(ui::EventFlags modifier_flag); 146 class StickyKeysHandlerDelegate {
147 public:
148 StickyKeysHandlerDelegate();
149 virtual ~StickyKeysHandlerDelegate();
150
151 // Dispatches keyboard event synchronously. |event| is an event that has
152 // been previously dispatched.
153 virtual void DispatchKeyEvent(ui::KeyEvent* event,
154 aura::Window* target) = 0;
155
156 // Dispatches mouse event synchronously. |event| is an event that has
157 // been previously dispatched.
158 virtual void DispatchMouseEvent(ui::MouseEvent* event,
159 aura::Window* target) = 0;
160
161 // Dispatches scroll event synchronously. |event| is an event that has
162 // been previously dispatched.
163 virtual void DispatchScrollEvent(ui::ScrollEvent* event,
164 aura::Window* target) = 0;
165 };
166
167 // This class takes an ownership of |delegate|.
168 StickyKeysHandler(ui::EventFlags modifier_flag,
169 StickyKeysHandlerDelegate* delegate);
189 ~StickyKeysHandler(); 170 ~StickyKeysHandler();
190 171
191 // Handles keyboard event. Returns true if Sticky key consumes keyboard event. 172 // Handles key event. Returns true if key is consumed.
192 // Sets its own modifier flag in |mod_down_flags| if it is active and needs 173 bool HandleKeyEvent(ui::KeyEvent* event);
193 // to be added to the event, and sets |released| if releasing it.
194 bool HandleKeyEvent(const ui::KeyEvent& event,
195 ui::KeyboardCode key_code,
196 int* mod_down_flags,
197 bool* released);
198 174
199 // Handles mouse event. Returns true if sticky key consumes mouse event. 175 // Handles a mouse event. Returns true if mouse event is consumed.
200 // Sets its own modifier flag in |mod_down_flags| if it is active and needs 176 bool HandleMouseEvent(ui::MouseEvent* event);
201 // to be added to the event, and sets |released| if releasing it.
202 bool HandleMouseEvent(const ui::MouseEvent& event,
203 int* mod_down_flags,
204 bool* released);
205 177
206 // Handles scroll event. Returns true if sticky key consumes scroll event. 178 // Handles a scroll event. Returns true if scroll event is consumed.
207 // Sets its own modifier flag in |mod_down_flags| if it is active and needs 179 bool HandleScrollEvent(ui::ScrollEvent* event);
208 // to be added to the event, and sets |released| if releasing it.
209 bool HandleScrollEvent(const ui::ScrollEvent& event,
210 int* mod_down_flags,
211 bool* released);
212
213 // Fetches a pending modifier-up event if one exists and the return
214 // parameter |new_event| is available (i.e. not set). Returns the number
215 // of pending events still remaining to be returned.
216 int GetModifierUpEvent(scoped_ptr<ui::Event>* new_event);
217 180
218 // Returns current internal state. 181 // Returns current internal state.
219 StickyKeyState current_state() const { return current_state_; } 182 StickyKeyState current_state() const { return current_state_; }
220 183
221 private: 184 private:
222 // Represents event type in Sticky Key context. 185 // Represents event type in Sticky Key context.
223 enum KeyEventType { 186 enum KeyEventType {
224 TARGET_MODIFIER_DOWN, // The monitoring modifier key is down. 187 TARGET_MODIFIER_DOWN, // The monitoring modifier key is down.
225 TARGET_MODIFIER_UP, // The monitoring modifier key is up. 188 TARGET_MODIFIER_UP, // The monitoring modifier key is up.
226 NORMAL_KEY_DOWN, // The non modifier key is down. 189 NORMAL_KEY_DOWN, // The non modifier key is down.
227 NORMAL_KEY_UP, // The non modifier key is up. 190 NORMAL_KEY_UP, // The non modifier key is up.
228 OTHER_MODIFIER_DOWN, // The modifier key but not monitored key is down. 191 OTHER_MODIFIER_DOWN, // The modifier key but not monitored key is down.
229 OTHER_MODIFIER_UP, // The modifier key but not monitored key is up. 192 OTHER_MODIFIER_UP, // The modifier key but not monitored key is up.
230 }; 193 };
231 194
232 // Translates event type and key code to sticky keys event type. 195 // Translates |event| to sticky keys event type.
233 KeyEventType TranslateKeyEvent(ui::EventType type, ui::KeyboardCode key_code); 196 KeyEventType TranslateKeyEvent(ui::KeyEvent* event);
234 197
235 // Handles key event in DISABLED state. Returns true if sticky keys 198 // Handles key event in DISABLED state.
236 // consumes the keyboard event. 199 bool HandleDisabledState(ui::KeyEvent* event);
237 bool HandleDisabledState(const ui::KeyEvent& event,
238 ui::KeyboardCode key_code);
239 200
240 // Handles key event in ENABLED state. Returns true if sticky keys 201 // Handles key event in ENABLED state.
241 // consumes the keyboard event. 202 bool HandleEnabledState(ui::KeyEvent* event);
242 bool HandleEnabledState(const ui::KeyEvent& event,
243 ui::KeyboardCode key_code,
244 int* mod_down_flags,
245 bool* released);
246 203
247 // Handles key event in LOCKED state. Returns true if sticky keys 204 // Handles key event in LOCKED state.
248 // consumes the keyboard event. 205 bool HandleLockedState(ui::KeyEvent* event);
249 bool HandleLockedState(const ui::KeyEvent& event, 206
250 ui::KeyboardCode key_code, 207 // Dispatches |event| to its target and then dispatch a key released event
251 int* mod_down_flags, 208 // for the modifier key. This function is required to ensure that the events
252 bool* released); 209 // are sent in the correct order when disabling sticky key after a key/mouse
210 // button press.
211 void DispatchEventAndReleaseModifier(ui::Event* event);
212
213 // Adds |modifier_flags_| to a native X11 event state mask.
214 void AppendNativeEventMask(unsigned int* state);
215
216 // Adds |modifier_flags_| into |event|.
217 void AppendModifier(ui::KeyEvent* event);
218 void AppendModifier(ui::MouseEvent* event);
219 void AppendModifier(ui::ScrollEvent* event);
253 220
254 // The modifier flag to be monitored and appended to events. 221 // The modifier flag to be monitored and appended to events.
255 const ui::EventFlags modifier_flag_; 222 const ui::EventFlags modifier_flag_;
256 223
257 // The current sticky key status. 224 // The current sticky key status.
258 StickyKeyState current_state_; 225 StickyKeyState current_state_;
259 226
227 // True if the received key event is sent by StickyKeyHandler.
228 bool event_from_myself_;
229
260 // True if we received the TARGET_MODIFIER_DOWN event while in the DISABLED 230 // True if we received the TARGET_MODIFIER_DOWN event while in the DISABLED
261 // state but before we receive the TARGET_MODIFIER_UP event. Normal 231 // state but before we receive the TARGET_MODIFIER_UP event. Normal
262 // shortcuts (eg. ctrl + t) during this time will prevent a transition to 232 // shortcuts (eg. ctrl + t) during this time will prevent a transition to
263 // the ENABLED state. 233 // the ENABLED state.
264 bool preparing_to_enable_; 234 bool preparing_to_enable_;
265 235
266 // Tracks the scroll direction of the current scroll sequence. Sticky keys 236 // Tracks the scroll direction of the current scroll sequence. Sticky keys
267 // stops modifying the scroll events of the sequence when the direction 237 // stops modifying the scroll events of the sequence when the direction
268 // changes. If no sequence is tracked, the value is 0. 238 // changes. If no sequence is tracked, the value is 0.
269 int scroll_delta_; 239 int scroll_delta_;
270 240
271 // The modifier up key event to be sent on non modifier key on ENABLED state. 241 // The modifier up key event to be sent on non modifier key on ENABLED state.
272 scoped_ptr<ui::KeyEvent> modifier_up_event_; 242 scoped_ptr<ui::KeyEvent> modifier_up_event_;
273 243
244 scoped_ptr<StickyKeysHandlerDelegate> delegate_;
245
274 DISALLOW_COPY_AND_ASSIGN(StickyKeysHandler); 246 DISALLOW_COPY_AND_ASSIGN(StickyKeysHandler);
275 }; 247 };
276 248
277 } // namespace ash 249 } // namespace ash
278 250
279 #endif // ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ 251 #endif // ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_
OLDNEW
« no previous file with comments | « trunk/src/ash/shell.cc ('k') | trunk/src/ash/sticky_keys/sticky_keys_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698