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

Unified Diff: content/browser/renderer_host/input/synthetic_gesture_target_android.cc

Issue 26664002: SyntheticGestureTarget implementation for injecting synthetic input events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove unused forward decl Created 7 years, 2 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/browser/renderer_host/input/synthetic_gesture_target_android.cc
diff --git a/content/browser/renderer_host/input/synthetic_gesture_target_android.cc b/content/browser/renderer_host/input/synthetic_gesture_target_android.cc
new file mode 100644
index 0000000000000000000000000000000000000000..fcc371fecc19c517123162a9ba73da2e37791c29
--- /dev/null
+++ b/content/browser/renderer_host/input/synthetic_gesture_target_android.cc
@@ -0,0 +1,90 @@
+// Copyright 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/browser/renderer_host/input/synthetic_gesture_target_android.h"
+
+#include "content/browser/android/content_view_core_impl.h"
+#include "jni/SyntheticTouchEvent_jni.h"
+#include "third_party/WebKit/public/web/WebInputEvent.h"
+
+using WebKit::WebTouchEvent;
+
+namespace {
+bool g_jni_initialized = false;
+
+void RegisterNativesIfNeeded(JNIEnv* env) {
+ if (!g_jni_initialized) {
+ content::RegisterNativesImpl(env);
+ g_jni_initialized = true;
+ }
+}
+} // namespace
+
+namespace content {
+
+SyntheticGestureTargetAndroid::SyntheticGestureTargetAndroid(
+ RenderWidgetHostViewAndroid* render_view)
+ : SyntheticGestureTargetBase(render_view),
+ env_(base::android::AttachCurrentThread()),
+ java_touch_event_(
+ render_view->content_view_core()->CreateSyntheticTouchEvent()) {
+ CHECK(!java_touch_event_.is_null());
+ RegisterNativesIfNeeded(env_);
+}
+
+SyntheticGestureTargetAndroid::~SyntheticGestureTargetAndroid() {
+}
+
+void SyntheticGestureTargetAndroid::TouchSetPointer(
+ int index, int x, int y, int id) {
+ Java_SyntheticTouchEvent_setPointer(env_, java_touch_event_.obj(),
+ index, x, y, id);
+}
+
+void SyntheticGestureTargetAndroid::TouchInject(
+ Action action, int pointer_count) {
+ Java_SyntheticTouchEvent_inject(env_, java_touch_event_.obj(),
+ static_cast<int>(action), pointer_count);
+}
+
+void SyntheticGestureTargetAndroid::QueueWebTouchEventToPlatform(
+ const WebKit::WebTouchEvent& web_touch, const ui::LatencyInfo&) {
+ SyntheticGestureTargetAndroid::Action action =
+ SyntheticGestureTargetAndroid::ActionInvalid;
+ switch (web_touch.type) {
+ case WebKit::WebInputEvent::TouchStart:
+ action = SyntheticGestureTargetAndroid::ActionStart;
+ break;
+ case WebKit::WebInputEvent::TouchMove:
+ action = SyntheticGestureTargetAndroid::ActionMove;
+ break;
+ case WebKit::WebInputEvent::TouchCancel:
+ action = SyntheticGestureTargetAndroid::ActionCancel;
+ break;
+ case WebKit::WebInputEvent::TouchEnd:
+ action = SyntheticGestureTargetAndroid::ActionEnd;
+ break;
+ default:
+ NOTREACHED();
+ }
+ const unsigned num_touches = web_touch.touchesLength;
+ for (unsigned i = 0; i < num_touches; ++i) {
+ const WebKit::WebTouchPoint* point = &web_touch.touches[i];
+ TouchSetPointer(i, point->position.x, point->position.y, point->id);
+ }
+
+ TouchInject(action, num_touches);
+}
+
+SyntheticGestureParams::GestureSourceType
+SyntheticGestureTargetAndroid::GetDefaultSyntheticGestureSourceType() const {
+ return SyntheticGestureParams::TOUCH_INPUT;
+}
+
+bool SyntheticGestureTargetAndroid::SupportsSyntheticGestureSourceType(
+ SyntheticGestureParams::GestureSourceType gesture_source_type) const {
+ return gesture_source_type == SyntheticGestureParams::TOUCH_INPUT;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698