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/time/tick_clock.h" | 8 #include "base/time/tick_clock.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 // of the screen can change settings. | 48 // of the screen can change settings. |
49 // | 49 // |
50 // ** Short version ** | 50 // ** Short version ** |
51 // | 51 // |
52 // At a high-level, single-finger events are used for accessibility - | 52 // At a high-level, single-finger events are used for accessibility - |
53 // exploring the screen gets turned into mouse moves (which can then be | 53 // exploring the screen gets turned into mouse moves (which can then be |
54 // spoken by an accessibility service running), a single tap while the user | 54 // spoken by an accessibility service running), a single tap while the user |
55 // is in touch exploration or a double-tap simulates a click, and gestures | 55 // is in touch exploration or a double-tap simulates a click, and gestures |
56 // can be used to send high-level accessibility commands. For example, a swipe | 56 // can be used to send high-level accessibility commands. For example, a swipe |
57 // right would correspond to the keyboard short cut shift+search+right. | 57 // right would correspond to the keyboard short cut shift+search+right. |
58 // When two or more fingers are pressed initially, from then on the events | 58 // Swipes with up to four fingers are also mapped to commands. Slide |
59 // are passed through, but with the initial finger removed - so if you swipe | |
60 // down with two fingers, the running app will see a one-finger swipe. Slide | |
61 // gestures performed on the edge of the screen can change settings | 59 // gestures performed on the edge of the screen can change settings |
62 // continuously. For example, sliding a finger along the right side of the | 60 // continuously. For example, sliding a finger along the right side of the |
63 // screen will change the volume. | 61 // screen will change the volume. |
64 // When a user double taps and holds with one finger, the finger is passed | 62 // When a user double taps and holds with one finger, the finger is passed |
65 // through as if accessibility was turned off. | 63 // through as if accessibility was turned off. |
66 // | 64 // |
67 // ** Long version ** | 65 // ** Long version ** |
68 // | 66 // |
69 // Here are the details of the implementation: | 67 // Here are the details of the implementation: |
70 // | 68 // |
(...skipping 11 matching lines...) Expand all Loading... | |
82 // If the user taps and releases their finger, after 300 ms from the initial | 80 // If the user taps and releases their finger, after 300 ms from the initial |
83 // touch, a single mouse move is fired. | 81 // touch, a single mouse move is fired. |
84 // | 82 // |
85 // While in touch exploration mode, the user can perform a single tap | 83 // While in touch exploration mode, the user can perform a single tap |
86 // if the user releases their finger and taps before 300 ms passes. | 84 // if the user releases their finger and taps before 300 ms passes. |
87 // This will result in a click on the last successful touch exploration | 85 // This will result in a click on the last successful touch exploration |
88 // location. This allows the user to perform a single tap | 86 // location. This allows the user to perform a single tap |
89 // anywhere to activate it. | 87 // anywhere to activate it. |
90 // | 88 // |
91 // The user can perform swipe gestures in one of the four cardinal directions | 89 // The user can perform swipe gestures in one of the four cardinal directions |
92 // which will be interpreted and used to control the UI. The gesture will only | 90 // which will be interpreted and used to control the UI. One finger gestures |
lisayin
2014/08/06 22:43:29
Should this be multifinger gestures?
evy
2014/08/06 22:59:14
Done.
| |
93 // be registered if the finger moves outside the slop and completed within the | 91 // will only be registered if the fingers move outside the slop, and all fingers |
94 // grace period. If additional fingers are added during the grace period, the | 92 // will only be registered if they are completed within the grace period. If a |
95 // state changes to wait for those fingers to be released, and then goes to | 93 // single finger gesture fails to be completed within the grace period, the |
96 // touch exploration mode. If the gesture fails to be completed within the | 94 // state changes to touch exploration mode. If a multi finger gesture fails to |
97 // grace period, the state changes to touch exploration mode. Once the state has | 95 // be completed within the grace period, the user must lift all fingers before |
98 // changed, any gestures made during the grace period are discarded. | 96 // completing any more actions. |
99 // | 97 // |
100 // If the user double-taps, the second tap is passed through, allowing the | 98 // If the user double-taps, the second tap is passed through, allowing the |
101 // user to click - however, the double-tap location is changed to the location | 99 // user to click - however, the double-tap location is changed to the location |
102 // of the last successful touch exploration - that allows the user to explore | 100 // of the last successful touch exploration - that allows the user to explore |
103 // anywhere on the screen, hear its description, then double-tap anywhere | 101 // anywhere on the screen, hear its description, then double-tap anywhere |
104 // to activate it. | 102 // to activate it. |
105 // | 103 // |
106 // If the user double taps and holds, any event from that finger is passed | 104 // If the user double taps and holds, any event from that finger is passed |
107 // through. These events are passed through with an offset such that the first | 105 // through. These events are passed through with an offset such that the first |
108 // touch is offset to be at the location of the last touch exploration | 106 // touch is offset to be at the location of the last touch exploration |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 ui::EventRewriteStatus InSingleTapPressed( | 162 ui::EventRewriteStatus InSingleTapPressed( |
165 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 163 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
166 ui::EventRewriteStatus InSingleTapOrTouchExploreReleased( | 164 ui::EventRewriteStatus InSingleTapOrTouchExploreReleased( |
167 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 165 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
168 ui::EventRewriteStatus InDoubleTapPending( | 166 ui::EventRewriteStatus InDoubleTapPending( |
169 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 167 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
170 ui::EventRewriteStatus InTouchReleasePending( | 168 ui::EventRewriteStatus InTouchReleasePending( |
171 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 169 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
172 ui::EventRewriteStatus InTouchExploration( | 170 ui::EventRewriteStatus InTouchExploration( |
173 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 171 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
174 ui::EventRewriteStatus InTwoToOneFinger( | |
175 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | |
176 ui::EventRewriteStatus InOneFingerPassthrough( | 172 ui::EventRewriteStatus InOneFingerPassthrough( |
177 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 173 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
178 ui::EventRewriteStatus InGestureInProgress( | 174 ui::EventRewriteStatus InGestureInProgress( |
179 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 175 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
180 ui::EventRewriteStatus InTouchExploreSecondPress( | 176 ui::EventRewriteStatus InTouchExploreSecondPress( |
181 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 177 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
182 ui::EventRewriteStatus InWaitForOneFinger( | 178 ui::EventRewriteStatus InWaitForNoFingers( |
183 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 179 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
184 ui::EventRewriteStatus InSlideGesture( | 180 ui::EventRewriteStatus InSlideGesture( |
185 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 181 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
186 | 182 |
187 // Returns the current time of the tick clock. | 183 // Returns the current time of the tick clock. |
188 base::TimeDelta Now(); | 184 base::TimeDelta Now(); |
189 | 185 |
190 // This timer is started every time we get the first press event, and | 186 // This timer is started every time we get the first press event, and |
191 // it fires after the double-click timeout elapses (300 ms by default). | 187 // it fires after the double-click timeout elapses (300 ms by default). |
192 // If the user taps and releases within 300 ms and doesn't press again, | 188 // If the user taps and releases within 300 ms and doesn't press again, |
193 // we treat that as a single mouse move (touch exploration) event. | 189 // we treat that as a single mouse move (touch exploration) event. |
194 void StartTapTimer(); | 190 void StartTapTimer(); |
195 void OnTapTimerFired(); | 191 void OnTapTimerFired(); |
196 | 192 |
197 // Dispatch a new event outside of the event rewriting flow. | 193 // Dispatch a new event outside of the event rewriting flow. |
198 void DispatchEvent(ui::Event* event); | 194 void DispatchEvent(ui::Event* event); |
199 | 195 |
200 // Overridden from GestureProviderAuraClient. | 196 // Overridden from GestureProviderAuraClient. |
201 // | 197 // |
202 // The gesture provider keeps track of all the touch events after | 198 // The gesture provider keeps track of all the touch events after |
203 // the user moves fast enough to trigger a gesture. After the user | 199 // the user moves fast enough to trigger a gesture. After the user |
204 // completes their gesture, this method will decide what keyboard | 200 // completes their gesture, this method will decide what keyboard |
205 // input their gesture corresponded to. | 201 // input their gesture corresponded to. |
206 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE; | 202 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE; |
207 | 203 |
208 // Process the gesture events that have been created. | 204 // Process the gesture events that have been created. |
209 void ProcessGestureEvents(); | 205 void ProcessGestureEvents(); |
210 | 206 |
211 void OnSwipeEvent(ui::GestureEvent* swipe_gesture); | 207 void OnSwipeEvent(ui::GestureEvent* swipe_gesture); |
212 | |
213 void SideSlideControl(ui::GestureEvent* gesture); | 208 void SideSlideControl(ui::GestureEvent* gesture); |
214 | 209 |
215 // Dispatches the keyboard short cut Shift+Search+<arrow key> | 210 // Dispatches the keyboard short cut Shift+Search+<key> |
216 // outside the event rewritting flow. | 211 // outside the event rewritting flow. |
217 void DispatchShiftSearchKeyEvent(const ui::KeyboardCode direction); | 212 void DispatchShiftSearchKeyEvent(const ui::KeyboardCode third_key); |
213 | |
214 // Dispatches a single key with the given flags. | |
215 void DispatchKeyWithFlags(const ui::KeyboardCode key, int flags); | |
218 | 216 |
219 scoped_ptr<ui::Event> CreateMouseMoveEvent(const gfx::PointF& location, | 217 scoped_ptr<ui::Event> CreateMouseMoveEvent(const gfx::PointF& location, |
220 int flags); | 218 int flags); |
221 | 219 |
222 void EnterTouchToMouseMode(); | 220 void EnterTouchToMouseMode(); |
223 | 221 |
224 // Set the state to NO_FINGERS_DOWN and reset any other fields to their | 222 // Set the state to NO_FINGERS_DOWN and reset any other fields to their |
225 // default value. | 223 // default value. |
226 void ResetToNoFingersDown(); | 224 void ResetToNoFingersDown(); |
227 | 225 |
(...skipping 23 matching lines...) Expand all Loading... | |
251 | 249 |
252 // The user pressed and released a single finger - a tap - but we have | 250 // The user pressed and released a single finger - a tap - but we have |
253 // to wait until the end of the grace period to allow the user to tap the | 251 // to wait until the end of the grace period to allow the user to tap the |
254 // second time. If the second tap doesn't occurs within the grace period, | 252 // second time. If the second tap doesn't occurs within the grace period, |
255 // we dispatch a mouse move at the location of the first tap. | 253 // we dispatch a mouse move at the location of the first tap. |
256 SINGLE_TAP_RELEASED, | 254 SINGLE_TAP_RELEASED, |
257 | 255 |
258 // The user was in touch explore mode and released the finger. | 256 // The user was in touch explore mode and released the finger. |
259 // If another touch press occurs within the grace period, a single | 257 // If another touch press occurs within the grace period, a single |
260 // tap click occurs. This state differs from SINGLE_TAP_RELEASED | 258 // tap click occurs. This state differs from SINGLE_TAP_RELEASED |
261 // In that if a second tap doesn't occur within the grace period, | 259 // in that if a second tap doesn't occur within the grace period, |
262 // there is no mouse move dispatched. | 260 // there is no mouse move dispatched. |
263 TOUCH_EXPLORE_RELEASED, | 261 TOUCH_EXPLORE_RELEASED, |
264 | 262 |
265 // The user tapped once, and before the grace period expired, pressed | 263 // The user tapped once, and before the grace period expired, pressed |
266 // one finger down to begin a double-tap, but has not released it yet. | 264 // one finger down to begin a double-tap, but has not released it yet. |
267 // This could become passthrough, so no touch press is dispatched yet. | 265 // This could become passthrough, so no touch press is dispatched yet. |
268 DOUBLE_TAP_PENDING, | 266 DOUBLE_TAP_PENDING, |
269 | 267 |
270 // The user was doing touch exploration, started split tap, but lifted the | 268 // The user was doing touch exploration, started split tap, but lifted the |
271 // touch exploration finger. Once they remove all fingers, a touch release | 269 // touch exploration finger. Once they remove all fingers, a touch release |
(...skipping 26 matching lines...) Expand all Loading... | |
298 | 296 |
299 // After the user double taps and holds with a single finger, all events | 297 // After the user double taps and holds with a single finger, all events |
300 // for that finger are passed through, displaced by an offset. Adding | 298 // for that finger are passed through, displaced by an offset. Adding |
301 // extra fingers has no effect. This state is left when the user removes | 299 // extra fingers has no effect. This state is left when the user removes |
302 // all fingers. | 300 // all fingers. |
303 ONE_FINGER_PASSTHROUGH, | 301 ONE_FINGER_PASSTHROUGH, |
304 | 302 |
305 // If the user added another finger in SINGLE_TAP_PRESSED, or if the user | 303 // If the user added another finger in SINGLE_TAP_PRESSED, or if the user |
306 // has multiple fingers fingers down in any other state between | 304 // has multiple fingers fingers down in any other state between |
307 // passthrough, touch exploration, and gestures, they must release | 305 // passthrough, touch exploration, and gestures, they must release |
308 // all fingers except before completing any more actions. This state is | 306 // all fingers before completing any more actions. This state is |
309 // generally useful for developing new features, because it creates a | 307 // generally useful for developing new features, because it creates a |
310 // simple way to handle a dead end in user flow. | 308 // simple way to handle a dead end in user flow. |
311 WAIT_FOR_ONE_FINGER, | 309 WAIT_FOR_NO_FINGERS, |
312 | 310 |
313 // If the user is within the given bounds from an edge of the screen, not | 311 // If the user is within the given bounds from an edge of the screen, not |
314 // including corners, then the resulting movements will be interpreted as | 312 // including corners, then the resulting movements will be interpreted as |
315 // slide gestures. | 313 // slide gestures. |
316 SLIDE_GESTURE, | 314 SLIDE_GESTURE, |
317 }; | 315 }; |
318 | 316 |
319 enum ScreenLocation { | 317 enum ScreenLocation { |
320 // Hot "edges" of the screen are each represented by a respective bit. | 318 // Hot "edges" of the screen are each represented by a respective bit. |
321 NO_EDGE = 0, | 319 NO_EDGE = 0, |
322 RIGHT_EDGE = 1 << 0, | 320 RIGHT_EDGE = 1 << 0, |
323 TOP_EDGE = 1 << 1, | 321 TOP_EDGE = 1 << 1, |
324 LEFT_EDGE = 1 << 2, | 322 LEFT_EDGE = 1 << 2, |
325 BOTTOM_EDGE = 1 << 3, | 323 BOTTOM_EDGE = 1 << 3, |
326 }; | 324 }; |
327 | 325 |
328 // Given a point, if it is within the given bounds of an edge, returns the | 326 // Given a point, if it is within the given bounds of an edge, returns the |
329 // edge. If it is within the given bounds of two edges, returns an int with | 327 // edge. If it is within the given bounds of two edges, returns an int with |
330 // both bits that represent the respective edges turned on. Otherwise returns | 328 // both bits that represent the respective edges turned on. Otherwise returns |
331 // SCREEN_CENTER. | 329 // SCREEN_CENTER. |
332 int FindEdgesWithinBounds(gfx::Point point, float bounds); | 330 int FindEdgesWithinBounds(gfx::Point point, float bounds); |
333 | 331 |
334 void VlogState(const char* function_name); | 332 void VlogState(const char* function_name); |
335 | 333 |
336 void VlogEvent(const ui::TouchEvent& event, const char* function_name); | 334 void VlogEvent(const ui::TouchEvent& event, const char* function_name); |
337 | 335 |
338 // Gets enum name from integer value. | 336 // Gets enum name from integer value. |
339 const char* EnumStateToString(State state); | 337 const char* EnumStateToString(State state); |
340 | 338 |
339 // Maps each single/multi finger swipe to the function that dispatches | |
340 // the corresponding key events. | |
341 void InitializeSwipeGestureMaps(); | |
342 | |
341 aura::Window* root_window_; | 343 aura::Window* root_window_; |
342 | 344 |
343 // Handles volume control. Not owned. | 345 // Handles volume control. Not owned. |
344 ui::TouchExplorationControllerDelegate* delegate_; | 346 ui::TouchExplorationControllerDelegate* delegate_; |
345 | 347 |
346 // A set of touch ids for fingers currently touching the screen. | 348 // A set of touch ids for fingers currently touching the screen. |
347 std::vector<int> current_touch_ids_; | 349 std::vector<int> current_touch_ids_; |
348 | 350 |
349 // Map of touch ids to their last known location. | 351 // Map of touch ids to their last known location. |
350 std::map<int, gfx::PointF> touch_locations_; | 352 std::map<int, gfx::PointF> touch_locations_; |
(...skipping 10 matching lines...) Expand all Loading... | |
361 | 363 |
362 // Stores the most recent event from a finger that is currently not | 364 // Stores the most recent event from a finger that is currently not |
363 // sending events through, but might in the future (e.g. before a finger | 365 // sending events through, but might in the future (e.g. before a finger |
364 // enters double-tap-hold passthrough, we need to update its location.) | 366 // enters double-tap-hold passthrough, we need to update its location.) |
365 scoped_ptr<ui::TouchEvent> last_unused_finger_event_; | 367 scoped_ptr<ui::TouchEvent> last_unused_finger_event_; |
366 | 368 |
367 // The last synthesized mouse move event. When the user double-taps, | 369 // The last synthesized mouse move event. When the user double-taps, |
368 // we send the passed-through tap to the location of this event. | 370 // we send the passed-through tap to the location of this event. |
369 scoped_ptr<ui::TouchEvent> last_touch_exploration_; | 371 scoped_ptr<ui::TouchEvent> last_touch_exploration_; |
370 | 372 |
371 // A timer to fire the mouse move event after the double-tap delay. | 373 // A timer that fires after the double-tap delay. |
372 base::OneShotTimer<TouchExplorationController> tap_timer_; | 374 base::OneShotTimer<TouchExplorationController> tap_timer_; |
373 | 375 |
374 // A timer to fire an indicating sound when sliding to change volume. | 376 // A timer to fire an indicating sound when sliding to change volume. |
375 base::RepeatingTimer<TouchExplorationController> sound_timer_; | 377 base::RepeatingTimer<TouchExplorationController> sound_timer_; |
376 | 378 |
377 // For testing only, an event handler to use for generated events | 379 // For testing only, an event handler to use for generated events |
378 // outside of the normal event rewriting flow. | 380 // outside of the normal event rewriting flow. |
379 ui::EventHandler* event_handler_for_testing_; | 381 ui::EventHandler* event_handler_for_testing_; |
380 | 382 |
381 // A default gesture detector config, so we can share the same | 383 // A default gesture detector config, so we can share the same |
382 // timeout and pixel slop constants. | 384 // timeout and pixel slop constants. |
383 ui::GestureDetector::Config gesture_detector_config_; | 385 ui::GestureDetector::Config gesture_detector_config_; |
384 | 386 |
385 // Gesture Handler to interpret the touch events. | 387 // Gesture Handler to interpret the touch events. |
386 ui::GestureProviderAura gesture_provider_; | 388 scoped_ptr<ui::GestureProviderAura> gesture_provider_; |
387 | 389 |
388 // The previous state entered. | 390 // The previous state entered. |
389 State prev_state_; | 391 State prev_state_; |
390 | 392 |
391 // A copy of the previous event passed. | 393 // A copy of the previous event passed. |
392 scoped_ptr<ui::TouchEvent> prev_event_; | 394 scoped_ptr<ui::TouchEvent> prev_event_; |
393 | 395 |
394 // This toggles whether VLOGS are turned on or not. | 396 // This toggles whether VLOGS are turned on or not. |
395 bool VLOG_on_; | 397 bool VLOG_on_; |
396 | 398 |
397 // When touch_exploration_controller gets time relative to real time during | 399 // When touch_exploration_controller gets time relative to real time during |
398 // testing, this clock is set to the simulated clock and used. | 400 // testing, this clock is set to the simulated clock and used. |
399 base::TickClock* tick_clock_; | 401 base::TickClock* tick_clock_; |
400 | 402 |
403 // Maps swipes with the resulting functions that dispatch key events. | |
404 std::map<int, base::Closure> left_swipe_gestures_; | |
405 std::map<int, base::Closure> right_swipe_gestures_; | |
406 std::map<int, base::Closure> up_swipe_gestures_; | |
407 std::map<int, base::Closure> down_swipe_gestures_; | |
408 | |
401 DISALLOW_COPY_AND_ASSIGN(TouchExplorationController); | 409 DISALLOW_COPY_AND_ASSIGN(TouchExplorationController); |
402 }; | 410 }; |
403 | 411 |
404 } // namespace ui | 412 } // namespace ui |
405 | 413 |
406 #endif // UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ | 414 #endif // UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ |
OLD | NEW |