OLD | NEW |
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 Loading... |
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 // Rewrite keyboard event. |
113 // Adds to |mod_down_flags| any flag to be added to the key event. | 86 ui::EventRewriteStatus RewriteKeyEvent( |
114 // Sets |released| if any modifier is to be released after the key event. | 87 const ui::KeyEvent& event, |
115 bool HandleKeyEvent(const ui::KeyEvent& event, | 88 std::unique_ptr<ui::Event>* rewritten_event); |
116 ui::KeyboardCode key_code, | |
117 int* mod_down_flags, | |
118 bool* released); | |
119 | 89 |
120 // Handles mouse event. Returns true if Sticky key consumes keyboard event. | 90 // Rewrite mouse event. |
121 // Sets |released| if any modifier is to be released after the key event. | 91 ui::EventRewriteStatus RewriteMouseEvent( |
122 bool HandleMouseEvent(const ui::MouseEvent& event, | 92 const ui::MouseEvent& event, |
123 int* mod_down_flags, | 93 std::unique_ptr<ui::Event>* rewritten_event); |
124 bool* released); | |
125 | 94 |
126 // Handles scroll event. Returns true if Sticky key consumes keyboard event. | 95 // Rewrite scroll event. |
127 // Sets |released| if any modifier is to be released after the key event. | 96 ui::EventRewriteStatus RewriteScrollEvent( |
128 bool HandleScrollEvent(const ui::ScrollEvent& event, | 97 const ui::ScrollEvent& event, |
129 int* mod_down_flags, | 98 std::unique_ptr<ui::Event>* rewritten_event); |
130 bool* released); | |
131 | 99 |
132 // Updates the overlay UI with the current state of the sticky keys. | 100 // Updates the overlay UI with the current state of the sticky keys. |
133 void UpdateOverlay(); | 101 void UpdateOverlay(); |
134 | 102 |
135 // Whether sticky keys is activated and modifying events. | 103 // Whether sticky keys is activated and modifying events. |
136 bool enabled_; | 104 bool enabled_; |
137 | 105 |
138 // Whether the current layout has a mod3 key. | 106 // Whether the current layout has a mod3 key. |
139 bool mod3_enabled_; | 107 bool mod3_enabled_; |
140 | 108 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // is modified. | 153 // is modified. |
186 class ASH_EXPORT StickyKeysHandler { | 154 class ASH_EXPORT StickyKeysHandler { |
187 public: | 155 public: |
188 explicit StickyKeysHandler(ui::EventFlags modifier_flag); | 156 explicit StickyKeysHandler(ui::EventFlags modifier_flag); |
189 ~StickyKeysHandler(); | 157 ~StickyKeysHandler(); |
190 | 158 |
191 // Handles keyboard event. Returns true if Sticky key consumes keyboard event. | 159 // 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 | 160 // 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. | 161 // to be added to the event, and sets |released| if releasing it. |
194 bool HandleKeyEvent(const ui::KeyEvent& event, | 162 bool HandleKeyEvent(const ui::KeyEvent& event, |
195 ui::KeyboardCode key_code, | |
196 int* mod_down_flags, | 163 int* mod_down_flags, |
197 bool* released); | 164 bool* released); |
198 | 165 |
199 // Handles mouse event. Returns true if sticky key consumes mouse event. | 166 // 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 | 167 // 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. | 168 // to be added to the event, and sets |released| if releasing it. |
202 bool HandleMouseEvent(const ui::MouseEvent& event, | 169 bool HandleMouseEvent(const ui::MouseEvent& event, |
203 int* mod_down_flags, | 170 int* mod_down_flags, |
204 bool* released); | 171 bool* released); |
205 | 172 |
(...skipping 21 matching lines...) Expand all Loading... |
227 NORMAL_KEY_UP, // The non modifier key is up. | 194 NORMAL_KEY_UP, // The non modifier key is up. |
228 OTHER_MODIFIER_DOWN, // The modifier key but not monitored key is down. | 195 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. | 196 OTHER_MODIFIER_UP, // The modifier key but not monitored key is up. |
230 }; | 197 }; |
231 | 198 |
232 // Translates event type and key code to sticky keys event type. | 199 // Translates event type and key code to sticky keys event type. |
233 KeyEventType TranslateKeyEvent(ui::EventType type, ui::KeyboardCode key_code); | 200 KeyEventType TranslateKeyEvent(ui::EventType type, ui::KeyboardCode key_code); |
234 | 201 |
235 // Handles key event in DISABLED state. Returns true if sticky keys | 202 // Handles key event in DISABLED state. Returns true if sticky keys |
236 // consumes the keyboard event. | 203 // consumes the keyboard event. |
237 bool HandleDisabledState(const ui::KeyEvent& event, | 204 bool HandleDisabledState(const ui::KeyEvent& event); |
238 ui::KeyboardCode key_code); | |
239 | 205 |
240 // Handles key event in ENABLED state. Returns true if sticky keys | 206 // Handles key event in ENABLED state. Returns true if sticky keys |
241 // consumes the keyboard event. | 207 // consumes the keyboard event. |
242 bool HandleEnabledState(const ui::KeyEvent& event, | 208 bool HandleEnabledState(const ui::KeyEvent& event, |
243 ui::KeyboardCode key_code, | |
244 int* mod_down_flags, | 209 int* mod_down_flags, |
245 bool* released); | 210 bool* released); |
246 | 211 |
247 // Handles key event in LOCKED state. Returns true if sticky keys | 212 // Handles key event in LOCKED state. Returns true if sticky keys |
248 // consumes the keyboard event. | 213 // consumes the keyboard event. |
249 bool HandleLockedState(const ui::KeyEvent& event, | 214 bool HandleLockedState(const ui::KeyEvent& event, |
250 ui::KeyboardCode key_code, | |
251 int* mod_down_flags, | 215 int* mod_down_flags, |
252 bool* released); | 216 bool* released); |
253 | 217 |
254 // The modifier flag to be monitored and appended to events. | 218 // The modifier flag to be monitored and appended to events. |
255 const ui::EventFlags modifier_flag_; | 219 const ui::EventFlags modifier_flag_; |
256 | 220 |
257 // The current sticky key status. | 221 // The current sticky key status. |
258 StickyKeyState current_state_; | 222 StickyKeyState current_state_; |
259 | 223 |
260 // True if we received the TARGET_MODIFIER_DOWN event while in the DISABLED | 224 // 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 | 225 // state but before we receive the TARGET_MODIFIER_UP event. Normal |
262 // shortcuts (eg. ctrl + t) during this time will prevent a transition to | 226 // shortcuts (eg. ctrl + t) during this time will prevent a transition to |
263 // the ENABLED state. | 227 // the ENABLED state. |
264 bool preparing_to_enable_; | 228 bool preparing_to_enable_; |
265 | 229 |
266 // Tracks the scroll direction of the current scroll sequence. Sticky keys | 230 // Tracks the scroll direction of the current scroll sequence. Sticky keys |
267 // stops modifying the scroll events of the sequence when the direction | 231 // stops modifying the scroll events of the sequence when the direction |
268 // changes. If no sequence is tracked, the value is 0. | 232 // changes. If no sequence is tracked, the value is 0. |
269 int scroll_delta_; | 233 int scroll_delta_; |
270 | 234 |
271 // The modifier up key event to be sent on non modifier key on ENABLED state. | 235 // The modifier up key event to be sent on non modifier key on ENABLED state. |
272 std::unique_ptr<ui::KeyEvent> modifier_up_event_; | 236 std::unique_ptr<ui::KeyEvent> modifier_up_event_; |
273 | 237 |
274 DISALLOW_COPY_AND_ASSIGN(StickyKeysHandler); | 238 DISALLOW_COPY_AND_ASSIGN(StickyKeysHandler); |
275 }; | 239 }; |
276 | 240 |
277 } // namespace ash | 241 } // namespace ash |
278 | 242 |
279 #endif // ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ | 243 #endif // ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ |
OLD | NEW |