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/shell_delegate.h" | 7 #include "ash/shell_delegate.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "ui/aura/root_window.h" | 10 #include "ui/aura/root_window.h" |
11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
12 #include "ui/aura/window_property.h" | 12 #include "ui/aura/window_property.h" |
13 #include "ui/base/event.h" | 13 #include "ui/base/event.h" |
14 | 14 |
15 #if defined(USE_XI2_MT) | |
16 #include <X11/extensions/XInput2.h> | |
17 #include <X11/Xlib.h> | |
18 #endif | |
19 | |
15 namespace { | 20 namespace { |
16 | 21 |
17 enum GestureActionType { | 22 enum GestureActionType { |
18 GESTURE_UNKNOWN, | 23 GESTURE_UNKNOWN, |
19 GESTURE_OMNIBOX_PINCH, | 24 GESTURE_OMNIBOX_PINCH, |
20 GESTURE_OMNIBOX_SCROLL, | 25 GESTURE_OMNIBOX_SCROLL, |
21 GESTURE_TABSTRIP_PINCH, | 26 GESTURE_TABSTRIP_PINCH, |
22 GESTURE_TABSTRIP_SCROLL, | 27 GESTURE_TABSTRIP_SCROLL, |
23 GESTURE_BEZEL_SCROLL, | 28 GESTURE_BEZEL_SCROLL, |
24 GESTURE_DESKTOP_SCROLL, | 29 GESTURE_DESKTOP_SCROLL, |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchRadius", | 265 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchRadius", |
261 static_cast<int>(std::max(event.radius_x(), event.radius_y())), | 266 static_cast<int>(std::max(event.radius_x(), event.radius_y())), |
262 1, 500, 100); | 267 1, 500, 100); |
263 | 268 |
264 WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails); | 269 WindowTouchDetails* details = target->GetProperty(kWindowTouchDetails); |
265 if (!details) { | 270 if (!details) { |
266 details = new WindowTouchDetails; | 271 details = new WindowTouchDetails; |
267 target->SetProperty(kWindowTouchDetails, details); | 272 target->SetProperty(kWindowTouchDetails, details); |
268 } | 273 } |
269 | 274 |
275 // Record the location of the touch points. | |
276 const int kBucketCount = 100; | |
277 const gfx::Rect bounds = target->GetRootWindow()->bounds(); | |
278 const int kBucketSizeX = bounds.width() / kBucketCount; | |
sky
2012/08/10 19:18:33
Don't use kStyle for computed values like this.
sadrul
2012/08/10 19:20:24
Done.
| |
279 const int kBucketSizeY = bounds.height() / kBucketCount; | |
280 | |
281 gfx::Point position = event.root_location(); | |
282 | |
283 // Prefer raw event location (when available) over calibrated location. | |
284 if (event.HasNativeEvent()) { | |
285 #if defined(USE_XI2_MT) | |
286 XEvent* xevent = event.native_event(); | |
287 CHECK_EQ(GenericEvent, xevent->type); | |
288 XIEvent* xievent = static_cast<XIEvent*>(xevent->xcookie.data); | |
289 if (xievent->evtype == XI_TouchBegin || | |
290 xievent->evtype == XI_TouchUpdate || | |
291 xievent->evtype == XI_TouchEnd) { | |
292 XIDeviceEvent* device_event = | |
293 static_cast<XIDeviceEvent*>(xevent->xcookie.data); | |
294 position.SetPoint(static_cast<int>(device_event->event_x), | |
295 static_cast<int>(device_event->event_y)); | |
296 } else { | |
297 position = ui::EventLocationFromNative(event.native_event()); | |
298 } | |
299 #else | |
300 position = ui::EventLocationFromNative(event.native_event()); | |
301 #endif | |
302 } | |
303 | |
304 position.set_x(std::min(bounds.width() - 1, std::max(0, position.x()))); | |
305 position.set_y(std::min(bounds.height() - 1, std::max(0, position.y()))); | |
306 | |
307 STATIC_HISTOGRAM_POINTER_BLOCK("Ash.TouchPositionX", | |
308 Add(position.x() / kBucketSizeX), | |
309 base::LinearHistogram::FactoryGet("Ash.TouchPositionX", 1, kBucketCount, | |
310 kBucketCount + 1, base::Histogram::kUmaTargetedHistogramFlag)); | |
311 STATIC_HISTOGRAM_POINTER_BLOCK("Ash.TouchPositionY", | |
312 Add(position.y() / kBucketSizeY), | |
313 base::LinearHistogram::FactoryGet("Ash.TouchPositionY", 1, kBucketCount, | |
314 kBucketCount + 1, base::Histogram::kUmaTargetedHistogramFlag)); | |
315 | |
270 if (event.type() == ui::ET_TOUCH_PRESSED) { | 316 if (event.type() == ui::ET_TOUCH_PRESSED) { |
271 Shell::GetInstance()->delegate()->RecordUserMetricsAction( | 317 Shell::GetInstance()->delegate()->RecordUserMetricsAction( |
272 UMA_TOUCHSCREEN_TAP_DOWN); | 318 UMA_TOUCHSCREEN_TAP_DOWN); |
273 | 319 |
274 details->last_start_time_[event.touch_id()] = event.time_stamp(); | 320 details->last_start_time_[event.touch_id()] = event.time_stamp(); |
275 details->last_touch_position_[event.touch_id()] = event.location(); | 321 details->last_touch_position_[event.touch_id()] = event.location(); |
276 | 322 |
277 if (details->last_release_time_.ToInternalValue()) { | 323 if (details->last_release_time_.ToInternalValue()) { |
278 // Measuring the interval between a touch-release and the next | 324 // Measuring the interval between a touch-release and the next |
279 // touch-start is probably less useful when doing multi-touch (e.g. | 325 // touch-start is probably less useful when doing multi-touch (e.g. |
280 // gestures, or multi-touch friendly apps). So count this only if the user | 326 // gestures, or multi-touch friendly apps). So count this only if the user |
281 // hasn't done any multi-touch during the last 30 seconds. | 327 // hasn't done any multi-touch during the last 30 seconds. |
282 base::TimeDelta diff = event.time_stamp() - details->last_mt_time_; | 328 base::TimeDelta diff = event.time_stamp() - details->last_mt_time_; |
283 if (diff.InSeconds() > 30) { | 329 if (diff.InSeconds() > 30) { |
284 base::TimeDelta gap = event.time_stamp() - details->last_release_time_; | 330 base::TimeDelta gap = event.time_stamp() - details->last_release_time_; |
285 UMA_HISTOGRAM_COUNTS_10000("Ash.TouchStartAfterEnd", | 331 UMA_HISTOGRAM_COUNTS_10000("Ash.TouchStartAfterEnd", |
286 gap.InMilliseconds()); | 332 gap.InMilliseconds()); |
287 } | 333 } |
288 } | 334 } |
335 | |
336 // Record the number of touch-points currently active for the window. | |
337 const int kMaxTouchPoints = 10; | |
338 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.ActiveTouchPoints", | |
339 std::min(static_cast<int>(details->last_start_time_.size()), | |
340 kMaxTouchPoints), | |
341 1, kMaxTouchPoints, kMaxTouchPoints); | |
289 } else if (event.type() == ui::ET_TOUCH_RELEASED) { | 342 } else if (event.type() == ui::ET_TOUCH_RELEASED) { |
290 if (details->last_start_time_.count(event.touch_id())) { | 343 if (details->last_start_time_.count(event.touch_id())) { |
291 base::TimeDelta duration = event.time_stamp() - | 344 base::TimeDelta duration = event.time_stamp() - |
292 details->last_start_time_[event.touch_id()]; | 345 details->last_start_time_[event.touch_id()]; |
293 UMA_HISTOGRAM_COUNTS_100("Ash.TouchDuration", duration.InMilliseconds()); | 346 UMA_HISTOGRAM_COUNTS_100("Ash.TouchDuration", duration.InMilliseconds()); |
294 } | 347 } |
295 details->last_start_time_.erase(event.touch_id()); | 348 details->last_start_time_.erase(event.touch_id()); |
296 details->last_move_time_.erase(event.touch_id()); | 349 details->last_move_time_.erase(event.touch_id()); |
297 details->last_touch_position_.erase(event.touch_id()); | 350 details->last_touch_position_.erase(event.touch_id()); |
298 details->last_release_time_ = event.time_stamp(); | 351 details->last_release_time_ = event.time_stamp(); |
(...skipping 14 matching lines...) Expand all Loading... | |
313 | 366 |
314 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchMoveSteps", distance, 1, 1000, 50); | 367 UMA_HISTOGRAM_CUSTOM_COUNTS("Ash.TouchMoveSteps", distance, 1, 1000, 50); |
315 | 368 |
316 details->last_move_time_[event.touch_id()] = event.time_stamp(); | 369 details->last_move_time_[event.touch_id()] = event.time_stamp(); |
317 details->last_touch_position_[event.touch_id()] = event.location(); | 370 details->last_touch_position_[event.touch_id()] = event.location(); |
318 } | 371 } |
319 } | 372 } |
320 | 373 |
321 } // namespace internal | 374 } // namespace internal |
322 } // namespace ash | 375 } // namespace ash |
OLD | NEW |