OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ | 5 #ifndef UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ |
6 #define UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ | 6 #define UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ |
7 | 7 |
8 #include "base/timer/timer.h" | 8 #include "base/timer/timer.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "ui/chromeos/ui_chromeos_export.h" | 10 #include "ui/chromeos/ui_chromeos_export.h" |
11 #include "ui/events/event.h" | 11 #include "ui/events/event.h" |
12 #include "ui/events/event_rewriter.h" | 12 #include "ui/events/event_rewriter.h" |
13 #include "ui/events/gesture_detection/gesture_detector.h" | 13 #include "ui/events/gesture_detection/gesture_detector.h" |
14 #include "ui/events/gestures/gesture_provider_aura.h" | 14 #include "ui/events/gestures/gesture_provider_aura.h" |
15 #include "ui/gfx/geometry/point.h" | 15 #include "ui/gfx/geometry/point.h" |
16 | 16 |
17 namespace aura { | 17 namespace aura { |
18 class Window; | 18 class Window; |
19 } | 19 } |
20 | 20 |
21 namespace ui { | 21 namespace ui { |
22 | 22 |
23 class Event; | 23 class Event; |
24 class EventHandler; | 24 class EventHandler; |
25 class GestureEvent; | 25 class GestureEvent; |
26 class GestureProviderAura; | 26 class GestureProviderAura; |
27 class TouchEvent; | 27 class TouchEvent; |
28 | 28 |
29 // A delegate to handle commands in response to detected accessibility gesture | |
30 // events. | |
31 class TouchExplorationControllerDelegate { | |
32 public: | |
33 virtual ~TouchExplorationControllerDelegate() {} | |
34 | |
35 virtual void const PlayVolumeAdjustSound() = 0; | |
James Cook
2014/07/15 19:58:11
either const at end or not const
Also, please doc
lisayin
2014/07/15 21:46:45
Done.
| |
36 virtual void SetOutputLevel(float volume) = 0; | |
37 }; | |
38 | |
29 // TouchExplorationController is used in tandem with "Spoken Feedback" to | 39 // TouchExplorationController is used in tandem with "Spoken Feedback" to |
30 // make the touch UI accessible. Gestures are mapped to accessiblity key | 40 // make the touch UI accessible. Gestures performed in the middle of the screen |
31 // shortcuts. | 41 // are mapped to accessiblity key shortcuts while gestures performed on the edge |
42 // of the screen can change settings. | |
32 // | 43 // |
33 // ** Short version ** | 44 // ** Short version ** |
34 // | 45 // |
35 // At a high-level, single-finger events are used for accessibility - | 46 // At a high-level, single-finger events are used for accessibility - |
36 // exploring the screen gets turned into mouse moves (which can then be | 47 // exploring the screen gets turned into mouse moves (which can then be |
37 // spoken by an accessibility service running), a single tap while the user | 48 // spoken by an accessibility service running), a single tap while the user |
38 // is in touch exploration or a double-tap simulates a click, and gestures | 49 // is in touch exploration or a double-tap simulates a click, and gestures |
39 // can be used to send high-level accessibility commands. For example, a swipe | 50 // can be used to send high-level accessibility commands. For example, a swipe |
40 // right would correspond to the keyboard short cut shift+search+right. | 51 // right would correspond to the keyboard short cut shift+search+right. |
41 // When two or more fingers are pressed initially, from then on the events | 52 // When two or more fingers are pressed initially, from then on the events |
42 // are passed through, but with the initial finger removed - so if you swipe | 53 // are passed through, but with the initial finger removed - so if you swipe |
43 // down with two fingers, the running app will see a one-finger swipe. | 54 // down with two fingers, the running app will see a one-finger swipe. Slide |
55 // gestures performed on the edge of the screen can change settings | |
56 // continuously. For example, sliding a finger along the right side of the | |
57 // screen will change the volume. | |
44 // | 58 // |
45 // ** Long version ** | 59 // ** Long version ** |
46 // | 60 // |
47 // Here are the details of the implementation: | 61 // Here are the details of the implementation: |
48 // | 62 // |
49 // When the first touch is pressed, a 300 ms grace period timer starts. | 63 // When the first touch is pressed, a 300 ms grace period timer starts. |
50 // | 64 // |
51 // If the user keeps their finger down for more than 300 ms and doesn't | 65 // If the user keeps their finger down for more than 300 ms and doesn't |
52 // perform a supported accessibility gesture in that time (e.g. swipe right), | 66 // perform a supported accessibility gesture in that time (e.g. swipe right), |
53 // they enter touch exploration mode, and all movements are translated into | 67 // they enter touch exploration mode, and all movements are translated into |
(...skipping 30 matching lines...) Expand all Loading... | |
84 // their touch exploration finger by tapping anywhere else on the screen with | 98 // their touch exploration finger by tapping anywhere else on the screen with |
85 // a second finger, while the touch exploration finger is still pressed. | 99 // a second finger, while the touch exploration finger is still pressed. |
86 // | 100 // |
87 // If the user adds a second finger during the grace period, they enter | 101 // If the user adds a second finger during the grace period, they enter |
88 // two to one finger passthrough mode. In this mode, the first finger is | 102 // two to one finger passthrough mode. In this mode, the first finger is |
89 // ignored and the user can scroll or drag with the second finger. If either | 103 // ignored and the user can scroll or drag with the second finger. If either |
90 // finger is released, nothing happens until all fingers are up. If the user | 104 // finger is released, nothing happens until all fingers are up. If the user |
91 // adds a third finger while in two to one finger mode, all fingers and touch | 105 // adds a third finger while in two to one finger mode, all fingers and touch |
92 // events are passed through from then on. | 106 // events are passed through from then on. |
93 // | 107 // |
108 // If the user places a finger on the edge of the screen and moves their finger | |
109 // past slop, a slide gesture is performed. The user can then slide one finger | |
110 // along an edge of the screen and continuously control a setting. Once the user | |
111 // enters this state, the boundaries that define an edge expand so that the user | |
112 // can now adjust the setting within a slightly bigger width along the screen. | |
113 // If the user exits this area without lifting their finger, they will not be | |
114 // able to perform any actions, however if they keep their finger down and | |
115 // return to the "hot edge," then they can still adjust the setting. In order to | |
116 // perform other touch accessibility movements, the user must lift their finger. | |
117 // If additional fingers are added while in this state, the user will transition | |
118 // to passthrough. | |
119 // | |
120 // Currently, only the right edge is mapped to control the volume. Volume | |
121 // control along the edge of the screen is directly proportional to where the | |
122 // user's finger is located on the screen. The top right corner of the screen | |
123 // automatically sets the volume to 100% and the bottome right corner of the | |
124 // screen automatically sets the volume to 0% once the user has moved past slop. | |
125 // | |
94 // Once touch exploration mode has been activated, | 126 // Once touch exploration mode has been activated, |
95 // it remains in that mode until all fingers have been released. | 127 // it remains in that mode until all fingers have been released. |
96 // | 128 // |
97 // The caller is expected to retain ownership of instances of this class and | 129 // The caller is expected to retain ownership of instances of this class and |
98 // destroy them before |root_window| is destroyed. | 130 // destroy them before |root_window| is destroyed. |
99 class UI_CHROMEOS_EXPORT TouchExplorationController | 131 class UI_CHROMEOS_EXPORT TouchExplorationController |
100 : public ui::EventRewriter, | 132 : public ui::EventRewriter, |
101 public ui::GestureProviderAuraClient { | 133 public ui::GestureProviderAuraClient { |
102 public: | 134 public: |
103 explicit TouchExplorationController(aura::Window* root_window); | 135 explicit TouchExplorationController( |
136 aura::Window* root_window, | |
137 ui::TouchExplorationControllerDelegate* delegate); | |
104 virtual ~TouchExplorationController(); | 138 virtual ~TouchExplorationController(); |
105 | 139 |
106 void CallTapTimerNowForTesting(); | 140 void CallTapTimerNowForTesting(); |
107 void CallTapTimerNowIfRunningForTesting(); | 141 void CallTapTimerNowIfRunningForTesting(); |
108 void SetEventHandlerForTesting(ui::EventHandler* event_handler_for_testing); | 142 void SetEventHandlerForTesting(ui::EventHandler* event_handler_for_testing); |
109 bool IsInNoFingersDownStateForTesting() const; | 143 bool IsInNoFingersDownStateForTesting() const; |
110 bool IsInGestureInProgressStateForTesting() const; | 144 bool IsInGestureInProgressStateForTesting() const; |
145 bool IsInSlideGestureStateForTesting() const; | |
111 // VLOGs should be suppressed in tests that generate a lot of logs, | 146 // VLOGs should be suppressed in tests that generate a lot of logs, |
112 // for example permutations of nine touch events. | 147 // for example permutations of nine touch events. |
113 void SuppressVLOGsForTesting(bool suppress); | 148 void SuppressVLOGsForTesting(bool suppress); |
149 gfx::Rect BoundsOfRootWindowInDIPForTesting(); | |
114 | 150 |
115 private: | 151 private: |
116 // Overridden from ui::EventRewriter | 152 // Overridden from ui::EventRewriter |
117 virtual ui::EventRewriteStatus RewriteEvent( | 153 virtual ui::EventRewriteStatus RewriteEvent( |
118 const ui::Event& event, | 154 const ui::Event& event, |
119 scoped_ptr<ui::Event>* rewritten_event) OVERRIDE; | 155 scoped_ptr<ui::Event>* rewritten_event) OVERRIDE; |
120 virtual ui::EventRewriteStatus NextDispatchEvent( | 156 virtual ui::EventRewriteStatus NextDispatchEvent( |
121 const ui::Event& last_event, scoped_ptr<ui::Event>* new_event) OVERRIDE; | 157 const ui::Event& last_event, scoped_ptr<ui::Event>* new_event) OVERRIDE; |
122 | 158 |
123 // Event handlers based on the current state - see State, below. | 159 // Event handlers based on the current state - see State, below. |
(...skipping 10 matching lines...) Expand all Loading... | |
134 ui::EventRewriteStatus InTwoToOneFinger( | 170 ui::EventRewriteStatus InTwoToOneFinger( |
135 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 171 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
136 ui::EventRewriteStatus InPassthrough( | 172 ui::EventRewriteStatus InPassthrough( |
137 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 173 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
138 ui::EventRewriteStatus InGestureInProgress( | 174 ui::EventRewriteStatus InGestureInProgress( |
139 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 175 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
140 ui::EventRewriteStatus InTouchExploreSecondPress( | 176 ui::EventRewriteStatus InTouchExploreSecondPress( |
141 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 177 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
142 ui::EventRewriteStatus InWaitForRelease( | 178 ui::EventRewriteStatus InWaitForRelease( |
143 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 179 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
180 ui::EventRewriteStatus InSlideGesture( | |
181 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | |
144 | 182 |
145 // This timer is started every time we get the first press event, and | 183 // This timer is started every time we get the first press event, and |
146 // it fires after the double-click timeout elapses (300 ms by default). | 184 // it fires after the double-click timeout elapses (300 ms by default). |
147 // If the user taps and releases within 300 ms and doesn't press again, | 185 // If the user taps and releases within 300 ms and doesn't press again, |
148 // we treat that as a single mouse move (touch exploration) event. | 186 // we treat that as a single mouse move (touch exploration) event. |
149 void OnTapTimerFired(); | 187 void OnTapTimerFired(); |
150 | 188 |
151 // Dispatch a new event outside of the event rewriting flow. | 189 // Dispatch a new event outside of the event rewriting flow. |
152 void DispatchEvent(ui::Event* event); | 190 void DispatchEvent(ui::Event* event); |
153 | 191 |
154 // Overridden from GestureProviderAuraClient. | 192 // Overridden from GestureProviderAuraClient. |
155 // | 193 // |
156 // The gesture provider keeps track of all the touch events after | 194 // The gesture provider keeps track of all the touch events after |
157 // the user moves fast enough to trigger a gesture. After the user | 195 // the user moves fast enough to trigger a gesture. After the user |
158 // completes their gesture, this method will decide what keyboard | 196 // completes their gesture, this method will decide what keyboard |
159 // input their gesture corresponded to. | 197 // input their gesture corresponded to. |
160 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE; | 198 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE; |
161 | 199 |
162 // Process the gesture events that have been created. | 200 // Process the gesture events that have been created. |
163 void ProcessGestureEvents(); | 201 void ProcessGestureEvents(); |
164 | 202 |
165 void OnSwipeEvent(ui::GestureEvent* swipe_gesture); | 203 void OnSwipeEvent(ui::GestureEvent* swipe_gesture); |
166 | 204 |
205 void SideSlideControl(ui::GestureEvent* gesture); | |
206 | |
167 // Dispatches the keyboard short cut Shift+Search+<arrow key> | 207 // Dispatches the keyboard short cut Shift+Search+<arrow key> |
168 // outside the event rewritting flow. | 208 // outside the event rewritting flow. |
169 void DispatchShiftSearchKeyEvent(const ui::KeyboardCode direction); | 209 void DispatchShiftSearchKeyEvent(const ui::KeyboardCode direction); |
170 | 210 |
171 scoped_ptr<ui::Event> CreateMouseMoveEvent(const gfx::PointF& location, | 211 scoped_ptr<ui::Event> CreateMouseMoveEvent(const gfx::PointF& location, |
172 int flags); | 212 int flags); |
173 | 213 |
174 void EnterTouchToMouseMode(); | 214 void EnterTouchToMouseMode(); |
175 | 215 |
176 // Set the state to NO_FINGERS_DOWN and reset any other fields to their | 216 // Set the state to NO_FINGERS_DOWN and reset any other fields to their |
177 // default value. | 217 // default value. |
178 void ResetToNoFingersDown(); | 218 void ResetToNoFingersDown(); |
179 | 219 |
220 void PlaySoundForTimer(); | |
221 | |
180 enum State { | 222 enum State { |
181 // No fingers are down and no events are pending. | 223 // No fingers are down and no events are pending. |
182 NO_FINGERS_DOWN, | 224 NO_FINGERS_DOWN, |
183 | 225 |
184 // A single finger is down, but we're not yet sure if this is going | 226 // A single finger is down, but we're not yet sure if this is going |
185 // to be touch exploration or something else. | 227 // to be touch exploration or something else. |
186 SINGLE_TAP_PRESSED, | 228 SINGLE_TAP_PRESSED, |
187 | 229 |
188 // The user pressed and released a single finger - a tap - but we have | 230 // The user pressed and released a single finger - a tap - but we have |
189 // to wait until the end of the grace period to allow the user to tap the | 231 // to wait until the end of the grace period to allow the user to tap the |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 // If the user is in TWO_TO_ONE_FINGER with two fingers down and presses | 278 // If the user is in TWO_TO_ONE_FINGER with two fingers down and presses |
237 // a third finger, every finger and touch event is passed through until | 279 // a third finger, every finger and touch event is passed through until |
238 // all fingers are released. | 280 // all fingers are released. |
239 PASSTHROUGH, | 281 PASSTHROUGH, |
240 | 282 |
241 // If the user lifted a finger in TWO_TO_ONE_FINGER, they must release | 283 // If the user lifted a finger in TWO_TO_ONE_FINGER, they must release |
242 // all fingers before completing any more actions. This state is | 284 // all fingers before completing any more actions. This state is |
243 // generally useful for developing new features, because it creates a | 285 // generally useful for developing new features, because it creates a |
244 // simple way to handle a dead end in user flow. | 286 // simple way to handle a dead end in user flow. |
245 WAIT_FOR_RELEASE, | 287 WAIT_FOR_RELEASE, |
288 | |
289 // If the user is within the given bounds from an edge of the screen, not | |
290 // including corners, then the resulting movements will be interpreted as | |
291 // slide gestures. | |
292 SLIDE_GESTURE, | |
246 }; | 293 }; |
247 | 294 |
295 enum ScreenLocation { | |
296 // Hot "edges" of the screen are each represented by a respective bit. | |
297 RIGHT_EDGE = 0x1, | |
298 TOP_EDGE = 0x2, | |
299 LEFT_EDGE = 0x4, | |
300 BOTTOM_EDGE = 0x8, | |
301 SCREEN_CENTER = 0x0, | |
302 }; | |
303 | |
304 // Given a point, if it is within the given bounds of an edge, returns the | |
305 // edge. If it is within the given bounds of two edges, returns an int with | |
306 // both bits that represent the respective edges turned on. Otherwise returns | |
307 // SCREEN_CENTER. | |
308 int WithinBoundsOfEdge(gfx::Point point, float bounds); | |
309 | |
248 void VlogState(const char* function_name); | 310 void VlogState(const char* function_name); |
249 | 311 |
250 void VlogEvent(const ui::TouchEvent& event, const char* function_name); | 312 void VlogEvent(const ui::TouchEvent& event, const char* function_name); |
251 | 313 |
252 // Gets enum name from integer value. | 314 // Gets enum name from integer value. |
253 const char* EnumStateToString(State state); | 315 const char* EnumStateToString(State state); |
254 | 316 |
255 aura::Window* root_window_; | 317 aura::Window* root_window_; |
256 | 318 |
319 // Volume control. | |
320 scoped_ptr<ui::TouchExplorationControllerDelegate> delegate_; | |
321 | |
257 // A set of touch ids for fingers currently touching the screen. | 322 // A set of touch ids for fingers currently touching the screen. |
258 std::vector<int> current_touch_ids_; | 323 std::vector<int> current_touch_ids_; |
259 | 324 |
260 // Map of touch ids to their last known location. | 325 // Map of touch ids to their last known location. |
261 std::map<int, gfx::PointF> touch_locations_; | 326 std::map<int, gfx::PointF> touch_locations_; |
262 | 327 |
263 // The current state. | 328 // The current state. |
264 State state_; | 329 State state_; |
265 | 330 |
266 // A copy of the event from the initial touch press. | 331 // A copy of the event from the initial touch press. |
267 scoped_ptr<ui::TouchEvent> initial_press_; | 332 scoped_ptr<ui::TouchEvent> initial_press_; |
268 | 333 |
269 // Stores the most recent event from a finger that is currently not | 334 // Stores the most recent event from a finger that is currently not |
270 // sending events through, but might in the future (e.g. TwoToOneFinger | 335 // sending events through, but might in the future (e.g. TwoToOneFinger |
271 // to Passthrough state). | 336 // to Passthrough state). |
272 scoped_ptr<ui::TouchEvent> last_unused_finger_event_; | 337 scoped_ptr<ui::TouchEvent> last_unused_finger_event_; |
273 | 338 |
274 // The last synthesized mouse move event. When the user double-taps, | 339 // The last synthesized mouse move event. When the user double-taps, |
275 // we send the passed-through tap to the location of this event. | 340 // we send the passed-through tap to the location of this event. |
276 scoped_ptr<ui::TouchEvent> last_touch_exploration_; | 341 scoped_ptr<ui::TouchEvent> last_touch_exploration_; |
277 | 342 |
278 // The last event from the finger that is being passed through in | 343 // The last event from the finger that is being passed through in |
279 // TWO_TO_ONE_FINGER. When the user lifts a finger during two to one, | 344 // TWO_TO_ONE_FINGER. When the user lifts a finger during two to one, |
280 // the location and id of the touch release is from here. | 345 // the location and id of the touch release is from here. |
281 scoped_ptr<ui::TouchEvent> last_two_to_one_; | 346 scoped_ptr<ui::TouchEvent> last_two_to_one_; |
282 | 347 |
283 // A timer to fire the mouse move event after the double-tap delay. | 348 // A timer to fire the mouse move event after the double-tap delay. |
284 base::OneShotTimer<TouchExplorationController> tap_timer_; | 349 base::OneShotTimer<TouchExplorationController> tap_timer_; |
285 | 350 |
351 // A timer to fire a indicating sound when sliding to change volume. | |
352 base::RepeatingTimer<TouchExplorationController> sound_timer_; | |
353 | |
286 // For testing only, an event handler to use for generated events | 354 // For testing only, an event handler to use for generated events |
287 // outside of the normal event rewriting flow. | 355 // outside of the normal event rewriting flow. |
288 ui::EventHandler* event_handler_for_testing_; | 356 ui::EventHandler* event_handler_for_testing_; |
289 | 357 |
290 // A default gesture detector config, so we can share the same | 358 // A default gesture detector config, so we can share the same |
291 // timeout and pixel slop constants. | 359 // timeout and pixel slop constants. |
292 ui::GestureDetector::Config gesture_detector_config_; | 360 ui::GestureDetector::Config gesture_detector_config_; |
293 | 361 |
294 // Gesture Handler to interpret the touch events. | 362 // Gesture Handler to interpret the touch events. |
295 ui::GestureProviderAura gesture_provider_; | 363 ui::GestureProviderAura gesture_provider_; |
296 | 364 |
297 // The previous state entered. | 365 // The previous state entered. |
298 State prev_state_; | 366 State prev_state_; |
299 | 367 |
300 // A copy of the previous event passed. | 368 // A copy of the previous event passed. |
301 scoped_ptr<ui::TouchEvent> prev_event_; | 369 scoped_ptr<ui::TouchEvent> prev_event_; |
302 | 370 |
303 // This toggles whether VLOGS are turned on or not. | 371 // This toggles whether VLOGS are turned on or not. |
304 bool VLOG_on_; | 372 bool VLOG_on_; |
305 | 373 |
306 DISALLOW_COPY_AND_ASSIGN(TouchExplorationController); | 374 DISALLOW_COPY_AND_ASSIGN(TouchExplorationController); |
307 }; | 375 }; |
308 | 376 |
309 } // namespace ui | 377 } // namespace ui |
310 | 378 |
311 #endif // UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ | 379 #endif // UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ |
OLD | NEW |