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

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: Address jdduke comments. 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 : client_(client),
16 filtered_gesture_provider_(ui::DefaultGestureProviderConfig(), this) { 17 filtered_gesture_provider_(ui::DefaultGestureProviderConfig(), this) {
17 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false); 18 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false);
18 } 19 }
19 20
20 GestureProviderAura::~GestureProviderAura() {} 21 GestureProviderAura::~GestureProviderAura() {}
(...skipping 12 matching lines...) Expand all
33 // Ignore touch press events if we already believe the pointer is down. 34 // Ignore touch press events if we already believe the pointer is down.
34 return false; 35 return false;
35 } else if (event.type() != ET_TOUCH_PRESSED && !pointer_id_is_active) { 36 } 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 37 // 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 38 // move or touch up events without associated touch down events. Ignore
38 // them. 39 // them.
39 return false; 40 return false;
40 } 41 }
41 42
42 pointer_state_.OnTouch(event); 43 pointer_state_.OnTouch(event);
44
45 if (pointer_state_.GetAction() == MotionEvent::ACTION_DOWN) {
46 previous_down_event_ = current_down_event_.Pass();
47 current_down_event_ = pointer_state_.Clone();
48 }
49
43 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_); 50 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_);
44 pointer_state_.CleanupRemovedTouchPoints(event); 51 pointer_state_.CleanupRemovedTouchPoints(event);
45 return result; 52 return result;
46 } 53 }
47 54
48 void GestureProviderAura::OnTouchEventAck(bool event_consumed) { 55 void GestureProviderAura::OnTouchEventAck(bool event_consumed) {
49 filtered_gesture_provider_.OnTouchEventAck(event_consumed); 56 filtered_gesture_provider_.OnTouchEventAck(event_consumed);
50 } 57 }
51 58
52 void GestureProviderAura::OnGestureEvent( 59 void GestureProviderAura::OnGestureEvent(
53 const GestureEventData& gesture) { 60 const GestureEventData& gesture) {
61 GestureEventDetails details = gesture.details;
62
63 int tap_count = 1;
64 if (gesture.type == ET_GESTURE_TAP) {
65 if (previous_down_event_ && current_down_event_ &&
66 IsConsideredDoubleTap(
jdduke (slow) 2014/05/21 19:00:30 The reason I suggested just caching the tap detail
tdresser 2014/05/21 19:50:43 I hesitated because it does change the behavior (W
67 *previous_down_event_, previous_tap_->time, *current_down_event_)) {
68 tap_count = 1 + (previous_tap_->details.tap_count() % 3);
69 }
70 details = GestureEventDetails(ET_GESTURE_TAP, tap_count, 0);
71 previous_tap_.reset(new GestureEventData(gesture));
72 previous_tap_->details = details;
73 } else if (gesture.type == ET_GESTURE_TAP_CANCEL) {
74 previous_tap_.reset();
75 }
76
54 ui::GestureEvent event(gesture.type, 77 ui::GestureEvent event(gesture.type,
55 gesture.x, 78 gesture.x,
56 gesture.y, 79 gesture.y,
57 last_touch_event_flags_, 80 last_touch_event_flags_,
58 gesture.time - base::TimeTicks(), 81 gesture.time - base::TimeTicks(),
59 gesture.details, 82 details,
60 // ui::GestureEvent stores a bitfield indicating the 83 // ui::GestureEvent stores a bitfield indicating the
61 // ids of active touch points. This is currently only 84 // ids of active touch points. This is currently only
62 // used when one finger is down, and will eventually 85 // used when one finger is down, and will eventually
63 // be cleaned up. See crbug.com/366707. 86 // be cleaned up. See crbug.com/366707.
64 1 << gesture.motion_event_id); 87 1 << gesture.motion_event_id);
65 client_->OnGestureEvent(&event); 88 client_->OnGestureEvent(&event);
66 } 89 }
67 90
91 bool GestureProviderAura::IsConsideredDoubleTap(
92 const MotionEvent& previous_down,
93 const base::TimeTicks previous_tap_time,
94 const MotionEvent& current_down) const {
95 if (current_down.GetEventTime() - previous_tap_time >
96 base::TimeDelta::FromMilliseconds(
97 ui::GestureConfiguration::max_seconds_between_double_click() *
98 1000)) {
99 return false;
100 }
101
102 double double_tap_slop_square =
103 GestureConfiguration::max_distance_between_taps_for_double_tap();
104 double_tap_slop_square *= double_tap_slop_square;
105 const float delta_x = previous_down.GetX() - current_down.GetX();
106 const float delta_y = previous_down.GetY() - current_down.GetY();
107 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square);
108 }
109
68 } // namespace content 110 } // 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