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

Unified Diff: ui/chromeos/touch_exploration_controller.cc

Issue 330763007: Swipe Gestures for Accessibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gesture-vlogs
Patch Set: Added keyboard events and fixed nits Created 6 years, 6 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
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..d1a062ab378c371c756810be6751b0753c8875db 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,17 +181,32 @@ 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
+ // from the initial touch location, start gesture detection
+ // Otherwise, if the user moves far enough from the initial touch location
+ // outside the "slop" region, jump to the touch exploration mode early.
+ if (velocity > gesture_detector_config_.minimum_swipe_velocity) {
+ state_ = GESTURE_IN_PROGRESS;
+ VLOG_STATE();
+ return InGestureInProgress(event, rewritten_event);
+ }
+ else {
+ EnterTouchToMouseMode();
+ state_ = TOUCH_EXPLORATION;
+ VLOG_STATE();
+ return InTouchExploration(event, rewritten_event);
+ }
}
return EVENT_REWRITE_DISCARD;
@@ -283,6 +303,27 @@ 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 ||
+ event.touch_id() != initial_press_->touch_id()) {
+ return EVENT_REWRITE_DISCARD;
+ }
+ if (type == ui::ET_TOUCH_MOVED) {
+ gesture_provider_.OnTouchEvent(event);
+ 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();
@@ -366,6 +407,7 @@ ui::EventRewriteStatus TouchExplorationController::InTouchExploreSecondPress(
initial_press_->touch_id(),
event.time_stamp()));
(*rewritten_event)->set_flags(event.flags());
+ EnterTouchToMouseMode();
state_ = TOUCH_EXPLORATION;
VLOG_STATE();
return ui::EVENT_REWRITE_REWRITTEN;
@@ -375,13 +417,17 @@ 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 &&
+ 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 +448,65 @@ void TouchExplorationController::DispatchEvent(ui::Event* event) {
root_window_->GetHost()->dispatcher()->OnEventFromSource(event);
}
+void TouchExplorationController::OnGestureEvent(ui::GestureEvent* gesture) {
+ CHECK(gesture->IsGestureEvent());
+ if (tap_timer_.IsRunning())
+ tap_timer_.Stop();
+ switch (gesture->type()) {
+ case ET_GESTURE_SWIPE:
+ VLOG(0) << " \n Gesture Triggered: " << gesture->name();
dmazzoni 2014/06/23 18:37:26 Want to log this no matter what the gesture?
+ OnSwipeEvent(gesture);
+ return;
+ default:
+ if (current_touch_ids_.size() != 0) {
+ EnterTouchToMouseMode();
+ state_ = TOUCH_EXPLORATION;
+ } else
+ ResetToNoFingersDown();
+ break;
+ }
+}
+
+void TouchExplorationController::OnSwipeEvent(ui::GestureEvent* swipe_gesture) {
+ // A swipe gesture contains details for the direction in which the swipe
+ // occurred.
+ GestureEventDetails event_details = swipe_gesture->details();
+ if (event_details.swipe_left()) {
+ DispatchShiftSearchKeyEvent(ui::VKEY_LEFT);
+ return;
+ } else if (event_details.swipe_right()) {
+ DispatchShiftSearchKeyEvent(ui::VKEY_RIGHT);
+ return;
+ } else if (event_details.swipe_up()) {
+ DispatchShiftSearchKeyEvent(ui::VKEY_UP);
+ return;
+ } else if (event_details.swipe_down()) {
+ DispatchShiftSearchKeyEvent(ui::VKEY_DOWN);
+ return;
+ }
+}
+
+void TouchExplorationController::DispatchShiftSearchKeyEvent(
+ const ui::KeyboardCode direction) {
+ // In order to activate the shortcut shift+search+<arrow key>
+ // three KeyPressed events must be dispatched in succession along
+ // with three KeyReleased events.
+ DispatchEvent(new ui::KeyEvent(
+ ui::ET_KEY_PRESSED, ui::VKEY_SHIFT, ui::EF_SHIFT_DOWN, false));
+ // VKEY_LWIN is the search key on ChromeOS.
dmazzoni 2014/06/23 18:37:26 How about a constant at the top of the file: cons
+ DispatchEvent(new ui::KeyEvent(
+ ui::ET_KEY_PRESSED, ui::VKEY_LWIN, ui::EF_SHIFT_DOWN, false));
+ DispatchEvent(new ui::KeyEvent(
+ ui::ET_KEY_PRESSED, direction, ui::EF_SHIFT_DOWN, false));
+
+ DispatchEvent(new ui::KeyEvent(
+ ui::ET_KEY_RELEASED, direction, ui::EF_SHIFT_DOWN, false));
+ DispatchEvent(new ui::KeyEvent(
+ ui::ET_KEY_RELEASED, ui::VKEY_LWIN, ui::EF_SHIFT_DOWN, false));
+ DispatchEvent(new ui::KeyEvent(
+ ui::ET_KEY_RELEASED, ui::VKEY_SHIFT, ui::EF_NONE, false));
+}
+
scoped_ptr<ui::Event> TouchExplorationController::CreateMouseMoveEvent(
const gfx::PointF& location,
int flags) {
@@ -424,6 +529,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 +584,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:

Powered by Google App Engine
This is Rietveld 408576698