Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/renderer_host/input/synthetic_gesture_target_android.h " | |
| 6 | |
| 7 #include "content/browser/android/content_view_core_impl.h" | |
| 8 #include "jni/SyntheticTouchEvent_jni.h" | |
| 9 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 10 | |
| 11 using WebKit::WebTouchEvent; | |
| 12 | |
| 13 namespace { | |
| 14 bool g_jni_initialized = false; | |
|
aelias_OOO_until_Jul13
2013/10/31 01:47:48
This isn't the usual way to do this. Could you ad
kouhei (in TOK)
2013/10/31 04:26:36
Done.
| |
| 15 | |
| 16 void RegisterNativesIfNeeded(JNIEnv* env) { | |
| 17 if (!g_jni_initialized) { | |
| 18 content::RegisterNativesImpl(env); | |
| 19 g_jni_initialized = true; | |
| 20 } | |
| 21 } | |
| 22 } // namespace | |
| 23 | |
| 24 namespace content { | |
| 25 | |
| 26 SyntheticGestureTargetAndroid::SyntheticGestureTargetAndroid( | |
| 27 RenderWidgetHostViewAndroid* render_view, | |
| 28 base::android::ScopedJavaLocalRef<jobject> java_touch_event) | |
| 29 : SyntheticGestureTargetBase(render_view), | |
| 30 java_touch_event_(java_touch_event) { | |
| 31 CHECK(!java_touch_event_.is_null()); | |
|
aelias_OOO_until_Jul13
2013/10/31 01:47:48
I don't see a strong reason for a CHECK here, plea
kouhei (in TOK)
2013/10/31 04:26:36
Done.
| |
| 32 | |
| 33 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 34 RegisterNativesIfNeeded(env); | |
| 35 } | |
| 36 | |
| 37 SyntheticGestureTargetAndroid::~SyntheticGestureTargetAndroid() { | |
| 38 } | |
| 39 | |
| 40 void SyntheticGestureTargetAndroid::TouchSetPointer( | |
| 41 JNIEnv* env, int index, int x, int y, int id) { | |
| 42 | |
|
aelias_OOO_until_Jul13
2013/10/31 01:47:48
nit: extra newline
kouhei (in TOK)
2013/10/31 04:26:36
Done.
| |
| 43 Java_SyntheticTouchEvent_setPointer(env, java_touch_event_.obj(), | |
| 44 index, x, y, id); | |
| 45 } | |
| 46 | |
| 47 void SyntheticGestureTargetAndroid::TouchInject( | |
| 48 JNIEnv* env, Action action, int pointer_count) { | |
| 49 Java_SyntheticTouchEvent_inject(env, java_touch_event_.obj(), | |
| 50 static_cast<int>(action), pointer_count); | |
| 51 } | |
| 52 | |
| 53 void SyntheticGestureTargetAndroid::QueueWebTouchEventToPlatform( | |
| 54 const WebKit::WebTouchEvent& web_touch, const ui::LatencyInfo&) { | |
| 55 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 56 | |
| 57 SyntheticGestureTargetAndroid::Action action = | |
| 58 SyntheticGestureTargetAndroid::ActionInvalid; | |
| 59 switch (web_touch.type) { | |
| 60 case WebKit::WebInputEvent::TouchStart: | |
| 61 action = SyntheticGestureTargetAndroid::ActionStart; | |
| 62 break; | |
| 63 case WebKit::WebInputEvent::TouchMove: | |
| 64 action = SyntheticGestureTargetAndroid::ActionMove; | |
| 65 break; | |
| 66 case WebKit::WebInputEvent::TouchCancel: | |
| 67 action = SyntheticGestureTargetAndroid::ActionCancel; | |
| 68 break; | |
| 69 case WebKit::WebInputEvent::TouchEnd: | |
| 70 action = SyntheticGestureTargetAndroid::ActionEnd; | |
| 71 break; | |
| 72 default: | |
| 73 NOTREACHED(); | |
| 74 } | |
| 75 const unsigned num_touches = web_touch.touchesLength; | |
| 76 for (unsigned i = 0; i < num_touches; ++i) { | |
| 77 const WebKit::WebTouchPoint* point = &web_touch.touches[i]; | |
| 78 TouchSetPointer(env, i, point->position.x, point->position.y, point->id); | |
| 79 } | |
| 80 | |
| 81 TouchInject(env, action, num_touches); | |
| 82 } | |
| 83 | |
| 84 SyntheticGestureParams::GestureSourceType | |
| 85 SyntheticGestureTargetAndroid::GetDefaultSyntheticGestureSourceType() const { | |
| 86 return SyntheticGestureParams::TOUCH_INPUT; | |
| 87 } | |
| 88 | |
| 89 bool SyntheticGestureTargetAndroid::SupportsSyntheticGestureSourceType( | |
| 90 SyntheticGestureParams::GestureSourceType gesture_source_type) const { | |
| 91 return gesture_source_type == SyntheticGestureParams::TOUCH_INPUT; | |
| 92 } | |
| 93 | |
| 94 } // namespace content | |
| OLD | NEW |