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 "ui/aura/client/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
11 #include "ui/aura/window_event_dispatcher.h" | 11 #include "ui/aura/window_event_dispatcher.h" |
12 #include "ui/aura/window_tree_host.h" | 12 #include "ui/aura/window_tree_host.h" |
13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
14 #include "ui/events/event_processor.h" | 14 #include "ui/events/event_processor.h" |
15 #include "ui/events/event_utils.h" | 15 #include "ui/events/event_utils.h" |
16 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
17 | 17 |
18 #define VLOG_STATE() if (VLOG_IS_ON(0)) VlogState(__func__) | 18 #define VLOG_STATE() if (VLOG_IS_ON(0)) VlogState(__func__) |
19 #define VLOG_EVENT(event) if (VLOG_IS_ON(0)) VlogEvent(event, __func__) | 19 #define VLOG_EVENT(event) if (VLOG_IS_ON(0)) VlogEvent(event, __func__) |
20 | 20 |
21 namespace ui { | 21 namespace ui { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // Delay between adjustment sounds. | 25 // Delay between adjustment sounds. |
26 const base::TimeDelta kSoundDelay = base::TimeDelta::FromMilliseconds(150); | 26 const base::TimeDelta kSoundDelay = base::TimeDelta::FromMilliseconds(150); |
27 | 27 |
28 // In ChromeOS, VKEY_LWIN is synonymous for the search key. | 28 // In ChromeOS, VKEY_LWIN is synonymous for the search key. |
29 const ui::KeyboardCode kChromeOSSearchKey = ui::VKEY_LWIN; | 29 const ui::KeyboardCode kChromeOSSearchKey = ui::VKEY_LWIN; |
30 | |
31 // Delay to indicate that a two finger tap has occured. | |
32 const base::TimeDelta kTwoFingerTap = base::TimeDelta::FromMilliseconds(50); | |
33 | |
30 } // namespace | 34 } // namespace |
31 | 35 |
32 TouchExplorationController::TouchExplorationController( | 36 TouchExplorationController::TouchExplorationController( |
33 aura::Window* root_window, | 37 aura::Window* root_window, |
34 TouchExplorationControllerDelegate* delegate) | 38 TouchExplorationControllerDelegate* delegate) |
35 : root_window_(root_window), | 39 : root_window_(root_window), |
36 delegate_(delegate), | 40 delegate_(delegate), |
37 state_(NO_FINGERS_DOWN), | 41 state_(NO_FINGERS_DOWN), |
38 gesture_provider_(this), | 42 gesture_provider_(this), |
39 prev_state_(NO_FINGERS_DOWN), | 43 prev_state_(NO_FINGERS_DOWN), |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 case GESTURE_IN_PROGRESS: | 131 case GESTURE_IN_PROGRESS: |
128 return InGestureInProgress(touch_event, rewritten_event); | 132 return InGestureInProgress(touch_event, rewritten_event); |
129 case TOUCH_EXPLORE_SECOND_PRESS: | 133 case TOUCH_EXPLORE_SECOND_PRESS: |
130 return InTouchExploreSecondPress(touch_event, rewritten_event); | 134 return InTouchExploreSecondPress(touch_event, rewritten_event); |
131 case SLIDE_GESTURE: | 135 case SLIDE_GESTURE: |
132 return InSlideGesture(touch_event, rewritten_event); | 136 return InSlideGesture(touch_event, rewritten_event); |
133 case ONE_FINGER_PASSTHROUGH: | 137 case ONE_FINGER_PASSTHROUGH: |
134 return InOneFingerPassthrough(touch_event, rewritten_event); | 138 return InOneFingerPassthrough(touch_event, rewritten_event); |
135 case WAIT_FOR_ONE_FINGER: | 139 case WAIT_FOR_ONE_FINGER: |
136 return InWaitForOneFinger(touch_event, rewritten_event); | 140 return InWaitForOneFinger(touch_event, rewritten_event); |
141 case TWO_FINGER_TAP: | |
142 return InTwoFingerTap(touch_event, rewritten_event); | |
137 } | 143 } |
138 NOTREACHED(); | 144 NOTREACHED(); |
139 return ui::EVENT_REWRITE_CONTINUE; | 145 return ui::EVENT_REWRITE_CONTINUE; |
140 } | 146 } |
141 | 147 |
142 ui::EventRewriteStatus TouchExplorationController::NextDispatchEvent( | 148 ui::EventRewriteStatus TouchExplorationController::NextDispatchEvent( |
143 const ui::Event& last_event, scoped_ptr<ui::Event>* new_event) { | 149 const ui::Event& last_event, scoped_ptr<ui::Event>* new_event) { |
144 NOTREACHED(); | 150 NOTREACHED(); |
145 return ui::EVENT_REWRITE_CONTINUE; | 151 return ui::EVENT_REWRITE_CONTINUE; |
146 } | 152 } |
(...skipping 14 matching lines...) Expand all Loading... | |
161 } | 167 } |
162 NOTREACHED() << "Unexpected event type received: " << event.name(); | 168 NOTREACHED() << "Unexpected event type received: " << event.name(); |
163 return ui::EVENT_REWRITE_CONTINUE; | 169 return ui::EVENT_REWRITE_CONTINUE; |
164 } | 170 } |
165 | 171 |
166 ui::EventRewriteStatus TouchExplorationController::InSingleTapPressed( | 172 ui::EventRewriteStatus TouchExplorationController::InSingleTapPressed( |
167 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { | 173 const ui::TouchEvent& event, scoped_ptr<ui::Event>* rewritten_event) { |
168 const ui::EventType type = event.type(); | 174 const ui::EventType type = event.type(); |
169 | 175 |
170 if (type == ui::ET_TOUCH_PRESSED) { | 176 if (type == ui::ET_TOUCH_PRESSED) { |
177 if ((event.time_stamp() - initial_press_->time_stamp()) < kTwoFingerTap) { | |
178 state_ = TWO_FINGER_TAP; | |
179 VLOG_STATE(); | |
180 return EVENT_REWRITE_DISCARD; | |
aboxhall
2014/08/06 18:30:00
Does this have any implications for multi-finger s
lisayin
2014/08/06 20:41:35
Once we need to merge the two, we'll have a slop c
| |
181 } | |
171 // TODO (evy, lisayin) : add support for multifinger swipes. | 182 // TODO (evy, lisayin) : add support for multifinger swipes. |
172 // For now, we wait for there to be only one finger down again. | 183 // For now, we wait for there to be only one finger down again. |
173 state_ = WAIT_FOR_ONE_FINGER; | 184 state_ = WAIT_FOR_ONE_FINGER; |
174 return EVENT_REWRITE_DISCARD; | 185 return EVENT_REWRITE_DISCARD; |
175 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { | 186 } else if (type == ui::ET_TOUCH_RELEASED || type == ui::ET_TOUCH_CANCELLED) { |
176 if (current_touch_ids_.size() == 0 && | 187 if (current_touch_ids_.size() == 0 && |
177 event.touch_id() == initial_press_->touch_id()) { | 188 event.touch_id() == initial_press_->touch_id()) { |
178 state_ = SINGLE_TAP_RELEASED; | 189 state_ = SINGLE_TAP_RELEASED; |
179 VLOG_STATE(); | 190 VLOG_STATE(); |
180 } else if (current_touch_ids_.size() == 0) { | 191 } else if (current_touch_ids_.size() == 0) { |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
542 if (current_touch_ids_.size() == 0) { | 553 if (current_touch_ids_.size() == 0) { |
543 ResetToNoFingersDown(); | 554 ResetToNoFingersDown(); |
544 } | 555 } |
545 return ui::EVENT_REWRITE_DISCARD; | 556 return ui::EVENT_REWRITE_DISCARD; |
546 } | 557 } |
547 | 558 |
548 ProcessGestureEvents(); | 559 ProcessGestureEvents(); |
549 return ui::EVENT_REWRITE_DISCARD; | 560 return ui::EVENT_REWRITE_DISCARD; |
550 } | 561 } |
551 | 562 |
563 ui::EventRewriteStatus TouchExplorationController::InTwoFingerTap( | |
564 const ui::TouchEvent& event, | |
565 scoped_ptr<ui::Event>* rewritten_event) { | |
566 ui::EventType type = event.type(); | |
567 if (type == ui::ET_TOUCH_PRESSED) { | |
aboxhall
2014/08/06 18:30:00
And, does this have any implications for multi-fin
evy
2014/08/06 18:33:03
Yeah, whoever finishes last gets to add the change
| |
568 state_ = WAIT_FOR_ONE_FINGER; | |
569 VLOG_STATE(); | |
570 return ui::EVENT_REWRITE_DISCARD; | |
571 } | |
572 | |
573 if (current_touch_ids_.size() != 0) | |
574 return ui::EVENT_REWRITE_DISCARD; | |
575 | |
576 if (type == ui::ET_TOUCH_RELEASED) { | |
577 ui::KeyEvent control_down( | |
578 ui::ET_KEY_PRESSED, ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN); | |
579 ui::KeyEvent control_up(ui::ET_KEY_RELEASED, ui::VKEY_CONTROL, ui::EF_NONE); | |
580 | |
581 DispatchEvent(&control_down); | |
582 DispatchEvent(&control_up); | |
583 | |
584 ResetToNoFingersDown(); | |
585 return ui::EVENT_REWRITE_DISCARD; | |
586 } | |
587 return ui::EVENT_REWRITE_DISCARD; | |
588 } | |
589 | |
552 base::TimeDelta TouchExplorationController::Now() { | 590 base::TimeDelta TouchExplorationController::Now() { |
553 if (tick_clock_) { | 591 if (tick_clock_) { |
554 // This is the same as what EventTimeForNow() does, but here we do it | 592 // This is the same as what EventTimeForNow() does, but here we do it |
555 // with a clock that can be replaced with a simulated clock for tests. | 593 // with a clock that can be replaced with a simulated clock for tests. |
556 return base::TimeDelta::FromInternalValue( | 594 return base::TimeDelta::FromInternalValue( |
557 tick_clock_->NowTicks().ToInternalValue()); | 595 tick_clock_->NowTicks().ToInternalValue()); |
558 } | 596 } |
559 return ui::EventTimeForNow(); | 597 return ui::EventTimeForNow(); |
560 } | 598 } |
561 | 599 |
(...skipping 26 matching lines...) Expand all Loading... | |
588 DispatchEvent(passthrough_press.get()); | 626 DispatchEvent(passthrough_press.get()); |
589 return; | 627 return; |
590 } | 628 } |
591 case SINGLE_TAP_PRESSED: | 629 case SINGLE_TAP_PRESSED: |
592 case GESTURE_IN_PROGRESS: | 630 case GESTURE_IN_PROGRESS: |
593 // Discard any pending gestures. | 631 // Discard any pending gestures. |
594 delete gesture_provider_.GetAndResetPendingGestures(); | 632 delete gesture_provider_.GetAndResetPendingGestures(); |
595 state_ = TOUCH_EXPLORATION; | 633 state_ = TOUCH_EXPLORATION; |
596 VLOG_STATE(); | 634 VLOG_STATE(); |
597 break; | 635 break; |
636 case TWO_FINGER_TAP: | |
637 state_ = WAIT_FOR_ONE_FINGER; | |
638 VLOG_STATE(); | |
639 break; | |
598 default: | 640 default: |
599 return; | 641 return; |
600 } | 642 } |
601 EnterTouchToMouseMode(); | 643 EnterTouchToMouseMode(); |
602 scoped_ptr<ui::Event> mouse_move = | 644 scoped_ptr<ui::Event> mouse_move = |
603 CreateMouseMoveEvent(initial_press_->location(), initial_press_->flags()); | 645 CreateMouseMoveEvent(initial_press_->location(), initial_press_->flags()); |
604 DispatchEvent(mouse_move.get()); | 646 DispatchEvent(mouse_move.get()); |
605 last_touch_exploration_.reset(new TouchEvent(*initial_press_)); | 647 last_touch_exploration_.reset(new TouchEvent(*initial_press_)); |
606 } | 648 } |
607 | 649 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 case GESTURE_IN_PROGRESS: | 910 case GESTURE_IN_PROGRESS: |
869 return "GESTURE_IN_PROGRESS"; | 911 return "GESTURE_IN_PROGRESS"; |
870 case TOUCH_EXPLORE_SECOND_PRESS: | 912 case TOUCH_EXPLORE_SECOND_PRESS: |
871 return "TOUCH_EXPLORE_SECOND_PRESS"; | 913 return "TOUCH_EXPLORE_SECOND_PRESS"; |
872 case SLIDE_GESTURE: | 914 case SLIDE_GESTURE: |
873 return "SLIDE_GESTURE"; | 915 return "SLIDE_GESTURE"; |
874 case ONE_FINGER_PASSTHROUGH: | 916 case ONE_FINGER_PASSTHROUGH: |
875 return "ONE_FINGER_PASSTHROUGH"; | 917 return "ONE_FINGER_PASSTHROUGH"; |
876 case WAIT_FOR_ONE_FINGER: | 918 case WAIT_FOR_ONE_FINGER: |
877 return "WAIT_FOR_ONE_FINGER"; | 919 return "WAIT_FOR_ONE_FINGER"; |
920 case TWO_FINGER_TAP: | |
921 return "TWO_FINGER_TAP"; | |
878 } | 922 } |
879 return "Not a state"; | 923 return "Not a state"; |
880 } | 924 } |
881 | 925 |
882 } // namespace ui | 926 } // namespace ui |
OLD | NEW |