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