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

Unified Diff: content/common/input/web_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: Separate InputEvent types for events based on WebKit::WebInputEvent 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_event.cc
diff --git a/content/common/input/web_event.cc b/content/common/input/web_event.cc
new file mode 100644
index 0000000000000000000000000000000000000000..eb41b3d9c68c3517ea648b77a6d2a6695d8c4bb9
--- /dev/null
+++ b/content/common/input/web_event.cc
@@ -0,0 +1,76 @@
+// 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_event.h"
+
+#include "base/logging.h"
+#include "third_party/WebKit/public/web/WebInputEvent.h"
+
+namespace content {
+namespace {
+// TODO(jdduke): Destroy this and WebEvent entirely when we find a suitable
+// replacement for input event types in content/.
+static scoped_ptr<WebKit::WebInputEvent> CloneWebInputEvent(
+ const WebKit::WebInputEvent& event) {
+ scoped_ptr<WebKit::WebInputEvent> 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) {
+ DCHECK(clone->size == event.size);
+ memcpy(clone.get(), &event, event.size);
+ }
+
+ return clone.Pass();
+}
+} // namespace
+
+WebEvent::WebEvent(int64 id)
+ : InputEvent(InputEvent::WEB, id),
+ is_keyboard_shortcut(false),
+ creates_followup_events(false) {}
+
+scoped_ptr<WebEvent> WebEvent::Create() {
+ return make_scoped_ptr(new WebEvent(0));
+}
+
+scoped_ptr<WebEvent> WebEvent::Create(int64 id,
+ const WebKit::WebInputEvent& event,
+ const ui::LatencyInfo& latency_info,
+ bool is_keyboard_shortcut,
+ bool creates_followup_events) {
+ scoped_ptr<WebEvent> web_event(new WebEvent(id));
+ web_event->SetAll(event,
+ latency_info,
+ is_keyboard_shortcut,
+ creates_followup_events);
+ return web_event.Pass();
+}
+
+void WebEvent::SetAll(const WebKit::WebInputEvent& event,
+ const ui::LatencyInfo& latency_info,
+ bool is_keyboard_shortcut,
+ bool creates_followup_events) {
+ this->event = CloneWebInputEvent(event);
+ this->latency_info = latency_info;
+ this->is_keyboard_shortcut = is_keyboard_shortcut;
+ this->creates_followup_events = creates_followup_events;
+}
+
+const WebEvent* WebEvent::EventCast(const InputEvent* event) {
+ DCHECK_EQ(InputEvent::WEB, event->type);
+ return static_cast<const WebEvent*>(event);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698