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 "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "ash/sticky_keys/sticky_keys_constants.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "ui/events/event_constants.h" | 11 #include "ui/events/event_constants.h" |
11 #include "ui/events/event_handler.h" | 12 #include "ui/events/event_handler.h" |
12 | 13 |
13 namespace ui { | 14 namespace ui { |
14 class Event; | 15 class Event; |
15 class KeyEvent; | 16 class KeyEvent; |
16 class MouseEvent; | 17 class MouseEvent; |
17 } // namespace ui | 18 } // namespace ui |
18 | 19 |
19 namespace aura { | 20 namespace aura { |
20 class Window; | 21 class Window; |
21 } // namespace aura | 22 } // namespace aura |
22 | 23 |
23 namespace ash { | 24 namespace ash { |
24 | 25 |
| 26 class StickyKeysOverlay; |
25 class StickyKeysHandler; | 27 class StickyKeysHandler; |
26 | 28 |
27 // StickyKeysController is an accessibility feature for users to be able to | 29 // StickyKeysController is an accessibility feature for users to be able to |
28 // compose key and mouse event with modifier keys without simultaneous key | 30 // compose key and mouse event with modifier keys without simultaneous key |
29 // press event. Instead they can compose events separately pressing each of the | 31 // press event. Instead they can compose events separately pressing each of the |
30 // modifier keys involved. | 32 // modifier keys involved. |
31 // e.g. Composing Ctrl + T | 33 // e.g. Composing Ctrl + T |
32 // User Action : The KeyEvent widget will receives | 34 // User Action : The KeyEvent widget will receives |
33 // ---------------------------------------------------------- | 35 // ---------------------------------------------------------- |
34 // 1. Press Ctrl key : Ctrl Keydown. | 36 // 1. Press Ctrl key : Ctrl Keydown. |
(...skipping 23 matching lines...) Expand all Loading... |
58 // | 60 // |
59 // StickyKeysController is disabled by default. | 61 // StickyKeysController is disabled by default. |
60 class ASH_EXPORT StickyKeysController : public ui::EventHandler { | 62 class ASH_EXPORT StickyKeysController : public ui::EventHandler { |
61 public: | 63 public: |
62 StickyKeysController(); | 64 StickyKeysController(); |
63 virtual ~StickyKeysController(); | 65 virtual ~StickyKeysController(); |
64 | 66 |
65 // Activate sticky keys to intercept and modify incoming events. | 67 // Activate sticky keys to intercept and modify incoming events. |
66 void Enable(bool enabled); | 68 void Enable(bool enabled); |
67 | 69 |
| 70 // Overridden from ui::EventHandler: |
| 71 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
| 72 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
| 73 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; |
| 74 |
| 75 // Returns the StickyKeyOverlay used by the controller. Ownership is not |
| 76 // passed. |
| 77 StickyKeysOverlay* GetOverlayForTest(); |
| 78 |
68 private: | 79 private: |
69 // Handles keyboard event. Returns true if Sticky key consumes keyboard event. | 80 // Handles keyboard event. Returns true if Sticky key consumes keyboard event. |
70 bool HandleKeyEvent(ui::KeyEvent* event); | 81 bool HandleKeyEvent(ui::KeyEvent* event); |
71 | 82 |
72 // Handles mouse event. Returns true if sticky key consumes mouse event. | 83 // Handles mouse event. Returns true if sticky key consumes mouse event. |
73 bool HandleMouseEvent(ui::MouseEvent* event); | 84 bool HandleMouseEvent(ui::MouseEvent* event); |
74 | 85 |
75 // Handles scroll event. Returns true if sticky key consumes scroll event. | 86 // Handles scroll event. Returns true if sticky key consumes scroll event. |
76 bool HandleScrollEvent(ui::ScrollEvent* event); | 87 bool HandleScrollEvent(ui::ScrollEvent* event); |
77 | 88 |
78 // Overridden from ui::EventHandler: | 89 // Updates the overlay UI with the current state of the sticky keys. |
79 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | 90 void UpdateOverlay(); |
80 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; | |
81 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; | |
82 | 91 |
83 // Whether sticky keys is activated and modifying events. | 92 // Whether sticky keys is activated and modifying events. |
84 bool enabled_; | 93 bool enabled_; |
85 | 94 |
86 // Sticky key handlers. | 95 // Sticky key handlers. |
87 scoped_ptr<StickyKeysHandler> shift_sticky_key_; | 96 scoped_ptr<StickyKeysHandler> shift_sticky_key_; |
88 scoped_ptr<StickyKeysHandler> alt_sticky_key_; | 97 scoped_ptr<StickyKeysHandler> alt_sticky_key_; |
89 scoped_ptr<StickyKeysHandler> ctrl_sticky_key_; | 98 scoped_ptr<StickyKeysHandler> ctrl_sticky_key_; |
90 | 99 |
| 100 scoped_ptr<StickyKeysOverlay> overlay_; |
| 101 |
91 DISALLOW_COPY_AND_ASSIGN(StickyKeysController); | 102 DISALLOW_COPY_AND_ASSIGN(StickyKeysController); |
92 }; | 103 }; |
93 | 104 |
94 // StickyKeysHandler handles key event and controls sticky keysfor specific | 105 // StickyKeysHandler handles key event and controls sticky keysfor specific |
95 // modifier keys. If monitored keyboard events are recieved, StickyKeysHandler | 106 // modifier keys. If monitored keyboard events are recieved, StickyKeysHandler |
96 // changes internal state. If non modifier keyboard events or mouse events are | 107 // changes internal state. If non modifier keyboard events or mouse events are |
97 // received, StickyKeysHandler will append modifier based on internal state. | 108 // received, StickyKeysHandler will append modifier based on internal state. |
98 // For other events, StickyKeysHandler does nothing. | 109 // For other events, StickyKeysHandler does nothing. |
99 // | 110 // |
100 // The DISABLED state is default state and any incoming non modifier keyboard | 111 // The DISABLED state is default state and any incoming non modifier keyboard |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 aura::Window* target) = 0; | 143 aura::Window* target) = 0; |
133 | 144 |
134 // Dispatches mouse event synchronously. | 145 // Dispatches mouse event synchronously. |
135 virtual void DispatchMouseEvent(ui::MouseEvent* event, | 146 virtual void DispatchMouseEvent(ui::MouseEvent* event, |
136 aura::Window* target) = 0; | 147 aura::Window* target) = 0; |
137 | 148 |
138 // Dispatches scroll event synchronously. | 149 // Dispatches scroll event synchronously. |
139 virtual void DispatchScrollEvent(ui::ScrollEvent* event, | 150 virtual void DispatchScrollEvent(ui::ScrollEvent* event, |
140 aura::Window* target) = 0; | 151 aura::Window* target) = 0; |
141 }; | 152 }; |
142 // Represents Sticky Key state. | |
143 enum StickyKeyState { | |
144 // The sticky key is disabled. Incomming non modifier key events are not | |
145 // affected. | |
146 DISABLED, | |
147 // The sticky key is enabled. Incomming non modifier key down events are | |
148 // modified with |modifier_flag_|. After that, sticky key state become | |
149 // DISABLED. | |
150 ENABLED, | |
151 // The sticky key is locked. Incomming non modifier key down events are | |
152 // modified with |modifier_flag_|. | |
153 LOCKED, | |
154 }; | |
155 | 153 |
156 // This class takes an ownership of |delegate|. | 154 // This class takes an ownership of |delegate|. |
157 StickyKeysHandler(ui::EventFlags modifier_flag, | 155 StickyKeysHandler(ui::EventFlags modifier_flag, |
158 StickyKeysHandlerDelegate* delegate); | 156 StickyKeysHandlerDelegate* delegate); |
159 ~StickyKeysHandler(); | 157 ~StickyKeysHandler(); |
160 | 158 |
161 // Handles key event. Returns true if key is consumed. | 159 // Handles key event. Returns true if key is consumed. |
162 bool HandleKeyEvent(ui::KeyEvent* event); | 160 bool HandleKeyEvent(ui::KeyEvent* event); |
163 | 161 |
164 // Handles a mouse event. Returns true if mouse event is consumed. | 162 // Handles a mouse event. Returns true if mouse event is consumed. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 void DispatchEventAndReleaseModifier(ui::Event* event); | 198 void DispatchEventAndReleaseModifier(ui::Event* event); |
201 | 199 |
202 // Adds |modifier_flags_| to a native X11 event state mask. | 200 // Adds |modifier_flags_| to a native X11 event state mask. |
203 void AppendNativeEventMask(unsigned int* state); | 201 void AppendNativeEventMask(unsigned int* state); |
204 | 202 |
205 // Adds |modifier_flags_| into |event|. | 203 // Adds |modifier_flags_| into |event|. |
206 void AppendModifier(ui::KeyEvent* event); | 204 void AppendModifier(ui::KeyEvent* event); |
207 void AppendModifier(ui::MouseEvent* event); | 205 void AppendModifier(ui::MouseEvent* event); |
208 void AppendModifier(ui::ScrollEvent* event); | 206 void AppendModifier(ui::ScrollEvent* event); |
209 | 207 |
210 // The modifier flag to be monitored and appended. | 208 // The modifier flag to be monitored and appended to events. |
211 const ui::EventFlags modifier_flag_; | 209 const ui::EventFlags modifier_flag_; |
212 | 210 |
213 // The current sticky key status. | 211 // The current sticky key status. |
214 StickyKeyState current_state_; | 212 StickyKeyState current_state_; |
215 | 213 |
216 // True if the received key event is sent by StickyKeyHandler. | 214 // True if the received key event is sent by StickyKeyHandler. |
217 bool event_from_myself_; | 215 bool event_from_myself_; |
218 | 216 |
219 // True if we received the TARGET_MODIFIER_DOWN event while in the DISABLED | 217 // True if we received the TARGET_MODIFIER_DOWN event while in the DISABLED |
220 // state but before we receive the TARGET_MODIFIER_UP event. Normal | 218 // state but before we receive the TARGET_MODIFIER_UP event. Normal |
(...skipping 10 matching lines...) Expand all Loading... |
231 scoped_ptr<ui::KeyEvent> modifier_up_event_; | 229 scoped_ptr<ui::KeyEvent> modifier_up_event_; |
232 | 230 |
233 scoped_ptr<StickyKeysHandlerDelegate> delegate_; | 231 scoped_ptr<StickyKeysHandlerDelegate> delegate_; |
234 | 232 |
235 DISALLOW_COPY_AND_ASSIGN(StickyKeysHandler); | 233 DISALLOW_COPY_AND_ASSIGN(StickyKeysHandler); |
236 }; | 234 }; |
237 | 235 |
238 } // namespace ash | 236 } // namespace ash |
239 | 237 |
240 #endif // ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ | 238 #endif // ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ |
OLD | NEW |