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 5fe037a9c9d6437bb1db04f841b3a96c70d31dfe..ee1bc36a396dc06dc4f4be7d98fea8f2b52a7d22 100644 |
| --- a/ui/chromeos/touch_exploration_controller.cc |
| +++ b/ui/chromeos/touch_exploration_controller.cc |
| @@ -43,6 +43,7 @@ TouchExplorationController::TouchExplorationController( |
| tick_clock_(NULL) { |
| CHECK(root_window); |
| root_window->GetHost()->GetEventSource()->AddEventRewriter(this); |
| + InitializeSwipeClosures(); |
| } |
| TouchExplorationController::~TouchExplorationController() { |
| @@ -705,71 +706,18 @@ void TouchExplorationController::OnSwipeEvent(ui::GestureEvent* swipe_gesture) { |
| int num_fingers = event_details.touch_points(); |
| if(VLOG_on_) |
| VLOG(0) << "\nSwipe with " << num_fingers << " fingers."; |
| + |
| if (num_fingers > 4) |
| return; |
| - switch (num_fingers) { |
| - case 1: |
| - 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; |
| - } |
| - case 2: |
| - if (event_details.swipe_left()) { |
| - DispatchKeyWithFlags(VKEY_BROWSER_BACK, ui::EF_NONE); |
| - return; |
| - } else if (event_details.swipe_right()) { |
| - DispatchKeyWithFlags(VKEY_BROWSER_FORWARD, ui::EF_NONE); |
| - return; |
| - } else if (event_details.swipe_up()) { |
| - DispatchShiftSearchKeyEvent(ui::VKEY_A); |
| - return; |
| - } else if (event_details.swipe_down()) { |
| - DispatchShiftSearchKeyEvent(ui::VKEY_R); |
| - return; |
| - } |
| - case 3: |
| - if (event_details.swipe_left()) { |
| - DispatchKeyWithFlags(ui::VKEY_TAB, |
| - ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); |
| - } else if (event_details.swipe_right()) { |
| - DispatchKeyWithFlags(ui::VKEY_TAB, ui::EF_CONTROL_DOWN); |
| - } else if (event_details.swipe_up()) { |
| - DispatchKeyWithFlags(ui::VKEY_NEXT, ui::EF_NONE); |
| - return; |
| - } else if (event_details.swipe_down()) { |
| - DispatchKeyWithFlags(ui::VKEY_PRIOR, ui::EF_NONE); |
| - return; |
| - } |
| - return; |
| - case 4: |
| - // Brightness can be important for low vision users, but none of these |
| - // mappings are permanent. Four finger gestures should probably |
| - // eventually be used for rare needs that are hard to access through |
| - // menus. |
| - if (event_details.swipe_left()) { |
| - DispatchKeyWithFlags(VKEY_BRIGHTNESS_DOWN, ui::EF_NONE); |
| - return; |
| - } else if (event_details.swipe_right()) { |
| - DispatchKeyWithFlags(VKEY_BRIGHTNESS_UP, ui::EF_NONE); |
| - return; |
| - } else if (event_details.swipe_up()) { |
| - DispatchKeyWithFlags(VKEY_BROWSER_HOME, ui::EF_NONE); |
| - return; |
| - } else if (event_details.swipe_down()) { |
| - DispatchKeyWithFlags(VKEY_BROWSER_REFRESH, ui::EF_NONE); |
| - return; |
| - } |
| - } |
| - return; |
| + |
| + if (event_details.swipe_left()) |
|
aboxhall
2014/08/05 23:43:41
This looks so good now!
evy
2014/08/05 23:51:18
Acknowledged.
|
| + left_swipe_gestures_[num_fingers].Run(); |
| + else if (event_details.swipe_right()) |
| + right_swipe_gestures_[num_fingers].Run(); |
| + else if (event_details.swipe_up()) |
| + up_swipe_gestures_[num_fingers].Run(); |
| + else if (event_details.swipe_down()) |
| + down_swipe_gestures_[num_fingers].Run(); |
| } |
| int TouchExplorationController::FindEdgesWithinBounds(gfx::Point point, |
| @@ -956,4 +904,94 @@ const char* TouchExplorationController::EnumStateToString(State state) { |
| return "Not a state"; |
| } |
| +void TouchExplorationController::InitializeSwipeClosures() { |
| + // Gestures with one finger are used for navigation. |
| + left_swipe_gestures_[1] = |
| + base::Bind(&TouchExplorationController::DispatchShiftSearchKeyEvent, |
| + base::Unretained(this), |
| + ui::VKEY_LEFT); |
| + right_swipe_gestures_[1] = |
| + base::Bind(&TouchExplorationController::DispatchShiftSearchKeyEvent, |
| + base::Unretained(this), |
| + ui::VKEY_RIGHT); |
| + up_swipe_gestures_[1] = |
| + base::Bind(&TouchExplorationController::DispatchShiftSearchKeyEvent, |
| + base::Unretained(this), |
| + ui::VKEY_UP); |
| + down_swipe_gestures_[1] = |
| + base::Bind(&TouchExplorationController::DispatchShiftSearchKeyEvent, |
| + base::Unretained(this), |
| + ui::VKEY_DOWN); |
| + |
| + // Gestures with two fingers. |
| + left_swipe_gestures_[2] = |
| + base::Bind(&TouchExplorationController::DispatchKeyWithFlags, |
| + base::Unretained(this), |
| + ui::VKEY_BROWSER_BACK, |
| + ui::EF_NONE); |
| + right_swipe_gestures_[2] = |
| + base::Bind(&TouchExplorationController::DispatchKeyWithFlags, |
| + base::Unretained(this), |
| + ui::VKEY_BROWSER_FORWARD, |
| + ui::EF_NONE); |
| + // Jump to top. |
| + up_swipe_gestures_[2] = |
| + base::Bind(&TouchExplorationController::DispatchShiftSearchKeyEvent, |
| + base::Unretained(this), |
| + ui::VKEY_A); |
| + // Read from here. |
| + down_swipe_gestures_[2] = |
| + base::Bind(&TouchExplorationController::DispatchShiftSearchKeyEvent, |
| + base::Unretained(this), |
| + ui::VKEY_R); |
| + |
| + // Gestures with three fingers switch tabs left/right and scroll up/down. |
| + left_swipe_gestures_[3] = |
| + base::Bind(&TouchExplorationController::DispatchKeyWithFlags, |
| + base::Unretained(this), |
| + ui::VKEY_TAB, |
| + ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); |
| + right_swipe_gestures_[3] = |
| + base::Bind(&TouchExplorationController::DispatchKeyWithFlags, |
| + base::Unretained(this), |
| + ui::VKEY_TAB, |
| + ui::EF_CONTROL_DOWN); |
| + up_swipe_gestures_[3] = |
| + base::Bind(&TouchExplorationController::DispatchKeyWithFlags, |
| + base::Unretained(this), |
| + ui::VKEY_NEXT, |
| + ui::EF_NONE); |
| + down_swipe_gestures_[3] = |
| + base::Bind(&TouchExplorationController::DispatchKeyWithFlags, |
| + base::Unretained(this), |
| + ui::VKEY_PRIOR, |
| + ui::EF_NONE); |
| + |
| + // Gestures with four fingers should probably eventually be used for rare |
| + // needs that are hard to access through menus. |
| + // Note that brightness levels are here because they can be important for low |
| + // vision users. However, but none of these mappings are permanent. |
|
aboxhall
2014/08/05 23:43:41
nit: slightly awkward phrasing (however, but)
evy
2014/08/05 23:51:18
Done.
|
| + left_swipe_gestures_[4] = |
| + base::Bind(&TouchExplorationController::DispatchKeyWithFlags, |
| + base::Unretained(this), |
| + ui::VKEY_BRIGHTNESS_DOWN, |
| + ui::EF_NONE); |
| + right_swipe_gestures_[4] = |
| + base::Bind(&TouchExplorationController::DispatchKeyWithFlags, |
| + base::Unretained(this), |
| + VKEY_BRIGHTNESS_UP, |
| + ui::EF_NONE); |
| + up_swipe_gestures_[4] = |
| + base::Bind(&TouchExplorationController::DispatchKeyWithFlags, |
| + base::Unretained(this), |
| + VKEY_BROWSER_HOME, |
| + ui::EF_NONE); |
| + down_swipe_gestures_[4] = |
| + base::Bind(&TouchExplorationController::DispatchKeyWithFlags, |
| + base::Unretained(this), |
| + VKEY_BROWSER_REFRESH, |
| + ui::EF_NONE); |
| + |
| +} |
| + |
| } // namespace ui |