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

Unified Diff: sky/shell/ui/input_event_converter.cc

Issue 932283002: Port touch-demo.sky to Dart and make it work in SkyShell (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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: sky/shell/ui/input_event_converter.cc
diff --git a/sky/shell/ui/input_event_converter.cc b/sky/shell/ui/input_event_converter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9fcf49c3d23dfcec6b3ee8cebb75321924ad23dd
--- /dev/null
+++ b/sky/shell/ui/input_event_converter.cc
@@ -0,0 +1,64 @@
+// Copyright 2014 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 "sky/shell/ui/input_event_converter.h"
+
+#include "base/logging.h"
+#include "base/time/time.h"
+#include "sky/engine/public/platform/WebInputEvent.h"
+
+namespace sky {
+namespace {
+
+scoped_ptr<blink::WebInputEvent> BuildWebPointerEvent(
+ const InputEventPtr& event, float device_pixel_ratio) {
+ scoped_ptr<blink::WebPointerEvent> web_event(new blink::WebPointerEvent);
+
+ web_event->timeStampMS =
+ base::TimeDelta::FromInternalValue(event->time_stamp).InMillisecondsF();
+
+ switch (event->type) {
+ case EVENT_TYPE_POINTER_DOWN:
+ web_event->type = blink::WebInputEvent::PointerDown;
+ break;
+ case EVENT_TYPE_POINTER_UP:
+ web_event->type = blink::WebInputEvent::PointerUp;
+ break;
+ case EVENT_TYPE_POINTER_MOVE:
+ web_event->type = blink::WebInputEvent::PointerMove;
+ break;
+ case EVENT_TYPE_POINTER_CANCEL:
+ web_event->type = blink::WebInputEvent::PointerCancel;
+ break;
+ default:
+ NOTIMPLEMENTED() << "Received unexpected event: " << event->type;
+ break;
+ }
+
+ if (event->pointer_data) {
+ if (event->pointer_data->kind == POINTER_KIND_TOUCH)
+ web_event->kind = blink::WebPointerEvent::Touch;
+ web_event->pointer = event->pointer_data->pointer;
+ web_event->x = event->pointer_data->x / device_pixel_ratio;
+ web_event->y = event->pointer_data->y / device_pixel_ratio;
+ }
+
+ return web_event.Pass();
+}
+
+} // namespace
+
+scoped_ptr<blink::WebInputEvent> ConvertEvent(const InputEventPtr& event,
+ float device_pixel_ratio) {
+ if (event->type == EVENT_TYPE_POINTER_DOWN ||
+ event->type == EVENT_TYPE_POINTER_UP ||
+ event->type == EVENT_TYPE_POINTER_MOVE ||
+ event->type == EVENT_TYPE_POINTER_CANCEL) {
+ return BuildWebPointerEvent(event, device_pixel_ratio);
+ }
+
+ return scoped_ptr<blink::WebInputEvent>();
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698