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

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

Issue 2731283004: Do not use ash in chromeos::EventRewriter. (Closed)
Patch Set: Fix a crash Created 3 years, 9 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 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 <memory> 8 #include <memory>
9 9
10 #include "ash/ash_export.h" 10 #include "ash/ash_export.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // 6. Release 1 key : 1 Keyup event with Ctrl modifier. 52 // 6. Release 1 key : 1 Keyup event with Ctrl modifier.
53 // 7. Press 2 key : 2 Keydown event with Ctrl modifier. 53 // 7. Press 2 key : 2 Keydown event with Ctrl modifier.
54 // 8. Release 2 key : 2 Keyup event with Ctrl modifier. 54 // 8. Release 2 key : 2 Keyup event with Ctrl modifier.
55 // 9. Press Ctrl key : No event 55 // 9. Press Ctrl key : No event
56 // 10. Release Ctrl key: Ctrl Keyup 56 // 10. Release Ctrl key: Ctrl Keyup
57 // 57 //
58 // In the case of Chrome OS, StickyKeysController supports Shift,Alt,Ctrl 58 // In the case of Chrome OS, StickyKeysController supports Shift,Alt,Ctrl
59 // modifiers. Each handling or state is performed independently. 59 // modifiers. Each handling or state is performed independently.
60 // 60 //
61 // StickyKeysController is disabled by default. 61 // StickyKeysController is disabled by default.
62 class ASH_EXPORT StickyKeysController { 62 class ASH_EXPORT StickyKeysController : public ui::EventRewriter {
63 public: 63 public:
64 StickyKeysController(); 64 StickyKeysController();
65 virtual ~StickyKeysController(); 65 ~StickyKeysController() override;
66 66
67 // Activate sticky keys to intercept and modify incoming events. 67 // Activate sticky keys to intercept and modify incoming events.
68 void Enable(bool enabled); 68 void Enable(bool enabled);
69 69
70 void SetModifiersEnabled(bool mod3_enabled, bool altgr_enabled); 70 void SetModifiersEnabled(bool mod3_enabled, bool altgr_enabled);
71 71
72 // Returns the StickyKeyOverlay used by the controller. Ownership is not 72 // Returns the StickyKeyOverlay used by the controller. Ownership is not
73 // passed. 73 // passed.
74 StickyKeysOverlay* GetOverlayForTest(); 74 StickyKeysOverlay* GetOverlayForTest();
75 75
76 // Handles keyboard event. Returns an |EventRewriteStatus|, and may 76 // ui::EventRewriter:
77 // modify |flags|: 77 ui::EventRewriteStatus RewriteEvent(
78 // - Returns ui::EVENT_REWRITE_DISCARD, and leaves |flags| untouched, 78 const ui::Event& event,
79 // if the event is consumed (i.e. a sticky modifier press or release); 79 std::unique_ptr<ui::Event>* rewritten_event) override;
80 // - Returns ui::EVENT_REWRITE_REWRITTEN if the event needs to be modified
81 // according to the returned |flags| (i.e. a sticky-modified key);
82 // - Returns ui::EVENT_REWRITE_DISPATCH_ANOTHER if the event needs to be
83 // modified according to the returned |flags|, and there are delayed
84 // modifier-up events now to be retrieved using |NextDispatchEvent()|
85 // (i.e. a sticky-modified key that ends a sticky state);
86 // - Otherwise returns ui::EVENT_REWRITE_CONTINUE and leaves |flags|
87 // unchanged.
88 ui::EventRewriteStatus RewriteKeyEvent(const ui::KeyEvent& event,
89 ui::KeyboardCode key_code,
90 int* flags);
91
92 // Handles mouse event.
93 ui::EventRewriteStatus RewriteMouseEvent(const ui::MouseEvent& event,
94 int* flags);
95
96 // Handles scroll event.
97 ui::EventRewriteStatus RewriteScrollEvent(const ui::ScrollEvent& event,
98 int* flags);
99
100 // Obtains a pending modifier-up event. If the immediately previous
101 // call to |Rewrite...Event()| or |NextDispatchEvent()| returned
102 // ui::EVENT_REWRITE_DISPATCH_ANOTHER, this sets |new_event| and returns:
103 // - ui::EVENT_REWRITE_DISPATCH_ANOTHER if there is at least one more
104 // pending modifier-up event;
105 // - ui::EVENT_REWRITE_REWRITE if this is the last or only modifier-up event;
106 // Otherwise, there is no pending modifier-up event, and this function
107 // returns ui::EVENT_REWRITE_CONTINUE and sets |new_event| to NULL.
108 ui::EventRewriteStatus NextDispatchEvent( 80 ui::EventRewriteStatus NextDispatchEvent(
109 std::unique_ptr<ui::Event>* new_event); 81 const ui::Event& last_event,
82 std::unique_ptr<ui::Event>* new_event) override;
110 83
111 private: 84 private:
112 // Handles keyboard event. Returns true if Sticky key consumes keyboard event. 85 // Handles keyboard event. Returns true if Sticky key consumes keyboard event.
113 // Adds to |mod_down_flags| any flag to be added to the key event. 86 // Adds to |mod_down_flags| any flag to be added to the key event.
114 // Sets |released| if any modifier is to be released after the key event. 87 // Sets |released| if any modifier is to be released after the key event.
115 bool HandleKeyEvent(const ui::KeyEvent& event, 88 bool HandleKeyEvent(const ui::KeyEvent& event,
116 ui::KeyboardCode key_code,
117 int* mod_down_flags, 89 int* mod_down_flags,
118 bool* released); 90 bool* released);
119 91
120 // Handles mouse event. Returns true if Sticky key consumes keyboard event. 92 // Handles mouse event. Returns true if Sticky key consumes keyboard event.
121 // Sets |released| if any modifier is to be released after the key event. 93 // Sets |released| if any modifier is to be released after the key event.
122 bool HandleMouseEvent(const ui::MouseEvent& event, 94 bool HandleMouseEvent(const ui::MouseEvent& event,
123 int* mod_down_flags, 95 int* mod_down_flags,
124 bool* released); 96 bool* released);
125 97
126 // Handles scroll event. Returns true if Sticky key consumes keyboard event. 98 // Handles scroll event. Returns true if Sticky key consumes keyboard event.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 // is modified. 157 // is modified.
186 class ASH_EXPORT StickyKeysHandler { 158 class ASH_EXPORT StickyKeysHandler {
187 public: 159 public:
188 explicit StickyKeysHandler(ui::EventFlags modifier_flag); 160 explicit StickyKeysHandler(ui::EventFlags modifier_flag);
189 ~StickyKeysHandler(); 161 ~StickyKeysHandler();
190 162
191 // Handles keyboard event. Returns true if Sticky key consumes keyboard event. 163 // Handles keyboard event. Returns true if Sticky key consumes keyboard event.
192 // Sets its own modifier flag in |mod_down_flags| if it is active and needs 164 // Sets its own modifier flag in |mod_down_flags| if it is active and needs
193 // to be added to the event, and sets |released| if releasing it. 165 // to be added to the event, and sets |released| if releasing it.
194 bool HandleKeyEvent(const ui::KeyEvent& event, 166 bool HandleKeyEvent(const ui::KeyEvent& event,
195 ui::KeyboardCode key_code,
196 int* mod_down_flags, 167 int* mod_down_flags,
197 bool* released); 168 bool* released);
198 169
199 // Handles mouse event. Returns true if sticky key consumes mouse event. 170 // Handles mouse event. Returns true if sticky key consumes mouse event.
200 // Sets its own modifier flag in |mod_down_flags| if it is active and needs 171 // Sets its own modifier flag in |mod_down_flags| if it is active and needs
201 // to be added to the event, and sets |released| if releasing it. 172 // to be added to the event, and sets |released| if releasing it.
202 bool HandleMouseEvent(const ui::MouseEvent& event, 173 bool HandleMouseEvent(const ui::MouseEvent& event,
203 int* mod_down_flags, 174 int* mod_down_flags,
204 bool* released); 175 bool* released);
205 176
(...skipping 21 matching lines...) Expand all
227 NORMAL_KEY_UP, // The non modifier key is up. 198 NORMAL_KEY_UP, // The non modifier key is up.
228 OTHER_MODIFIER_DOWN, // The modifier key but not monitored key is down. 199 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. 200 OTHER_MODIFIER_UP, // The modifier key but not monitored key is up.
230 }; 201 };
231 202
232 // Translates event type and key code to sticky keys event type. 203 // Translates event type and key code to sticky keys event type.
233 KeyEventType TranslateKeyEvent(ui::EventType type, ui::KeyboardCode key_code); 204 KeyEventType TranslateKeyEvent(ui::EventType type, ui::KeyboardCode key_code);
234 205
235 // Handles key event in DISABLED state. Returns true if sticky keys 206 // Handles key event in DISABLED state. Returns true if sticky keys
236 // consumes the keyboard event. 207 // consumes the keyboard event.
237 bool HandleDisabledState(const ui::KeyEvent& event, 208 bool HandleDisabledState(const ui::KeyEvent& event);
238 ui::KeyboardCode key_code);
239 209
240 // Handles key event in ENABLED state. Returns true if sticky keys 210 // Handles key event in ENABLED state. Returns true if sticky keys
241 // consumes the keyboard event. 211 // consumes the keyboard event.
242 bool HandleEnabledState(const ui::KeyEvent& event, 212 bool HandleEnabledState(const ui::KeyEvent& event,
243 ui::KeyboardCode key_code,
244 int* mod_down_flags, 213 int* mod_down_flags,
245 bool* released); 214 bool* released);
246 215
247 // Handles key event in LOCKED state. Returns true if sticky keys 216 // Handles key event in LOCKED state. Returns true if sticky keys
248 // consumes the keyboard event. 217 // consumes the keyboard event.
249 bool HandleLockedState(const ui::KeyEvent& event, 218 bool HandleLockedState(const ui::KeyEvent& event,
250 ui::KeyboardCode key_code,
251 int* mod_down_flags, 219 int* mod_down_flags,
252 bool* released); 220 bool* released);
253 221
254 // The modifier flag to be monitored and appended to events. 222 // The modifier flag to be monitored and appended to events.
255 const ui::EventFlags modifier_flag_; 223 const ui::EventFlags modifier_flag_;
256 224
257 // The current sticky key status. 225 // The current sticky key status.
258 StickyKeyState current_state_; 226 StickyKeyState current_state_;
259 227
260 // True if we received the TARGET_MODIFIER_DOWN event while in the DISABLED 228 // 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 229 // state but before we receive the TARGET_MODIFIER_UP event. Normal
262 // shortcuts (eg. ctrl + t) during this time will prevent a transition to 230 // shortcuts (eg. ctrl + t) during this time will prevent a transition to
263 // the ENABLED state. 231 // the ENABLED state.
264 bool preparing_to_enable_; 232 bool preparing_to_enable_;
265 233
266 // Tracks the scroll direction of the current scroll sequence. Sticky keys 234 // Tracks the scroll direction of the current scroll sequence. Sticky keys
267 // stops modifying the scroll events of the sequence when the direction 235 // stops modifying the scroll events of the sequence when the direction
268 // changes. If no sequence is tracked, the value is 0. 236 // changes. If no sequence is tracked, the value is 0.
269 int scroll_delta_; 237 int scroll_delta_;
270 238
271 // The modifier up key event to be sent on non modifier key on ENABLED state. 239 // The modifier up key event to be sent on non modifier key on ENABLED state.
272 std::unique_ptr<ui::KeyEvent> modifier_up_event_; 240 std::unique_ptr<ui::KeyEvent> modifier_up_event_;
273 241
274 DISALLOW_COPY_AND_ASSIGN(StickyKeysHandler); 242 DISALLOW_COPY_AND_ASSIGN(StickyKeysHandler);
275 }; 243 };
276 244
277 } // namespace ash 245 } // namespace ash
278 246
279 #endif // ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ 247 #endif // ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_
OLDNEW
« no previous file with comments | « no previous file | ash/sticky_keys/sticky_keys_controller.cc » ('j') | ash/sticky_keys/sticky_keys_controller.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698