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" |
(...skipping 14 matching lines...) Expand all Loading... |
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 | 29 // A delegate to handle commands in response to detected accessibility gesture |
30 // events. | 30 // events. |
31 class TouchExplorationControllerDelegate { | 31 class TouchExplorationControllerDelegate { |
32 public: | 32 public: |
33 virtual ~TouchExplorationControllerDelegate() {} | 33 virtual ~TouchExplorationControllerDelegate() {} |
34 | 34 |
35 // This function should be called whenever the delegate wants to play a sound | |
36 // when the volume adjusts. | |
37 virtual void PlayVolumeAdjustSound() = 0; | |
38 | |
39 // Takes an int from 0.0 to 100.0 that indicates the percent the volume | 35 // Takes an int from 0.0 to 100.0 that indicates the percent the volume |
40 // should be set to. | 36 // should be set to. |
41 virtual void SetOutputLevel(int volume) = 0; | 37 virtual void SetOutputLevel(int volume) = 0; |
| 38 |
| 39 // This function should be called when the volume adjust earcon should be |
| 40 // played |
| 41 virtual void PlayVolumeAdjustEarcon() = 0; |
| 42 |
| 43 // This function should be called when the passthrough earcon should be |
| 44 // played. |
| 45 virtual void PlayPassthroughEarcon() = 0; |
| 46 |
| 47 // This function should be called when the exit screen earcon should be |
| 48 // played. |
| 49 virtual void PlayExitScreenEarcon() = 0; |
| 50 |
| 51 // This function should be called when the enter screen earcon should be |
| 52 // played. |
| 53 virtual void PlayEnterScreenEarcon() = 0; |
42 }; | 54 }; |
43 | 55 |
44 // TouchExplorationController is used in tandem with "Spoken Feedback" to | 56 // TouchExplorationController is used in tandem with "Spoken Feedback" to |
45 // make the touch UI accessible. Gestures performed in the middle of the screen | 57 // make the touch UI accessible. Gestures performed in the middle of the screen |
46 // are mapped to accessiblity key shortcuts while gestures performed on the edge | 58 // are mapped to accessiblity key shortcuts while gestures performed on the edge |
47 // of the screen can change settings. | 59 // of the screen can change settings. |
48 // | 60 // |
49 // ** Short version ** | 61 // ** Short version ** |
50 // | 62 // |
51 // At a high-level, single-finger events are used for accessibility - | 63 // At a high-level, single-finger events are used for accessibility - |
52 // exploring the screen gets turned into mouse moves (which can then be | 64 // exploring the screen gets turned into mouse moves (which can then be |
53 // spoken by an accessibility service running), a single tap while the user | 65 // spoken by an accessibility service running), a single tap while the user |
54 // is in touch exploration or a double-tap simulates a click, and gestures | 66 // is in touch exploration or a double-tap simulates a click, and gestures |
55 // can be used to send high-level accessibility commands. For example, a swipe | 67 // can be used to send high-level accessibility commands. For example, a swipe |
56 // right would correspond to the keyboard short cut shift+search+right. | 68 // right would correspond to the keyboard short cut shift+search+right. |
57 // When two or more fingers are pressed initially, from then on the events | 69 // When two or more fingers are pressed initially, from then on the events |
58 // are passed through, but with the initial finger removed - so if you swipe | 70 // are passed through, but with the initial finger removed - so if you swipe |
59 // down with two fingers, the running app will see a one-finger swipe. Slide | 71 // down with two fingers, the running app will see a one-finger swipe. If the |
| 72 // user holds down the corner of the screen until an earcon sounds, all |
| 73 // subsequent fingers will also be passed through in a similar manner. Slide |
60 // gestures performed on the edge of the screen can change settings | 74 // gestures performed on the edge of the screen can change settings |
61 // continuously. For example, sliding a finger along the right side of the | 75 // continuously. For example, sliding a finger along the right side of the |
62 // screen will change the volume. | 76 // screen will change the volume. |
63 // | 77 // |
64 // ** Long version ** | 78 // ** Long version ** |
65 // | 79 // |
66 // Here are the details of the implementation: | 80 // Here are the details of the implementation: |
67 // | 81 // |
68 // When the first touch is pressed, a 300 ms grace period timer starts. | 82 // When the first touch is pressed, a 300 ms grace period timer starts. |
69 // | 83 // |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 ui::EventRewriteStatus InSingleTapPressed( | 172 ui::EventRewriteStatus InSingleTapPressed( |
159 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 173 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
160 ui::EventRewriteStatus InSingleTapOrTouchExploreReleased( | 174 ui::EventRewriteStatus InSingleTapOrTouchExploreReleased( |
161 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 175 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
162 ui::EventRewriteStatus InDoubleTapPressed( | 176 ui::EventRewriteStatus InDoubleTapPressed( |
163 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 177 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
164 ui::EventRewriteStatus InTouchExploration( | 178 ui::EventRewriteStatus InTouchExploration( |
165 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 179 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
166 ui::EventRewriteStatus InTwoToOneFinger( | 180 ui::EventRewriteStatus InTwoToOneFinger( |
167 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 181 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
| 182 ui::EventRewriteStatus InCornerPassthrough( |
| 183 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
168 ui::EventRewriteStatus InPassthrough( | 184 ui::EventRewriteStatus InPassthrough( |
169 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 185 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
170 ui::EventRewriteStatus InGestureInProgress( | 186 ui::EventRewriteStatus InGestureInProgress( |
171 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 187 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
172 ui::EventRewriteStatus InTouchExploreSecondPress( | 188 ui::EventRewriteStatus InTouchExploreSecondPress( |
173 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 189 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
174 ui::EventRewriteStatus InWaitForRelease( | 190 ui::EventRewriteStatus InWaitForRelease( |
175 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 191 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
176 ui::EventRewriteStatus InSlideGesture( | 192 ui::EventRewriteStatus InSlideGesture( |
177 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 193 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
178 | 194 |
179 // This timer is started every time we get the first press event, and | 195 // This timer is started every time we get the first press event and the |
180 // it fires after the double-click timeout elapses (300 ms by default). | 196 // finger is not in the corner of the screen. |
| 197 // It fires after the double-click timeout elapses (300 ms by default). |
181 // If the user taps and releases within 300 ms and doesn't press again, | 198 // If the user taps and releases within 300 ms and doesn't press again, |
182 // we treat that as a single mouse move (touch exploration) event. | 199 // we treat that as a single mouse move (touch exploration) event. If the user |
| 200 // completes a swipe gesture within 300 ms, then the gesture is processed. |
183 void OnTapTimerFired(); | 201 void OnTapTimerFired(); |
184 | 202 |
| 203 // This timer is started every timer we get the first press event and the |
| 204 // finger is in the corner of the screen. |
| 205 // It fires after the long_press timeout elapses (500 ms by default). If the |
| 206 // user is still in the corner by the time this timre fires, all subsequent |
| 207 // fingers added on the screen will be passed through. |
| 208 void OnLongPressTimerFired(); |
| 209 |
185 // Dispatch a new event outside of the event rewriting flow. | 210 // Dispatch a new event outside of the event rewriting flow. |
186 void DispatchEvent(ui::Event* event); | 211 void DispatchEvent(ui::Event* event); |
187 | 212 |
188 // Overridden from GestureProviderAuraClient. | 213 // Overridden from GestureProviderAuraClient. |
189 // | 214 // |
190 // The gesture provider keeps track of all the touch events after | 215 // The gesture provider keeps track of all the touch events after |
191 // the user moves fast enough to trigger a gesture. After the user | 216 // the user moves fast enough to trigger a gesture. After the user |
192 // completes their gesture, this method will decide what keyboard | 217 // completes their gesture, this method will decide what keyboard |
193 // input their gesture corresponded to. | 218 // input their gesture corresponded to. |
194 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE; | 219 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 // touch explore. Any fingers pressed past the first two are ignored. | 303 // touch explore. Any fingers pressed past the first two are ignored. |
279 TOUCH_EXPLORE_SECOND_PRESS, | 304 TOUCH_EXPLORE_SECOND_PRESS, |
280 | 305 |
281 // The user placed two fingers down within the grace period. | 306 // The user placed two fingers down within the grace period. |
282 // We're now in two to one finger mode until one of the fingers is | 307 // We're now in two to one finger mode until one of the fingers is |
283 // lifted. The first finger is ignored and the events for the second | 308 // lifted. The first finger is ignored and the events for the second |
284 // finger are passed throuugh. If either finger is released, nothing | 309 // finger are passed throuugh. If either finger is released, nothing |
285 // happens until all fingers are up. | 310 // happens until all fingers are up. |
286 TWO_TO_ONE_FINGER, | 311 TWO_TO_ONE_FINGER, |
287 | 312 |
| 313 // If the user has pressed and held down the left corner past long press, |
| 314 // then as long as they are holding the corner, all subsequent fingers |
| 315 // registered will be in passthrough. |
| 316 CORNER_PASSTHROUGH, |
| 317 |
288 // If the user is in TWO_TO_ONE_FINGER with two fingers down and presses | 318 // If the user is in TWO_TO_ONE_FINGER with two fingers down and presses |
289 // a third finger, every finger and touch event is passed through until | 319 // a third finger, every finger and touch event is passed through until |
290 // all fingers are released. | 320 // all fingers are released. |
291 PASSTHROUGH, | 321 PASSTHROUGH, |
292 | 322 |
293 // If the user lifted a finger in TWO_TO_ONE_FINGER, they must release | 323 // If the user lifted a finger in TWO_TO_ONE_FINGER, they must release |
294 // all fingers before completing any more actions. This state is | 324 // all fingers before completing any more actions. This state is |
295 // generally useful for developing new features, because it creates a | 325 // generally useful for developing new features, because it creates a |
296 // simple way to handle a dead end in user flow. | 326 // simple way to handle a dead end in user flow. |
297 WAIT_FOR_RELEASE, | 327 WAIT_FOR_RELEASE, |
298 | 328 |
299 // If the user is within the given bounds from an edge of the screen, not | 329 // If the user is within the given bounds from an edge of the screen, not |
300 // including corners, then the resulting movements will be interpreted as | 330 // including corners, then the resulting movements will be interpreted as |
301 // slide gestures. | 331 // slide gestures. |
302 SLIDE_GESTURE, | 332 SLIDE_GESTURE, |
303 }; | 333 }; |
304 | 334 |
305 enum ScreenLocation { | 335 enum ScreenLocation { |
306 // Hot "edges" of the screen are each represented by a respective bit. | 336 // Hot "edges" of the screen are each represented by a respective bit. |
307 NO_EDGE = 0, | 337 NO_EDGE = 0, |
308 RIGHT_EDGE = 1 << 0, | 338 RIGHT_EDGE = 1 << 0, |
309 TOP_EDGE = 1 << 1, | 339 TOP_EDGE = 1 << 1, |
310 LEFT_EDGE = 1 << 2, | 340 LEFT_EDGE = 1 << 2, |
311 BOTTOM_EDGE = 1 << 3, | 341 BOTTOM_EDGE = 1 << 3, |
| 342 BOTTOM_LEFT_CORNER = LEFT_EDGE | BOTTOM_EDGE, |
| 343 BOTTOM_RIGHT_CORNER = RIGHT_EDGE | BOTTOM_EDGE, |
312 }; | 344 }; |
313 | 345 |
314 // Given a point, if it is within the given bounds of an edge, returns the | 346 // Given a point, if it is within the given bounds of an edge, returns the |
315 // edge. If it is within the given bounds of two edges, returns an int with | 347 // edge. If it is within the given bounds of two edges, returns an int with |
316 // both bits that represent the respective edges turned on. Otherwise returns | 348 // both bits that represent the respective edges turned on. Otherwise returns |
317 // SCREEN_CENTER. | 349 // SCREEN_CENTER. |
318 int FindEdgesWithinBounds(gfx::Point point, float bounds); | 350 int FindEdgesWithinBounds(gfx::Point point, float bounds); |
319 | 351 |
320 void VlogState(const char* function_name); | 352 void VlogState(const char* function_name); |
321 | 353 |
(...skipping 26 matching lines...) Expand all Loading... |
348 | 380 |
349 // The last synthesized mouse move event. When the user double-taps, | 381 // The last synthesized mouse move event. When the user double-taps, |
350 // we send the passed-through tap to the location of this event. | 382 // we send the passed-through tap to the location of this event. |
351 scoped_ptr<ui::TouchEvent> last_touch_exploration_; | 383 scoped_ptr<ui::TouchEvent> last_touch_exploration_; |
352 | 384 |
353 // The last event from the finger that is being passed through in | 385 // The last event from the finger that is being passed through in |
354 // TWO_TO_ONE_FINGER. When the user lifts a finger during two to one, | 386 // TWO_TO_ONE_FINGER. When the user lifts a finger during two to one, |
355 // the location and id of the touch release is from here. | 387 // the location and id of the touch release is from here. |
356 scoped_ptr<ui::TouchEvent> last_two_to_one_; | 388 scoped_ptr<ui::TouchEvent> last_two_to_one_; |
357 | 389 |
358 // A timer to fire the mouse move event after the double-tap delay. | 390 // A timer that fires after a long press delay. |
| 391 base::OneShotTimer<TouchExplorationController> long_press_timer_; |
| 392 |
| 393 // A timer that fires after a double tap delay. |
359 base::OneShotTimer<TouchExplorationController> tap_timer_; | 394 base::OneShotTimer<TouchExplorationController> tap_timer_; |
360 | 395 |
361 // A timer to fire an indicating sound when sliding to change volume. | 396 // A timer to fire an indicating sound when sliding to change volume. |
362 base::RepeatingTimer<TouchExplorationController> sound_timer_; | 397 base::RepeatingTimer<TouchExplorationController> sound_timer_; |
363 | 398 |
364 // A default gesture detector config, so we can share the same | 399 // A default gesture detector config, so we can share the same |
365 // timeout and pixel slop constants. | 400 // timeout and pixel slop constants. |
366 ui::GestureDetector::Config gesture_detector_config_; | 401 ui::GestureDetector::Config gesture_detector_config_; |
367 | 402 |
368 // Gesture Handler to interpret the touch events. | 403 // Gesture Handler to interpret the touch events. |
369 ui::GestureProviderAura gesture_provider_; | 404 ui::GestureProviderAura gesture_provider_; |
370 | 405 |
371 // The previous state entered. | 406 // The previous state entered. |
372 State prev_state_; | 407 State prev_state_; |
373 | 408 |
374 // A copy of the previous event passed. | 409 // A copy of the previous event passed. |
375 scoped_ptr<ui::TouchEvent> prev_event_; | 410 scoped_ptr<ui::TouchEvent> prev_event_; |
376 | 411 |
377 // This toggles whether VLOGS are turned on or not. | 412 // This toggles whether VLOGS are turned on or not. |
378 bool VLOG_on_; | 413 bool VLOG_on_; |
379 | 414 |
| 415 // Indicates if a finger is in the lower left corner waiting for the timer to |
| 416 // run out. |
| 417 bool waiting_for_corner_passthrough_; |
| 418 |
380 DISALLOW_COPY_AND_ASSIGN(TouchExplorationController); | 419 DISALLOW_COPY_AND_ASSIGN(TouchExplorationController); |
381 }; | 420 }; |
382 | 421 |
383 } // namespace ui | 422 } // namespace ui |
384 | 423 |
385 #endif // UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ | 424 #endif // UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ |
OLD | NEW |