Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: ui/chromeos/touch_exploration_controller.h

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

Powered by Google App Engine
This is Rietveld 408576698