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_BROWSER_RENDERER_HOST_EVENT_WITH_LATENCY_INFO_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_EVENT_WITH_LATENCY_INFO_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_EVENT_WITH_LATENCY_INFO_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_EVENT_WITH_LATENCY_INFO_H_ |
7 | 7 |
8 #include "ui/events/latency_info.h" | 8 #include "content/common/input/event_with_latency_info.h" |
9 | |
10 #include "content/common/input/web_input_event_traits.h" | |
11 #include "content/public/browser/native_web_keyboard_event.h" | 9 #include "content/public/browser/native_web_keyboard_event.h" |
12 | 10 |
13 namespace blink { | |
14 class WebGestureEvent; | |
15 class WebMouseEvent; | |
16 class WebMouseWheelEvent; | |
17 class WebTouchEvent; | |
18 } | |
19 | |
20 namespace content { | 11 namespace content { |
21 | 12 |
22 template <typename T> | |
23 class EventWithLatencyInfo { | |
24 public: | |
25 T event; | |
26 mutable ui::LatencyInfo latency; | |
27 | |
28 explicit EventWithLatencyInfo(const T& e) : event(e) {} | |
29 | |
30 EventWithLatencyInfo(const T& e, const ui::LatencyInfo& l) | |
31 : event(e), latency(l) {} | |
32 | |
33 EventWithLatencyInfo() {} | |
34 | |
35 bool CanCoalesceWith(const EventWithLatencyInfo& other) | |
36 const WARN_UNUSED_RESULT { | |
37 return WebInputEventTraits::CanCoalesce(other.event, event); | |
38 } | |
39 | |
40 void CoalesceWith(const EventWithLatencyInfo& other) { | |
41 // |other| should be a newer event than |this|. | |
42 if (other.latency.trace_id() >= 0 && latency.trace_id() >= 0) | |
43 DCHECK_GT(other.latency.trace_id(), latency.trace_id()); | |
44 double old_timestamp = event.timeStampSeconds; | |
45 WebInputEventTraits::Coalesce(other.event, &event); | |
46 // When coalescing two input events, we keep the oldest LatencyInfo | |
47 // for Telemetry latency test since it will represent the longest | |
48 // latency. | |
49 if (other.latency.trace_id() >= 0 && | |
50 (latency.trace_id() < 0 || | |
51 other.latency.trace_id() < latency.trace_id())) { | |
52 latency = other.latency; | |
53 } | |
54 latency.AddCoalescedEventTimestamp(old_timestamp); | |
55 } | |
56 }; | |
57 | |
58 typedef EventWithLatencyInfo<NativeWebKeyboardEvent> | 13 typedef EventWithLatencyInfo<NativeWebKeyboardEvent> |
59 NativeWebKeyboardEventWithLatencyInfo; | 14 NativeWebKeyboardEventWithLatencyInfo; |
60 typedef EventWithLatencyInfo<blink::WebGestureEvent> | |
61 GestureEventWithLatencyInfo; | |
62 typedef EventWithLatencyInfo<blink::WebMouseWheelEvent> | |
63 MouseWheelEventWithLatencyInfo; | |
64 typedef EventWithLatencyInfo<blink::WebMouseEvent> | |
65 MouseEventWithLatencyInfo; | |
66 typedef EventWithLatencyInfo<blink::WebTouchEvent> | |
67 TouchEventWithLatencyInfo; | |
68 | 15 |
69 } // namespace content | 16 } // namespace content |
70 | 17 |
71 #endif // CONTENT_BROWSER_RENDERER_HOST_EVENT_WITH_LATENCY_INFO_H_ | 18 #endif // CONTENT_BROWSER_RENDERER_HOST_EVENT_WITH_LATENCY_INFO_H_ |
OLD | NEW |