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 "ui/events/blink/event_with_callback.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "ui/events/blink/blink_event_util.h" |
| 9 #include "ui/events/blink/did_overscroll_params.h" |
| 10 #include "ui/events/blink/web_input_event_traits.h" |
| 11 |
| 12 using blink::WebInputEvent; |
| 13 using blink::WebGestureEvent; |
| 14 |
| 15 namespace ui { |
| 16 |
| 17 EventWithCallback::EventWithCallback( |
| 18 ScopedWebInputEvent event, |
| 19 const LatencyInfo& latency, |
| 20 base::TimeTicks timestamp_now, |
| 21 const InputHandlerProxy::EventDispositionCallback& callback) |
| 22 : event_(WebInputEventTraits::Clone(*event)), |
| 23 latency_(latency), |
| 24 creation_timestamp_(timestamp_now), |
| 25 last_coalesced_timestamp_(timestamp_now) { |
| 26 original_events_.emplace_back(std::move(event), callback); |
| 27 } |
| 28 |
| 29 EventWithCallback::~EventWithCallback() {} |
| 30 |
| 31 bool EventWithCallback::CanCoalesceWith(const EventWithCallback& other) const { |
| 32 return CanCoalesce(other.event(), event()); |
| 33 } |
| 34 |
| 35 void EventWithCallback::CoalesceWith(EventWithCallback* other, |
| 36 base::TimeTicks timestamp_now) { |
| 37 // |other| should be a newer event than |this|. |
| 38 if (other->latency_.trace_id() >= 0 && latency_.trace_id() >= 0) |
| 39 DCHECK_GT(other->latency_.trace_id(), latency_.trace_id()); |
| 40 |
| 41 // New events get coalesced into older events, and the newer timestamp |
| 42 // should always be preserved. |
| 43 const double time_stamp_seconds = other->event().timeStampSeconds; |
| 44 Coalesce(other->event(), event_.get()); |
| 45 event_->timeStampSeconds = time_stamp_seconds; |
| 46 |
| 47 // When coalescing two input events, we keep the oldest LatencyInfo |
| 48 // since it will represent the longest latency. |
| 49 other->latency_ = latency_; |
| 50 other->latency_.set_coalesced(); |
| 51 |
| 52 // Move original events. |
| 53 original_events_.splice(original_events_.end(), other->original_events_); |
| 54 last_coalesced_timestamp_ = timestamp_now; |
| 55 } |
| 56 |
| 57 void EventWithCallback::RunCallbacks( |
| 58 InputHandlerProxy::EventDisposition disposition, |
| 59 const LatencyInfo& latency, |
| 60 std::unique_ptr<DidOverscrollParams> did_overscroll_params) { |
| 61 for (auto& original_event : original_events_) { |
| 62 std::unique_ptr<DidOverscrollParams> did_overscroll_params_copy; |
| 63 if (did_overscroll_params) { |
| 64 did_overscroll_params_copy = |
| 65 base::MakeUnique<DidOverscrollParams>(*did_overscroll_params); |
| 66 } |
| 67 original_event.callback_.Run(disposition, std::move(original_event.event_), |
| 68 latency, std::move(did_overscroll_params)); |
| 69 } |
| 70 } |
| 71 |
| 72 EventWithCallback::OriginalEventWithCallback::OriginalEventWithCallback( |
| 73 ScopedWebInputEvent event, |
| 74 const InputHandlerProxy::EventDispositionCallback& callback) |
| 75 : event_(std::move(event)), callback_(callback) {} |
| 76 |
| 77 EventWithCallback::OriginalEventWithCallback::~OriginalEventWithCallback() {} |
| 78 |
| 79 } // namespace ui |
OLD | NEW |