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

Unified Diff: third_party/WebKit/Source/platform/exported/WebCoalescedInputEvent.cpp

Issue 2576013002: Introducing WebCoalescedInputEvent and inclusion in content/common (Closed)
Patch Set: Fix a few DCHECK hits Created 3 years, 11 months 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
Index: third_party/WebKit/Source/platform/exported/WebCoalescedInputEvent.cpp
diff --git a/third_party/WebKit/Source/platform/exported/WebCoalescedInputEvent.cpp b/third_party/WebKit/Source/platform/exported/WebCoalescedInputEvent.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..4699fb3ed86cfbbbccd07cab900ec046ad28facf
--- /dev/null
+++ b/third_party/WebKit/Source/platform/exported/WebCoalescedInputEvent.cpp
@@ -0,0 +1,123 @@
+// 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 "public/platform/WebCoalescedInputEvent.h"
+
+#include "public/platform/WebGestureEvent.h"
+#include "public/platform/WebMouseWheelEvent.h"
+
+namespace blink {
+
+namespace {
+
+WebScopedInputEvent makeWebScopedInputEvent(const blink::WebInputEvent& event) {
+ if (blink::WebInputEvent::isGestureEventType(event.type)) {
+ return WebScopedInputEvent(new blink::WebGestureEvent(
+ static_cast<const blink::WebGestureEvent&>(event)));
+ }
+ if (blink::WebInputEvent::isMouseEventType(event.type)) {
+ return WebScopedInputEvent(new blink::WebMouseEvent(
+ static_cast<const blink::WebMouseEvent&>(event)));
+ }
+ if (blink::WebInputEvent::isTouchEventType(event.type)) {
+ return WebScopedInputEvent(new blink::WebTouchEvent(
+ static_cast<const blink::WebTouchEvent&>(event)));
+ }
+ if (event.type == blink::WebInputEvent::MouseWheel) {
+ return WebScopedInputEvent(new blink::WebMouseWheelEvent(
+ static_cast<const blink::WebMouseWheelEvent&>(event)));
+ }
+ if (blink::WebInputEvent::isKeyboardEventType(event.type)) {
+ return WebScopedInputEvent(new blink::WebKeyboardEvent(
+ static_cast<const blink::WebKeyboardEvent&>(event)));
+ }
+ NOTREACHED();
+ return WebScopedInputEvent();
+}
+
+struct WebInputEventDelete {
+ template <class EventType>
+ bool Execute(WebInputEvent* event) const {
+ if (!event)
+ return false;
+ DCHECK_EQ(sizeof(EventType), event->size);
+ delete static_cast<EventType*>(event);
+ return true;
+ }
+};
+
+template <typename Operator, typename ArgIn>
+bool Apply(Operator op, WebInputEvent::Type type, const ArgIn& argIn) {
+ if (WebInputEvent::isMouseEventType(type))
+ return op.template Execute<WebMouseEvent>(argIn);
+ if (type == WebInputEvent::MouseWheel)
+ return op.template Execute<WebMouseWheelEvent>(argIn);
+ if (WebInputEvent::isKeyboardEventType(type))
+ return op.template Execute<WebKeyboardEvent>(argIn);
+ if (WebInputEvent::isTouchEventType(type))
+ return op.template Execute<WebTouchEvent>(argIn);
+ if (WebInputEvent::isGestureEventType(type))
+ return op.template Execute<WebGestureEvent>(argIn);
+
+ NOTREACHED() << "Unknown webkit event type " << type;
+ return false;
+}
+}
+
+void WebInputEventDeleter::operator()(WebInputEvent* event) const {
+ if (!event)
+ return;
+ Apply(WebInputEventDelete(), event->type, event);
+}
+
+WebInputEvent* WebCoalescedInputEvent::eventPointer() {
+ return m_event.get();
+}
+
+void WebCoalescedInputEvent::addCoalescedEvent(
+ const blink::WebInputEvent& event) {
+ m_coalescedEvents.push_back(makeWebScopedInputEvent(event));
+}
+
+const WebInputEvent& WebCoalescedInputEvent::event() const {
+ return *m_event.get();
+}
+
+size_t WebCoalescedInputEvent::coalescedEventSize() const {
+ return m_coalescedEvents.size();
+}
+
+const WebInputEvent* WebCoalescedInputEvent::coalescedEvent(int index) const {
+ return m_coalescedEvents[index].get();
+}
+
+std::vector<const WebInputEvent*>
+WebCoalescedInputEvent::getCoalescedEventsPointers() const {
+ std::vector<const WebInputEvent*> events;
+ for (const auto& event : m_coalescedEvents)
+ events.push_back(event.get());
+ return events;
+}
+
+WebCoalescedInputEvent::WebCoalescedInputEvent(WebScopedInputEvent event)
+ : m_event(std::move(event)), m_coalescedEvents() {
+ m_coalescedEvents.push_back(makeWebScopedInputEvent(*(m_event.get())));
+}
+
+WebCoalescedInputEvent::WebCoalescedInputEvent(const WebInputEvent& event)
+ : m_event(), m_coalescedEvents() {
+ m_event = makeWebScopedInputEvent(event);
+ m_coalescedEvents.push_back(makeWebScopedInputEvent(event));
+}
+
+WebCoalescedInputEvent::WebCoalescedInputEvent(
+ const WebInputEvent& event,
+ const std::vector<const WebInputEvent*>& coalescedEvents)
+ : m_event(), m_coalescedEvents(coalescedEvents.size()) {
+ m_event = makeWebScopedInputEvent(event);
+ for (const auto& coalescedEvent : coalescedEvents)
+ m_coalescedEvents.push_back(makeWebScopedInputEvent(*coalescedEvent));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698