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

Unified Diff: ui/events/gestures/gesture_sequence.cc

Issue 101933004: Eager Gesture Recognizer (WIP) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Starting work on Android. Created 6 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/events/gestures/gesture_sequence.h ('k') | ui/events/gestures/gesture_types.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/gestures/gesture_sequence.cc
diff --git a/ui/events/gestures/gesture_sequence.cc b/ui/events/gestures/gesture_sequence.cc
index 65d813aa83c016e3f4617b243fe2a50ac85d5620..c516c33f498848cfe407e3aacd46be7504751f33 100644
--- a/ui/events/gestures/gesture_sequence.cc
+++ b/ui/events/gestures/gesture_sequence.cc
@@ -479,23 +479,23 @@ void UpdateGestureEventLatencyInfo(const TouchEvent& event,
////////////////////////////////////////////////////////////////////////////////
// GestureSequence Public:
-GestureSequence::GestureSequence(GestureSequenceDelegate* delegate)
+GestureSequence::GestureSequence(GestureEventQueueTimerInterface* geq_timers)
: state_(GS_NO_GESTURE),
flags_(0),
pinch_distance_start_(0.f),
pinch_distance_current_(0.f),
scroll_type_(ST_FREE),
point_count_(0),
- delegate_(delegate) {
- CHECK(delegate_);
+ geq_timers_(geq_timers) {
}
GestureSequence::~GestureSequence() {
}
GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture(
- const TouchEvent& event,
- EventResult result) {
+ const TouchEvent& event) {
+ // TODO(tdresser): Remove depency on EventResult from GestureSequence.
+ EventResult result = ER_UNHANDLED;
StopTimersIfRequired(event);
last_touch_location_ = event.location();
if (result & ER_CONSUMED)
@@ -531,8 +531,11 @@ GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture(
RecreateBoundingBox();
flags_ = event.flags();
const int point_id = point.point_id();
- if (point_id < 0)
+ if (point_id < 0) {
+ LOG(ERROR) << "GS sees event for touch which isn't down " << event.type();
+ LOG(ERROR) << "Touch id is " << event.touch_id();
return NULL;
+ }
// Send GESTURE_BEGIN for any touch pressed.
if (event.type() == ui::ET_TOUCH_PRESSED)
@@ -751,8 +754,14 @@ GestureSequence::Gestures* GestureSequence::ProcessTouchEventForGesture(
<< " touch id: " << event.touch_id();
if (last_state == GS_PENDING_SYNTHETIC_CLICK && state_ != last_state) {
- GetLongPressTimer()->Stop();
- GetShowPressTimer()->Stop();
+ if (GetLongPressTimer()->IsRunning()) {
+ GetLongPressTimer()->Stop();
+ geq_timers_->TimerCancelled();
+ }
+ if (GetShowPressTimer()->IsRunning()) {
+ GetShowPressTimer()->Stop();
+ geq_timers_->TimerCancelled();
+ }
}
// The set of point_ids must be contiguous and include 0.
@@ -818,17 +827,20 @@ void GestureSequence::ResetVelocities() {
////////////////////////////////////////////////////////////////////////////////
// GestureSequence Protected:
-base::OneShotTimer<GestureSequence>* GestureSequence::CreateTimer() {
- return new base::OneShotTimer<GestureSequence>();
+base::OneShotTimer<GestureEventQueueTimerInterface>*
+GestureSequence::CreateTimer() {
+ return new base::OneShotTimer<GestureEventQueueTimerInterface>();
}
-base::OneShotTimer<GestureSequence>* GestureSequence::GetLongPressTimer() {
+base::OneShotTimer<GestureEventQueueTimerInterface>*
+GestureSequence::GetLongPressTimer() {
if (!long_press_timer_.get())
long_press_timer_.reset(CreateTimer());
return long_press_timer_.get();
}
-base::OneShotTimer<GestureSequence>* GestureSequence::GetShowPressTimer() {
+base::OneShotTimer<GestureEventQueueTimerInterface>*
+GestureSequence::GetShowPressTimer() {
if (!show_press_timer_.get())
show_press_timer_.reset(CreateTimer());
return show_press_timer_.get();
@@ -1110,7 +1122,7 @@ bool GestureSequence::Click(const TouchEvent& event,
tap_count = 2;
if (tap_count == 1 && GetShowPressTimer()->IsRunning()) {
GetShowPressTimer()->Stop();
- AppendShowPressGestureEvent();
+ geq_timers_->TimerCancelled();
}
AppendClickGestureEvent(point, tap_count, gestures);
return true;
@@ -1164,19 +1176,22 @@ bool GestureSequence::TouchDown(const TouchEvent& event,
Gestures* gestures) {
DCHECK(state_ == GS_NO_GESTURE);
AppendTapDownGestureEvent(point, gestures);
+ AppendLongPressGestureEvent(point, gestures);
+ AppendShowPressGestureEvent(point, gestures);
+
GetLongPressTimer()->Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(
GestureConfiguration::long_press_time_in_seconds() * 1000),
- this,
- &GestureSequence::AppendLongPressGestureEvent);
+ geq_timers_,
+ &GestureEventQueueTimerInterface::TimerFired);
GetShowPressTimer()->Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(
GestureConfiguration::show_press_delay_in_ms()),
- this,
- &GestureSequence::AppendShowPressGestureEvent);
+ geq_timers_,
+ &GestureEventQueueTimerInterface::TimerFired);
return true;
}
@@ -1225,26 +1240,25 @@ bool GestureSequence::TwoFingerTouchReleased(const TouchEvent& event,
return true;
}
-void GestureSequence::AppendLongPressGestureEvent() {
- const GesturePoint* point = GetPointByPointId(0);
- scoped_ptr<GestureEvent> gesture(CreateGestureEvent(
+void GestureSequence::AppendLongPressGestureEvent(const GesturePoint& point,
+ Gestures* gestures) {
+ gestures->push_back(CreateGestureEvent(
GestureEventDetails(ui::ET_GESTURE_LONG_PRESS, 0, 0),
- point->first_touch_position(),
+ point.first_touch_position(),
flags_,
- base::Time::FromDoubleT(point->last_touch_time()),
- 1 << point->touch_id()));
- delegate_->DispatchPostponedGestureEvent(gesture.get());
+ base::Time::FromDoubleT(point.last_touch_time()),
+ 1 << point.touch_id()));
}
-void GestureSequence::AppendShowPressGestureEvent() {
- const GesturePoint* point = GetPointByPointId(0);
- scoped_ptr<GestureEvent> gesture(CreateGestureEvent(
+
+void GestureSequence::AppendShowPressGestureEvent(const GesturePoint& point,
+ Gestures* gestures) {
+ gestures->push_back(CreateGestureEvent(
GestureEventDetails(ui::ET_GESTURE_SHOW_PRESS, 0, 0),
- point->first_touch_position(),
+ point.first_touch_position(),
flags_,
- base::Time::FromDoubleT(point->last_touch_time()),
- 1 << point->touch_id()));
- delegate_->DispatchPostponedGestureEvent(gesture.get());
+ base::Time::FromDoubleT(point.last_touch_time()),
+ 1 << point.touch_id()));
}
void GestureSequence::AppendLongTapGestureEvent(const GesturePoint& point,
@@ -1440,8 +1454,14 @@ void GestureSequence::StopTimersIfRequired(const TouchEvent& event) {
const GesturePoint* point = GetPointByPointId(0);
if (!ui::gestures::IsInsideManhattanSquare(point->first_touch_position(),
event.location())) {
- GetLongPressTimer()->Stop();
- GetShowPressTimer()->Stop();
+ if (GetLongPressTimer()->IsRunning()) {
+ GetLongPressTimer()->Stop();
+ geq_timers_->TimerCancelled();
+ }
+ if (GetShowPressTimer()->IsRunning()) {
+ GetShowPressTimer()->Stop();
+ geq_timers_->TimerCancelled();
+ }
}
}
« no previous file with comments | « ui/events/gestures/gesture_sequence.h ('k') | ui/events/gestures/gesture_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698