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

Unified Diff: content/common/input/web_platform_input_event.cc

Issue 19624005: Add InputEvent and EventPacket types for batched input delivery (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 7 years, 4 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: content/common/input/web_platform_input_event.cc
diff --git a/content/common/input/web_platform_input_event.cc b/content/common/input/web_platform_input_event.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7a17affb3526cc36f818f5b0b60b9c71a07590ce
--- /dev/null
+++ b/content/common/input/web_platform_input_event.cc
@@ -0,0 +1,98 @@
+// Copyright (c) 2013 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 "content/common/input/web_platform_input_event.h"
+
+#include "base/logging.h"
+#include "third_party/WebKit/public/web/WebInputEvent.h"
+
+namespace content {
+namespace {
+static WebPlatformInputEvent::ScopedWebInputEvent CloneWebInputEvent(
+ const WebKit::WebInputEvent& event) {
+ WebPlatformInputEvent::ScopedWebInputEvent clone;
+ if (WebKit::WebInputEvent::isMouseEventType(event.type))
+ clone.reset(new WebKit::WebMouseEvent());
+ else if (event.type == WebKit::WebInputEvent::MouseWheel)
+ clone.reset(new WebKit::WebMouseWheelEvent());
+ else if (WebKit::WebInputEvent::isKeyboardEventType(event.type))
+ clone.reset(new WebKit::WebKeyboardEvent());
+ else if (WebKit::WebInputEvent::isTouchEventType(event.type))
+ clone.reset(new WebKit::WebTouchEvent());
+ else if (WebKit::WebInputEvent::isGestureEventType(event.type))
+ clone.reset(new WebKit::WebGestureEvent());
+ else
+ NOTREACHED() << "Unknown webkit event type " << event.type;
+
+ if (!clone)
+ return clone.Pass();
+
+ DCHECK_EQ(event.size, clone->size);
+ memcpy(clone.get(), &event, event.size);
+ return clone.Pass();
+}
+} // namespace
+
+WebPlatformInputEvent::WebInputEventDeleter::WebInputEventDeleter() {}
+
+void WebPlatformInputEvent::WebInputEventDeleter::operator()(
+ WebKit::WebInputEvent* event) const {
+ if (!event)
+ return;
+
+ if (WebKit::WebInputEvent::isMouseEventType(event->type))
+ delete static_cast<WebKit::WebMouseEvent*>(event);
+ else if (event->type == WebKit::WebInputEvent::MouseWheel)
+ delete static_cast<WebKit::WebMouseWheelEvent*>(event);
+ else if (WebKit::WebInputEvent::isKeyboardEventType(event->type))
+ delete static_cast<WebKit::WebKeyboardEvent*>(event);
+ else if (WebKit::WebInputEvent::isTouchEventType(event->type))
+ delete static_cast<WebKit::WebTouchEvent*>(event);
+ else if (WebKit::WebInputEvent::isGestureEventType(event->type))
+ delete static_cast<WebKit::WebGestureEvent*>(event);
+ else
+ NOTREACHED() << "Unknown webkit event type " << event->type;
+}
+
+WebPlatformInputEvent::WebPlatformInputEvent(AckType ack_type, int64 id)
+ : InputEvent(WEB_PLATFORM, ack_type, id),
+ is_keyboard_shortcut(false) {}
+
+WebPlatformInputEvent::~WebPlatformInputEvent() {}
+
+scoped_ptr<WebPlatformInputEvent> WebPlatformInputEvent::Create() {
+ return make_scoped_ptr(new WebPlatformInputEvent(ACK_REQUIRED, 0));
+}
+
+scoped_ptr<WebPlatformInputEvent> WebPlatformInputEvent::Create(
+ int64 id,
+ const WebKit::WebInputEvent& event,
+ const ui::LatencyInfo& latency_info,
+ bool is_keyboard_shortcut,
+ bool can_create_followup_events) {
+ AckType ack_type = can_create_followup_events ? ACK_CAN_CREATE_FOLLOWUP_EVENTS
+ : ACK_REQUIRED;
+ scoped_ptr<WebPlatformInputEvent> web_event(
+ new WebPlatformInputEvent(ack_type, id));
+ web_event->Initialize(event,
+ latency_info,
+ is_keyboard_shortcut);
+ return web_event.Pass();
+}
+
+void WebPlatformInputEvent::Initialize(const WebKit::WebInputEvent& event,
+ const ui::LatencyInfo& latency_info,
+ bool is_keyboard_shortcut) {
+ this->event = CloneWebInputEvent(event);
+ this->latency_info = latency_info;
+ this->is_keyboard_shortcut = is_keyboard_shortcut;
+}
+
+const WebPlatformInputEvent* WebPlatformInputEvent::EventCast(
+ const InputEvent* event) {
+ DCHECK_EQ(InputEvent::WEB_PLATFORM, event->type);
+ return static_cast<const WebPlatformInputEvent*>(event);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698