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 <utility> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
9 #include "base/time/default_tick_clock.h" | 11 #include "base/time/default_tick_clock.h" |
10 #include "ui/aura/client/cursor_client.h" | 12 #include "ui/aura/client/cursor_client.h" |
11 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
12 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
13 #include "ui/aura/window_tree_host.h" | 15 #include "ui/aura/window_tree_host.h" |
14 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
15 #include "ui/events/event_processor.h" | 17 #include "ui/events/event_processor.h" |
16 #include "ui/events/event_utils.h" | 18 #include "ui/events/event_utils.h" |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 touch_press->set_location_f(last_touch_exploration_->location_f()); | 373 touch_press->set_location_f(last_touch_exploration_->location_f()); |
372 touch_press->set_root_location_f(last_touch_exploration_->location_f()); | 374 touch_press->set_root_location_f(last_touch_exploration_->location_f()); |
373 DispatchEvent(touch_press.get()); | 375 DispatchEvent(touch_press.get()); |
374 | 376 |
375 scoped_ptr<ui::TouchEvent> new_event( | 377 scoped_ptr<ui::TouchEvent> new_event( |
376 new ui::TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(), | 378 new ui::TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(), |
377 initial_press_->touch_id(), event.time_stamp())); | 379 initial_press_->touch_id(), event.time_stamp())); |
378 new_event->set_location_f(last_touch_exploration_->location_f()); | 380 new_event->set_location_f(last_touch_exploration_->location_f()); |
379 new_event->set_root_location_f(last_touch_exploration_->location_f()); | 381 new_event->set_root_location_f(last_touch_exploration_->location_f()); |
380 new_event->set_flags(event.flags()); | 382 new_event->set_flags(event.flags()); |
381 *rewritten_event = new_event.Pass(); | 383 *rewritten_event = std::move(new_event); |
382 SET_STATE(NO_FINGERS_DOWN); | 384 SET_STATE(NO_FINGERS_DOWN); |
383 return ui::EVENT_REWRITE_REWRITTEN; | 385 return ui::EVENT_REWRITE_REWRITTEN; |
384 } | 386 } |
385 NOTREACHED(); | 387 NOTREACHED(); |
386 return ui::EVENT_REWRITE_CONTINUE; | 388 return ui::EVENT_REWRITE_CONTINUE; |
387 } | 389 } |
388 | 390 |
389 ui::EventRewriteStatus TouchExplorationController::InTouchReleasePending( | 391 ui::EventRewriteStatus TouchExplorationController::InTouchReleasePending( |
390 const ui::TouchEvent& event, | 392 const ui::TouchEvent& event, |
391 scoped_ptr<ui::Event>* rewritten_event) { | 393 scoped_ptr<ui::Event>* rewritten_event) { |
392 const ui::EventType type = event.type(); | 394 const ui::EventType type = event.type(); |
393 if (type == ui::ET_TOUCH_PRESSED || type == ui::ET_TOUCH_MOVED) { | 395 if (type == ui::ET_TOUCH_PRESSED || type == ui::ET_TOUCH_MOVED) { |
394 return ui::EVENT_REWRITE_DISCARD; | 396 return ui::EVENT_REWRITE_DISCARD; |
395 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { | 397 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { |
396 if (current_touch_ids_.size() != 0) | 398 if (current_touch_ids_.size() != 0) |
397 return EVENT_REWRITE_DISCARD; | 399 return EVENT_REWRITE_DISCARD; |
398 | 400 |
399 scoped_ptr<ui::TouchEvent> new_event( | 401 scoped_ptr<ui::TouchEvent> new_event( |
400 new ui::TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(), | 402 new ui::TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(), |
401 initial_press_->touch_id(), event.time_stamp())); | 403 initial_press_->touch_id(), event.time_stamp())); |
402 new_event->set_location_f(last_touch_exploration_->location_f()); | 404 new_event->set_location_f(last_touch_exploration_->location_f()); |
403 new_event->set_root_location_f(last_touch_exploration_->location_f()); | 405 new_event->set_root_location_f(last_touch_exploration_->location_f()); |
404 new_event->set_flags(event.flags()); | 406 new_event->set_flags(event.flags()); |
405 *rewritten_event = new_event.Pass(); | 407 *rewritten_event = std::move(new_event); |
406 SET_STATE(NO_FINGERS_DOWN); | 408 SET_STATE(NO_FINGERS_DOWN); |
407 return ui::EVENT_REWRITE_REWRITTEN; | 409 return ui::EVENT_REWRITE_REWRITTEN; |
408 } | 410 } |
409 NOTREACHED(); | 411 NOTREACHED(); |
410 return ui::EVENT_REWRITE_CONTINUE; | 412 return ui::EVENT_REWRITE_CONTINUE; |
411 } | 413 } |
412 | 414 |
413 ui::EventRewriteStatus TouchExplorationController::InTouchExploration( | 415 ui::EventRewriteStatus TouchExplorationController::InTouchExploration( |
414 const ui::TouchEvent& event, | 416 const ui::TouchEvent& event, |
415 scoped_ptr<ui::Event>* rewritten_event) { | 417 scoped_ptr<ui::Event>* rewritten_event) { |
416 const ui::EventType type = event.type(); | 418 const ui::EventType type = event.type(); |
417 if (type == ui::ET_TOUCH_PRESSED) { | 419 if (type == ui::ET_TOUCH_PRESSED) { |
418 // Handle split-tap. | 420 // Handle split-tap. |
419 initial_press_.reset(new TouchEvent(event)); | 421 initial_press_.reset(new TouchEvent(event)); |
420 tap_timer_.Stop(); | 422 tap_timer_.Stop(); |
421 scoped_ptr<ui::TouchEvent> new_event( | 423 scoped_ptr<ui::TouchEvent> new_event( |
422 new ui::TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(), event.touch_id(), | 424 new ui::TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(), event.touch_id(), |
423 event.time_stamp())); | 425 event.time_stamp())); |
424 new_event->set_location_f(last_touch_exploration_->location_f()); | 426 new_event->set_location_f(last_touch_exploration_->location_f()); |
425 new_event->set_root_location_f(last_touch_exploration_->location_f()); | 427 new_event->set_root_location_f(last_touch_exploration_->location_f()); |
426 new_event->set_flags(event.flags()); | 428 new_event->set_flags(event.flags()); |
427 *rewritten_event = new_event.Pass(); | 429 *rewritten_event = std::move(new_event); |
428 SET_STATE(TOUCH_EXPLORE_SECOND_PRESS); | 430 SET_STATE(TOUCH_EXPLORE_SECOND_PRESS); |
429 return ui::EVENT_REWRITE_REWRITTEN; | 431 return ui::EVENT_REWRITE_REWRITTEN; |
430 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { | 432 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { |
431 initial_press_.reset(new TouchEvent(event)); | 433 initial_press_.reset(new TouchEvent(event)); |
432 StartTapTimer(); | 434 StartTapTimer(); |
433 SET_STATE(TOUCH_EXPLORE_RELEASED); | 435 SET_STATE(TOUCH_EXPLORE_RELEASED); |
434 } else if (type != ui::ET_TOUCH_MOVED) { | 436 } else if (type != ui::ET_TOUCH_MOVED) { |
435 NOTREACHED(); | 437 NOTREACHED(); |
436 return ui::EVENT_REWRITE_CONTINUE; | 438 return ui::EVENT_REWRITE_CONTINUE; |
437 } | 439 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 476 } |
475 SET_STATE(WAIT_FOR_NO_FINGERS); | 477 SET_STATE(WAIT_FOR_NO_FINGERS); |
476 return ui::EVENT_REWRITE_DISCARD; | 478 return ui::EVENT_REWRITE_DISCARD; |
477 } | 479 } |
478 | 480 |
479 scoped_ptr<ui::TouchEvent> new_event(new ui::TouchEvent( | 481 scoped_ptr<ui::TouchEvent> new_event(new ui::TouchEvent( |
480 type, gfx::Point(), event.touch_id(), event.time_stamp())); | 482 type, gfx::Point(), event.touch_id(), event.time_stamp())); |
481 new_event->set_location_f(event.location_f()); | 483 new_event->set_location_f(event.location_f()); |
482 new_event->set_root_location_f(event.location_f()); | 484 new_event->set_root_location_f(event.location_f()); |
483 new_event->set_flags(event.flags()); | 485 new_event->set_flags(event.flags()); |
484 *rewritten_event = new_event.Pass(); | 486 *rewritten_event = std::move(new_event); |
485 | 487 |
486 if (current_touch_ids_.size() == 0) | 488 if (current_touch_ids_.size() == 0) |
487 SET_STATE(NO_FINGERS_DOWN); | 489 SET_STATE(NO_FINGERS_DOWN); |
488 | 490 |
489 return ui::EVENT_REWRITE_REWRITTEN; | 491 return ui::EVENT_REWRITE_REWRITTEN; |
490 } | 492 } |
491 | 493 |
492 ui::EventRewriteStatus TouchExplorationController::InOneFingerPassthrough( | 494 ui::EventRewriteStatus TouchExplorationController::InOneFingerPassthrough( |
493 const ui::TouchEvent& event, | 495 const ui::TouchEvent& event, |
494 scoped_ptr<ui::Event>* rewritten_event) { | 496 scoped_ptr<ui::Event>* rewritten_event) { |
495 if (event.touch_id() != initial_press_->touch_id()) { | 497 if (event.touch_id() != initial_press_->touch_id()) { |
496 if (current_touch_ids_.size() == 0) { | 498 if (current_touch_ids_.size() == 0) { |
497 SET_STATE(NO_FINGERS_DOWN); | 499 SET_STATE(NO_FINGERS_DOWN); |
498 } | 500 } |
499 return ui::EVENT_REWRITE_DISCARD; | 501 return ui::EVENT_REWRITE_DISCARD; |
500 } | 502 } |
501 scoped_ptr<ui::TouchEvent> new_event(new ui::TouchEvent( | 503 scoped_ptr<ui::TouchEvent> new_event(new ui::TouchEvent( |
502 event.type(), gfx::Point(), event.touch_id(), event.time_stamp())); | 504 event.type(), gfx::Point(), event.touch_id(), event.time_stamp())); |
503 new_event->set_location_f(event.location_f() - passthrough_offset_); | 505 new_event->set_location_f(event.location_f() - passthrough_offset_); |
504 new_event->set_root_location_f(event.location_f() - passthrough_offset_); | 506 new_event->set_root_location_f(event.location_f() - passthrough_offset_); |
505 new_event->set_flags(event.flags()); | 507 new_event->set_flags(event.flags()); |
506 *rewritten_event = new_event.Pass(); | 508 *rewritten_event = std::move(new_event); |
507 if (current_touch_ids_.size() == 0) { | 509 if (current_touch_ids_.size() == 0) { |
508 SET_STATE(NO_FINGERS_DOWN); | 510 SET_STATE(NO_FINGERS_DOWN); |
509 } | 511 } |
510 return ui::EVENT_REWRITE_REWRITTEN; | 512 return ui::EVENT_REWRITE_REWRITTEN; |
511 } | 513 } |
512 | 514 |
513 ui::EventRewriteStatus TouchExplorationController::InTouchExploreSecondPress( | 515 ui::EventRewriteStatus TouchExplorationController::InTouchExploreSecondPress( |
514 const ui::TouchEvent& event, | 516 const ui::TouchEvent& event, |
515 scoped_ptr<ui::Event>* rewritten_event) { | 517 scoped_ptr<ui::Event>* rewritten_event) { |
516 ui::EventType type = event.type(); | 518 ui::EventType type = event.type(); |
517 gfx::PointF location = event.location_f(); | 519 gfx::PointF location = event.location_f(); |
518 if (type == ui::ET_TOUCH_PRESSED) { | 520 if (type == ui::ET_TOUCH_PRESSED) { |
519 // A third finger being pressed means that a split tap can no longer go | 521 // A third finger being pressed means that a split tap can no longer go |
520 // through. The user enters the wait state, Since there has already been | 522 // through. The user enters the wait state, Since there has already been |
521 // a press dispatched when split tap began, the touch needs to be | 523 // a press dispatched when split tap began, the touch needs to be |
522 // cancelled. | 524 // cancelled. |
523 scoped_ptr<ui::TouchEvent> new_event( | 525 scoped_ptr<ui::TouchEvent> new_event( |
524 new ui::TouchEvent(ui::ET_TOUCH_CANCELLED, gfx::Point(), | 526 new ui::TouchEvent(ui::ET_TOUCH_CANCELLED, gfx::Point(), |
525 initial_press_->touch_id(), event.time_stamp())); | 527 initial_press_->touch_id(), event.time_stamp())); |
526 new_event->set_location_f(last_touch_exploration_->location_f()); | 528 new_event->set_location_f(last_touch_exploration_->location_f()); |
527 new_event->set_root_location_f(last_touch_exploration_->location_f()); | 529 new_event->set_root_location_f(last_touch_exploration_->location_f()); |
528 new_event->set_flags(event.flags()); | 530 new_event->set_flags(event.flags()); |
529 *rewritten_event = new_event.Pass(); | 531 *rewritten_event = std::move(new_event); |
530 SET_STATE(WAIT_FOR_NO_FINGERS); | 532 SET_STATE(WAIT_FOR_NO_FINGERS); |
531 return ui::EVENT_REWRITE_REWRITTEN; | 533 return ui::EVENT_REWRITE_REWRITTEN; |
532 } else if (type == ui::ET_TOUCH_MOVED) { | 534 } else if (type == ui::ET_TOUCH_MOVED) { |
533 // If the fingers have moved too far from their original locations, | 535 // If the fingers have moved too far from their original locations, |
534 // the user can no longer split tap. | 536 // the user can no longer split tap. |
535 ui::TouchEvent* original_touch; | 537 ui::TouchEvent* original_touch; |
536 if (event.touch_id() == last_touch_exploration_->touch_id()) { | 538 if (event.touch_id() == last_touch_exploration_->touch_id()) { |
537 original_touch = last_touch_exploration_.get(); | 539 original_touch = last_touch_exploration_.get(); |
538 } else if (event.touch_id() == initial_press_->touch_id()) { | 540 } else if (event.touch_id() == initial_press_->touch_id()) { |
539 original_touch = initial_press_.get(); | 541 original_touch = initial_press_.get(); |
540 } else { | 542 } else { |
541 NOTREACHED(); | 543 NOTREACHED(); |
542 SET_STATE(WAIT_FOR_NO_FINGERS); | 544 SET_STATE(WAIT_FOR_NO_FINGERS); |
543 return ui::EVENT_REWRITE_DISCARD; | 545 return ui::EVENT_REWRITE_DISCARD; |
544 } | 546 } |
545 // Check the distance between the current finger location and the original | 547 // Check the distance between the current finger location and the original |
546 // location. The slop for this is a bit more generous since keeping two | 548 // location. The slop for this is a bit more generous since keeping two |
547 // fingers in place is a bit harder. If the user has left the slop, the | 549 // fingers in place is a bit harder. If the user has left the slop, the |
548 // split tap press (which was previous dispatched) is lifted with a touch | 550 // split tap press (which was previous dispatched) is lifted with a touch |
549 // cancelled, and the user enters the wait state. | 551 // cancelled, and the user enters the wait state. |
550 if ((event.location_f() - original_touch->location_f()).Length() > | 552 if ((event.location_f() - original_touch->location_f()).Length() > |
551 GetSplitTapTouchSlop()) { | 553 GetSplitTapTouchSlop()) { |
552 scoped_ptr<ui::TouchEvent> new_event( | 554 scoped_ptr<ui::TouchEvent> new_event( |
553 new ui::TouchEvent(ui::ET_TOUCH_CANCELLED, gfx::Point(), | 555 new ui::TouchEvent(ui::ET_TOUCH_CANCELLED, gfx::Point(), |
554 initial_press_->touch_id(), event.time_stamp())); | 556 initial_press_->touch_id(), event.time_stamp())); |
555 new_event->set_location_f(last_touch_exploration_->location_f()); | 557 new_event->set_location_f(last_touch_exploration_->location_f()); |
556 new_event->set_root_location_f(last_touch_exploration_->location_f()); | 558 new_event->set_root_location_f(last_touch_exploration_->location_f()); |
557 new_event->set_flags(event.flags()); | 559 new_event->set_flags(event.flags()); |
558 *rewritten_event = new_event.Pass(); | 560 *rewritten_event = std::move(new_event); |
559 SET_STATE(WAIT_FOR_NO_FINGERS); | 561 SET_STATE(WAIT_FOR_NO_FINGERS); |
560 return ui::EVENT_REWRITE_REWRITTEN; | 562 return ui::EVENT_REWRITE_REWRITTEN; |
561 } | 563 } |
562 return ui::EVENT_REWRITE_DISCARD; | 564 return ui::EVENT_REWRITE_DISCARD; |
563 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { | 565 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { |
564 // If the touch exploration finger is lifted, there is no option to return | 566 // If the touch exploration finger is lifted, there is no option to return |
565 // to touch explore anymore. The remaining finger acts as a pending | 567 // to touch explore anymore. The remaining finger acts as a pending |
566 // tap or long tap for the last touch explore location. | 568 // tap or long tap for the last touch explore location. |
567 if (event.touch_id() == last_touch_exploration_->touch_id()) { | 569 if (event.touch_id() == last_touch_exploration_->touch_id()) { |
568 SET_STATE(TOUCH_RELEASE_PENDING); | 570 SET_STATE(TOUCH_RELEASE_PENDING); |
569 return EVENT_REWRITE_DISCARD; | 571 return EVENT_REWRITE_DISCARD; |
570 } | 572 } |
571 | 573 |
572 // Continue to release the touch only if the touch explore finger is the | 574 // Continue to release the touch only if the touch explore finger is the |
573 // only finger remaining. | 575 // only finger remaining. |
574 if (current_touch_ids_.size() != 1) | 576 if (current_touch_ids_.size() != 1) |
575 return EVENT_REWRITE_DISCARD; | 577 return EVENT_REWRITE_DISCARD; |
576 | 578 |
577 // Rewrite at location of last touch exploration. | 579 // Rewrite at location of last touch exploration. |
578 scoped_ptr<ui::TouchEvent> new_event( | 580 scoped_ptr<ui::TouchEvent> new_event( |
579 new ui::TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(), | 581 new ui::TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(), |
580 initial_press_->touch_id(), event.time_stamp())); | 582 initial_press_->touch_id(), event.time_stamp())); |
581 new_event->set_location_f(last_touch_exploration_->location_f()); | 583 new_event->set_location_f(last_touch_exploration_->location_f()); |
582 new_event->set_root_location_f(last_touch_exploration_->location_f()); | 584 new_event->set_root_location_f(last_touch_exploration_->location_f()); |
583 new_event->set_flags(event.flags()); | 585 new_event->set_flags(event.flags()); |
584 *rewritten_event = new_event.Pass(); | 586 *rewritten_event = std::move(new_event); |
585 SET_STATE(TOUCH_EXPLORATION); | 587 SET_STATE(TOUCH_EXPLORATION); |
586 EnterTouchToMouseMode(); | 588 EnterTouchToMouseMode(); |
587 return ui::EVENT_REWRITE_REWRITTEN; | 589 return ui::EVENT_REWRITE_REWRITTEN; |
588 } | 590 } |
589 NOTREACHED(); | 591 NOTREACHED(); |
590 return ui::EVENT_REWRITE_CONTINUE; | 592 return ui::EVENT_REWRITE_CONTINUE; |
591 } | 593 } |
592 | 594 |
593 ui::EventRewriteStatus TouchExplorationController::InWaitForNoFingers( | 595 ui::EventRewriteStatus TouchExplorationController::InWaitForNoFingers( |
594 const ui::TouchEvent& event, | 596 const ui::TouchEvent& event, |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 up_swipe_gestures_[4] = BindKeyEventWithFlags(VKEY_BROWSER_HOME, ui::EF_NONE); | 1160 up_swipe_gestures_[4] = BindKeyEventWithFlags(VKEY_BROWSER_HOME, ui::EF_NONE); |
1159 down_swipe_gestures_[4] = | 1161 down_swipe_gestures_[4] = |
1160 BindKeyEventWithFlags(VKEY_BROWSER_REFRESH, ui::EF_NONE); | 1162 BindKeyEventWithFlags(VKEY_BROWSER_REFRESH, ui::EF_NONE); |
1161 } | 1163 } |
1162 | 1164 |
1163 float TouchExplorationController::GetSplitTapTouchSlop() { | 1165 float TouchExplorationController::GetSplitTapTouchSlop() { |
1164 return gesture_detector_config_.touch_slop * 3; | 1166 return gesture_detector_config_.touch_slop * 3; |
1165 } | 1167 } |
1166 | 1168 |
1167 } // namespace ui | 1169 } // namespace ui |
OLD | NEW |