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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 bool HandleMouseEvent(ui::MouseEvent* event); | 75 bool HandleMouseEvent(ui::MouseEvent* event); |
74 | 76 |
75 // Handles scroll event. Returns true if sticky key consumes scroll event. | 77 // Handles scroll event. Returns true if sticky key consumes scroll event. |
76 bool HandleScrollEvent(ui::ScrollEvent* event); | 78 bool HandleScrollEvent(ui::ScrollEvent* event); |
77 | 79 |
78 // Overridden from ui::EventHandler: | 80 // Overridden from ui::EventHandler: |
79 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; | 81 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; |
80 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; | 82 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; |
81 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; | 83 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; |
82 | 84 |
| 85 // Updates the overlay UI with the current state of the sticky keys. |
| 86 void UpdateOverlay(); |
| 87 |
83 // Whether sticky keys is activated and modifying events. | 88 // Whether sticky keys is activated and modifying events. |
84 bool enabled_; | 89 bool enabled_; |
85 | 90 |
86 // Sticky key handlers. | 91 // Sticky key handlers. |
87 scoped_ptr<StickyKeysHandler> shift_sticky_key_; | 92 scoped_ptr<StickyKeysHandler> shift_sticky_key_; |
88 scoped_ptr<StickyKeysHandler> alt_sticky_key_; | 93 scoped_ptr<StickyKeysHandler> alt_sticky_key_; |
89 scoped_ptr<StickyKeysHandler> ctrl_sticky_key_; | 94 scoped_ptr<StickyKeysHandler> ctrl_sticky_key_; |
90 | 95 |
| 96 scoped_ptr<StickyKeysOverlay> overlay_; |
| 97 |
91 DISALLOW_COPY_AND_ASSIGN(StickyKeysController); | 98 DISALLOW_COPY_AND_ASSIGN(StickyKeysController); |
92 }; | 99 }; |
93 | 100 |
94 // StickyKeysHandler handles key event and controls sticky keysfor specific | 101 // StickyKeysHandler handles key event and controls sticky keysfor specific |
95 // modifier keys. If monitored keyboard events are recieved, StickyKeysHandler | 102 // modifier keys. If monitored keyboard events are recieved, StickyKeysHandler |
96 // changes internal state. If non modifier keyboard events or mouse events are | 103 // changes internal state. If non modifier keyboard events or mouse events are |
97 // received, StickyKeysHandler will append modifier based on internal state. | 104 // received, StickyKeysHandler will append modifier based on internal state. |
98 // For other events, StickyKeysHandler does nothing. | 105 // For other events, StickyKeysHandler does nothing. |
99 // | 106 // |
100 // The DISABLED state is default state and any incoming non modifier keyboard | 107 // 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; | 139 aura::Window* target) = 0; |
133 | 140 |
134 // Dispatches mouse event synchronously. | 141 // Dispatches mouse event synchronously. |
135 virtual void DispatchMouseEvent(ui::MouseEvent* event, | 142 virtual void DispatchMouseEvent(ui::MouseEvent* event, |
136 aura::Window* target) = 0; | 143 aura::Window* target) = 0; |
137 | 144 |
138 // Dispatches scroll event synchronously. | 145 // Dispatches scroll event synchronously. |
139 virtual void DispatchScrollEvent(ui::ScrollEvent* event, | 146 virtual void DispatchScrollEvent(ui::ScrollEvent* event, |
140 aura::Window* target) = 0; | 147 aura::Window* target) = 0; |
141 }; | 148 }; |
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 | 149 |
156 // This class takes an ownership of |delegate|. | 150 // This class takes an ownership of |delegate|. |
157 StickyKeysHandler(ui::EventFlags modifier_flag, | 151 StickyKeysHandler(StickyKeyModifier modifier, |
158 StickyKeysHandlerDelegate* delegate); | 152 StickyKeysHandlerDelegate* delegate); |
159 ~StickyKeysHandler(); | 153 ~StickyKeysHandler(); |
160 | 154 |
161 // Handles key event. Returns true if key is consumed. | 155 // Handles key event. Returns true if key is consumed. |
162 bool HandleKeyEvent(ui::KeyEvent* event); | 156 bool HandleKeyEvent(ui::KeyEvent* event); |
163 | 157 |
164 // Handles a mouse event. Returns true if mouse event is consumed. | 158 // Handles a mouse event. Returns true if mouse event is consumed. |
165 bool HandleMouseEvent(ui::MouseEvent* event); | 159 bool HandleMouseEvent(ui::MouseEvent* event); |
166 | 160 |
167 // Handles a scroll event. Returns true if scroll event is consumed. | 161 // Handles a scroll event. Returns true if scroll event is consumed. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 void DispatchEventAndReleaseModifier(ui::Event* event); | 194 void DispatchEventAndReleaseModifier(ui::Event* event); |
201 | 195 |
202 // Adds |modifier_flags_| to a native X11 event state mask. | 196 // Adds |modifier_flags_| to a native X11 event state mask. |
203 void AppendNativeEventMask(unsigned int* state); | 197 void AppendNativeEventMask(unsigned int* state); |
204 | 198 |
205 // Adds |modifier_flags_| into |event|. | 199 // Adds |modifier_flags_| into |event|. |
206 void AppendModifier(ui::KeyEvent* event); | 200 void AppendModifier(ui::KeyEvent* event); |
207 void AppendModifier(ui::MouseEvent* event); | 201 void AppendModifier(ui::MouseEvent* event); |
208 void AppendModifier(ui::ScrollEvent* event); | 202 void AppendModifier(ui::ScrollEvent* event); |
209 | 203 |
210 // The modifier flag to be monitored and appended. | 204 // The modifier key this handler is responsible for. |
| 205 StickyKeyModifier modifier_; |
| 206 |
| 207 // The modifier flag to be monitored and appended to events. |
211 const ui::EventFlags modifier_flag_; | 208 const ui::EventFlags modifier_flag_; |
212 | 209 |
213 // The current sticky key status. | 210 // The current sticky key status. |
214 StickyKeyState current_state_; | 211 StickyKeyState current_state_; |
215 | 212 |
216 // True if the received key event is sent by StickyKeyHandler. | 213 // True if the received key event is sent by StickyKeyHandler. |
217 bool event_from_myself_; | 214 bool event_from_myself_; |
218 | 215 |
219 // True if we received the TARGET_MODIFIER_DOWN event while in the DISABLED | 216 // 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 | 217 // 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_; | 228 scoped_ptr<ui::KeyEvent> modifier_up_event_; |
232 | 229 |
233 scoped_ptr<StickyKeysHandlerDelegate> delegate_; | 230 scoped_ptr<StickyKeysHandlerDelegate> delegate_; |
234 | 231 |
235 DISALLOW_COPY_AND_ASSIGN(StickyKeysHandler); | 232 DISALLOW_COPY_AND_ASSIGN(StickyKeysHandler); |
236 }; | 233 }; |
237 | 234 |
238 } // namespace ash | 235 } // namespace ash |
239 | 236 |
240 #endif // ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ | 237 #endif // ASH_STICKY_KEYS_STICKY_KEYS_CONTROLLER_H_ |
OLD | NEW |