Chromium Code Reviews| 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/gfx/geometry/point.h" | 15 #include "ui/gfx/geometry/point.h" |
| 15 | 16 |
| 16 namespace aura { | 17 namespace aura { |
| 17 class Window; | 18 class Window; |
| 18 } | 19 } |
| 19 | 20 |
| 20 namespace ui { | 21 namespace ui { |
| 21 | 22 |
| 22 class Event; | 23 class Event; |
| 23 class EventHandler; | 24 class EventHandler; |
| 25 class GestureEvent; | |
| 26 class GestureProviderAura; | |
| 24 class TouchEvent; | 27 class TouchEvent; |
| 25 | 28 |
| 26 // TouchExplorationController is used in tandem with "Spoken Feedback" to | 29 // TouchExplorationController is used in tandem with "Spoken Feedback" to |
| 27 // make the touch UI accessible. | 30 // make the touch UI accessible. Gestures are mapped to accessible key |
|
dmazzoni
2014/06/25 05:06:02
This comment has a one-sentence intro, then a one-
lisayin
2014/06/25 22:51:05
Done.
| |
| 31 // shortcuts. | |
| 28 // | 32 // |
| 29 // ** Short version ** | 33 // ** Short version ** |
| 30 // | 34 // |
| 31 // At a high-level, single-finger events are used for accessibility - | 35 // At a high-level, single-finger events are used for accessibility - |
| 32 // exploring the screen gets turned into mouse moves (which can then be | 36 // exploring the screen gets turned into mouse moves (which can then be |
| 33 // spoken by an accessibility service running), a single tap while the user | 37 // spoken by an accessibility service running), a single tap while the user |
| 34 // is in touch exploration or a double-tap simulates a click, and gestures | 38 // is in touch exploration or a double-tap simulates a click, and gestures |
| 35 // can be used to send high-level accessibility commands. | 39 // can be used to send high-level accessibility commands. |
| 36 // When two or more fingers are pressed initially, from then on the events | 40 // When two or more fingers are pressed initially, from then on the events |
| 37 // are passed through, but with the initial finger removed - so if you swipe | 41 // are passed through, but with the initial finger removed - so if you swipe |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 // continue to pass through events, allowing the user to start a scroll | 83 // continue to pass through events, allowing the user to start a scroll |
| 80 // with two fingers but finish it with one. Sometimes this requires rewriting | 84 // with two fingers but finish it with one. Sometimes this requires rewriting |
| 81 // the touch ids. | 85 // the touch ids. |
| 82 // | 86 // |
| 83 // Once either touch exploration or passthrough mode has been activated, | 87 // Once either touch exploration or passthrough mode has been activated, |
| 84 // it remains in that mode until all fingers have been released. | 88 // it remains in that mode until all fingers have been released. |
| 85 // | 89 // |
| 86 // The caller is expected to retain ownership of instances of this class and | 90 // The caller is expected to retain ownership of instances of this class and |
| 87 // destroy them before |root_window| is destroyed. | 91 // destroy them before |root_window| is destroyed. |
| 88 class UI_CHROMEOS_EXPORT TouchExplorationController : | 92 class UI_CHROMEOS_EXPORT TouchExplorationController : |
| 89 public ui::EventRewriter { | 93 public ui::EventRewriter, public ui::GestureProviderAuraClient { |
| 90 public: | 94 public: |
| 91 explicit TouchExplorationController(aura::Window* root_window); | 95 explicit TouchExplorationController(aura::Window* root_window); |
| 92 virtual ~TouchExplorationController(); | 96 virtual ~TouchExplorationController(); |
| 93 | 97 |
| 94 void CallTapTimerNowForTesting(); | 98 void CallTapTimerNowForTesting(); |
| 95 void SetEventHandlerForTesting(ui::EventHandler* event_handler_for_testing); | 99 void SetEventHandlerForTesting(ui::EventHandler* event_handler_for_testing); |
| 96 bool IsInNoFingersDownStateForTesting() const; | 100 bool IsInNoFingersDownStateForTesting() const; |
| 101 bool IsInGestureInProgressStateForTesting() const; | |
| 97 | 102 |
| 98 private: | 103 private: |
| 99 // Overridden from ui::EventRewriter | 104 // Overridden from ui::EventRewriter |
| 100 virtual ui::EventRewriteStatus RewriteEvent( | 105 virtual ui::EventRewriteStatus RewriteEvent( |
| 101 const ui::Event& event, | 106 const ui::Event& event, |
| 102 scoped_ptr<ui::Event>* rewritten_event) OVERRIDE; | 107 scoped_ptr<ui::Event>* rewritten_event) OVERRIDE; |
| 103 virtual ui::EventRewriteStatus NextDispatchEvent( | 108 virtual ui::EventRewriteStatus NextDispatchEvent( |
| 104 const ui::Event& last_event, scoped_ptr<ui::Event>* new_event) OVERRIDE; | 109 const ui::Event& last_event, scoped_ptr<ui::Event>* new_event) OVERRIDE; |
| 105 | 110 |
| 106 // Event handlers based on the current state - see State, below. | 111 // Event handlers based on the current state - see State, below. |
| 107 ui::EventRewriteStatus InNoFingersDown( | 112 ui::EventRewriteStatus InNoFingersDown( |
| 108 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 113 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
| 109 ui::EventRewriteStatus InSingleTapPressed( | 114 ui::EventRewriteStatus InSingleTapPressed( |
| 110 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 115 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
| 111 ui::EventRewriteStatus InSingleTapOrTouchExploreReleased( | 116 ui::EventRewriteStatus InSingleTapOrTouchExploreReleased( |
| 112 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 117 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
| 113 ui::EventRewriteStatus InDoubleTapPressed( | 118 ui::EventRewriteStatus InDoubleTapPressed( |
| 114 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 119 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
| 115 ui::EventRewriteStatus InTouchExploration( | 120 ui::EventRewriteStatus InTouchExploration( |
| 116 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 121 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
| 122 ui::EventRewriteStatus InGestureInProgress( | |
| 123 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | |
| 117 ui::EventRewriteStatus InPassthroughMinusOne( | 124 ui::EventRewriteStatus InPassthroughMinusOne( |
| 118 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 125 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
| 119 ui::EventRewriteStatus InTouchExploreSecondPress( | 126 ui::EventRewriteStatus InTouchExploreSecondPress( |
| 120 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); | 127 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event); |
| 128 | |
| 121 // This timer is started every time we get the first press event, and | 129 // This timer is started every time we get the first press event, and |
| 122 // it fires after the double-click timeout elapses (300 ms by default). | 130 // it fires after the double-click timeout elapses (300 ms by default). |
| 123 // If the user taps and releases within 300 ms and doesn't press again, | 131 // If the user taps and releases within 300 ms and doesn't press again, |
| 124 // we treat that as a single mouse move (touch exploration) event. | 132 // we treat that as a single mouse move (touch exploration) event. |
| 125 void OnTapTimerFired(); | 133 void OnTapTimerFired(); |
| 126 | 134 |
| 127 // Dispatch a new event outside of the event rewriting flow. | 135 // Dispatch a new event outside of the event rewriting flow. |
| 128 void DispatchEvent(ui::Event* event); | 136 void DispatchEvent(ui::Event* event); |
| 129 | 137 |
| 138 // Overridden from GestureProviderAuraClient. | |
| 139 // | |
| 140 // The gesture provider keeps track of all the touch events after | |
| 141 // the user moves fast enough to trigger a gesture. After the user | |
| 142 // completes their gesture, this method will decide what keyboard | |
| 143 // input their gesture corresponded to. | |
| 144 void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE; | |
| 145 | |
| 146 void OnSwipeEvent(ui::GestureEvent* swipe_gesture); | |
| 147 | |
| 148 // Dispatches the keyboard short cut Shift+Search+<arrow key> | |
| 149 // outside the event rewritting flow. | |
| 150 void DispatchShiftSearchKeyEvent(const ui::KeyboardCode direction); | |
| 151 | |
| 130 scoped_ptr<ui::Event> CreateMouseMoveEvent(const gfx::PointF& location, | 152 scoped_ptr<ui::Event> CreateMouseMoveEvent(const gfx::PointF& location, |
| 131 int flags); | 153 int flags); |
| 132 | 154 |
| 133 void EnterTouchToMouseMode(); | 155 void EnterTouchToMouseMode(); |
| 134 | 156 |
| 135 // Set the state to NO_FINGERS_DOWN and reset any other fields to their | 157 // Set the state to NO_FINGERS_DOWN and reset any other fields to their |
| 136 // default value. | 158 // default value. |
| 137 void ResetToNoFingersDown(); | 159 void ResetToNoFingersDown(); |
| 138 | 160 |
| 139 enum State { | 161 enum State { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 162 DOUBLE_TAP_PRESSED, | 184 DOUBLE_TAP_PRESSED, |
| 163 | 185 |
| 164 // We're in touch exploration mode. Anything other than the first finger | 186 // We're in touch exploration mode. Anything other than the first finger |
| 165 // is ignored, and movements of the first finger are rewritten as mouse | 187 // is ignored, and movements of the first finger are rewritten as mouse |
| 166 // move events. This mode is entered if a single finger is pressed and | 188 // move events. This mode is entered if a single finger is pressed and |
| 167 // after the grace period the user hasn't added a second finger or | 189 // after the grace period the user hasn't added a second finger or |
| 168 // moved the finger outside of the slop region. We'll stay in this | 190 // moved the finger outside of the slop region. We'll stay in this |
| 169 // mode until all fingers are lifted. | 191 // mode until all fingers are lifted. |
| 170 TOUCH_EXPLORATION, | 192 TOUCH_EXPLORATION, |
| 171 | 193 |
| 194 // If the user moves their finger faster than the threshold velocity after a | |
| 195 // single tap, the touch events that follow will be translated into gesture | |
| 196 // events. If the user successfully completes a gesture within the grace | |
| 197 // period, the gesture will be collected and sent to the GestureClient. | |
|
dmazzoni
2014/06/25 05:06:02
"sent to the GestureClient" is an implementation d
lisayin
2014/06/25 22:51:05
Done.
| |
| 198 // Otherwise, the collected gestures are discarded and the state changes to | |
| 199 // touch_exploration. | |
| 200 GESTURE_IN_PROGRESS, | |
| 201 | |
| 172 // The user placed two or more fingers down within the grace period. | 202 // The user placed two or more fingers down within the grace period. |
| 173 // We're now in passthrough mode until all fingers are lifted. Initially | 203 // We're now in passthrough mode until all fingers are lifted. Initially |
| 174 // the first finger is ignored and other fingers are passed through | 204 // the first finger is ignored and other fingers are passed through |
| 175 // as-is. If a finger other than the initial one is the first to be | 205 // as-is. If a finger other than the initial one is the first to be |
| 176 // released, we rewrite the first finger with the touch id of the finger | 206 // released, we rewrite the first finger with the touch id of the finger |
| 177 // that was released, from now on. The motivation for this is that if | 207 // that was released, from now on. The motivation for this is that if |
| 178 // the user starts a scroll with 2 fingers, they can release either one | 208 // the user starts a scroll with 2 fingers, they can release either one |
| 179 // and continue the scrolling. | 209 // and continue the scrolling. |
| 180 PASSTHROUGH_MINUS_ONE, | 210 PASSTHROUGH_MINUS_ONE, |
| 181 | 211 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 base::OneShotTimer<TouchExplorationController> tap_timer_; | 254 base::OneShotTimer<TouchExplorationController> tap_timer_; |
| 225 | 255 |
| 226 // For testing only, an event handler to use for generated events | 256 // For testing only, an event handler to use for generated events |
| 227 // outside of the normal event rewriting flow. | 257 // outside of the normal event rewriting flow. |
| 228 ui::EventHandler* event_handler_for_testing_; | 258 ui::EventHandler* event_handler_for_testing_; |
| 229 | 259 |
| 230 // A default gesture detector config, so we can share the same | 260 // A default gesture detector config, so we can share the same |
| 231 // timeout and pixel slop constants. | 261 // timeout and pixel slop constants. |
| 232 ui::GestureDetector::Config gesture_detector_config_; | 262 ui::GestureDetector::Config gesture_detector_config_; |
| 233 | 263 |
| 264 // Gesture Handler to interpret the touch events. | |
| 265 ui::GestureProviderAura gesture_provider_; | |
| 266 | |
| 234 // The previous state entered. | 267 // The previous state entered. |
| 235 State prev_state_; | 268 State prev_state_; |
| 236 | 269 |
| 237 // A copy of the previous event passed. | 270 // A copy of the previous event passed. |
| 238 scoped_ptr<ui::TouchEvent> prev_event_; | 271 scoped_ptr<ui::TouchEvent> prev_event_; |
| 239 | 272 |
| 240 DISALLOW_COPY_AND_ASSIGN(TouchExplorationController); | 273 DISALLOW_COPY_AND_ASSIGN(TouchExplorationController); |
| 241 }; | 274 }; |
| 242 | 275 |
| 243 } // namespace ui | 276 } // namespace ui |
| 244 | 277 |
| 245 #endif // UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ | 278 #endif // UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ |
| OLD | NEW |