Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Unified Diff: ui/events/blink/event_with_callback.cc

Issue 2429953002: Implement compositor thread VSync aligned event queue (Closed)
Patch Set: dtapuska&enne's review: Call |Now()| once per loop; Chromium style; Remove parameterized test Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/events/blink/event_with_callback.h ('k') | ui/events/blink/input_handler_proxy.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/blink/event_with_callback.cc
diff --git a/ui/events/blink/event_with_callback.cc b/ui/events/blink/event_with_callback.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bcbd862ec5208e8ef3c4b3ad7b7d01c1575c8f9c
--- /dev/null
+++ b/ui/events/blink/event_with_callback.cc
@@ -0,0 +1,79 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/events/blink/event_with_callback.h"
+
+#include "base/memory/ptr_util.h"
+#include "ui/events/blink/blink_event_util.h"
+#include "ui/events/blink/did_overscroll_params.h"
+#include "ui/events/blink/web_input_event_traits.h"
+
+using blink::WebInputEvent;
+using blink::WebGestureEvent;
+
+namespace ui {
+
+EventWithCallback::EventWithCallback(
+ ScopedWebInputEvent event,
+ const LatencyInfo& latency,
+ base::TimeTicks timestamp_now,
+ const InputHandlerProxy::EventDispositionCallback& callback)
+ : event_(WebInputEventTraits::Clone(*event)),
+ latency_(latency),
+ creation_timestamp_(timestamp_now),
+ last_coalesced_timestamp_(timestamp_now) {
+ original_events_.emplace_back(std::move(event), callback);
+}
+
+EventWithCallback::~EventWithCallback() {}
+
+bool EventWithCallback::CanCoalesceWith(const EventWithCallback& other) const {
+ return CanCoalesce(other.event(), event());
+}
+
+void EventWithCallback::CoalesceWith(EventWithCallback* other,
+ base::TimeTicks timestamp_now) {
+ // |other| should be a newer event than |this|.
+ if (other->latency_.trace_id() >= 0 && latency_.trace_id() >= 0)
+ DCHECK_GT(other->latency_.trace_id(), latency_.trace_id());
+
+ // New events get coalesced into older events, and the newer timestamp
+ // should always be preserved.
+ const double time_stamp_seconds = other->event().timeStampSeconds;
+ Coalesce(other->event(), event_.get());
+ event_->timeStampSeconds = time_stamp_seconds;
+
+ // When coalescing two input events, we keep the oldest LatencyInfo
+ // since it will represent the longest latency.
+ other->latency_ = latency_;
+ other->latency_.set_coalesced();
+
+ // Move original events.
+ original_events_.splice(original_events_.end(), other->original_events_);
+ last_coalesced_timestamp_ = timestamp_now;
+}
+
+void EventWithCallback::RunCallbacks(
+ InputHandlerProxy::EventDisposition disposition,
+ const LatencyInfo& latency,
+ std::unique_ptr<DidOverscrollParams> did_overscroll_params) {
+ for (auto& original_event : original_events_) {
+ std::unique_ptr<DidOverscrollParams> did_overscroll_params_copy;
+ if (did_overscroll_params) {
+ did_overscroll_params_copy =
+ base::MakeUnique<DidOverscrollParams>(*did_overscroll_params);
+ }
+ original_event.callback_.Run(disposition, std::move(original_event.event_),
+ latency, std::move(did_overscroll_params));
+ }
+}
+
+EventWithCallback::OriginalEventWithCallback::OriginalEventWithCallback(
+ ScopedWebInputEvent event,
+ const InputHandlerProxy::EventDispositionCallback& callback)
+ : event_(std::move(event)), callback_(callback) {}
+
+EventWithCallback::OriginalEventWithCallback::~OriginalEventWithCallback() {}
+
+} // namespace ui
« no previous file with comments | « ui/events/blink/event_with_callback.h ('k') | ui/events/blink/input_handler_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698