| 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 blink::WebScopedInputEvent event, | 12 blink::WebScopedInputEvent 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 latency_(latency_info) {} |
| 15 | 16 |
| 16 ScopedWebInputEventWithLatencyInfo::~ScopedWebInputEventWithLatencyInfo() {} | 17 ScopedWebInputEventWithLatencyInfo::~ScopedWebInputEventWithLatencyInfo() {} |
| 17 | 18 |
| 18 bool ScopedWebInputEventWithLatencyInfo::CanCoalesceWith( | 19 bool ScopedWebInputEventWithLatencyInfo::CanCoalesceWith( |
| 19 const ScopedWebInputEventWithLatencyInfo& other) const { | 20 const ScopedWebInputEventWithLatencyInfo& other) const { |
| 20 return ui::CanCoalesce(other.event(), event()); | 21 return ui::CanCoalesce(other.event(), event()); |
| 21 } | 22 } |
| 22 | 23 |
| 23 void ScopedWebInputEventWithLatencyInfo::CoalesceWith( | 24 void ScopedWebInputEventWithLatencyInfo::CoalesceWith( |
| 24 const ScopedWebInputEventWithLatencyInfo& other) { | 25 const ScopedWebInputEventWithLatencyInfo& other) { |
| 25 // |other| should be a newer event than |this|. | 26 // |other| should be a newer event than |this|. |
| 26 if (other.latency_.trace_id() >= 0 && latency_.trace_id() >= 0) | 27 if (other.latency_.trace_id() >= 0 && latency_.trace_id() >= 0) |
| 27 DCHECK_GT(other.latency_.trace_id(), latency_.trace_id()); | 28 DCHECK_GT(other.latency_.trace_id(), latency_.trace_id()); |
| 28 | 29 |
| 29 // New events get coalesced into older events, and the newer timestamp | 30 // New events get coalesced into older events, and the newer timestamp |
| 30 // should always be preserved. | 31 // should always be preserved. |
| 31 const double time_stamp_seconds = other.event().timeStampSeconds(); | 32 const double time_stamp_seconds = other.event().timeStampSeconds(); |
| 32 ui::Coalesce(other.event(), event_.get()); | 33 ui::Coalesce(other.event(), event_->eventPointer()); |
| 33 event_->setTimeStampSeconds(time_stamp_seconds); | 34 event_->eventPointer()->setTimeStampSeconds(time_stamp_seconds); |
| 35 event_->addCoalescedEvent(other.event()); |
| 34 | 36 |
| 35 // When coalescing two input events, we keep the oldest LatencyInfo | 37 // When coalescing two input events, we keep the oldest LatencyInfo |
| 36 // since it will represent the longest latency. | 38 // since it will represent the longest latency. |
| 37 other.latency_ = latency_; | 39 other.latency_ = latency_; |
| 38 other.latency_.set_coalesced(); | 40 other.latency_.set_coalesced(); |
| 39 } | 41 } |
| 40 | 42 |
| 41 const blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() const { | 43 const blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() const { |
| 44 return event_->event(); |
| 45 } |
| 46 |
| 47 blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() { |
| 48 return *event_->eventPointer(); |
| 49 } |
| 50 |
| 51 const blink::WebCoalescedInputEvent& |
| 52 ScopedWebInputEventWithLatencyInfo::coalesced_event() const { |
| 42 return *event_; | 53 return *event_; |
| 43 } | 54 } |
| 44 | 55 |
| 45 blink::WebInputEvent& ScopedWebInputEventWithLatencyInfo::event() { | |
| 46 return *event_; | |
| 47 } | |
| 48 | |
| 49 } // namespace content | 56 } // namespace content |
| OLD | NEW |