| 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" |
| 11 #include "third_party/WebKit/public/platform/WebGestureEvent.h" | 11 #include "third_party/WebKit/public/platform/WebGestureEvent.h" |
| 12 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 12 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 13 #include "ui/events/blink/blink_event_util.h" |
| 13 #include "ui/events/blink/scoped_web_input_event.h" | 14 #include "ui/events/blink/scoped_web_input_event.h" |
| 14 #include "ui/events/latency_info.h" | 15 #include "ui/events/latency_info.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 namespace internal { | |
| 18 | |
| 19 bool CONTENT_EXPORT CanCoalesce(const blink::WebMouseEvent& event_to_coalesce, | |
| 20 const blink::WebMouseEvent& event); | |
| 21 void CONTENT_EXPORT Coalesce(const blink::WebMouseEvent& event_to_coalesce, | |
| 22 blink::WebMouseEvent* event); | |
| 23 bool CONTENT_EXPORT | |
| 24 CanCoalesce(const blink::WebMouseWheelEvent& event_to_coalesce, | |
| 25 const blink::WebMouseWheelEvent& event); | |
| 26 void CONTENT_EXPORT Coalesce(const blink::WebMouseWheelEvent& event_to_coalesce, | |
| 27 blink::WebMouseWheelEvent* event); | |
| 28 bool CONTENT_EXPORT CanCoalesce(const blink::WebTouchEvent& event_to_coalesce, | |
| 29 const blink::WebTouchEvent& event); | |
| 30 void CONTENT_EXPORT Coalesce(const blink::WebTouchEvent& event_to_coalesce, | |
| 31 blink::WebTouchEvent* event); | |
| 32 bool CONTENT_EXPORT CanCoalesce(const blink::WebGestureEvent& event_to_coalesce, | |
| 33 const blink::WebGestureEvent& event); | |
| 34 void CONTENT_EXPORT Coalesce(const blink::WebGestureEvent& event_to_coalesce, | |
| 35 blink::WebGestureEvent* event); | |
| 36 | |
| 37 } // namespace internal | |
| 38 | 18 |
| 39 class ScopedWebInputEventWithLatencyInfo { | 19 class ScopedWebInputEventWithLatencyInfo { |
| 40 public: | 20 public: |
| 41 ScopedWebInputEventWithLatencyInfo(ui::ScopedWebInputEvent, | 21 ScopedWebInputEventWithLatencyInfo(ui::ScopedWebInputEvent, |
| 42 const ui::LatencyInfo&); | 22 const ui::LatencyInfo&); |
| 43 | 23 |
| 44 ~ScopedWebInputEventWithLatencyInfo(); | 24 ~ScopedWebInputEventWithLatencyInfo(); |
| 45 | 25 |
| 46 bool CanCoalesceWith(const ScopedWebInputEventWithLatencyInfo& other) const | 26 bool CanCoalesceWith(const ScopedWebInputEventWithLatencyInfo& other) const |
| 47 WARN_UNUSED_RESULT; | 27 WARN_UNUSED_RESULT; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 71 EventWithLatencyInfo() {} | 51 EventWithLatencyInfo() {} |
| 72 | 52 |
| 73 bool CanCoalesceWith(const EventWithLatencyInfo& other) | 53 bool CanCoalesceWith(const EventWithLatencyInfo& other) |
| 74 const WARN_UNUSED_RESULT { | 54 const WARN_UNUSED_RESULT { |
| 75 if (other.event.type != event.type) | 55 if (other.event.type != event.type) |
| 76 return false; | 56 return false; |
| 77 | 57 |
| 78 DCHECK_EQ(sizeof(T), event.size); | 58 DCHECK_EQ(sizeof(T), event.size); |
| 79 DCHECK_EQ(sizeof(T), other.event.size); | 59 DCHECK_EQ(sizeof(T), other.event.size); |
| 80 | 60 |
| 81 return internal::CanCoalesce(other.event, event); | 61 return ui::CanCoalesce(other.event, event); |
| 82 } | 62 } |
| 83 | 63 |
| 84 void CoalesceWith(const EventWithLatencyInfo& other) { | 64 void CoalesceWith(const EventWithLatencyInfo& other) { |
| 85 // |other| should be a newer event than |this|. | 65 // |other| should be a newer event than |this|. |
| 86 if (other.latency.trace_id() >= 0 && latency.trace_id() >= 0) | 66 if (other.latency.trace_id() >= 0 && latency.trace_id() >= 0) |
| 87 DCHECK_GT(other.latency.trace_id(), latency.trace_id()); | 67 DCHECK_GT(other.latency.trace_id(), latency.trace_id()); |
| 88 | 68 |
| 89 // New events get coalesced into older events, and the newer timestamp | 69 // New events get coalesced into older events, and the newer timestamp |
| 90 // should always be preserved. | 70 // should always be preserved. |
| 91 const double time_stamp_seconds = other.event.timeStampSeconds; | 71 const double time_stamp_seconds = other.event.timeStampSeconds; |
| 92 internal::Coalesce(other.event, &event); | 72 ui::Coalesce(other.event, &event); |
| 93 event.timeStampSeconds = time_stamp_seconds; | 73 event.timeStampSeconds = time_stamp_seconds; |
| 94 | 74 |
| 95 // When coalescing two input events, we keep the oldest LatencyInfo | 75 // When coalescing two input events, we keep the oldest LatencyInfo |
| 96 // for Telemetry latency tests, since it will represent the longest | 76 // for Telemetry latency tests, since it will represent the longest |
| 97 // latency. | 77 // latency. |
| 98 other.latency = latency; | 78 other.latency = latency; |
| 99 other.latency.set_coalesced(); | 79 other.latency.set_coalesced(); |
| 100 } | 80 } |
| 101 }; | 81 }; |
| 102 | 82 |
| 103 typedef EventWithLatencyInfo<blink::WebGestureEvent> | 83 typedef EventWithLatencyInfo<blink::WebGestureEvent> |
| 104 GestureEventWithLatencyInfo; | 84 GestureEventWithLatencyInfo; |
| 105 typedef EventWithLatencyInfo<blink::WebMouseWheelEvent> | 85 typedef EventWithLatencyInfo<blink::WebMouseWheelEvent> |
| 106 MouseWheelEventWithLatencyInfo; | 86 MouseWheelEventWithLatencyInfo; |
| 107 typedef EventWithLatencyInfo<blink::WebMouseEvent> | 87 typedef EventWithLatencyInfo<blink::WebMouseEvent> |
| 108 MouseEventWithLatencyInfo; | 88 MouseEventWithLatencyInfo; |
| 109 typedef EventWithLatencyInfo<blink::WebTouchEvent> | 89 typedef EventWithLatencyInfo<blink::WebTouchEvent> |
| 110 TouchEventWithLatencyInfo; | 90 TouchEventWithLatencyInfo; |
| 111 | 91 |
| 112 } // namespace content | 92 } // namespace content |
| 113 | 93 |
| 114 #endif // CONTENT_COMMON_INPUT_EVENT_WITH_LATENCY_INFO_H_ | 94 #endif // CONTENT_COMMON_INPUT_EVENT_WITH_LATENCY_INFO_H_ |
| OLD | NEW |