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

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

Issue 2576013002: Introducing WebCoalescedInputEvent and inclusion in content/common (Closed)
Patch Set: Created 4 years 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/WebCoalescedInputEvent.cpp
diff --git a/third_party/WebKit/Source/web/WebCoalescedInputEvent.cpp b/third_party/WebKit/Source/web/WebCoalescedInputEvent.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..4872ac2909d0114a14d0d669b88a7164266e8187
--- /dev/null
+++ b/third_party/WebKit/Source/web/WebCoalescedInputEvent.cpp
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2009 Google Inc. All rights reserved.
esprehn 2016/12/20 20:46:18 2009? Also use the short copyright for new files.
Navid Zolghadr 2016/12/22 20:50:33 Done.
+ *
+ * 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/WebCoalescedInputEvent.h"
+
+#include "public/platform/WebGestureEvent.h"
+
+namespace blink {
+
+namespace {
+
+WebCoalescedInputEvent::ScopedWebInputEvent makeScopedWebInputEvent(
+ const blink::WebInputEvent& event) {
+ if (blink::WebInputEvent::isGestureEventType(event.type)) {
+ return WebCoalescedInputEvent::ScopedWebInputEvent(
+ new blink::WebGestureEvent(
+ static_cast<const blink::WebGestureEvent&>(event)));
+ }
+ if (blink::WebInputEvent::isMouseEventType(event.type)) {
+ return WebCoalescedInputEvent::ScopedWebInputEvent(new blink::WebMouseEvent(
+ static_cast<const blink::WebMouseEvent&>(event)));
+ }
+ if (blink::WebInputEvent::isTouchEventType(event.type)) {
+ return WebCoalescedInputEvent::ScopedWebInputEvent(new blink::WebTouchEvent(
+ static_cast<const blink::WebTouchEvent&>(event)));
+ }
+ if (event.type == blink::WebInputEvent::MouseWheel) {
+ return WebCoalescedInputEvent::ScopedWebInputEvent(
+ new blink::WebMouseWheelEvent(
+ static_cast<const blink::WebMouseWheelEvent&>(event)));
+ }
+ if (blink::WebInputEvent::isKeyboardEventType(event.type)) {
+ return WebCoalescedInputEvent::ScopedWebInputEvent(
+ new blink::WebKeyboardEvent(
+ static_cast<const blink::WebKeyboardEvent&>(event)));
+ }
+ NOTREACHED();
+ return WebCoalescedInputEvent::ScopedWebInputEvent();
+}
+}
+
+WebCoalescedInputEvent::WebInputEventDeleter::WebInputEventDeleter() {}
+
+void WebCoalescedInputEvent::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();
+}
+
+WebInputEvent* WebCoalescedInputEvent::eventPointer() {
+ return mEvent.get();
+}
+
+void WebCoalescedInputEvent::addCoalescedEvent(
+ const blink::WebInputEvent& event) {
+ mCoalescedEvents.push_back(makeScopedWebInputEvent(event));
+}
+
+const WebInputEvent& WebCoalescedInputEvent::event() const {
+ return *mEvent.get();
+}
+
+size_t WebCoalescedInputEvent::coalescedEventSize() const {
+ return mCoalescedEvents.size();
+}
+
+const WebInputEvent* WebCoalescedInputEvent::coalescedEvent(int index) const {
+ return mCoalescedEvents[index].get();
+}
+
+std::vector<const WebInputEvent*>
+WebCoalescedInputEvent::getCoalescedEventsPointers() const {
+ std::vector<const WebInputEvent*> events(mCoalescedEvents.size());
+ for (const auto& event : mCoalescedEvents)
+ events.push_back(event.get());
+ return events;
+}
+
+WebCoalescedInputEvent::WebCoalescedInputEvent(ScopedWebInputEvent event)
+ : mEvent(std::move(event)), mCoalescedEvents() {
+ mCoalescedEvents.push_back(makeScopedWebInputEvent(*(mEvent.get())));
+}
+
+WebCoalescedInputEvent::WebCoalescedInputEvent(const WebInputEvent& event)
+ : mEvent(), mCoalescedEvents() {
+ mEvent = makeScopedWebInputEvent(event);
+ mCoalescedEvents.push_back(makeScopedWebInputEvent(event));
+}
+
+WebCoalescedInputEvent::WebCoalescedInputEvent(
+ const WebInputEvent& event,
+ const std::vector<const WebInputEvent*>& coalescedEvents)
+ : mEvent(), mCoalescedEvents(coalescedEvents.size()) {
+ mEvent = makeScopedWebInputEvent(event);
+ for (const auto& coalescedEvent : coalescedEvents)
+ mCoalescedEvents.push_back(makeScopedWebInputEvent(*coalescedEvent));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698