Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: ui/base/gestures/gesture_sequence.cc

Issue 10816008: ash: Record some additional information about the gestures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/base/gestures/gesture_sequence.h" 5 #include "ui/base/gestures/gesture_sequence.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 gfx::Point p2 = GetPointByPointId(1)->last_touch_position(); 544 gfx::Point p2 = GetPointByPointId(1)->last_touch_position();
545 double max_distance = 545 double max_distance =
546 ui::GestureConfiguration::max_distance_for_two_finger_tap_in_pixels(); 546 ui::GestureConfiguration::max_distance_for_two_finger_tap_in_pixels();
547 double distance = (p1.x() - p2.x()) * (p1.x() - p2.x()) + 547 double distance = (p1.x() - p2.x()) * (p1.x() - p2.x()) +
548 (p1.y() - p2.y()) * (p1.y() - p2.y()); 548 (p1.y() - p2.y()) * (p1.y() - p2.y());
549 if (distance < max_distance * max_distance) 549 if (distance < max_distance * max_distance)
550 return true; 550 return true;
551 return false; 551 return false;
552 } 552 }
553 553
554 GestureEvent* GestureSequence::CreateGestureEvent(
555 GestureEventDetails details,
556 const gfx::Point& location,
557 int flags,
558 base::Time timestamp,
559 unsigned int touch_id_bitmask) {
560 details.set_touch_points(point_count_);
561 return helper_->CreateGestureEvent(details, location, flags, timestamp,
562 touch_id_bitmask);
563 }
564
554 void GestureSequence::AppendTapDownGestureEvent(const GesturePoint& point, 565 void GestureSequence::AppendTapDownGestureEvent(const GesturePoint& point,
555 Gestures* gestures) { 566 Gestures* gestures) {
556 gestures->push_back(helper_->CreateGestureEvent( 567 gestures->push_back(CreateGestureEvent(
557 ui::ET_GESTURE_TAP_DOWN, 568 GestureEventDetails(ui::ET_GESTURE_TAP_DOWN, 0, 0),
558 point.first_touch_position(), 569 point.first_touch_position(),
559 flags_, 570 flags_,
560 base::Time::FromDoubleT(point.last_touch_time()), 571 base::Time::FromDoubleT(point.last_touch_time()),
561 0, 0.f, 1 << point.touch_id())); 572 1 << point.touch_id()));
562 } 573 }
563 574
564 void GestureSequence::AppendBeginGestureEvent(const GesturePoint& point, 575 void GestureSequence::AppendBeginGestureEvent(const GesturePoint& point,
565 Gestures* gestures) { 576 Gestures* gestures) {
566 gestures->push_back(helper_->CreateGestureEvent( 577 gestures->push_back(CreateGestureEvent(
567 ui::ET_GESTURE_BEGIN, 578 GestureEventDetails(ui::ET_GESTURE_BEGIN, point_count_, 0),
568 point.first_touch_position(), 579 point.first_touch_position(),
569 flags_, 580 flags_,
570 base::Time::FromDoubleT(point.last_touch_time()), 581 base::Time::FromDoubleT(point.last_touch_time()),
571 point_count_, 0.f, 1 << point.touch_id())); 582 1 << point.touch_id()));
572 } 583 }
573 584
574 void GestureSequence::AppendEndGestureEvent(const GesturePoint& point, 585 void GestureSequence::AppendEndGestureEvent(const GesturePoint& point,
575 Gestures* gestures) { 586 Gestures* gestures) {
576 gestures->push_back(helper_->CreateGestureEvent( 587 gestures->push_back(CreateGestureEvent(
577 ui::ET_GESTURE_END, 588 GestureEventDetails(ui::ET_GESTURE_END, point_count_, 0),
578 point.first_touch_position(), 589 point.first_touch_position(),
579 flags_, 590 flags_,
580 base::Time::FromDoubleT(point.last_touch_time()), 591 base::Time::FromDoubleT(point.last_touch_time()),
581 point_count_, 0.f, 1 << point.touch_id())); 592 1 << point.touch_id()));
582 } 593 }
583 594
584 void GestureSequence::AppendClickGestureEvent(const GesturePoint& point, 595 void GestureSequence::AppendClickGestureEvent(const GesturePoint& point,
585 Gestures* gestures) { 596 Gestures* gestures) {
586 gfx::Rect er = point.enclosing_rectangle(); 597 gfx::Rect er = point.enclosing_rectangle();
587 gfx::Point center = er.CenterPoint(); 598 gfx::Point center = er.CenterPoint();
588 gestures->push_back(helper_->CreateGestureEvent( 599 gestures->push_back(CreateGestureEvent(
589 ui::ET_GESTURE_TAP, 600 GestureEventDetails(ui::ET_GESTURE_TAP, er.width() / 2, er.height() / 2),
590 center, 601 center,
591 flags_, 602 flags_,
592 base::Time::FromDoubleT(point.last_touch_time()), 603 base::Time::FromDoubleT(point.last_touch_time()),
593 er.width() / 2,
594 er.height() / 2,
595 1 << point.touch_id())); 604 1 << point.touch_id()));
596 } 605 }
597 606
598 void GestureSequence::AppendDoubleClickGestureEvent(const GesturePoint& point, 607 void GestureSequence::AppendDoubleClickGestureEvent(const GesturePoint& point,
599 Gestures* gestures) { 608 Gestures* gestures) {
600 gestures->push_back(helper_->CreateGestureEvent( 609 gestures->push_back(CreateGestureEvent(
601 ui::ET_GESTURE_DOUBLE_TAP, 610 GestureEventDetails(ui::ET_GESTURE_DOUBLE_TAP, 0, 0),
602 point.first_touch_position(), 611 point.first_touch_position(),
603 flags_, 612 flags_,
604 base::Time::FromDoubleT(point.last_touch_time()), 613 base::Time::FromDoubleT(point.last_touch_time()),
605 0.f, 0.f, 1 << point.touch_id())); 614 1 << point.touch_id()));
606 } 615 }
607 616
608 void GestureSequence::AppendScrollGestureBegin(const GesturePoint& point, 617 void GestureSequence::AppendScrollGestureBegin(const GesturePoint& point,
609 const gfx::Point& location, 618 const gfx::Point& location,
610 Gestures* gestures) { 619 Gestures* gestures) {
611 gestures->push_back(helper_->CreateGestureEvent( 620 gestures->push_back(CreateGestureEvent(
612 ui::ET_GESTURE_SCROLL_BEGIN, 621 GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, 0, 0),
613 location, 622 location,
614 flags_, 623 flags_,
615 base::Time::FromDoubleT(point.last_touch_time()), 624 base::Time::FromDoubleT(point.last_touch_time()),
616 0.f, 0.f, 1 << point.touch_id())); 625 1 << point.touch_id()));
617 } 626 }
618 627
619 void GestureSequence::AppendScrollGestureEnd(const GesturePoint& point, 628 void GestureSequence::AppendScrollGestureEnd(const GesturePoint& point,
620 const gfx::Point& location, 629 const gfx::Point& location,
621 Gestures* gestures, 630 Gestures* gestures,
622 float x_velocity, 631 float x_velocity,
623 float y_velocity) { 632 float y_velocity) {
624 float railed_x_velocity = x_velocity; 633 float railed_x_velocity = x_velocity;
625 float railed_y_velocity = y_velocity; 634 float railed_y_velocity = y_velocity;
626 635
627 if (scroll_type_ == ST_HORIZONTAL) 636 if (scroll_type_ == ST_HORIZONTAL)
628 railed_y_velocity = 0; 637 railed_y_velocity = 0;
629 else if (scroll_type_ == ST_VERTICAL) 638 else if (scroll_type_ == ST_VERTICAL)
630 railed_x_velocity = 0; 639 railed_x_velocity = 0;
631 640
632 // TODO(rjkroege): It is conceivable that we could suppress sending the 641 // TODO(rjkroege): It is conceivable that we could suppress sending the
633 // GestureScrollEnd if it is immediately followed by a GestureFlingStart. 642 // GestureScrollEnd if it is immediately followed by a GestureFlingStart.
634 gestures->push_back(helper_->CreateGestureEvent( 643 gestures->push_back(CreateGestureEvent(
635 ui::ET_GESTURE_SCROLL_END, 644 GestureEventDetails(ui::ET_GESTURE_SCROLL_END, 0, 0),
636 location, 645 location,
637 flags_, 646 flags_,
638 base::Time::FromDoubleT(point.last_touch_time()), 647 base::Time::FromDoubleT(point.last_touch_time()),
639 0., 0., 1 << point.touch_id())); 648 1 << point.touch_id()));
640 649
641 if (railed_x_velocity != 0 || railed_y_velocity != 0) { 650 if (railed_x_velocity != 0 || railed_y_velocity != 0) {
642 // TODO(sad|rjkroege): fling-curve is currently configured to work well with 651 // TODO(sad|rjkroege): fling-curve is currently configured to work well with
643 // touchpad scroll-events. This curve needs to be adjusted to work correctly 652 // touchpad scroll-events. This curve needs to be adjusted to work correctly
644 // with both touchpad and touchscreen. Until then, scale quadratically. 653 // with both touchpad and touchscreen. Until then, scale quadratically.
645 // http://crbug.com/120154 654 // http://crbug.com/120154
646 const float velocity_scaling = 1.f / 900.f; 655 const float velocity_scaling = 1.f / 900.f;
647 656
648 gestures->push_back(helper_->CreateGestureEvent( 657 gestures->push_back(CreateGestureEvent(
649 ui::ET_SCROLL_FLING_START, 658 GestureEventDetails(ui::ET_SCROLL_FLING_START,
659 velocity_scaling * railed_x_velocity * fabsf(railed_x_velocity),
660 velocity_scaling * railed_y_velocity * fabsf(railed_y_velocity)),
650 location, 661 location,
651 flags_, 662 flags_,
652 base::Time::FromDoubleT(point.last_touch_time()), 663 base::Time::FromDoubleT(point.last_touch_time()),
653 velocity_scaling * railed_x_velocity * fabsf(railed_x_velocity),
654 velocity_scaling * railed_y_velocity * fabsf(railed_y_velocity),
655 1 << point.touch_id())); 664 1 << point.touch_id()));
656 } 665 }
657 } 666 }
658 667
659 void GestureSequence::AppendScrollGestureUpdate(const GesturePoint& point, 668 void GestureSequence::AppendScrollGestureUpdate(const GesturePoint& point,
660 const gfx::Point& location, 669 const gfx::Point& location,
661 Gestures* gestures) { 670 Gestures* gestures) {
662 int dx = location.x() - bounding_box_last_center_.x(); 671 int dx = location.x() - bounding_box_last_center_.x();
663 int dy = location.y() - bounding_box_last_center_.y(); 672 int dy = location.y() - bounding_box_last_center_.y();
664 if (dx == 0 && dy == 0) 673 if (dx == 0 && dy == 0)
665 return; 674 return;
666 if (scroll_type_ == ST_HORIZONTAL) 675 if (scroll_type_ == ST_HORIZONTAL)
667 dy = 0; 676 dy = 0;
668 else if (scroll_type_ == ST_VERTICAL) 677 else if (scroll_type_ == ST_VERTICAL)
669 dx = 0; 678 dx = 0;
670 679
671 gestures->push_back(helper_->CreateGestureEvent( 680 gestures->push_back(CreateGestureEvent(
672 ui::ET_GESTURE_SCROLL_UPDATE, 681 GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, dx, dy),
673 location, 682 location,
674 flags_, 683 flags_,
675 base::Time::FromDoubleT(point.last_touch_time()), 684 base::Time::FromDoubleT(point.last_touch_time()),
676 dx, dy, ComputeTouchBitmask(points_))); 685 ComputeTouchBitmask(points_)));
677 } 686 }
678 687
679 void GestureSequence::AppendPinchGestureBegin(const GesturePoint& p1, 688 void GestureSequence::AppendPinchGestureBegin(const GesturePoint& p1,
680 const GesturePoint& p2, 689 const GesturePoint& p2,
681 Gestures* gestures) { 690 Gestures* gestures) {
682 gfx::Point center = bounding_box_.CenterPoint(); 691 gfx::Point center = bounding_box_.CenterPoint();
683 gestures->push_back(helper_->CreateGestureEvent( 692 gestures->push_back(CreateGestureEvent(
684 ui::ET_GESTURE_PINCH_BEGIN, 693 GestureEventDetails(ui::ET_GESTURE_PINCH_BEGIN, 0, 0),
685 center, 694 center,
686 flags_, 695 flags_,
687 base::Time::FromDoubleT(p1.last_touch_time()), 696 base::Time::FromDoubleT(p1.last_touch_time()),
688 0.f, 0.f, 1 << p1.touch_id() | 1 << p2.touch_id())); 697 1 << p1.touch_id() | 1 << p2.touch_id()));
689 } 698 }
690 699
691 void GestureSequence::AppendPinchGestureEnd(const GesturePoint& p1, 700 void GestureSequence::AppendPinchGestureEnd(const GesturePoint& p1,
692 const GesturePoint& p2, 701 const GesturePoint& p2,
693 float scale, 702 float scale,
694 Gestures* gestures) { 703 Gestures* gestures) {
695 gfx::Point center = bounding_box_.CenterPoint(); 704 gfx::Point center = bounding_box_.CenterPoint();
696 gestures->push_back(helper_->CreateGestureEvent( 705 gestures->push_back(CreateGestureEvent(
697 ui::ET_GESTURE_PINCH_END, 706 GestureEventDetails(ui::ET_GESTURE_PINCH_END, 0, 0),
698 center, 707 center,
699 flags_, 708 flags_,
700 base::Time::FromDoubleT(p1.last_touch_time()), 709 base::Time::FromDoubleT(p1.last_touch_time()),
701 0.f, 0.f,
702 1 << p1.touch_id() | 1 << p2.touch_id())); 710 1 << p1.touch_id() | 1 << p2.touch_id()));
703 } 711 }
704 712
705 void GestureSequence::AppendPinchGestureUpdate(const GesturePoint& point, 713 void GestureSequence::AppendPinchGestureUpdate(const GesturePoint& point,
706 float scale, 714 float scale,
707 Gestures* gestures) { 715 Gestures* gestures) {
708 // TODO(sad): Compute rotation and include it in delta_y. 716 // TODO(sad): Compute rotation and include it in delta_y.
709 // http://crbug.com/113145 717 // http://crbug.com/113145
710 gestures->push_back(helper_->CreateGestureEvent( 718 gestures->push_back(CreateGestureEvent(
711 ui::ET_GESTURE_PINCH_UPDATE, 719 GestureEventDetails(ui::ET_GESTURE_PINCH_UPDATE, scale, 0),
712 bounding_box_.CenterPoint(), 720 bounding_box_.CenterPoint(),
713 flags_, 721 flags_,
714 base::Time::FromDoubleT(point.last_touch_time()), 722 base::Time::FromDoubleT(point.last_touch_time()),
715 scale, 0.f,
716 ComputeTouchBitmask(points_))); 723 ComputeTouchBitmask(points_)));
717 } 724 }
718 725
719 void GestureSequence::AppendSwipeGesture(const GesturePoint& point, 726 void GestureSequence::AppendSwipeGesture(const GesturePoint& point,
720 int swipe_x, 727 int swipe_x,
721 int swipe_y, 728 int swipe_y,
722 Gestures* gestures) { 729 Gestures* gestures) {
723 gestures->push_back(helper_->CreateGestureEvent( 730 gestures->push_back(CreateGestureEvent(
724 ui::ET_GESTURE_MULTIFINGER_SWIPE, 731 GestureEventDetails(ui::ET_GESTURE_MULTIFINGER_SWIPE, swipe_x, swipe_y),
725 bounding_box_.CenterPoint(), 732 bounding_box_.CenterPoint(),
726 flags_, 733 flags_,
727 base::Time::FromDoubleT(point.last_touch_time()), 734 base::Time::FromDoubleT(point.last_touch_time()),
728 swipe_x, swipe_y, ComputeTouchBitmask(points_))); 735 ComputeTouchBitmask(points_)));
729 } 736 }
730 737
731 void GestureSequence::AppendTwoFingerTapGestureEvent(Gestures* gestures) { 738 void GestureSequence::AppendTwoFingerTapGestureEvent(Gestures* gestures) {
732 const GesturePoint* point = GetPointByPointId(0); 739 const GesturePoint* point = GetPointByPointId(0);
733 gestures->push_back(helper_->CreateGestureEvent( 740 gestures->push_back(CreateGestureEvent(
734 ui::ET_GESTURE_TWO_FINGER_TAP, 741 GestureEventDetails(ui::ET_GESTURE_TWO_FINGER_TAP, 0, 0),
735 point->enclosing_rectangle().CenterPoint(), 742 point->enclosing_rectangle().CenterPoint(),
736 flags_, 743 flags_,
737 base::Time::FromDoubleT(point->last_touch_time()), 744 base::Time::FromDoubleT(point->last_touch_time()),
738 0.f, 0.f, 1 << point->touch_id())); 745 1 << point->touch_id()));
739 } 746 }
740 747
741 bool GestureSequence::Click(const TouchEvent& event, 748 bool GestureSequence::Click(const TouchEvent& event,
742 const GesturePoint& point, Gestures* gestures) { 749 const GesturePoint& point, Gestures* gestures) {
743 DCHECK(state_ == GS_PENDING_SYNTHETIC_CLICK); 750 DCHECK(state_ == GS_PENDING_SYNTHETIC_CLICK);
744 if (point.IsInClickWindow(event)) { 751 if (point.IsInClickWindow(event)) {
745 AppendClickGestureEvent(point, gestures); 752 AppendClickGestureEvent(point, gestures);
746 if (point.IsInDoubleClickWindow(event)) 753 if (point.IsInDoubleClickWindow(event))
747 AppendDoubleClickGestureEvent(point, gestures); 754 AppendDoubleClickGestureEvent(point, gestures);
748 return true; 755 return true;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 base::TimeDelta time_delta = event.GetTimestamp() - second_touch_time_; 844 base::TimeDelta time_delta = event.GetTimestamp() - second_touch_time_;
838 base::TimeDelta max_delta = base::TimeDelta::FromMilliseconds(1000 * 845 base::TimeDelta max_delta = base::TimeDelta::FromMilliseconds(1000 *
839 ui::GestureConfiguration::max_touch_down_duration_in_seconds_for_click()); 846 ui::GestureConfiguration::max_touch_down_duration_in_seconds_for_click());
840 if (time_delta < max_delta && point.IsInsideManhattanSquare(event)) 847 if (time_delta < max_delta && point.IsInsideManhattanSquare(event))
841 AppendTwoFingerTapGestureEvent(gestures); 848 AppendTwoFingerTapGestureEvent(gestures);
842 return true; 849 return true;
843 } 850 }
844 851
845 void GestureSequence::AppendLongPressGestureEvent() { 852 void GestureSequence::AppendLongPressGestureEvent() {
846 const GesturePoint* point = GetPointByPointId(0); 853 const GesturePoint* point = GetPointByPointId(0);
847 scoped_ptr<GestureEvent> gesture(helper_->CreateGestureEvent( 854 scoped_ptr<GestureEvent> gesture(CreateGestureEvent(
848 ui::ET_GESTURE_LONG_PRESS, 855 GestureEventDetails(ui::ET_GESTURE_LONG_PRESS, 0, 0),
849 point->first_touch_position(), 856 point->first_touch_position(),
850 flags_, 857 flags_,
851 base::Time::FromDoubleT(point->last_touch_time()), 858 base::Time::FromDoubleT(point->last_touch_time()),
852 0.f, 0.f, 1 << point->touch_id())); 859 1 << point->touch_id()));
853 helper_->DispatchLongPressGestureEvent(gesture.get()); 860 helper_->DispatchLongPressGestureEvent(gesture.get());
854 } 861 }
855 862
856 bool GestureSequence::ScrollEnd(const TouchEvent& event, 863 bool GestureSequence::ScrollEnd(const TouchEvent& event,
857 GesturePoint& point, Gestures* gestures) { 864 GesturePoint& point, Gestures* gestures) {
858 DCHECK(state_ == GS_SCROLL); 865 DCHECK(state_ == GS_SCROLL);
859 if (point.IsInFlickWindow(event)) { 866 if (point.IsInFlickWindow(event)) {
860 AppendScrollGestureEnd(point, point.last_touch_position(), gestures, 867 AppendScrollGestureEnd(point, point.last_touch_position(), gestures,
861 point.XVelocity(), point.YVelocity()); 868 point.XVelocity(), point.YVelocity());
862 } else { 869 } else {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 return; 1006 return;
1000 1007
1001 // Since long press timer has been started, there should be a non-NULL point. 1008 // Since long press timer has been started, there should be a non-NULL point.
1002 const GesturePoint* point = GetPointByPointId(0); 1009 const GesturePoint* point = GetPointByPointId(0);
1003 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), 1010 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(),
1004 event.GetLocation())) 1011 event.GetLocation()))
1005 long_press_timer_->Stop(); 1012 long_press_timer_->Stop();
1006 } 1013 }
1007 1014
1008 } // namespace ui 1015 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698