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