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

Unified Diff: third_party/WebKit/Source/web/CoalescedWebInputEvent.cpp

Issue 2479123003: WIP Add getCoalescedEvents API using vector of WebInputEvents (Closed)
Patch Set: Creating CoalescedWebInputEvent 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
Index: third_party/WebKit/Source/web/CoalescedWebInputEvent.cpp
diff --git a/third_party/WebKit/Source/web/CoalescedWebInputEvent.cpp b/third_party/WebKit/Source/web/CoalescedWebInputEvent.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9b9f5be32141546a2b308703f0c850dea3c3a323
--- /dev/null
+++ b/third_party/WebKit/Source/web/CoalescedWebInputEvent.cpp
@@ -0,0 +1,132 @@
+/*
jbroman 2016/11/22 15:27:37 Blink-side implementations of classes in public/pl
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "public/platform/CoalescedWebInputEvent.h"
+
+#include "public/platform/WebGestureEvent.h"
+
+namespace blink {
+
+namespace {
+
+CoalescedWebInputEvent::ScopedWebInputEvent makeScopedWebInputEvent(
+ const blink::WebInputEvent& event) {
+ if (blink::WebInputEvent::isGestureEventType(event.type)) {
dtapuska 2016/11/21 18:21:18 What about keyboard?
+ return CoalescedWebInputEvent::ScopedWebInputEvent(
+ new blink::WebGestureEvent(
+ static_cast<const blink::WebGestureEvent&>(event)));
+ }
+ if (blink::WebInputEvent::isMouseEventType(event.type)) {
+ return CoalescedWebInputEvent::ScopedWebInputEvent(new blink::WebMouseEvent(
+ static_cast<const blink::WebMouseEvent&>(event)));
+ }
+ if (blink::WebInputEvent::isTouchEventType(event.type)) {
+ return CoalescedWebInputEvent::ScopedWebInputEvent(new blink::WebTouchEvent(
+ static_cast<const blink::WebTouchEvent&>(event)));
+ }
+ if (event.type == blink::WebInputEvent::MouseWheel) {
+ return CoalescedWebInputEvent::ScopedWebInputEvent(
+ new blink::WebMouseWheelEvent(
+ static_cast<const blink::WebMouseWheelEvent&>(event)));
+ }
+ NOTREACHED();
+ return CoalescedWebInputEvent::ScopedWebInputEvent();
+}
+}
+
+CoalescedWebInputEvent::WebInputEventDeleter::WebInputEventDeleter() {}
+
+void CoalescedWebInputEvent::WebInputEventDeleter::operator()(
+ WebInputEvent* event) const {
+ if (!event)
+ return;
+ const WebInputEvent::Type& type = event->type;
+ if (WebInputEvent::isMouseEventType(type))
+ delete static_cast<WebMouseEvent*>(event);
+ else if (type == WebInputEvent::MouseWheel)
+ delete static_cast<WebMouseWheelEvent*>(event);
+ else if (WebInputEvent::isKeyboardEventType(type))
+ delete static_cast<WebKeyboardEvent*>(event);
+ else if (WebInputEvent::isTouchEventType(type))
+ delete static_cast<WebTouchEvent*>(event);
+ else if (WebInputEvent::isGestureEventType(type))
+ delete static_cast<WebGestureEvent*>(event);
+ NOTREACHED();
jbroman 2016/11/22 15:27:37 This looks like it _is_ reached; there's no early
+}
+
+const WebInputEvent& CoalescedWebInputEvent::event() const {
+ return *mEvent.get();
+}
+
+WebInputEvent* CoalescedWebInputEvent::event() {
+ return mEvent.get();
+}
+
+void CoalescedWebInputEvent::addCoalescedEvent(
+ const blink::WebInputEvent& event) {
+ mCoalescedEvents.push_back(makeScopedWebInputEvent(event));
+}
+
+size_t CoalescedWebInputEvent::coalescedEventSize() {
+ return mCoalescedEvents.size();
+}
+
+WebInputEvent* CoalescedWebInputEvent::coalescedEvent(int index) {
+ return mCoalescedEvents[index];
+}
+
+const std::vector<WebInputEvent*>&
+CoalescedWebInputEvent::getCoalescedEventsPointers() {
+ std::vector<WebInputEvent*> events(mCoalescedEvents.size());
+ for (const auto& event : mCoalescedEvents)
+ events.push_back(event.get());
+ return events;
+}
+
+CoalescedWebInputEvent::CoalescedWebInputEvent(ScopedWebInputEvent event)
+ : mEvent(std::move(event)), mCoalescedEvents() {
+ mCoalescedEvents.push_back(makeScopedWebInputEvent(*(mEvent.get())));
+}
+
+CoalescedWebInputEvent::CoalescedWebInputEvent(const WebInputEvent& event)
+ : mEvent(makeScopedWebInputEvent(event)), mCoalescedEvents() {
+ mCoalescedEvents.push_back(makeScopedWebInputEvent(event));
+}
+
+CoalescedWebInputEvent::CoalescedWebInputEvent(
+ const WebInputEvent&,
+ const std::vector<const WebInputEvent*>& coalescedEvents)
+ : mEvent(makeScopedWebInputEvent(event)),
+ mCoalescedEvents(coalescedEvents.size()) {
+ for (const auto& coalescedEvent : coalescedEvents)
+ mCoalescedEvents.push_back(makeScopedWebInputEvent(*coalescedEvent));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698