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 "ui/events/event_utils.h" | 5 #include "ui/events/event_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "ui/display/display.h" | 10 #include "ui/display/display.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 default: | 54 default: |
55 break; | 55 break; |
56 } | 56 } |
57 return event; | 57 return event; |
58 } | 58 } |
59 | 59 |
60 int RegisterCustomEventType() { | 60 int RegisterCustomEventType() { |
61 return ++g_custom_event_types; | 61 return ++g_custom_event_types; |
62 } | 62 } |
63 | 63 |
64 base::TimeDelta EventTimeForNow() { | 64 base::TimeTicks EventTimeForNow() { |
65 return base::TimeDelta::FromInternalValue( | 65 return base::TimeTicks::Now(); |
66 base::TimeTicks::Now().ToInternalValue()); | |
67 } | 66 } |
68 | 67 |
69 bool ShouldDefaultToNaturalScroll() { | 68 bool ShouldDefaultToNaturalScroll() { |
70 return GetInternalDisplayTouchSupport() == | 69 return GetInternalDisplayTouchSupport() == |
71 display::Display::TOUCH_SUPPORT_AVAILABLE; | 70 display::Display::TOUCH_SUPPORT_AVAILABLE; |
72 } | 71 } |
73 | 72 |
74 display::Display::TouchSupport GetInternalDisplayTouchSupport() { | 73 display::Display::TouchSupport GetInternalDisplayTouchSupport() { |
75 display::Screen* screen = display::Screen::GetScreen(); | 74 display::Screen* screen = display::Screen::GetScreen(); |
76 // No screen in some unit tests. | 75 // No screen in some unit tests. |
77 if (!screen) | 76 if (!screen) |
78 return display::Display::TOUCH_SUPPORT_UNKNOWN; | 77 return display::Display::TOUCH_SUPPORT_UNKNOWN; |
79 const std::vector<display::Display>& displays = screen->GetAllDisplays(); | 78 const std::vector<display::Display>& displays = screen->GetAllDisplays(); |
80 for (std::vector<display::Display>::const_iterator it = displays.begin(); | 79 for (std::vector<display::Display>::const_iterator it = displays.begin(); |
81 it != displays.end(); ++it) { | 80 it != displays.end(); ++it) { |
82 if (it->IsInternal()) | 81 if (it->IsInternal()) |
83 return it->touch_support(); | 82 return it->touch_support(); |
84 } | 83 } |
85 return display::Display::TOUCH_SUPPORT_UNAVAILABLE; | 84 return display::Display::TOUCH_SUPPORT_UNAVAILABLE; |
86 } | 85 } |
87 | 86 |
88 void ComputeEventLatencyOS(const base::NativeEvent& native_event) { | 87 void ComputeEventLatencyOS(const base::NativeEvent& native_event) { |
89 base::TimeDelta current_time = EventTimeForNow(); | 88 base::TimeTicks current_time = EventTimeForNow(); |
90 base::TimeDelta time_stamp = EventTimeFromNative(native_event); | 89 base::TimeTicks time_stamp = EventTimeFromNative(native_event); |
91 base::TimeDelta delta = current_time - time_stamp; | 90 base::TimeDelta delta = current_time - time_stamp; |
92 | 91 |
93 EventType type = EventTypeFromNative(native_event); | 92 EventType type = EventTypeFromNative(native_event); |
94 switch (type) { | 93 switch (type) { |
95 case ET_MOUSEWHEEL: | 94 case ET_MOUSEWHEEL: |
96 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.MOUSE_WHEEL", | 95 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.MOUSE_WHEEL", |
97 delta.InMicroseconds(), 1, 1000000, 50); | 96 delta.InMicroseconds(), 1, 1000000, 50); |
98 return; | 97 return; |
99 case ET_TOUCH_MOVED: | 98 case ET_TOUCH_MOVED: |
100 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_MOVED", | 99 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_MOVED", |
101 delta.InMicroseconds(), 1, 1000000, 50); | 100 delta.InMicroseconds(), 1, 1000000, 50); |
102 return; | 101 return; |
103 case ET_TOUCH_PRESSED: | 102 case ET_TOUCH_PRESSED: |
104 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_PRESSED", | 103 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_PRESSED", |
105 delta.InMicroseconds(), 1, 1000000, 50); | 104 delta.InMicroseconds(), 1, 1000000, 50); |
106 return; | 105 return; |
107 case ET_TOUCH_RELEASED: | 106 case ET_TOUCH_RELEASED: |
108 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", | 107 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", |
109 delta.InMicroseconds(), 1, 1000000, 50); | 108 delta.InMicroseconds(), 1, 1000000, 50); |
110 return; | 109 return; |
111 default: | 110 default: |
112 return; | 111 return; |
113 } | 112 } |
114 } | 113 } |
115 | 114 |
116 } // namespace ui | 115 } // namespace ui |
OLD | NEW |