1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/events/gesture_detection/gesture_touch_uma_histogram.h"
#include "base/metrics/histogram.h"
namespace ui {
GestureTouchUMAHistogram::GestureTouchUMAHistogram()
: max_distance_from_start_squared_(0), is_single_finger_(true) {
}
GestureTouchUMAHistogram::~GestureTouchUMAHistogram() {
}
void GestureTouchUMAHistogram::RecordGestureEvent(
const GestureEventData& gesture) {
UMA_HISTOGRAM_ENUMERATION(
"Event.GestureCreated", UMAEventTypeFromEvent(gesture), UMA_ET_COUNT);
}
void GestureTouchUMAHistogram::RecordTouchEvent(const MotionEvent& event) {
if (event.GetAction() == MotionEvent::ACTION_DOWN) {
start_time_ = event.GetEventTime();
start_touch_position_ = gfx::Point(event.GetX(), event.GetY());
is_single_finger_ = true;
max_distance_from_start_squared_ = 0;
} else if (event.GetAction() == MotionEvent::ACTION_MOVE &&
is_single_finger_) {
float cur_dist = (start_touch_position_ -
gfx::Point(event.GetX(), event.GetY())).LengthSquared();
if (cur_dist > max_distance_from_start_squared_)
max_distance_from_start_squared_ = cur_dist;
} else {
if (event.GetAction() == MotionEvent::ACTION_UP && is_single_finger_) {
UMA_HISTOGRAM_CUSTOM_COUNTS(
"Event.TouchMaxDistance",
static_cast<int>(sqrt(max_distance_from_start_squared_)),
0,
1500,
50);
base::TimeDelta duration = event.GetEventTime() - start_time_;
UMA_HISTOGRAM_TIMES("Event.TouchDuration", duration);
}
is_single_finger_ = false;
}
}
UMAEventType GestureTouchUMAHistogram::UMAEventTypeFromEvent(
const GestureEventData& gesture) {
switch (gesture.type()) {
case ET_TOUCH_RELEASED:
return UMA_ET_TOUCH_RELEASED;
case ET_TOUCH_PRESSED:
return UMA_ET_TOUCH_PRESSED;
case ET_TOUCH_MOVED:
return UMA_ET_TOUCH_MOVED;
case ET_TOUCH_CANCELLED:
return UMA_ET_TOUCH_CANCELLED;
case ET_GESTURE_SCROLL_BEGIN:
return UMA_ET_GESTURE_SCROLL_BEGIN;
case ET_GESTURE_SCROLL_END:
return UMA_ET_GESTURE_SCROLL_END;
case ET_GESTURE_SCROLL_UPDATE: {
int touch_points = gesture.details.touch_points();
if (touch_points == 1)
return UMA_ET_GESTURE_SCROLL_UPDATE;
else if (touch_points == 2)
return UMA_ET_GESTURE_SCROLL_UPDATE_2;
else if (touch_points == 3)
return UMA_ET_GESTURE_SCROLL_UPDATE_3;
return UMA_ET_GESTURE_SCROLL_UPDATE_4P;
}
case ET_GESTURE_TAP: {
int tap_count = gesture.details.tap_count();
if (tap_count == 1)
return UMA_ET_GESTURE_TAP;
if (tap_count == 2)
return UMA_ET_GESTURE_DOUBLE_TAP;
if (tap_count == 3)
return UMA_ET_GESTURE_TRIPLE_TAP;
NOTREACHED() << "Received tap with tapcount " << tap_count;
return UMA_ET_UNKNOWN;
}
case ET_GESTURE_TAP_DOWN:
return UMA_ET_GESTURE_TAP_DOWN;
case ET_GESTURE_BEGIN:
return UMA_ET_GESTURE_BEGIN;
case ET_GESTURE_END:
return UMA_ET_GESTURE_END;
case ET_GESTURE_TWO_FINGER_TAP:
return UMA_ET_GESTURE_TWO_FINGER_TAP;
case ET_GESTURE_PINCH_BEGIN:
return UMA_ET_GESTURE_PINCH_BEGIN;
case ET_GESTURE_PINCH_END:
return UMA_ET_GESTURE_PINCH_END;
case ET_GESTURE_PINCH_UPDATE: {
int touch_points = gesture.details.touch_points();
if (touch_points >= 4)
return UMA_ET_GESTURE_PINCH_UPDATE_4P;
else if (touch_points == 3)
return UMA_ET_GESTURE_PINCH_UPDATE_3;
return UMA_ET_GESTURE_PINCH_UPDATE;
}
case ET_GESTURE_LONG_PRESS:
return UMA_ET_GESTURE_LONG_PRESS;
case ET_GESTURE_LONG_TAP:
return UMA_ET_GESTURE_LONG_TAP;
case ET_GESTURE_SWIPE: {
int touch_points = gesture.details.touch_points();
if (touch_points == 1)
return UMA_ET_GESTURE_SWIPE_1;
else if (touch_points == 2)
return UMA_ET_GESTURE_SWIPE_2;
else if (touch_points == 3)
return UMA_ET_GESTURE_SWIPE_3;
return UMA_ET_GESTURE_SWIPE_4P;
}
case ET_GESTURE_WIN8_EDGE_SWIPE:
return UMA_ET_GESTURE_WIN8_EDGE_SWIPE;
case ET_GESTURE_TAP_CANCEL:
return UMA_ET_GESTURE_TAP_CANCEL;
case ET_GESTURE_SHOW_PRESS:
return UMA_ET_GESTURE_SHOW_PRESS;
case ET_SCROLL:
return UMA_ET_SCROLL;
case ET_SCROLL_FLING_START:
return UMA_ET_SCROLL_FLING_START;
case ET_SCROLL_FLING_CANCEL:
return UMA_ET_SCROLL_FLING_CANCEL;
case ET_GESTURE_TAP_UNCONFIRMED:
return UMA_ET_GESTURE_TAP_UNCONFIRMED;
case ET_GESTURE_DOUBLE_TAP:
return UMA_ET_GESTURE_DOUBLE_TAP;
default:
NOTREACHED();
return UMA_ET_UNKNOWN;
}
}
} // namespace ui
|