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

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

Issue 10837107: gesture recognizer: Make sure the pinch/scroll only when the finger is moved for real. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test Created 8 years, 4 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
« no previous file with comments | « ui/aura/gestures/gesture_recognizer_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 1 << point.touch_id())); 668 1 << point.touch_id()));
669 } 669 }
670 } 670 }
671 671
672 void GestureSequence::AppendScrollGestureUpdate(const GesturePoint& point, 672 void GestureSequence::AppendScrollGestureUpdate(const GesturePoint& point,
673 const gfx::Point& location, 673 const gfx::Point& location,
674 Gestures* gestures) { 674 Gestures* gestures) {
675 gfx::Point current_center = bounding_box_.CenterPoint(); 675 gfx::Point current_center = bounding_box_.CenterPoint();
676 int dx = current_center.x() - bounding_box_last_center_.x(); 676 int dx = current_center.x() - bounding_box_last_center_.x();
677 int dy = current_center.y() - bounding_box_last_center_.y(); 677 int dy = current_center.y() - bounding_box_last_center_.y();
678 if (dx == 0 && dy == 0)
679 return;
680 if (scroll_type_ == ST_HORIZONTAL) 678 if (scroll_type_ == ST_HORIZONTAL)
681 dy = 0; 679 dy = 0;
682 else if (scroll_type_ == ST_VERTICAL) 680 else if (scroll_type_ == ST_VERTICAL)
683 dx = 0; 681 dx = 0;
682 if (dx == 0 && dy == 0)
683 return;
684 684
685 gestures->push_back(CreateGestureEvent( 685 gestures->push_back(CreateGestureEvent(
686 GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, dx, dy), 686 GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, dx, dy),
687 location, 687 location,
688 flags_, 688 flags_,
689 base::Time::FromDoubleT(point.last_touch_time()), 689 base::Time::FromDoubleT(point.last_touch_time()),
690 ComputeTouchBitmask(points_))); 690 ComputeTouchBitmask(points_)));
691 } 691 }
692 692
693 void GestureSequence::AppendPinchGestureBegin(const GesturePoint& p1, 693 void GestureSequence::AppendPinchGestureBegin(const GesturePoint& p1,
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 AppendScrollGestureBegin(point, center, gestures); 901 AppendScrollGestureBegin(point, center, gestures);
902 } 902 }
903 903
904 return true; 904 return true;
905 } 905 }
906 906
907 bool GestureSequence::PinchUpdate(const TouchEvent& event, 907 bool GestureSequence::PinchUpdate(const TouchEvent& event,
908 const GesturePoint& point, Gestures* gestures) { 908 const GesturePoint& point, Gestures* gestures) {
909 DCHECK(state_ == GS_PINCH); 909 DCHECK(state_ == GS_PINCH);
910 910
911 // It is possible that the none of the touch-points changed their position,
912 // but their radii changed, and that caused the bounding box to also change.
913 // But in such cases, we do not want to either pinch or scroll.
914 // To avoid small jiggles, it is also necessary to make sure that at least one
915 // of the fingers moved enough before a pinch or scroll update is created.
916 bool did_scroll = false;
917 for (int i = 0; i < kMaxGesturePoints; ++i) {
918 if (!points_[i].in_use() || !points_[i].DidScroll(event, 2))
919 continue;
920 did_scroll = true;
921 break;
922 }
923
924 if (!did_scroll)
925 return false;
926
911 float distance = BoundingBoxDiagonal(bounding_box_); 927 float distance = BoundingBoxDiagonal(bounding_box_);
912 928
913 if (abs(distance - pinch_distance_current_) >= 929 if (abs(distance - pinch_distance_current_) >=
914 GestureConfiguration::min_pinch_update_distance_in_pixels()) { 930 GestureConfiguration::min_pinch_update_distance_in_pixels()) {
915 AppendPinchGestureUpdate(point, 931 AppendPinchGestureUpdate(point,
916 distance / pinch_distance_current_, gestures); 932 distance / pinch_distance_current_, gestures);
917 pinch_distance_current_ = distance; 933 pinch_distance_current_ = distance;
918 } else { 934 } else {
919 gfx::Point center = bounding_box_.CenterPoint(); 935 gfx::Point center = bounding_box_.CenterPoint();
920 AppendScrollGestureUpdate(point, center, gestures); 936 AppendScrollGestureUpdate(point, center, gestures);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 return; 1028 return;
1013 1029
1014 // Since long press timer has been started, there should be a non-NULL point. 1030 // Since long press timer has been started, there should be a non-NULL point.
1015 const GesturePoint* point = GetPointByPointId(0); 1031 const GesturePoint* point = GetPointByPointId(0);
1016 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), 1032 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(),
1017 event.GetLocation())) 1033 event.GetLocation()))
1018 long_press_timer_->Stop(); 1034 long_press_timer_->Stop();
1019 } 1035 }
1020 1036
1021 } // namespace ui 1037 } // namespace ui
OLDNEW
« no previous file with comments | « ui/aura/gestures/gesture_recognizer_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698