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; |
24 class TouchEvent; | 25 class TouchEvent; |
26 class GestureProviderAura; | |
dmazzoni
2014/06/23 15:50:45
Nit: sort these (alphabetize)
| |
27 class GestureEvent; | |
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. |
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. |
(...skipping 37 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 // The gesture provider keeps track of all the touch events after | |
dmazzoni
2014/06/23 15:50:44
Put an extra line at the top of this comment block
| |
130 // the user moves fast enough to trigger a gesture. After the user | |
131 // completes their gesture, this method will decide what keyboard | |
132 // input their gesture corresponded to. | |
133 void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE; | |
134 | |
123 scoped_ptr<ui::Event> CreateMouseMoveEvent(const gfx::PointF& location, | 135 scoped_ptr<ui::Event> CreateMouseMoveEvent(const gfx::PointF& location, |
124 int flags); | 136 int flags); |
125 | 137 |
126 void EnterTouchToMouseMode(); | 138 void EnterTouchToMouseMode(); |
127 | 139 |
128 // Set the state to NO_FINGERS_DOWN and reset any other fields to their | 140 // Set the state to NO_FINGERS_DOWN and reset any other fields to their |
129 // default value. | 141 // default value. |
130 void ResetToNoFingersDown(); | 142 void ResetToNoFingersDown(); |
131 | 143 |
132 enum State { | 144 enum State { |
(...skipping 15 matching lines...) Expand all Loading... | |
148 DOUBLE_TAP_PRESSED, | 160 DOUBLE_TAP_PRESSED, |
149 | 161 |
150 // We're in touch exploration mode. Anything other than the first finger | 162 // 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 | 163 // 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 | 164 // 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 | 165 // 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 | 166 // moved the finger outside of the slop region. We'll stay in this |
155 // mode until all fingers are lifted. | 167 // mode until all fingers are lifted. |
156 TOUCH_EXPLORATION, | 168 TOUCH_EXPLORATION, |
157 | 169 |
170 // We're currently making a gesture. | |
dmazzoni
2014/06/23 15:50:44
Add a bit more detail here: explain how we enter t
| |
171 GESTURE_IN_PROGRESS, | |
172 | |
158 // The user placed two or more fingers down within the grace period. | 173 // 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 | 174 // We're now in passthrough mode until all fingers are lifted. Initially |
160 // the first finger is ignored and other fingers are passed through | 175 // 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 | 176 // 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 | 177 // 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 | 178 // 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 | 179 // the user starts a scroll with 2 fingers, they can release either one |
165 // and continue the scrolling. | 180 // and continue the scrolling. |
166 PASSTHROUGH_MINUS_ONE, | 181 PASSTHROUGH_MINUS_ONE, |
167 | 182 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 base::OneShotTimer<TouchExplorationController> tap_timer_; | 225 base::OneShotTimer<TouchExplorationController> tap_timer_; |
211 | 226 |
212 // For testing only, an event handler to use for generated events | 227 // For testing only, an event handler to use for generated events |
213 // outside of the normal event rewriting flow. | 228 // outside of the normal event rewriting flow. |
214 ui::EventHandler* event_handler_for_testing_; | 229 ui::EventHandler* event_handler_for_testing_; |
215 | 230 |
216 // A default gesture detector config, so we can share the same | 231 // A default gesture detector config, so we can share the same |
217 // timeout and pixel slop constants. | 232 // timeout and pixel slop constants. |
218 ui::GestureDetector::Config gesture_detector_config_; | 233 ui::GestureDetector::Config gesture_detector_config_; |
219 | 234 |
235 // Gesture Handler to interpret the touch events | |
dmazzoni
2014/06/23 15:50:44
Nit: end with period.
| |
236 ui::GestureProviderAura gesture_provider_; | |
237 | |
220 // The previous state entered. | 238 // The previous state entered. |
221 State prev_state_; | 239 State prev_state_; |
222 | 240 |
223 // A copy of the previous event passed. | 241 // A copy of the previous event passed. |
224 scoped_ptr<ui::TouchEvent> prev_event_; | 242 scoped_ptr<ui::TouchEvent> prev_event_; |
225 | 243 |
226 DISALLOW_COPY_AND_ASSIGN(TouchExplorationController); | 244 DISALLOW_COPY_AND_ASSIGN(TouchExplorationController); |
227 }; | 245 }; |
228 | 246 |
229 } // namespace ui | 247 } // namespace ui |
230 | 248 |
231 #endif // UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ | 249 #endif // UI_CHROMEOS_TOUCH_EXPLORATION_CONTROLLER_H_ |
OLD | NEW |