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

Side by Side Diff: ui/aura/gestures/gesture_point.cc

Issue 9104021: aura: Update GestureRecognizer to be able to process multi-point gestures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/aura/gestures/gesture_point.h"
6
7 #include "ui/aura/event.h"
8 #include "ui/base/events.h"
9
10 namespace {
11
12 // TODO(girard): Make these configurable in sync with this CL
13 // http://crbug.com/100773
14 const double kMaximumTouchDownDurationInSecondsForClick = 0.8;
15 const double kMinimumTouchDownDurationInSecondsForClick = 0.01;
16 const double kMaximumSecondsBetweenDoubleClick = 0.7;
17 const int kMaximumTouchMoveInPixelsForClick = 20;
18 const float kMinFlickSpeedSquared = 550.f * 550.f;
19
20 } // namespace aura
21
22 namespace aura {
23
24 GesturePoint::GesturePoint()
25 : first_touch_time_(0.0),
26 last_touch_time_(0.0),
27 last_click_time_(0.0),
28 x_velocity_(0.0),
29 y_velocity_(0.0) {
30 }
31
32 void GesturePoint::Reset() {
33 first_touch_time_ = last_touch_time_ = 0.0;
34 x_velocity_ = y_velocity_ = 0.0;
35 }
36
37 void GesturePoint::UpdateValues(const TouchEvent& event, GestureState state) {
38 if (state != GS_NO_GESTURE && event.type() == ui::ET_TOUCH_MOVED) {
39 double interval(event.time_stamp().InSecondsF() - last_touch_time_);
40 x_velocity_ = (event.x() - last_touch_position_.x()) / interval;
41 y_velocity_ = (event.y() - last_touch_position_.y()) / interval;
42 }
43
44 last_touch_time_ = event.time_stamp().InSecondsF();
45 last_touch_position_ = event.location();
46
47 if (state == GS_NO_GESTURE) {
48 first_touch_time_ = last_touch_time_;
49 first_touch_position_ = event.location();
50 x_velocity_ = 0.0;
51 y_velocity_ = 0.0;
52 }
53 }
54
55 void GesturePoint::UpdateForTap() {
56 last_click_time_ = last_touch_time_;
57 last_click_position_ = last_touch_position_;
58 Reset();
59 }
60
61 void GesturePoint::UpdateForScroll() {
62 first_touch_position_ = last_touch_position_;
63 }
64
65 bool GesturePoint::IsInClickTimeWindow() const {
66 double duration(last_touch_time_ - first_touch_time_);
67 return duration >= kMinimumTouchDownDurationInSecondsForClick &&
68 duration < kMaximumTouchDownDurationInSecondsForClick;
69 }
70
71 bool GesturePoint::IsInSecondClickTimeWindow() const {
72 double duration(last_touch_time_ - last_click_time_);
73 return duration < kMaximumSecondsBetweenDoubleClick;
74 }
75
76 bool GesturePoint::IsInsideManhattanSquare(const TouchEvent& event) const {
77 int manhattanDistance = abs(event.x() - first_touch_position_.x()) +
78 abs(event.y() - first_touch_position_.y());
79 return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
80 }
81
82 bool GesturePoint::IsSecondClickInsideManhattanSquare(
83 const TouchEvent& event) const {
84 int manhattanDistance = abs(event.x() - last_click_position_.x()) +
85 abs(event.y() - last_click_position_.y());
86 return manhattanDistance < kMaximumTouchMoveInPixelsForClick;
87 }
88
89 bool GesturePoint::IsOverMinFlickSpeed() const {
90 return (x_velocity_ * x_velocity_ + y_velocity_ * y_velocity_) >
91 kMinFlickSpeedSquared;
92 }
93
94 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698