OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef CONTENT_COMMON_INPUT_EVENT_WITH_LATENCY_INFO_H_ | 5 #ifndef CONTENT_COMMON_INPUT_EVENT_WITH_LATENCY_INFO_H_ |
6 #define CONTENT_COMMON_INPUT_EVENT_WITH_LATENCY_INFO_H_ | 6 #define CONTENT_COMMON_INPUT_EVENT_WITH_LATENCY_INFO_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 class EventWithLatencyInfo { | 41 class EventWithLatencyInfo { |
42 public: | 42 public: |
43 T event; | 43 T event; |
44 mutable ui::LatencyInfo latency; | 44 mutable ui::LatencyInfo latency; |
45 | 45 |
46 explicit EventWithLatencyInfo(const T& e) : event(e) {} | 46 explicit EventWithLatencyInfo(const T& e) : event(e) {} |
47 | 47 |
48 EventWithLatencyInfo(const T& e, const ui::LatencyInfo& l) | 48 EventWithLatencyInfo(const T& e, const ui::LatencyInfo& l) |
49 : event(e), latency(l) {} | 49 : event(e), latency(l) {} |
50 | 50 |
| 51 EventWithLatencyInfo(blink::WebInputEvent::Type type, |
| 52 int modifiers, |
| 53 double timeStampSeconds, |
| 54 const ui::LatencyInfo& l) |
| 55 : event(type, modifiers, timeStampSeconds), latency(l) {} |
| 56 |
51 EventWithLatencyInfo() {} | 57 EventWithLatencyInfo() {} |
52 | 58 |
53 bool CanCoalesceWith(const EventWithLatencyInfo& other) | 59 bool CanCoalesceWith(const EventWithLatencyInfo& other) |
54 const WARN_UNUSED_RESULT { | 60 const WARN_UNUSED_RESULT { |
55 if (other.event.type != event.type) | 61 if (other.event.type != event.type) |
56 return false; | 62 return false; |
57 | 63 |
58 DCHECK_EQ(sizeof(T), event.size); | 64 DCHECK_EQ(sizeof(T), event.size); |
59 DCHECK_EQ(sizeof(T), other.event.size); | 65 DCHECK_EQ(sizeof(T), other.event.size); |
60 | 66 |
61 return ui::CanCoalesce(other.event, event); | 67 return ui::CanCoalesce(other.event, event); |
62 } | 68 } |
63 | 69 |
64 void CoalesceWith(const EventWithLatencyInfo& other) { | 70 void CoalesceWith(const EventWithLatencyInfo& other) { |
65 // |other| should be a newer event than |this|. | 71 // |other| should be a newer event than |this|. |
66 if (other.latency.trace_id() >= 0 && latency.trace_id() >= 0) | 72 if (other.latency.trace_id() >= 0 && latency.trace_id() >= 0) |
67 DCHECK_GT(other.latency.trace_id(), latency.trace_id()); | 73 DCHECK_GT(other.latency.trace_id(), latency.trace_id()); |
68 | 74 |
69 // New events get coalesced into older events, and the newer timestamp | 75 // New events get coalesced into older events, and the newer timestamp |
70 // should always be preserved. | 76 // should always be preserved. |
71 const double time_stamp_seconds = other.event.timeStampSeconds; | 77 const double time_stamp_seconds = other.event.timeStampSeconds; |
72 ui::Coalesce(other.event, &event); | 78 ui::Coalesce(other.event, &event); |
73 event.timeStampSeconds = time_stamp_seconds; | 79 event.setTimeStampSeconds(time_stamp_seconds); |
74 | 80 |
75 // When coalescing two input events, we keep the oldest LatencyInfo | 81 // When coalescing two input events, we keep the oldest LatencyInfo |
76 // for Telemetry latency tests, since it will represent the longest | 82 // for Telemetry latency tests, since it will represent the longest |
77 // latency. | 83 // latency. |
78 other.latency = latency; | 84 other.latency = latency; |
79 other.latency.set_coalesced(); | 85 other.latency.set_coalesced(); |
80 } | 86 } |
81 }; | 87 }; |
82 | 88 |
83 typedef EventWithLatencyInfo<blink::WebGestureEvent> | 89 typedef EventWithLatencyInfo<blink::WebGestureEvent> |
84 GestureEventWithLatencyInfo; | 90 GestureEventWithLatencyInfo; |
85 typedef EventWithLatencyInfo<blink::WebMouseWheelEvent> | 91 typedef EventWithLatencyInfo<blink::WebMouseWheelEvent> |
86 MouseWheelEventWithLatencyInfo; | 92 MouseWheelEventWithLatencyInfo; |
87 typedef EventWithLatencyInfo<blink::WebMouseEvent> | 93 typedef EventWithLatencyInfo<blink::WebMouseEvent> |
88 MouseEventWithLatencyInfo; | 94 MouseEventWithLatencyInfo; |
89 typedef EventWithLatencyInfo<blink::WebTouchEvent> | 95 typedef EventWithLatencyInfo<blink::WebTouchEvent> |
90 TouchEventWithLatencyInfo; | 96 TouchEventWithLatencyInfo; |
91 | 97 |
92 } // namespace content | 98 } // namespace content |
93 | 99 |
94 #endif // CONTENT_COMMON_INPUT_EVENT_WITH_LATENCY_INFO_H_ | 100 #endif // CONTENT_COMMON_INPUT_EVENT_WITH_LATENCY_INFO_H_ |
OLD | NEW |