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 #include "ui/chromeos/touch_exploration_controller.h" | 5 #include "ui/chromeos/touch_exploration_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "ui/aura/client/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 case SINGLE_TAP_PRESSED: | 123 case SINGLE_TAP_PRESSED: |
124 return InSingleTapPressed(touch_event, rewritten_event); | 124 return InSingleTapPressed(touch_event, rewritten_event); |
125 case SINGLE_TAP_RELEASED: | 125 case SINGLE_TAP_RELEASED: |
126 return InSingleTapReleased(touch_event, rewritten_event); | 126 return InSingleTapReleased(touch_event, rewritten_event); |
127 case DOUBLE_TAP_PRESSED: | 127 case DOUBLE_TAP_PRESSED: |
128 return InDoubleTapPressed(touch_event, rewritten_event); | 128 return InDoubleTapPressed(touch_event, rewritten_event); |
129 case TOUCH_EXPLORATION: | 129 case TOUCH_EXPLORATION: |
130 return InTouchExploration(touch_event, rewritten_event); | 130 return InTouchExploration(touch_event, rewritten_event); |
131 case PASSTHROUGH_MINUS_ONE: | 131 case PASSTHROUGH_MINUS_ONE: |
132 return InPassthroughMinusOne(touch_event, rewritten_event); | 132 return InPassthroughMinusOne(touch_event, rewritten_event); |
133 case TE_SECOND_PRESS: | |
134 return InTouchExplSecondPress(touch_event, rewritten_event); | |
133 } | 135 } |
134 | 136 |
135 NOTREACHED(); | 137 NOTREACHED(); |
136 return ui::EVENT_REWRITE_CONTINUE; | 138 return ui::EVENT_REWRITE_CONTINUE; |
137 } | 139 } |
138 | 140 |
139 ui::EventRewriteStatus TouchExplorationController::NextDispatchEvent( | 141 ui::EventRewriteStatus TouchExplorationController::NextDispatchEvent( |
140 const ui::Event& last_event, scoped_ptr<ui::Event>* new_event) { | 142 const ui::Event& last_event, scoped_ptr<ui::Event>* new_event) { |
141 NOTREACHED(); | 143 NOTREACHED(); |
142 return ui::EVENT_REWRITE_CONTINUE; | 144 return ui::EVENT_REWRITE_CONTINUE; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 NOTREACHED() << "Unexpected event type received."; | 193 NOTREACHED() << "Unexpected event type received."; |
192 return ui::EVENT_REWRITE_CONTINUE; | 194 return ui::EVENT_REWRITE_CONTINUE; |
193 } | 195 } |
194 | 196 |
195 ui::EventRewriteStatus TouchExplorationController::InSingleTapReleased( | 197 ui::EventRewriteStatus TouchExplorationController::InSingleTapReleased( |
196 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { | 198 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { |
197 const ui::EventType type = event.type(); | 199 const ui::EventType type = event.type(); |
198 if (type == ui::ET_TOUCH_PRESSED) { | 200 if (type == ui::ET_TOUCH_PRESSED) { |
199 // This is the second tap in a double-tap (or double tap-hold). | 201 // This is the second tap in a double-tap (or double tap-hold). |
200 // Rewrite at location of last touch exploration. | 202 // Rewrite at location of last touch exploration. |
201 ui::TouchEvent* rewritten_press_event = new ui::TouchEvent( | 203 // If there is no touch exploration yet, discard instead. |
202 ui::ET_TOUCH_PRESSED, | 204 if (last_touch_exploration_ == NULL) { |
dmazzoni
2014/06/16 18:21:19
A scoped_ptr has a "!" operator, so instead of tes
evy
2014/06/16 20:34:20
The release was supposed to be discarded! Added th
| |
203 last_touch_exploration_location_, | 205 return ui::EVENT_REWRITE_DISCARD; |
204 event.touch_id(), | 206 } |
205 event.time_stamp()); | 207 ui::TouchEvent* rewritten_press_event = |
208 new ui::TouchEvent(ui::ET_TOUCH_PRESSED, | |
209 last_touch_exploration_->location(), | |
210 event.touch_id(), | |
211 event.time_stamp()); | |
206 rewritten_press_event->set_flags(event.flags()); | 212 rewritten_press_event->set_flags(event.flags()); |
207 rewritten_event->reset(rewritten_press_event); | 213 rewritten_event->reset(rewritten_press_event); |
208 state_ = DOUBLE_TAP_PRESSED; | 214 state_ = DOUBLE_TAP_PRESSED; |
209 VLOG_STATE(); | 215 VLOG_STATE(); |
210 return ui::EVENT_REWRITE_REWRITTEN; | 216 return ui::EVENT_REWRITE_REWRITTEN; |
211 } | 217 } |
212 | 218 |
213 NOTREACHED(); | 219 NOTREACHED(); |
214 return ui::EVENT_REWRITE_CONTINUE; | 220 return ui::EVENT_REWRITE_CONTINUE; |
215 } | 221 } |
216 | 222 |
217 ui::EventRewriteStatus TouchExplorationController::InDoubleTapPressed( | 223 ui::EventRewriteStatus TouchExplorationController::InDoubleTapPressed( |
218 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { | 224 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { |
219 const ui::EventType type = event.type(); | 225 const ui::EventType type = event.type(); |
220 if (type == ui::ET_TOUCH_PRESSED) { | 226 if (type == ui::ET_TOUCH_PRESSED) { |
221 return ui::EVENT_REWRITE_DISCARD; | 227 return ui::EVENT_REWRITE_DISCARD; |
222 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { | 228 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { |
223 if (current_touch_ids_.size() != 0) | 229 if (current_touch_ids_.size() != 0) |
224 return EVENT_REWRITE_DISCARD; | 230 return EVENT_REWRITE_DISCARD; |
225 | 231 |
226 // Rewrite at location of last touch exploration. | 232 // Rewrite at location of last touch exploration. |
227 ui::TouchEvent* rewritten_release_event = new ui::TouchEvent( | 233 ui::TouchEvent* rewritten_release_event = new ui::TouchEvent( |
228 ui::ET_TOUCH_RELEASED, | 234 ui::ET_TOUCH_RELEASED, |
229 last_touch_exploration_location_, | 235 last_touch_exploration_->location(), |
230 event.touch_id(), | 236 event.touch_id(), |
231 event.time_stamp()); | 237 event.time_stamp()); |
232 rewritten_release_event->set_flags(event.flags()); | 238 rewritten_release_event->set_flags(event.flags()); |
233 rewritten_event->reset(rewritten_release_event); | 239 rewritten_event->reset(rewritten_release_event); |
234 ResetToNoFingersDown(); | 240 ResetToNoFingersDown(); |
235 return ui::EVENT_REWRITE_REWRITTEN; | 241 return ui::EVENT_REWRITE_REWRITTEN; |
236 } else if (type == ui::ET_TOUCH_MOVED) { | 242 } else if (type == ui::ET_TOUCH_MOVED) { |
237 return ui::EVENT_REWRITE_DISCARD; | 243 return ui::EVENT_REWRITE_DISCARD; |
238 } | 244 } |
239 NOTREACHED() << "Unexpected event type received."; | 245 NOTREACHED() << "Unexpected event type received."; |
240 return ui::EVENT_REWRITE_CONTINUE; | 246 return ui::EVENT_REWRITE_CONTINUE; |
241 } | 247 } |
242 | 248 |
243 ui::EventRewriteStatus TouchExplorationController::InTouchExploration( | 249 ui::EventRewriteStatus TouchExplorationController::InTouchExploration( |
244 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { | 250 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { |
245 const ui::EventType type = event.type(); | 251 const ui::EventType type = event.type(); |
246 if (type == ui::ET_TOUCH_PRESSED) { | 252 if (type == ui::ET_TOUCH_PRESSED) { |
247 | 253 // Split-tap |
dmazzoni
2014/06/16 18:21:19
Nit: Make this a sentence, like "Handle split-tap"
evy
2014/06/16 20:34:20
Done.
| |
248 // Ignore any additional fingers when we're already in touch exploration | 254 initial_press_.reset(new TouchEvent(event)); |
249 // mode. TODO(evy, lisayin): Support "split-tap" here instead. | 255 if (tap_timer_.IsRunning()) |
250 return ui::EVENT_REWRITE_DISCARD; | 256 tap_timer_.Stop(); |
257 ui::TouchEvent* rewritten_touch_event = | |
258 new ui::TouchEvent(ui::ET_TOUCH_PRESSED, | |
259 last_touch_exploration_->location(), | |
260 event.touch_id(), | |
261 event.time_stamp()); | |
262 rewritten_touch_event->set_flags(event.flags()); | |
263 rewritten_event->reset(rewritten_touch_event); | |
264 state_ = TE_SECOND_PRESS; | |
265 VLOG_STATE(); | |
266 return ui::EVENT_REWRITE_REWRITTEN; | |
251 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { | 267 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { |
252 if (current_touch_ids_.size() == 0) | 268 if (current_touch_ids_.size() == 0) |
253 ResetToNoFingersDown(); | 269 ResetToNoFingersDown(); |
254 } else if (type != ui::ET_TOUCH_MOVED) { | 270 } else if (type != ui::ET_TOUCH_MOVED) { |
255 NOTREACHED() << "Unexpected event type received."; | 271 NOTREACHED() << "Unexpected event type received."; |
256 return ui::EVENT_REWRITE_CONTINUE; | 272 return ui::EVENT_REWRITE_CONTINUE; |
257 } | 273 } |
258 | 274 |
259 // Rewrite as a mouse-move event. | 275 // Rewrite as a mouse-move event. |
260 *rewritten_event = CreateMouseMoveEvent(event.location(), event.flags()); | 276 *rewritten_event = CreateMouseMoveEvent(event.location(), event.flags()); |
261 last_touch_exploration_location_ = event.location(); | 277 last_touch_exploration_.reset(new TouchEvent(event)); |
262 return ui::EVENT_REWRITE_REWRITTEN; | 278 return ui::EVENT_REWRITE_REWRITTEN; |
263 } | 279 } |
264 | 280 |
265 ui::EventRewriteStatus TouchExplorationController::InPassthroughMinusOne( | 281 ui::EventRewriteStatus TouchExplorationController::InPassthroughMinusOne( |
266 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { | 282 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { |
267 ui::EventType type = event.type(); | 283 ui::EventType type = event.type(); |
268 gfx::PointF location = event.location_f(); | 284 gfx::PointF location = event.location_f(); |
269 | 285 |
270 if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { | 286 if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { |
271 if (current_touch_ids_.size() == 0) | 287 if (current_touch_ids_.size() == 0) |
(...skipping 30 matching lines...) Expand all Loading... | |
302 initial_touch_id_passthrough_mapping_, | 318 initial_touch_id_passthrough_mapping_, |
303 event.time_stamp()); | 319 event.time_stamp()); |
304 rewritten_passthrough_event->set_flags(event.flags()); | 320 rewritten_passthrough_event->set_flags(event.flags()); |
305 rewritten_event->reset(rewritten_passthrough_event); | 321 rewritten_event->reset(rewritten_passthrough_event); |
306 return ui::EVENT_REWRITE_REWRITTEN; | 322 return ui::EVENT_REWRITE_REWRITTEN; |
307 } | 323 } |
308 | 324 |
309 return ui::EVENT_REWRITE_CONTINUE; | 325 return ui::EVENT_REWRITE_CONTINUE; |
310 } | 326 } |
311 | 327 |
328 ui::EventRewriteStatus TouchExplorationController::InTouchExplSecondPress( | |
329 const ui::TouchEvent& event, | |
330 scoped_ptr<ui::Event>* rewritten_event) { | |
331 ui::EventType type = event.type(); | |
332 gfx::PointF location = event.location_f(); | |
333 if (type == ui::ET_TOUCH_PRESSED) { | |
334 return ui::EVENT_REWRITE_DISCARD; | |
335 } else if (type == ui::ET_TOUCH_MOVED) { | |
336 // Currently this is a discard, but could be something like rotor | |
337 // in the future. | |
338 return ui::EVENT_REWRITE_DISCARD; | |
339 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { | |
340 // If the touch exploration finger is lifted, there is no option to return | |
341 // to touch explore anymore. The remaining finger acts as a pending | |
342 // tap or long tap for the last touch explore location. | |
343 if (event.touch_id() == last_touch_exploration_->touch_id()){ | |
344 state_ = DOUBLE_TAP_PRESSED; | |
345 VLOG_STATE(); | |
346 return EVENT_REWRITE_DISCARD; | |
347 } | |
348 | |
349 // Continue to release the touch only if the touch explore finger is the | |
350 // only finger remaining. | |
351 if (current_touch_ids_.size() != 1) | |
352 return EVENT_REWRITE_DISCARD; | |
353 | |
354 // Rewrite at location of last touch exploration. | |
355 ui::TouchEvent* rewritten_release_event = new ui::TouchEvent( | |
356 ui::ET_TOUCH_RELEASED, | |
357 last_touch_exploration_->location(), | |
358 initial_press_->touch_id(), | |
359 event.time_stamp()); | |
360 rewritten_release_event->set_flags(event.flags()); | |
361 rewritten_event->reset(rewritten_release_event); | |
362 state_ = TOUCH_EXPLORATION; | |
363 VLOG_STATE(); | |
364 return ui::EVENT_REWRITE_REWRITTEN; | |
365 } | |
366 NOTREACHED() << "Unexpected event type received."; | |
367 return ui::EVENT_REWRITE_CONTINUE; | |
368 } | |
369 | |
312 void TouchExplorationController::OnTapTimerFired() { | 370 void TouchExplorationController::OnTapTimerFired() { |
313 if (state_ != SINGLE_TAP_RELEASED && state_ != SINGLE_TAP_PRESSED) | 371 if (state_ != SINGLE_TAP_RELEASED && state_ != SINGLE_TAP_PRESSED) |
314 return; | 372 return; |
315 | 373 |
316 if (state_ == SINGLE_TAP_RELEASED) { | 374 if (state_ == SINGLE_TAP_RELEASED) { |
317 ResetToNoFingersDown(); | 375 ResetToNoFingersDown(); |
318 } else { | 376 } else { |
319 EnterTouchToMouseMode(); | 377 EnterTouchToMouseMode(); |
320 state_ = TOUCH_EXPLORATION; | 378 state_ = TOUCH_EXPLORATION; |
321 VLOG_STATE(); | 379 VLOG_STATE(); |
322 } | 380 } |
323 | 381 |
324 scoped_ptr<ui::Event> mouse_move = CreateMouseMoveEvent( | 382 scoped_ptr<ui::Event> mouse_move = CreateMouseMoveEvent( |
325 initial_press_->location(), initial_press_->flags()); | 383 initial_press_->location(), initial_press_->flags()); |
326 DispatchEvent(mouse_move.get()); | 384 DispatchEvent(mouse_move.get()); |
327 last_touch_exploration_location_ = initial_press_->location(); | 385 last_touch_exploration_.reset(new TouchEvent(*initial_press_)); |
328 } | 386 } |
329 | 387 |
330 void TouchExplorationController::DispatchEvent(ui::Event* event) { | 388 void TouchExplorationController::DispatchEvent(ui::Event* event) { |
331 if (event_handler_for_testing_) { | 389 if (event_handler_for_testing_) { |
332 event_handler_for_testing_->OnEvent(event); | 390 event_handler_for_testing_->OnEvent(event); |
333 return; | 391 return; |
334 } | 392 } |
335 ui::EventDispatchDetails result ALLOW_UNUSED = | 393 ui::EventDispatchDetails result ALLOW_UNUSED = |
336 root_window_->GetHost()->dispatcher()->OnEventFromSource(event); | 394 root_window_->GetHost()->dispatcher()->OnEventFromSource(event); |
337 } | 395 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 case SINGLE_TAP_PRESSED: | 457 case SINGLE_TAP_PRESSED: |
400 return "SINGLE_TAP_PRESSED"; | 458 return "SINGLE_TAP_PRESSED"; |
401 case SINGLE_TAP_RELEASED: | 459 case SINGLE_TAP_RELEASED: |
402 return "SINGLE_TAP_RELEASED"; | 460 return "SINGLE_TAP_RELEASED"; |
403 case DOUBLE_TAP_PRESSED: | 461 case DOUBLE_TAP_PRESSED: |
404 return "DOUBLE_TAP_PRESSED"; | 462 return "DOUBLE_TAP_PRESSED"; |
405 case TOUCH_EXPLORATION: | 463 case TOUCH_EXPLORATION: |
406 return "TOUCH_EXPLORATION"; | 464 return "TOUCH_EXPLORATION"; |
407 case PASSTHROUGH_MINUS_ONE: | 465 case PASSTHROUGH_MINUS_ONE: |
408 return "PASSTHROUGH_MINUS_ONE"; | 466 return "PASSTHROUGH_MINUS_ONE"; |
467 case TE_SECOND_PRESS: | |
468 return "TE_SECOND_PRESS"; | |
409 } | 469 } |
410 return "Not a state"; | 470 return "Not a state"; |
411 } | 471 } |
412 | 472 |
413 const char* TouchExplorationController::EnumEventTypeToString( | 473 const char* TouchExplorationController::EnumEventTypeToString( |
414 ui::EventType type) { | 474 ui::EventType type) { |
415 // Add more cases later. For now, these are the most frequently seen | 475 // Add more cases later. For now, these are the most frequently seen |
416 // event types. | 476 // event types. |
417 switch (type) { | 477 switch (type) { |
418 case ET_TOUCH_RELEASED: | 478 case ET_TOUCH_RELEASED: |
419 return "ET_TOUCH_RELEASED"; | 479 return "ET_TOUCH_RELEASED"; |
420 case ET_TOUCH_PRESSED: | 480 case ET_TOUCH_PRESSED: |
421 return "ET_TOUCH_PRESSED"; | 481 return "ET_TOUCH_PRESSED"; |
422 case ET_TOUCH_MOVED: | 482 case ET_TOUCH_MOVED: |
423 return "ET_TOUCH_MOVED"; | 483 return "ET_TOUCH_MOVED"; |
424 case ET_TOUCH_CANCELLED: | 484 case ET_TOUCH_CANCELLED: |
425 return "ET_TOUCH_CANCELLED"; | 485 return "ET_TOUCH_CANCELLED"; |
426 default: | 486 default: |
427 return base::IntToString(type).c_str(); | 487 return base::IntToString(type).c_str(); |
428 } | 488 } |
429 } | 489 } |
430 | 490 |
431 } // namespace ui | 491 } // namespace ui |
OLD | NEW |