OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/touch/touch_uma.h" | 5 #include "ash/touch/touch_uma.h" |
6 | 6 |
7 #include "ash/metrics/user_metrics_recorder.h" | 7 #include "ash/metrics/user_metrics_recorder.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "ui/aura/env.h" | 11 #include "ui/aura/env.h" |
12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
13 #include "ui/aura/window_event_dispatcher.h" | 13 #include "ui/aura/window_event_dispatcher.h" |
14 #include "ui/aura/window_property.h" | 14 #include "ui/aura/window_property.h" |
15 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
16 #include "ui/events/event_utils.h" | 16 #include "ui/events/event_utils.h" |
17 #include "ui/gfx/point_conversions.h" | 17 #include "ui/gfx/point_conversions.h" |
18 | 18 |
19 #if defined(USE_XI2_MT) | 19 #if defined(USE_XI2_MT) |
20 #include <X11/extensions/XInput2.h> | 20 #include <X11/extensions/XInput2.h> |
21 #include <X11/Xlib.h> | 21 #include <X11/Xlib.h> |
22 #endif | 22 #endif |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 enum UMAEventType { | |
27 // WARNING: Do not change the numerical values of any of these types. | |
28 // Do not remove deprecated types - just comment them as deprecated. | |
29 UMA_ET_UNKNOWN = 0, | |
30 UMA_ET_TOUCH_RELEASED = 1, | |
31 UMA_ET_TOUCH_PRESSED = 2, | |
32 UMA_ET_TOUCH_MOVED = 3, | |
33 UMA_ET_TOUCH_STATIONARY = 4, // Deprecated. Do not remove. | |
34 UMA_ET_TOUCH_CANCELLED = 5, | |
35 UMA_ET_GESTURE_SCROLL_BEGIN = 6, | |
36 UMA_ET_GESTURE_SCROLL_END = 7, | |
37 UMA_ET_GESTURE_SCROLL_UPDATE = 8, | |
38 UMA_ET_GESTURE_TAP = 9, | |
39 UMA_ET_GESTURE_TAP_DOWN = 10, | |
40 UMA_ET_GESTURE_BEGIN = 11, | |
41 UMA_ET_GESTURE_END = 12, | |
42 UMA_ET_GESTURE_DOUBLE_TAP = 13, | |
43 UMA_ET_GESTURE_TRIPLE_TAP = 14, | |
44 UMA_ET_GESTURE_TWO_FINGER_TAP = 15, | |
45 UMA_ET_GESTURE_PINCH_BEGIN = 16, | |
46 UMA_ET_GESTURE_PINCH_END = 17, | |
47 UMA_ET_GESTURE_PINCH_UPDATE = 18, | |
48 UMA_ET_GESTURE_LONG_PRESS = 19, | |
49 UMA_ET_GESTURE_SWIPE_2 = 20, // Swipe with 2 fingers | |
50 UMA_ET_SCROLL = 21, | |
51 UMA_ET_SCROLL_FLING_START = 22, | |
52 UMA_ET_SCROLL_FLING_CANCEL = 23, | |
53 UMA_ET_GESTURE_SWIPE_3 = 24, // Swipe with 3 fingers | |
54 UMA_ET_GESTURE_SWIPE_4P = 25, // Swipe with 4+ fingers | |
55 UMA_ET_GESTURE_SCROLL_UPDATE_2 = 26, | |
56 UMA_ET_GESTURE_SCROLL_UPDATE_3 = 27, | |
57 UMA_ET_GESTURE_SCROLL_UPDATE_4P = 28, | |
58 UMA_ET_GESTURE_PINCH_UPDATE_3 = 29, | |
59 UMA_ET_GESTURE_PINCH_UPDATE_4P = 30, | |
60 UMA_ET_GESTURE_LONG_TAP = 31, | |
61 UMA_ET_GESTURE_SHOW_PRESS = 32, | |
62 UMA_ET_GESTURE_TAP_CANCEL = 33, | |
63 UMA_ET_GESTURE_WIN8_EDGE_SWIPE = 34, | |
64 UMA_ET_GESTURE_SWIPE_1 = 35, // Swipe with 1 finger | |
65 // NOTE: Add new event types only immediately above this line. Make sure to | |
66 // update the UIEventType enum in tools/metrics/histograms/histograms.xml | |
67 // accordingly. | |
68 UMA_ET_COUNT | |
69 }; | |
70 | |
71 struct WindowTouchDetails { | 26 struct WindowTouchDetails { |
72 WindowTouchDetails() | |
73 : max_distance_from_start_squared_(0) { | |
74 } | |
75 | |
76 // Move and start times of the touch points. The key is the touch-id. | 27 // Move and start times of the touch points. The key is the touch-id. |
77 std::map<int, base::TimeDelta> last_move_time_; | 28 std::map<int, base::TimeDelta> last_move_time_; |
78 std::map<int, base::TimeDelta> last_start_time_; | 29 std::map<int, base::TimeDelta> last_start_time_; |
79 | 30 |
80 // The first and last positions of the touch points. | 31 // The first and last positions of the touch points. |
81 std::map<int, gfx::Point> start_touch_position_; | 32 std::map<int, gfx::Point> start_touch_position_; |
82 std::map<int, gfx::Point> last_touch_position_; | 33 std::map<int, gfx::Point> last_touch_position_; |
83 | 34 |
84 // The maximum distance the first touch point travelled from its starting | |
85 // location in pixels. | |
86 float max_distance_from_start_squared_; | |
87 | |
88 // Last time-stamp of the last touch-end event. | 35 // Last time-stamp of the last touch-end event. |
89 base::TimeDelta last_release_time_; | 36 base::TimeDelta last_release_time_; |
90 | 37 |
91 // Stores the time of the last touch released on this window (if there was a | 38 // Stores the time of the last touch released on this window (if there was a |
92 // multi-touch gesture on the window, then this is the release-time of the | 39 // multi-touch gesture on the window, then this is the release-time of the |
93 // last touch on the window). | 40 // last touch on the window). |
94 base::TimeDelta last_mt_time_; | 41 base::TimeDelta last_mt_time_; |
95 }; | 42 }; |
96 | 43 |
97 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowTouchDetails, | 44 DEFINE_OWNED_WINDOW_PROPERTY_KEY(WindowTouchDetails, |
98 kWindowTouchDetails, | 45 kWindowTouchDetails, |
99 NULL); | 46 NULL); |
100 | |
101 | |
102 UMAEventType UMAEventTypeFromEvent(const ui::Event& event) { | |
103 switch (event.type()) { | |
104 case ui::ET_TOUCH_RELEASED: | |
105 return UMA_ET_TOUCH_RELEASED; | |
106 case ui::ET_TOUCH_PRESSED: | |
107 return UMA_ET_TOUCH_PRESSED; | |
108 case ui::ET_TOUCH_MOVED: | |
109 return UMA_ET_TOUCH_MOVED; | |
110 case ui::ET_TOUCH_CANCELLED: | |
111 return UMA_ET_TOUCH_CANCELLED; | |
112 case ui::ET_GESTURE_SCROLL_BEGIN: | |
113 return UMA_ET_GESTURE_SCROLL_BEGIN; | |
114 case ui::ET_GESTURE_SCROLL_END: | |
115 return UMA_ET_GESTURE_SCROLL_END; | |
116 case ui::ET_GESTURE_SCROLL_UPDATE: { | |
117 const ui::GestureEvent& gesture = | |
118 static_cast<const ui::GestureEvent&>(event); | |
119 if (gesture.details().touch_points() == 1) | |
120 return UMA_ET_GESTURE_SCROLL_UPDATE; | |
121 else if (gesture.details().touch_points() == 2) | |
122 return UMA_ET_GESTURE_SCROLL_UPDATE_2; | |
123 else if (gesture.details().touch_points() == 3) | |
124 return UMA_ET_GESTURE_SCROLL_UPDATE_3; | |
125 return UMA_ET_GESTURE_SCROLL_UPDATE_4P; | |
126 } | |
127 case ui::ET_GESTURE_TAP: { | |
128 const ui::GestureEvent& gesture = | |
129 static_cast<const ui::GestureEvent&>(event); | |
130 int tap_count = gesture.details().tap_count(); | |
131 if (tap_count == 1) | |
132 return UMA_ET_GESTURE_TAP; | |
133 if (tap_count == 2) | |
134 return UMA_ET_GESTURE_DOUBLE_TAP; | |
135 if (tap_count == 3) | |
136 return UMA_ET_GESTURE_TRIPLE_TAP; | |
137 NOTREACHED() << "Received tap with tapcount " << tap_count; | |
138 return UMA_ET_UNKNOWN; | |
139 } | |
140 case ui::ET_GESTURE_TAP_DOWN: | |
141 return UMA_ET_GESTURE_TAP_DOWN; | |
142 case ui::ET_GESTURE_BEGIN: | |
143 return UMA_ET_GESTURE_BEGIN; | |
144 case ui::ET_GESTURE_END: | |
145 return UMA_ET_GESTURE_END; | |
146 case ui::ET_GESTURE_TWO_FINGER_TAP: | |
147 return UMA_ET_GESTURE_TWO_FINGER_TAP; | |
148 case ui::ET_GESTURE_PINCH_BEGIN: | |
149 return UMA_ET_GESTURE_PINCH_BEGIN; | |
150 case ui::ET_GESTURE_PINCH_END: | |
151 return UMA_ET_GESTURE_PINCH_END; | |
152 case ui::ET_GESTURE_PINCH_UPDATE: { | |
153 const ui::GestureEvent& gesture = | |
154 static_cast<const ui::GestureEvent&>(event); | |
155 if (gesture.details().touch_points() >= 4) | |
156 return UMA_ET_GESTURE_PINCH_UPDATE_4P; | |
157 else if (gesture.details().touch_points() == 3) | |
158 return UMA_ET_GESTURE_PINCH_UPDATE_3; | |
159 return UMA_ET_GESTURE_PINCH_UPDATE; | |
160 } | |
161 case ui::ET_GESTURE_LONG_PRESS: | |
162 return UMA_ET_GESTURE_LONG_PRESS; | |
163 case ui::ET_GESTURE_LONG_TAP: | |
164 return UMA_ET_GESTURE_LONG_TAP; | |
165 case ui::ET_GESTURE_SWIPE: { | |
166 const ui::GestureEvent& gesture = | |
167 static_cast<const ui::GestureEvent&>(event); | |
168 if (gesture.details().touch_points() == 1) | |
169 return UMA_ET_GESTURE_SWIPE_1; | |
170 else if (gesture.details().touch_points() == 2) | |
171 return UMA_ET_GESTURE_SWIPE_2; | |
172 else if (gesture.details().touch_points() == 3) | |
173 return UMA_ET_GESTURE_SWIPE_3; | |
174 return UMA_ET_GESTURE_SWIPE_4P; | |
175 } | |
176 case ui::ET_GESTURE_WIN8_EDGE_SWIPE: | |
177 return UMA_ET_GESTURE_WIN8_EDGE_SWIPE; | |
178 case ui::ET_GESTURE_TAP_CANCEL: | |
179 return UMA_ET_GESTURE_TAP_CANCEL; | |
180 case ui::ET_GESTURE_SHOW_PRESS: | |
181 return UMA_ET_GESTURE_SHOW_PRESS; | |
182 case ui::ET_SCROLL: | |
183 return UMA_ET_SCROLL; | |
184 case ui::ET_SCROLL_FLING_START: | |
185 return UMA_ET_SCROLL_FLING_START; | |
186 case ui::ET_SCROLL_FLING_CANCEL: | |
187 return UMA_ET_SCROLL_FLING_CANCEL; | |
188 default: | |
189 NOTREACHED(); | |
190 return UMA_ET_UNKNOWN; | |
191 } | |
192 } | |
193 | |
194 } | 47 } |
195 | 48 |
196 namespace ash { | 49 namespace ash { |
197 | 50 |
198 // static | 51 // static |
199 TouchUMA* TouchUMA::GetInstance() { | 52 TouchUMA* TouchUMA::GetInstance() { |
200 return Singleton<TouchUMA>::get(); | 53 return Singleton<TouchUMA>::get(); |
201 } | 54 } |
202 | 55 |
203 void TouchUMA::RecordGestureEvent(aura::Window* target, | 56 void TouchUMA::RecordGestureEvent(aura::Window* target, |
204 const ui::GestureEvent& event) { | 57 const ui::GestureEvent& event) { |
205 UMA_HISTOGRAM_ENUMERATION("Ash.GestureCreated", | |
206 UMAEventTypeFromEvent(event), | |
207 UMA_ET_COUNT); | |
208 | |
209 GestureActionType action = FindGestureActionType(target, event); | 58 GestureActionType action = FindGestureActionType(target, event); |
210 RecordGestureAction(action); | 59 RecordGestureAction(action); |
211 | 60 |
212 if (event.type() == ui::ET_GESTURE_END && | 61 if (event.type() == ui::ET_GESTURE_END && |
213 event.details().touch_points() == 2) { | 62 event.details().touch_points() == 2) { |
214 WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails); | 63 WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails); |
215 if (!details) { | 64 if (!details) { |
216 LOG(ERROR) << "Window received gesture events without receiving any touch" | 65 LOG(ERROR) << "Window received gesture events without receiving any touch" |
217 " events"; | 66 " events"; |
218 return; | 67 return; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 position.y() / bucket_size_y, | 134 position.y() / bucket_size_y, |
286 0, kBucketCountForLocation, kBucketCountForLocation + 1); | 135 0, kBucketCountForLocation, kBucketCountForLocation + 1); |
287 | 136 |
288 if (event.type() == ui::ET_TOUCH_PRESSED) { | 137 if (event.type() == ui::ET_TOUCH_PRESSED) { |
289 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 138 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
290 UMA_TOUCHSCREEN_TAP_DOWN); | 139 UMA_TOUCHSCREEN_TAP_DOWN); |
291 | 140 |
292 details->last_start_time_[event.touch_id()] = event.time_stamp(); | 141 details->last_start_time_[event.touch_id()] = event.time_stamp(); |
293 details->start_touch_position_[event.touch_id()] = event.root_location(); | 142 details->start_touch_position_[event.touch_id()] = event.root_location(); |
294 details->last_touch_position_[event.touch_id()] = event.location(); | 143 details->last_touch_position_[event.touch_id()] = event.location(); |
295 details->max_distance_from_start_squared_ = 0; | |
296 | 144 |
297 if (details->last_release_time_.ToInternalValue()) { | 145 if (details->last_release_time_.ToInternalValue()) { |
298 // Measuring the interval between a touch-release and the next | 146 // Measuring the interval between a touch-release and the next |
299 // touch-start is probably less useful when doing multi-touch (e.g. | 147 // touch-start is probably less useful when doing multi-touch (e.g. |
300 // gestures, or multi-touch friendly apps). So count this only if the user | 148 // gestures, or multi-touch friendly apps). So count this only if the user |
301 // hasn't done any multi-touch during the last 30 seconds. | 149 // hasn't done any multi-touch during the last 30 seconds. |
302 base::TimeDelta diff = event.time_stamp() - details->last_mt_time_; | 150 base::TimeDelta diff = event.time_stamp() - details->last_mt_time_; |
303 if (diff.InSeconds() > 30) { | 151 if (diff.InSeconds() > 30) { |
304 base::TimeDelta gap = event.time_stamp() - details->last_release_time_; | 152 base::TimeDelta gap = event.time_stamp() - details->last_release_time_; |
305 UMA_HISTOGRAM_COUNTS_10000("Ash.TouchStartAfterEnd", | 153 UMA_HISTOGRAM_COUNTS_10000("Ash.TouchStartAfterEnd", |
306 gap.InMilliseconds()); | 154 gap.InMilliseconds()); |
307 } | 155 } |
308 } | 156 } |
309 | 157 |
310 // Record the number of touch-points currently active for the window. | 158 // Record the number of touch-points currently active for the window. |
311 const int kMaxTouchPoints = 10; | 159 const int kMaxTouchPoints = 10; |
312 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.ActiveTouchPoints", | 160 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.ActiveTouchPoints", |
313 details->last_start_time_.size(), | 161 details->last_start_time_.size(), |
314 1, kMaxTouchPoints, kMaxTouchPoints + 1); | 162 1, kMaxTouchPoints, kMaxTouchPoints + 1); |
315 } else if (event.type() == ui::ET_TOUCH_RELEASED) { | 163 } else if (event.type() == ui::ET_TOUCH_RELEASED) { |
316 if (is_single_finger_gesture_) { | |
317 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchMaxDistance", | |
318 static_cast<int>( | |
319 sqrt(details->max_distance_from_start_squared_)), 0, 1500, 50); | |
320 } | |
321 | |
322 if (details->last_start_time_.count(event.touch_id())) { | 164 if (details->last_start_time_.count(event.touch_id())) { |
323 base::TimeDelta duration = event.time_stamp() - | 165 base::TimeDelta duration = event.time_stamp() - |
324 details->last_start_time_[event.touch_id()]; | 166 details->last_start_time_[event.touch_id()]; |
325 UMA_HISTOGRAM_TIMES("Ash.TouchDuration2", duration); | |
326 | |
327 // Look for touches that were [almost] stationary for a long time. | 167 // Look for touches that were [almost] stationary for a long time. |
328 const double kLongStationaryTouchDuration = 10; | 168 const double kLongStationaryTouchDuration = 10; |
329 const int kLongStationaryTouchDistanceSquared = 100; | 169 const int kLongStationaryTouchDistanceSquared = 100; |
330 if (duration.InSecondsF() > kLongStationaryTouchDuration) { | 170 if (duration.InSecondsF() > kLongStationaryTouchDuration) { |
331 gfx::Vector2d distance = event.root_location() - | 171 gfx::Vector2d distance = event.root_location() - |
332 details->start_touch_position_[event.touch_id()]; | 172 details->start_touch_position_[event.touch_id()]; |
333 if (distance.LengthSquared() < kLongStationaryTouchDistanceSquared) { | 173 if (distance.LengthSquared() < kLongStationaryTouchDistanceSquared) { |
334 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.StationaryTouchDuration", | 174 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.StationaryTouchDuration", |
335 duration.InSeconds(), | 175 duration.InSeconds(), |
336 kLongStationaryTouchDuration, | 176 kLongStationaryTouchDuration, |
(...skipping 20 matching lines...) Expand all Loading... |
357 details->last_move_time_[event.touch_id()]; | 197 details->last_move_time_[event.touch_id()]; |
358 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchMoveInterval", | 198 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchMoveInterval", |
359 move_delay.InMilliseconds(), | 199 move_delay.InMilliseconds(), |
360 1, 50, 25); | 200 1, 50, 25); |
361 } | 201 } |
362 | 202 |
363 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchMoveSteps", distance, 1, 1000, 50); | 203 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchMoveSteps", distance, 1, 1000, 50); |
364 | 204 |
365 details->last_move_time_[event.touch_id()] = event.time_stamp(); | 205 details->last_move_time_[event.touch_id()] = event.time_stamp(); |
366 details->last_touch_position_[event.touch_id()] = event.location(); | 206 details->last_touch_position_[event.touch_id()] = event.location(); |
367 | |
368 float cur_dist = (details->start_touch_position_[event.touch_id()] - | |
369 event.root_location()).LengthSquared(); | |
370 if (cur_dist > details->max_distance_from_start_squared_) | |
371 details->max_distance_from_start_squared_ = cur_dist; | |
372 } | 207 } |
373 } | 208 } |
374 | 209 |
375 TouchUMA::TouchUMA() | 210 TouchUMA::TouchUMA() |
376 : is_single_finger_gesture_(false), | 211 : is_single_finger_gesture_(false), |
377 touch_in_progress_(false), | 212 touch_in_progress_(false), |
378 burst_length_(0) { | 213 burst_length_(0) { |
379 } | 214 } |
380 | 215 |
381 TouchUMA::~TouchUMA() { | 216 TouchUMA::~TouchUMA() { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 return GESTURE_OMNIBOX_SCROLL; | 303 return GESTURE_OMNIBOX_SCROLL; |
469 if (event.type() == ui::ET_GESTURE_PINCH_BEGIN) | 304 if (event.type() == ui::ET_GESTURE_PINCH_BEGIN) |
470 return GESTURE_OMNIBOX_PINCH; | 305 return GESTURE_OMNIBOX_PINCH; |
471 return GESTURE_UNKNOWN; | 306 return GESTURE_UNKNOWN; |
472 } | 307 } |
473 | 308 |
474 return GESTURE_UNKNOWN; | 309 return GESTURE_UNKNOWN; |
475 } | 310 } |
476 | 311 |
477 } // namespace ash | 312 } // namespace ash |
OLD | NEW |