Chromium Code Reviews| Index: ui/chromeos/touch_exploration_controller.cc |
| diff --git a/ui/chromeos/touch_exploration_controller.cc b/ui/chromeos/touch_exploration_controller.cc |
| index a253c828a4efcfba636b5351be792f202a2ef7c1..612ec8b8314371bcf083d9198372274262b22a0f 100644 |
| --- a/ui/chromeos/touch_exploration_controller.cc |
| +++ b/ui/chromeos/touch_exploration_controller.cc |
| @@ -39,6 +39,7 @@ TouchExplorationController::TouchExplorationController( |
| initial_touch_id_passthrough_mapping_(kTouchIdUnassigned), |
| state_(NO_FINGERS_DOWN), |
| event_handler_for_testing_(NULL), |
| + gesture_provider_(this), |
| prev_state_(NO_FINGERS_DOWN) { |
| CHECK(root_window); |
| root_window->GetHost()->GetEventSource()->AddEventRewriter(this); |
| @@ -127,6 +128,8 @@ ui::EventRewriteStatus TouchExplorationController::RewriteEvent( |
| return InDoubleTapPressed(touch_event, rewritten_event); |
| case TOUCH_EXPLORATION: |
| return InTouchExploration(touch_event, rewritten_event); |
| + case GESTURE_IN_PROGRESS: |
| + return InGestureInProgress(touch_event, rewritten_event); |
| case PASSTHROUGH_MINUS_ONE: |
| return InPassthroughMinusOne(touch_event, rewritten_event); |
| case TOUCH_EXPLORE_SECOND_PRESS: |
| @@ -152,6 +155,8 @@ ui::EventRewriteStatus TouchExplorationController::InNoFingersDown( |
| gesture_detector_config_.double_tap_timeout, |
| this, |
| &TouchExplorationController::OnTapTimerFired); |
| + gesture_provider_.OnTouchEvent(event); |
| + gesture_provider_.OnTouchEventAck(false); |
| state_ = SINGLE_TAP_PRESSED; |
| VLOG_STATE(); |
| return ui::EVENT_REWRITE_DISCARD; |
| @@ -176,19 +181,33 @@ ui::EventRewriteStatus TouchExplorationController::InSingleTapPressed( |
| VLOG_STATE(); |
| return EVENT_REWRITE_DISCARD; |
| } else if (type == ui::ET_TOUCH_MOVED) { |
| - // If the user moves far enough from the initial touch location (outside |
| - // the "slop" region, jump to the touch exploration mode early. |
| - // TODO(evy, lisayin): Add gesture recognition here instead - |
| - // we should probably jump to gesture mode here if the velocity is |
| - // high enough, and touch exploration if the velocity is lower. |
| - float delta = (event.location() - initial_press_->location()).Length(); |
| - if (delta > gesture_detector_config_.touch_slop) { |
| - EnterTouchToMouseMode(); |
| - state_ = TOUCH_EXPLORATION; |
| - VLOG_STATE(); |
| - return InTouchExploration(event, rewritten_event); |
| + float delta_time = |
| + (event.time_stamp() - initial_press_->time_stamp()).InSecondsF(); |
| + float delta_distance = |
| + (event.location() - initial_press_->location()).Length(); |
| + float velocity = delta_distance / delta_time; |
| + VLOG(0) << "\n Delta time: " << delta_time |
| + << "\n Delta distance: " << delta_distance |
| + << "\n Velocity of click: " << velocity |
| + << "\n Minimum swipe velocity: " |
| + << gesture_detector_config_.minimum_swipe_velocity; |
| + if (delta_distance > gesture_detector_config_.touch_slop) { |
| + // If the user moves fast enough and far enough |
|
dmazzoni
2014/06/23 15:50:44
Nit: indent the comment to match inside the block.
|
| + // from the initial touch location, start gesture detection |
| + if (velocity > gesture_detector_config_.minimum_swipe_velocity) { |
| + state_ = GESTURE_IN_PROGRESS; |
| + VLOG_STATE(); |
| + return InGestureInProgress(event, rewritten_event); |
| + } |
| + // Otherwise, if the user moves far enough from the initial touch location |
|
dmazzoni
2014/06/23 15:50:44
Nit: don't put comments in-between the final } of
|
| + // outside the "slop" region, jump to the touch exploration mode early. |
| + else { |
| + EnterTouchToMouseMode(); |
| + state_ = TOUCH_EXPLORATION; |
| + VLOG_STATE(); |
| + return InTouchExploration(event, rewritten_event); |
| + } |
| } |
| - |
| return EVENT_REWRITE_DISCARD; |
| } |
| NOTREACHED() << "Unexpected event type received."; |
| @@ -283,6 +302,26 @@ ui::EventRewriteStatus TouchExplorationController::InTouchExploration( |
| return ui::EVENT_REWRITE_REWRITTEN; |
| } |
| +ui::EventRewriteStatus TouchExplorationController::InGestureInProgress( |
| + const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { |
| + ui::EventType type = event.type(); |
| + gfx::PointF location = event.location_f(); |
| + if (type == ui::ET_TOUCH_PRESSED) { |
| + return EVENT_REWRITE_DISCARD; |
| + } |
| + if (type == ui::ET_TOUCH_MOVED) { |
| + gesture_provider_.OnTouchEvent(event); |
|
dmazzoni
2014/06/23 15:50:44
If you're throwing away "pressed" events for any f
lisayin
2014/06/23 16:48:43
Just to clarify, I should check the id of the even
|
| + gesture_provider_.OnTouchEventAck(false); |
| + } |
| + if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { |
| + gesture_provider_.OnTouchEvent(event); |
| + gesture_provider_.OnTouchEventAck(true); |
| + if (current_touch_ids_.size() == 0) |
| + ResetToNoFingersDown(); |
| + } |
| + return ui::EVENT_REWRITE_DISCARD; |
| +} |
| + |
| ui::EventRewriteStatus TouchExplorationController::InPassthroughMinusOne( |
| const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { |
| ui::EventType type = event.type(); |
| @@ -375,13 +414,16 @@ ui::EventRewriteStatus TouchExplorationController::InTouchExploreSecondPress( |
| } |
| void TouchExplorationController::OnTapTimerFired() { |
| - if (state_ != SINGLE_TAP_RELEASED && state_ != SINGLE_TAP_PRESSED) |
| + if (state_ != SINGLE_TAP_RELEASED && state_ != SINGLE_TAP_PRESSED && |
|
dmazzoni
2014/06/23 15:50:44
Nit: for readability, when there are multiple line
|
| + state_ != GESTURE_IN_PROGRESS) |
| return; |
| if (state_ == SINGLE_TAP_RELEASED) { |
| ResetToNoFingersDown(); |
| } else { |
| EnterTouchToMouseMode(); |
| + // Discard any pending gestures |
| + delete gesture_provider_.GetAndResetPendingGestures(); |
| state_ = TOUCH_EXPLORATION; |
| VLOG_STATE(); |
| } |
| @@ -402,6 +444,11 @@ void TouchExplorationController::DispatchEvent(ui::Event* event) { |
| root_window_->GetHost()->dispatcher()->OnEventFromSource(event); |
| } |
| +void TouchExplorationController::OnGestureEvent(ui::GestureEvent* gesture) { |
| + CHECK(gesture->IsGestureEvent()); |
| + VLOG(0) << " \n Gesture Triggered: " << gesture->name(); |
| +} |
| + |
| scoped_ptr<ui::Event> TouchExplorationController::CreateMouseMoveEvent( |
| const gfx::PointF& location, |
| int flags) { |
| @@ -424,6 +471,15 @@ void TouchExplorationController::EnterTouchToMouseMode() { |
| } |
| void TouchExplorationController::ResetToNoFingersDown() { |
| + scoped_ptr<ScopedVector<ui::GestureEvent> > gestures; |
| + gestures.reset(gesture_provider_.GetAndResetPendingGestures()); |
| + if (gestures != NULL) { |
| + for (ScopedVector<GestureEvent>::iterator i = gestures->begin(); |
| + i != gestures->end(); |
| + ++i) { |
| + OnGestureEvent(*i); |
| + } |
| + } |
| state_ = NO_FINGERS_DOWN; |
| initial_touch_id_passthrough_mapping_ = kTouchIdUnassigned; |
| VLOG_STATE(); |
| @@ -470,6 +526,8 @@ const char* TouchExplorationController::EnumStateToString(State state) { |
| return "DOUBLE_TAP_PRESSED"; |
| case TOUCH_EXPLORATION: |
| return "TOUCH_EXPLORATION"; |
| + case GESTURE_IN_PROGRESS: |
| + return "GESTURE_IN_PROGRESS"; |
| case PASSTHROUGH_MINUS_ONE: |
| return "PASSTHROUGH_MINUS_ONE"; |
| case TOUCH_EXPLORE_SECOND_PRESS: |