Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 1 << point.touch_id())); | 667 1 << point.touch_id())); |
| 668 } | 668 } |
| 669 } | 669 } |
| 670 | 670 |
| 671 void GestureSequence::AppendScrollGestureUpdate(const GesturePoint& point, | 671 void GestureSequence::AppendScrollGestureUpdate(const GesturePoint& point, |
| 672 const gfx::Point& location, | 672 const gfx::Point& location, |
| 673 Gestures* gestures) { | 673 Gestures* gestures) { |
| 674 gfx::Point current_center = bounding_box_.CenterPoint(); | 674 gfx::Point current_center = bounding_box_.CenterPoint(); |
| 675 int dx = current_center.x() - bounding_box_last_center_.x(); | 675 int dx = current_center.x() - bounding_box_last_center_.x(); |
| 676 int dy = current_center.y() - bounding_box_last_center_.y(); | 676 int dy = current_center.y() - bounding_box_last_center_.y(); |
| 677 if (dx == 0 && dy == 0) | |
| 678 return; | |
| 679 if (scroll_type_ == ST_HORIZONTAL) | 677 if (scroll_type_ == ST_HORIZONTAL) |
| 680 dy = 0; | 678 dy = 0; |
| 681 else if (scroll_type_ == ST_VERTICAL) | 679 else if (scroll_type_ == ST_VERTICAL) |
| 682 dx = 0; | 680 dx = 0; |
| 681 if (dx == 0 && dy == 0) | |
| 682 return; | |
| 683 | 683 |
| 684 gestures->push_back(CreateGestureEvent( | 684 gestures->push_back(CreateGestureEvent( |
| 685 GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, dx, dy), | 685 GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, dx, dy), |
| 686 location, | 686 location, |
| 687 flags_, | 687 flags_, |
| 688 base::Time::FromDoubleT(point.last_touch_time()), | 688 base::Time::FromDoubleT(point.last_touch_time()), |
| 689 ComputeTouchBitmask(points_))); | 689 ComputeTouchBitmask(points_))); |
| 690 } | 690 } |
| 691 | 691 |
| 692 void GestureSequence::AppendPinchGestureBegin(const GesturePoint& p1, | 692 void GestureSequence::AppendPinchGestureBegin(const GesturePoint& p1, |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 899 AppendScrollGestureBegin(point, center, gestures); | 899 AppendScrollGestureBegin(point, center, gestures); |
| 900 } | 900 } |
| 901 | 901 |
| 902 return true; | 902 return true; |
| 903 } | 903 } |
| 904 | 904 |
| 905 bool GestureSequence::PinchUpdate(const TouchEvent& event, | 905 bool GestureSequence::PinchUpdate(const TouchEvent& event, |
| 906 const GesturePoint& point, Gestures* gestures) { | 906 const GesturePoint& point, Gestures* gestures) { |
| 907 DCHECK(state_ == GS_PINCH); | 907 DCHECK(state_ == GS_PINCH); |
| 908 | 908 |
| 909 // It is possible that the none of the touch-points changed their position, | |
| 910 // but their radii changed, and that caused the bounding box to also change. | |
| 911 // But in such cases, we do not want to either pinch or scroll. | |
| 912 // To avoid small jiggles, it is also necessary to make sure that at least one | |
| 913 // of the fingers moved enough before a pinch or scroll update is created. | |
| 914 bool did_scroll = false; | |
| 915 for (int i = 0; i < kMaxGesturePoints; ++i) { | |
| 916 if (!points_[i].in_use() || !points_[i].DidScroll(event, 2)) | |
|
rjkroege
2012/08/07 15:02:51
aside: the difference between DidScroll and the ma
sadrul
2012/08/07 20:28:10
DidScroll looks for movement in any one direction,
| |
| 917 continue; | |
| 918 did_scroll = true; | |
| 919 break; | |
| 920 } | |
| 921 | |
| 922 if (!did_scroll) | |
| 923 return false; | |
| 924 | |
| 909 float distance = BoundingBoxDiagonal(bounding_box_); | 925 float distance = BoundingBoxDiagonal(bounding_box_); |
| 910 | 926 |
| 911 if (abs(distance - pinch_distance_current_) >= | 927 if (abs(distance - pinch_distance_current_) >= |
| 912 GestureConfiguration::min_pinch_update_distance_in_pixels()) { | 928 GestureConfiguration::min_pinch_update_distance_in_pixels()) { |
| 913 AppendPinchGestureUpdate(point, | 929 AppendPinchGestureUpdate(point, |
| 914 distance / pinch_distance_current_, gestures); | 930 distance / pinch_distance_current_, gestures); |
| 915 pinch_distance_current_ = distance; | 931 pinch_distance_current_ = distance; |
| 916 } else { | 932 } else { |
| 917 gfx::Point center = bounding_box_.CenterPoint(); | 933 gfx::Point center = bounding_box_.CenterPoint(); |
| 918 AppendScrollGestureUpdate(point, center, gestures); | 934 AppendScrollGestureUpdate(point, center, gestures); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1010 return; | 1026 return; |
| 1011 | 1027 |
| 1012 // Since long press timer has been started, there should be a non-NULL point. | 1028 // Since long press timer has been started, there should be a non-NULL point. |
| 1013 const GesturePoint* point = GetPointByPointId(0); | 1029 const GesturePoint* point = GetPointByPointId(0); |
| 1014 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), | 1030 if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(), |
| 1015 event.GetLocation())) | 1031 event.GetLocation())) |
| 1016 long_press_timer_->Stop(); | 1032 long_press_timer_->Stop(); |
| 1017 } | 1033 } |
| 1018 | 1034 |
| 1019 } // namespace ui | 1035 } // namespace ui |
| OLD | NEW |