| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "content/common/input/event_with_latency_info.h" | 5 #include "content/common/input/event_with_latency_info.h" |
| 6 | 6 |
| 7 using blink::WebInputEvent; | 7 using blink::WebInputEvent; |
| 8 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 | 10 |
| 11 ScopedWebInputEventWithLatencyInfo::ScopedWebInputEventWithLatencyInfo( | 11 ScopedWebInputEventWithLatencyInfo::ScopedWebInputEventWithLatencyInfo( |
| 12 ui::ScopedWebInputEvent event, | 12 blink::WebCoalescedInputEvent::ScopedWebInputEvent event, |
| 13 const ui::LatencyInfo& latency_info) | 13 const ui::LatencyInfo& latency_info) |
| 14 : event_(std::move(event)), latency_(latency_info) { | 14 : event_(new blink::WebCoalescedInputEvent(std::move(event))), |
| 15 } | 15 latency_(latency_info) {} |
| 16 | 16 |
| 17 ScopedWebInputEventWithLatencyInfo::~ScopedWebInputEventWithLatencyInfo() {} | 17 ScopedWebInputEventWithLatencyInfo::~ScopedWebInputEventWithLatencyInfo() {} |
| 18 | 18 |
| 19 bool ScopedWebInputEventWithLatencyInfo::CanCoalesceWith( | 19 bool ScopedWebInputEventWithLatencyInfo::CanCoalesceWith( |
| 20 const ScopedWebInputEventWithLatencyInfo& other) const { | 20 const ScopedWebInputEventWithLatencyInfo& other) const { |
| 21 return ui::CanCoalesce(other.event(), event()); | 21 return ui::CanCoalesce(other.coalescedEvent().event(), |
| 22 coalescedEvent().event()); |
| 22 } | 23 } |
| 23 | 24 |
| 24 void ScopedWebInputEventWithLatencyInfo::CoalesceWith( | 25 void ScopedWebInputEventWithLatencyInfo::CoalesceWith( |
| 25 const ScopedWebInputEventWithLatencyInfo& other) { | 26 const ScopedWebInputEventWithLatencyInfo& other) { |
| 26 // |other| should be a newer event than |this|. | 27 // |other| should be a newer event than |this|. |
| 27 if (other.latency_.trace_id() >= 0 && latency_.trace_id() >= 0) | 28 if (other.latency_.trace_id() >= 0 && latency_.trace_id() >= 0) |
| 28 DCHECK_GT(other.latency_.trace_id(), latency_.trace_id()); | 29 DCHECK_GT(other.latency_.trace_id(), latency_.trace_id()); |
| 29 | 30 |
| 30 // New events get coalesced into older events, and the newer timestamp | 31 // New events get coalesced into older events, and the newer timestamp |
| 31 // should always be preserved. | 32 // should always be preserved. |
| 32 const double time_stamp_seconds = other.event().timeStampSeconds; | 33 const double time_stamp_seconds = |
| 33 ui::Coalesce(other.event(), event_.get()); | 34 other.coalescedEvent().event().timeStampSeconds; |
| 34 event_->timeStampSeconds = time_stamp_seconds; | 35 event_->addCoalescedEvent(other.coalescedEvent().event()); |
| 36 ui::Coalesce(other.coalescedEvent().event(), event_->eventPointer()); |
| 37 event_->eventPointer()->timeStampSeconds = time_stamp_seconds; |
| 35 | 38 |
| 36 // When coalescing two input events, we keep the oldest LatencyInfo | 39 // When coalescing two input events, we keep the oldest LatencyInfo |
| 37 // since it will represent the longest latency. | 40 // since it will represent the longest latency. |
| 38 other.latency_ = latency_; | 41 other.latency_ = latency_; |
| 39 other.latency_.set_coalesced(); | 42 other.latency_.set_coalesced(); |
| 40 } | 43 } |
| 41 | 44 |
| 42 const blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() const { | 45 const blink::WebCoalescedInputEvent& |
| 46 ScopedWebInputEventWithLatencyInfo::coalescedEvent() const { |
| 43 return *event_; | 47 return *event_; |
| 44 } | 48 } |
| 45 | 49 |
| 46 blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() { | 50 blink::WebCoalescedInputEvent& |
| 51 ScopedWebInputEventWithLatencyInfo::coalescedEvent() { |
| 47 return *event_; | 52 return *event_; |
| 48 } | 53 } |
| 49 | 54 |
| 50 } // namespace content | 55 } // namespace content |
| OLD | NEW |