OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/chromeos/touch_exploration_controller.h" | 5 #include "ui/chromeos/touch_exploration_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/time/default_tick_clock.h" | 9 #include "base/time/default_tick_clock.h" |
10 #include "ui/aura/client/cursor_client.h" | 10 #include "ui/aura/client/cursor_client.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 : root_window_(root_window), | 36 : root_window_(root_window), |
37 delegate_(delegate), | 37 delegate_(delegate), |
38 state_(NO_FINGERS_DOWN), | 38 state_(NO_FINGERS_DOWN), |
39 event_handler_for_testing_(NULL), | 39 event_handler_for_testing_(NULL), |
40 gesture_provider_(this), | 40 gesture_provider_(this), |
41 prev_state_(NO_FINGERS_DOWN), | 41 prev_state_(NO_FINGERS_DOWN), |
42 VLOG_on_(true), | 42 VLOG_on_(true), |
43 tick_clock_(NULL) { | 43 tick_clock_(NULL) { |
44 CHECK(root_window); | 44 CHECK(root_window); |
45 root_window->GetHost()->GetEventSource()->AddEventRewriter(this); | 45 root_window->GetHost()->GetEventSource()->AddEventRewriter(this); |
46 InitializeSwipeClosures(); | |
46 } | 47 } |
47 | 48 |
48 TouchExplorationController::~TouchExplorationController() { | 49 TouchExplorationController::~TouchExplorationController() { |
49 root_window_->GetHost()->GetEventSource()->RemoveEventRewriter(this); | 50 root_window_->GetHost()->GetEventSource()->RemoveEventRewriter(this); |
50 } | 51 } |
51 | 52 |
52 ui::EventRewriteStatus TouchExplorationController::RewriteEvent( | 53 ui::EventRewriteStatus TouchExplorationController::RewriteEvent( |
53 const ui::Event& event, | 54 const ui::Event& event, |
54 scoped_ptr<ui::Event>* rewritten_event) { | 55 scoped_ptr<ui::Event>* rewritten_event) { |
55 if (!event.IsTouchEvent()) { | 56 if (!event.IsTouchEvent()) { |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 | 699 |
699 void TouchExplorationController::OnSwipeEvent(ui::GestureEvent* swipe_gesture) { | 700 void TouchExplorationController::OnSwipeEvent(ui::GestureEvent* swipe_gesture) { |
700 // A swipe gesture contains details for the direction in which the swipe | 701 // A swipe gesture contains details for the direction in which the swipe |
701 // occurred. TODO(evy) : Research which swipe results users most want and | 702 // occurred. TODO(evy) : Research which swipe results users most want and |
702 // remap these swipes to the best events. Hopefully in the near future | 703 // remap these swipes to the best events. Hopefully in the near future |
703 // there will also be a menu for users to pick custom mappings. | 704 // there will also be a menu for users to pick custom mappings. |
704 GestureEventDetails event_details = swipe_gesture->details(); | 705 GestureEventDetails event_details = swipe_gesture->details(); |
705 int num_fingers = event_details.touch_points(); | 706 int num_fingers = event_details.touch_points(); |
706 if(VLOG_on_) | 707 if(VLOG_on_) |
707 VLOG(0) << "\nSwipe with " << num_fingers << " fingers."; | 708 VLOG(0) << "\nSwipe with " << num_fingers << " fingers."; |
709 | |
708 if (num_fingers > 4) | 710 if (num_fingers > 4) |
709 return; | 711 return; |
710 switch (num_fingers) { | 712 |
711 case 1: | 713 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.
| |
712 if (event_details.swipe_left()) { | 714 left_swipe_gestures_[num_fingers].Run(); |
713 DispatchShiftSearchKeyEvent(ui::VKEY_LEFT); | 715 else if (event_details.swipe_right()) |
714 return; | 716 right_swipe_gestures_[num_fingers].Run(); |
715 } else if (event_details.swipe_right()) { | 717 else if (event_details.swipe_up()) |
716 DispatchShiftSearchKeyEvent(ui::VKEY_RIGHT); | 718 up_swipe_gestures_[num_fingers].Run(); |
717 return; | 719 else if (event_details.swipe_down()) |
718 } else if (event_details.swipe_up()) { | 720 down_swipe_gestures_[num_fingers].Run(); |
719 DispatchShiftSearchKeyEvent(ui::VKEY_UP); | |
720 return; | |
721 } else if (event_details.swipe_down()) { | |
722 DispatchShiftSearchKeyEvent(ui::VKEY_DOWN); | |
723 return; | |
724 } | |
725 case 2: | |
726 if (event_details.swipe_left()) { | |
727 DispatchKeyWithFlags(VKEY_BROWSER_BACK, ui::EF_NONE); | |
728 return; | |
729 } else if (event_details.swipe_right()) { | |
730 DispatchKeyWithFlags(VKEY_BROWSER_FORWARD, ui::EF_NONE); | |
731 return; | |
732 } else if (event_details.swipe_up()) { | |
733 DispatchShiftSearchKeyEvent(ui::VKEY_A); | |
734 return; | |
735 } else if (event_details.swipe_down()) { | |
736 DispatchShiftSearchKeyEvent(ui::VKEY_R); | |
737 return; | |
738 } | |
739 case 3: | |
740 if (event_details.swipe_left()) { | |
741 DispatchKeyWithFlags(ui::VKEY_TAB, | |
742 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); | |
743 } else if (event_details.swipe_right()) { | |
744 DispatchKeyWithFlags(ui::VKEY_TAB, ui::EF_CONTROL_DOWN); | |
745 } else if (event_details.swipe_up()) { | |
746 DispatchKeyWithFlags(ui::VKEY_NEXT, ui::EF_NONE); | |
747 return; | |
748 } else if (event_details.swipe_down()) { | |
749 DispatchKeyWithFlags(ui::VKEY_PRIOR, ui::EF_NONE); | |
750 return; | |
751 } | |
752 return; | |
753 case 4: | |
754 // Brightness can be important for low vision users, but none of these | |
755 // mappings are permanent. Four finger gestures should probably | |
756 // eventually be used for rare needs that are hard to access through | |
757 // menus. | |
758 if (event_details.swipe_left()) { | |
759 DispatchKeyWithFlags(VKEY_BRIGHTNESS_DOWN, ui::EF_NONE); | |
760 return; | |
761 } else if (event_details.swipe_right()) { | |
762 DispatchKeyWithFlags(VKEY_BRIGHTNESS_UP, ui::EF_NONE); | |
763 return; | |
764 } else if (event_details.swipe_up()) { | |
765 DispatchKeyWithFlags(VKEY_BROWSER_HOME, ui::EF_NONE); | |
766 return; | |
767 } else if (event_details.swipe_down()) { | |
768 DispatchKeyWithFlags(VKEY_BROWSER_REFRESH, ui::EF_NONE); | |
769 return; | |
770 } | |
771 } | |
772 return; | |
773 } | 721 } |
774 | 722 |
775 int TouchExplorationController::FindEdgesWithinBounds(gfx::Point point, | 723 int TouchExplorationController::FindEdgesWithinBounds(gfx::Point point, |
776 float bounds) { | 724 float bounds) { |
777 // Since GetBoundsInScreen is in DIPs but point is not, then point needs to be | 725 // Since GetBoundsInScreen is in DIPs but point is not, then point needs to be |
778 // converted. | 726 // converted. |
779 root_window_->GetHost()->ConvertPointFromNativeScreen(&point); | 727 root_window_->GetHost()->ConvertPointFromNativeScreen(&point); |
780 gfx::Rect window = root_window_->GetBoundsInScreen(); | 728 gfx::Rect window = root_window_->GetBoundsInScreen(); |
781 | 729 |
782 float left_edge_limit = window.x() + bounds; | 730 float left_edge_limit = window.x() + bounds; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
949 case ONE_FINGER_PASSTHROUGH: | 897 case ONE_FINGER_PASSTHROUGH: |
950 return "ONE_FINGER_PASSTHROUGH"; | 898 return "ONE_FINGER_PASSTHROUGH"; |
951 case WAIT_FOR_NO_FINGERS: | 899 case WAIT_FOR_NO_FINGERS: |
952 return "WAIT_FOR_NO_FINGERS"; | 900 return "WAIT_FOR_NO_FINGERS"; |
953 case SLIDE_GESTURE: | 901 case SLIDE_GESTURE: |
954 return "SLIDE_GESTURE"; | 902 return "SLIDE_GESTURE"; |
955 } | 903 } |
956 return "Not a state"; | 904 return "Not a state"; |
957 } | 905 } |
958 | 906 |
907 void TouchExplorationController::InitializeSwipeClosures() { | |
908 // Gestures with one finger are used for navigation. | |
909 left_swipe_gestures_[1] = | |
910 base::Bind(&TouchExplorationController::DispatchShiftSearchKeyEvent, | |
911 base::Unretained(this), | |
912 ui::VKEY_LEFT); | |
913 right_swipe_gestures_[1] = | |
914 base::Bind(&TouchExplorationController::DispatchShiftSearchKeyEvent, | |
915 base::Unretained(this), | |
916 ui::VKEY_RIGHT); | |
917 up_swipe_gestures_[1] = | |
918 base::Bind(&TouchExplorationController::DispatchShiftSearchKeyEvent, | |
919 base::Unretained(this), | |
920 ui::VKEY_UP); | |
921 down_swipe_gestures_[1] = | |
922 base::Bind(&TouchExplorationController::DispatchShiftSearchKeyEvent, | |
923 base::Unretained(this), | |
924 ui::VKEY_DOWN); | |
925 | |
926 // Gestures with two fingers. | |
927 left_swipe_gestures_[2] = | |
928 base::Bind(&TouchExplorationController::DispatchKeyWithFlags, | |
929 base::Unretained(this), | |
930 ui::VKEY_BROWSER_BACK, | |
931 ui::EF_NONE); | |
932 right_swipe_gestures_[2] = | |
933 base::Bind(&TouchExplorationController::DispatchKeyWithFlags, | |
934 base::Unretained(this), | |
935 ui::VKEY_BROWSER_FORWARD, | |
936 ui::EF_NONE); | |
937 // Jump to top. | |
938 up_swipe_gestures_[2] = | |
939 base::Bind(&TouchExplorationController::DispatchShiftSearchKeyEvent, | |
940 base::Unretained(this), | |
941 ui::VKEY_A); | |
942 // Read from here. | |
943 down_swipe_gestures_[2] = | |
944 base::Bind(&TouchExplorationController::DispatchShiftSearchKeyEvent, | |
945 base::Unretained(this), | |
946 ui::VKEY_R); | |
947 | |
948 // Gestures with three fingers switch tabs left/right and scroll up/down. | |
949 left_swipe_gestures_[3] = | |
950 base::Bind(&TouchExplorationController::DispatchKeyWithFlags, | |
951 base::Unretained(this), | |
952 ui::VKEY_TAB, | |
953 ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); | |
954 right_swipe_gestures_[3] = | |
955 base::Bind(&TouchExplorationController::DispatchKeyWithFlags, | |
956 base::Unretained(this), | |
957 ui::VKEY_TAB, | |
958 ui::EF_CONTROL_DOWN); | |
959 up_swipe_gestures_[3] = | |
960 base::Bind(&TouchExplorationController::DispatchKeyWithFlags, | |
961 base::Unretained(this), | |
962 ui::VKEY_NEXT, | |
963 ui::EF_NONE); | |
964 down_swipe_gestures_[3] = | |
965 base::Bind(&TouchExplorationController::DispatchKeyWithFlags, | |
966 base::Unretained(this), | |
967 ui::VKEY_PRIOR, | |
968 ui::EF_NONE); | |
969 | |
970 // Gestures with four fingers should probably eventually be used for rare | |
971 // needs that are hard to access through menus. | |
972 // Note that brightness levels are here because they can be important for low | |
973 // 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.
| |
974 left_swipe_gestures_[4] = | |
975 base::Bind(&TouchExplorationController::DispatchKeyWithFlags, | |
976 base::Unretained(this), | |
977 ui::VKEY_BRIGHTNESS_DOWN, | |
978 ui::EF_NONE); | |
979 right_swipe_gestures_[4] = | |
980 base::Bind(&TouchExplorationController::DispatchKeyWithFlags, | |
981 base::Unretained(this), | |
982 VKEY_BRIGHTNESS_UP, | |
983 ui::EF_NONE); | |
984 up_swipe_gestures_[4] = | |
985 base::Bind(&TouchExplorationController::DispatchKeyWithFlags, | |
986 base::Unretained(this), | |
987 VKEY_BROWSER_HOME, | |
988 ui::EF_NONE); | |
989 down_swipe_gestures_[4] = | |
990 base::Bind(&TouchExplorationController::DispatchKeyWithFlags, | |
991 base::Unretained(this), | |
992 VKEY_BROWSER_REFRESH, | |
993 ui::EF_NONE); | |
994 | |
995 } | |
996 | |
959 } // namespace ui | 997 } // namespace ui |
OLD | NEW |