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" | |
tdresser
2016/06/30 14:16:39
Are we using this?
tapted
2016/07/01 02:53:45
Yep - for WARN_UNUSED_RESULT in the original code
| |
9 #include "base/logging.h" | |
10 #include "content/common/content_export.h" | |
11 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
8 #include "ui/events/latency_info.h" | 12 #include "ui/events/latency_info.h" |
9 | 13 |
10 #include "content/common/input/web_input_event_traits.h" | 14 namespace content { |
15 namespace internal { | |
11 | 16 |
12 namespace blink { | 17 bool CONTENT_EXPORT CanCoalesce(const blink::WebMouseEvent& event_to_coalesce, |
13 class WebGestureEvent; | 18 const blink::WebMouseEvent& event); |
14 class WebMouseEvent; | 19 void CONTENT_EXPORT Coalesce(const blink::WebMouseEvent& event_to_coalesce, |
15 class WebMouseWheelEvent; | 20 blink::WebMouseEvent* event); |
16 class WebTouchEvent; | 21 bool CONTENT_EXPORT |
17 } | 22 CanCoalesce(const blink::WebMouseWheelEvent& event_to_coalesce, |
23 const blink::WebMouseWheelEvent& event); | |
24 void CONTENT_EXPORT Coalesce(const blink::WebMouseWheelEvent& event_to_coalesce, | |
25 blink::WebMouseWheelEvent* event); | |
26 bool CONTENT_EXPORT CanCoalesce(const blink::WebTouchEvent& event_to_coalesce, | |
27 const blink::WebTouchEvent& event); | |
28 void CONTENT_EXPORT Coalesce(const blink::WebTouchEvent& event_to_coalesce, | |
29 blink::WebTouchEvent* event); | |
30 bool CONTENT_EXPORT CanCoalesce(const blink::WebGestureEvent& event_to_coalesce, | |
31 const blink::WebGestureEvent& event); | |
32 void CONTENT_EXPORT Coalesce(const blink::WebGestureEvent& event_to_coalesce, | |
33 blink::WebGestureEvent* event); | |
18 | 34 |
19 namespace content { | 35 } // namespace internal |
tapted
2016/06/30 12:13:45
This wasn't my first choice.. In http://crrev.com/
| |
20 | 36 |
21 template <typename T> | 37 template <typename T> |
22 class EventWithLatencyInfo { | 38 class EventWithLatencyInfo { |
23 public: | 39 public: |
24 T event; | 40 T event; |
25 mutable ui::LatencyInfo latency; | 41 mutable ui::LatencyInfo latency; |
26 | 42 |
27 explicit EventWithLatencyInfo(const T& e) : event(e) {} | 43 explicit EventWithLatencyInfo(const T& e) : event(e) {} |
28 | 44 |
29 EventWithLatencyInfo(const T& e, const ui::LatencyInfo& l) | 45 EventWithLatencyInfo(const T& e, const ui::LatencyInfo& l) |
30 : event(e), latency(l) {} | 46 : event(e), latency(l) {} |
31 | 47 |
32 EventWithLatencyInfo() {} | 48 EventWithLatencyInfo() {} |
33 | 49 |
34 bool CanCoalesceWith(const EventWithLatencyInfo& other) | 50 bool CanCoalesceWith(const EventWithLatencyInfo& other) |
35 const WARN_UNUSED_RESULT { | 51 const WARN_UNUSED_RESULT { |
36 return WebInputEventTraits::CanCoalesce(other.event, event); | 52 if (other.event.type != event.type) |
53 return false; | |
54 | |
55 DCHECK_EQ(sizeof(T), event.size); | |
56 DCHECK_EQ(sizeof(T), other.event.size); | |
57 | |
58 return internal::CanCoalesce(other.event, event); | |
37 } | 59 } |
38 | 60 |
39 void CoalesceWith(const EventWithLatencyInfo& other) { | 61 void CoalesceWith(const EventWithLatencyInfo& other) { |
40 // |other| should be a newer event than |this|. | 62 // |other| should be a newer event than |this|. |
41 if (other.latency.trace_id() >= 0 && latency.trace_id() >= 0) | 63 if (other.latency.trace_id() >= 0 && latency.trace_id() >= 0) |
42 DCHECK_GT(other.latency.trace_id(), latency.trace_id()); | 64 DCHECK_GT(other.latency.trace_id(), latency.trace_id()); |
43 WebInputEventTraits::Coalesce(other.event, &event); | 65 |
66 // New events get coalesced into older events, and the newer timestamp | |
67 // should always be preserved. | |
68 const double time_stamp_seconds = other.event.timeStampSeconds; | |
69 internal::Coalesce(other.event, &event); | |
70 event.timeStampSeconds = time_stamp_seconds; | |
71 | |
44 // When coalescing two input events, we keep the oldest LatencyInfo | 72 // When coalescing two input events, we keep the oldest LatencyInfo |
45 // for Telemetry latency tests, since it will represent the longest | 73 // for Telemetry latency tests, since it will represent the longest |
46 // latency. | 74 // latency. |
47 other.latency = latency; | 75 other.latency = latency; |
48 other.latency.set_coalesced(); | 76 other.latency.set_coalesced(); |
49 } | 77 } |
50 }; | 78 }; |
51 | 79 |
52 typedef EventWithLatencyInfo<blink::WebGestureEvent> | 80 typedef EventWithLatencyInfo<blink::WebGestureEvent> |
53 GestureEventWithLatencyInfo; | 81 GestureEventWithLatencyInfo; |
54 typedef EventWithLatencyInfo<blink::WebMouseWheelEvent> | 82 typedef EventWithLatencyInfo<blink::WebMouseWheelEvent> |
55 MouseWheelEventWithLatencyInfo; | 83 MouseWheelEventWithLatencyInfo; |
56 typedef EventWithLatencyInfo<blink::WebMouseEvent> | 84 typedef EventWithLatencyInfo<blink::WebMouseEvent> |
57 MouseEventWithLatencyInfo; | 85 MouseEventWithLatencyInfo; |
58 typedef EventWithLatencyInfo<blink::WebTouchEvent> | 86 typedef EventWithLatencyInfo<blink::WebTouchEvent> |
59 TouchEventWithLatencyInfo; | 87 TouchEventWithLatencyInfo; |
60 | 88 |
61 } // namespace content | 89 } // namespace content |
62 | 90 |
63 #endif // CONTENT_COMMON_INPUT_EVENT_WITH_LATENCY_INFO_H_ | 91 #endif // CONTENT_COMMON_INPUT_EVENT_WITH_LATENCY_INFO_H_ |
OLD | NEW |