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

Side by Side Diff: ui/events/gestures/gesture_provider_aura.cc

Issue 289373009: Support tap_count in ui::GestureProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move to GestureProviderAura. Created 6 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/events/gestures/gesture_provider_aura.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/events/gestures/gesture_provider_aura.h" 5 #include "ui/events/gestures/gesture_provider_aura.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/events/event.h" 8 #include "ui/events/event.h"
9 #include "ui/events/gesture_detection/gesture_config_helper.h" 9 #include "ui/events/gesture_detection/gesture_config_helper.h"
10 #include "ui/events/gesture_detection/gesture_event_data.h" 10 #include "ui/events/gesture_detection/gesture_event_data.h"
11 #include "ui/events/gestures/gesture_configuration.h"
11 12
12 namespace ui { 13 namespace ui {
13 14
14 GestureProviderAura::GestureProviderAura(GestureProviderAuraClient* client) 15 GestureProviderAura::GestureProviderAura(GestureProviderAuraClient* client)
15 : client_(client), 16 : tap_count_(0),
17 client_(client),
16 filtered_gesture_provider_(ui::DefaultGestureProviderConfig(), this) { 18 filtered_gesture_provider_(ui::DefaultGestureProviderConfig(), this) {
17 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false); 19 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false);
18 } 20 }
19 21
20 GestureProviderAura::~GestureProviderAura() {} 22 GestureProviderAura::~GestureProviderAura() {}
21 23
22 bool GestureProviderAura::OnTouchEvent(const TouchEvent& event) { 24 bool GestureProviderAura::OnTouchEvent(const TouchEvent& event) {
23 last_touch_event_flags_ = event.flags(); 25 last_touch_event_flags_ = event.flags();
24 bool pointer_id_is_active = false; 26 bool pointer_id_is_active = false;
25 for (size_t i = 0; i < pointer_state_.GetPointerCount(); ++i) { 27 for (size_t i = 0; i < pointer_state_.GetPointerCount(); ++i) {
26 if (event.touch_id() != pointer_state_.GetPointerId(i)) 28 if (event.touch_id() != pointer_state_.GetPointerId(i))
27 continue; 29 continue;
28 pointer_id_is_active = true; 30 pointer_id_is_active = true;
29 break; 31 break;
30 } 32 }
31 33
32 if (event.type() == ET_TOUCH_PRESSED && pointer_id_is_active) { 34 if (event.type() == ET_TOUCH_PRESSED && pointer_id_is_active) {
33 // Ignore touch press events if we already believe the pointer is down. 35 // Ignore touch press events if we already believe the pointer is down.
34 return false; 36 return false;
35 } else if (event.type() != ET_TOUCH_PRESSED && !pointer_id_is_active) { 37 } else if (event.type() != ET_TOUCH_PRESSED && !pointer_id_is_active) {
36 // We could have an active touch stream transfered to us, resulting in touch 38 // We could have an active touch stream transfered to us, resulting in touch
37 // move or touch up events without associated touch down events. Ignore 39 // move or touch up events without associated touch down events. Ignore
38 // them. 40 // them.
39 return false; 41 return false;
40 } 42 }
41 43
42 pointer_state_.OnTouch(event); 44 pointer_state_.OnTouch(event);
45
46 if (pointer_state_.GetAction() == MotionEvent::ACTION_DOWN) {
47 previous_down_event_ = current_down_event_.Pass();
48 current_down_event_ = pointer_state_.Clone();
49 }
50
43 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_); 51 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_);
44 pointer_state_.CleanupRemovedTouchPoints(event); 52 pointer_state_.CleanupRemovedTouchPoints(event);
45 return result; 53 return result;
46 } 54 }
47 55
48 void GestureProviderAura::OnTouchEventAck(bool event_consumed) { 56 void GestureProviderAura::OnTouchEventAck(bool event_consumed) {
49 filtered_gesture_provider_.OnTouchEventAck(event_consumed); 57 filtered_gesture_provider_.OnTouchEventAck(event_consumed);
50 } 58 }
51 59
52 void GestureProviderAura::OnGestureEvent( 60 void GestureProviderAura::OnGestureEvent(
53 const GestureEventData& gesture) { 61 const GestureEventData& gesture) {
62 const GestureEventDetails* details = &gesture.details;
63 scoped_ptr<GestureEventDetails> tap_details;
tdresser 2014/05/21 16:39:16 Do you have any other ideas on how to avoid constr
jdduke (slow) 2014/05/21 17:21:48 Hmm, yeah, the details object is pretty small, mig
tdresser 2014/05/21 18:47:49 Done.
64
65 if (gesture.type == ET_GESTURE_TAP) {
66 if (previous_down_event_ && current_down_event_ &&
67 IsConsideredDoubleTap(
68 *previous_down_event_, previous_tap_time_, *current_down_event_)) {
69 tap_count_ = 1 + (tap_count_ % 3);
70 } else {
71 tap_count_ = 1;
72 }
73 tap_details.reset(new GestureEventDetails(ET_GESTURE_TAP, tap_count_, 0));
74 details = tap_details.get();
75 previous_tap_time_ = gesture.time;
76 } else if (gesture.type == ET_GESTURE_TAP_CANCEL) {
77 tap_count_ = 0;
78 }
79
54 ui::GestureEvent event(gesture.type, 80 ui::GestureEvent event(gesture.type,
55 gesture.x, 81 gesture.x,
56 gesture.y, 82 gesture.y,
57 last_touch_event_flags_, 83 last_touch_event_flags_,
58 gesture.time - base::TimeTicks(), 84 gesture.time - base::TimeTicks(),
59 gesture.details, 85 *details,
60 // ui::GestureEvent stores a bitfield indicating the 86 // ui::GestureEvent stores a bitfield indicating the
61 // ids of active touch points. This is currently only 87 // ids of active touch points. This is currently only
62 // used when one finger is down, and will eventually 88 // used when one finger is down, and will eventually
63 // be cleaned up. See crbug.com/366707. 89 // be cleaned up. See crbug.com/366707.
64 1 << gesture.motion_event_id); 90 1 << gesture.motion_event_id);
65 client_->OnGestureEvent(&event); 91 client_->OnGestureEvent(&event);
66 } 92 }
67 93
94 bool GestureProviderAura::IsConsideredDoubleTap(
95 const MotionEvent& previous_down,
96 const base::TimeTicks previous_tap_time,
jdduke (slow) 2014/05/21 17:21:48 Hmm, could we just store the previous_tap_event_?
tdresser 2014/05/21 18:47:49 Done, with a scoped_ptr.
97 const MotionEvent& current_down) const {
98 if (current_down.GetEventTime() - previous_tap_time >
99 base::TimeDelta::FromMilliseconds(
100 ui::GestureConfiguration::max_seconds_between_double_click() *
101 1000)) {
102 return false;
103 }
104
105 double double_tap_slop_square =
106 GestureConfiguration::max_distance_between_taps_for_double_tap();
107 double_tap_slop_square *= double_tap_slop_square;
108 const float delta_x = previous_down.GetX() - current_down.GetX();
109 const float delta_y = previous_down.GetY() - current_down.GetY();
110 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square);
111 }
112
68 } // namespace content 113 } // namespace content
OLDNEW
« no previous file with comments | « ui/events/gestures/gesture_provider_aura.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698