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