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/events/gestures/gesture_provider_aura.h" | 5 #include "ui/events/gestures/gesture_provider_aura.h" |
6 | 6 |
7 #include "base/auto_reset.h" | |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
9 #include "ui/events/gesture_detection/gesture_config_helper.h" | 10 #include "ui/events/gesture_detection/gesture_config_helper.h" |
10 #include "ui/events/gesture_detection/gesture_event_data.h" | 11 #include "ui/events/gesture_detection/gesture_event_data.h" |
11 #include "ui/events/gestures/gesture_configuration.h" | 12 #include "ui/events/gestures/gesture_configuration.h" |
12 | 13 |
13 namespace ui { | 14 namespace ui { |
14 | 15 |
15 GestureProviderAura::GestureProviderAura(GestureProviderAuraClient* client) | 16 GestureProviderAura::GestureProviderAura(GestureProviderAuraClient* client) |
16 : client_(client), | 17 : client_(client), |
17 filtered_gesture_provider_(ui::DefaultGestureProviderConfig(), this) { | 18 filtered_gesture_provider_(ui::DefaultGestureProviderConfig(), this), |
19 handling_event_(false) { | |
18 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false); | 20 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false); |
19 } | 21 } |
20 | 22 |
21 GestureProviderAura::~GestureProviderAura() {} | 23 GestureProviderAura::~GestureProviderAura() {} |
22 | 24 |
23 bool GestureProviderAura::OnTouchEvent(const TouchEvent& event) { | 25 bool GestureProviderAura::OnTouchEvent(const TouchEvent& event) { |
24 last_touch_event_flags_ = event.flags(); | 26 last_touch_event_flags_ = event.flags(); |
25 bool pointer_id_is_active = false; | 27 bool pointer_id_is_active = false; |
26 for (size_t i = 0; i < pointer_state_.GetPointerCount(); ++i) { | 28 for (size_t i = 0; i < pointer_state_.GetPointerCount(); ++i) { |
27 if (event.touch_id() != pointer_state_.GetPointerId(i)) | 29 if (event.touch_id() != pointer_state_.GetPointerId(i)) |
(...skipping 13 matching lines...) Expand all Loading... | |
41 } | 43 } |
42 | 44 |
43 pointer_state_.OnTouch(event); | 45 pointer_state_.OnTouch(event); |
44 | 46 |
45 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_); | 47 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_); |
46 pointer_state_.CleanupRemovedTouchPoints(event); | 48 pointer_state_.CleanupRemovedTouchPoints(event); |
47 return result; | 49 return result; |
48 } | 50 } |
49 | 51 |
50 void GestureProviderAura::OnTouchEventAck(bool event_consumed) { | 52 void GestureProviderAura::OnTouchEventAck(bool event_consumed) { |
53 DCHECK(pending_gestures_.empty()); | |
54 DCHECK(!handling_event_); | |
55 base::AutoReset<bool> handling_event(&handling_event_, true); | |
51 filtered_gesture_provider_.OnTouchEventAck(event_consumed); | 56 filtered_gesture_provider_.OnTouchEventAck(event_consumed); |
52 } | 57 } |
53 | 58 |
54 void GestureProviderAura::OnGestureEvent( | 59 void GestureProviderAura::OnGestureEvent( |
55 const GestureEventData& gesture) { | 60 const GestureEventData& gesture) { |
56 GestureEventDetails details = gesture.details; | 61 GestureEventDetails details = gesture.details; |
57 | 62 |
58 if (gesture.type == ET_GESTURE_TAP) { | 63 if (gesture.type == ET_GESTURE_TAP) { |
59 int tap_count = 1; | 64 int tap_count = 1; |
60 if (previous_tap_ && IsConsideredDoubleTap(*previous_tap_, gesture)) | 65 if (previous_tap_ && IsConsideredDoubleTap(*previous_tap_, gesture)) |
61 tap_count = 1 + (previous_tap_->details.tap_count() % 3); | 66 tap_count = 1 + (previous_tap_->details.tap_count() % 3); |
62 details.set_tap_count(tap_count); | 67 details.set_tap_count(tap_count); |
63 if (!previous_tap_) | 68 if (!previous_tap_) |
64 previous_tap_.reset(new GestureEventData(gesture)); | 69 previous_tap_.reset(new GestureEventData(gesture)); |
65 else | 70 else |
66 *previous_tap_ = gesture; | 71 *previous_tap_ = gesture; |
67 previous_tap_->details = details; | 72 previous_tap_->details = details; |
68 } else if (gesture.type == ET_GESTURE_TAP_CANCEL) { | 73 } else if (gesture.type == ET_GESTURE_TAP_CANCEL) { |
69 previous_tap_.reset(); | 74 previous_tap_.reset(); |
70 } | 75 } |
71 | 76 |
72 ui::GestureEvent event(gesture.type, | 77 // Memory either deleted explicitly, if |!handling_event_|, or managed by |
73 gesture.x, | 78 // pending_gestures_. |
74 gesture.y, | 79 ui::GestureEvent* event = |
jdduke (slow)
2014/05/28 16:26:00
Let's use scoped_ptr<ui::GestureEvent> if we absol
tdresser
2014/05/29 14:26:21
We need to return a ScopedVector of GestureEvents
| |
75 last_touch_event_flags_, | 80 new ui::GestureEvent(gesture.type, |
76 gesture.time - base::TimeTicks(), | 81 gesture.x, |
77 details, | 82 gesture.y, |
78 // ui::GestureEvent stores a bitfield indicating the | 83 last_touch_event_flags_, |
79 // ids of active touch points. This is currently only | 84 gesture.time - base::TimeTicks(), |
80 // used when one finger is down, and will eventually | 85 details, |
81 // be cleaned up. See crbug.com/366707. | 86 // ui::GestureEvent stores a bitfield indicating the |
82 1 << gesture.motion_event_id); | 87 // ids of active touch points. This is currently only |
83 client_->OnGestureEvent(&event); | 88 // used when one finger is down, and will eventually |
89 // be cleaned up. See crbug.com/366707. | |
90 1 << gesture.motion_event_id); | |
91 | |
92 if (!handling_event_) { | |
93 // Dispatching event caused by timer. | |
94 client_->OnGestureEvent(event); | |
95 delete event; | |
96 } else { | |
97 // Memory managed by ScopedVector pending_gestures_. | |
98 pending_gestures_.push_back(event); | |
99 } | |
100 } | |
101 | |
102 ScopedVector<GestureEvent>* GestureProviderAura::GetAndResetPendingGestures() { | |
103 // Caller is responsible for deleting old_pending_gestures. | |
104 ScopedVector<GestureEvent>* old_pending_gestures = | |
105 new ScopedVector<GestureEvent>(); | |
106 old_pending_gestures->swap(pending_gestures_); | |
107 return old_pending_gestures; | |
84 } | 108 } |
85 | 109 |
86 bool GestureProviderAura::IsConsideredDoubleTap( | 110 bool GestureProviderAura::IsConsideredDoubleTap( |
87 const GestureEventData& previous_tap, | 111 const GestureEventData& previous_tap, |
88 const GestureEventData& current_tap) const { | 112 const GestureEventData& current_tap) const { |
89 if (current_tap.time - previous_tap.time > | 113 if (current_tap.time - previous_tap.time > |
90 base::TimeDelta::FromMilliseconds( | 114 base::TimeDelta::FromMilliseconds( |
91 ui::GestureConfiguration::max_seconds_between_double_click() * | 115 ui::GestureConfiguration::max_seconds_between_double_click() * |
92 1000)) { | 116 1000)) { |
93 return false; | 117 return false; |
94 } | 118 } |
95 | 119 |
96 double double_tap_slop_square = | 120 double double_tap_slop_square = |
97 GestureConfiguration::max_distance_between_taps_for_double_tap(); | 121 GestureConfiguration::max_distance_between_taps_for_double_tap(); |
98 double_tap_slop_square *= double_tap_slop_square; | 122 double_tap_slop_square *= double_tap_slop_square; |
99 const float delta_x = previous_tap.x - current_tap.x; | 123 const float delta_x = previous_tap.x - current_tap.x; |
100 const float delta_y = previous_tap.y - current_tap.y; | 124 const float delta_y = previous_tap.y - current_tap.y; |
101 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square); | 125 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square); |
102 } | 126 } |
103 | 127 |
104 } // namespace content | 128 } // namespace content |
OLD | NEW |