| 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/generic_touch_gesture_android.h" | |
| 6 | |
| 7 #include "base/debug/trace_event.h" | |
| 8 #include "content/browser/renderer_host/render_widget_host_impl.h" | |
| 9 #include "jni/GenericTouchGesture_jni.h" | |
| 10 | |
| 11 namespace { | |
| 12 bool g_jni_initialized = false; | |
| 13 | |
| 14 void RegisterNativesIfNeeded(JNIEnv* env) { | |
| 15 if (!g_jni_initialized) { | |
| 16 content::RegisterNativesImpl(env); | |
| 17 g_jni_initialized = true; | |
| 18 } | |
| 19 } | |
| 20 } // namespace | |
| 21 | |
| 22 namespace content { | |
| 23 | |
| 24 GenericTouchGestureAndroid::GenericTouchGestureAndroid( | |
| 25 RenderWidgetHost* rwh, | |
| 26 base::android::ScopedJavaLocalRef<jobject> java_touch_gesture) | |
| 27 : has_started_(false), | |
| 28 has_finished_(false), | |
| 29 rwh_(rwh), | |
| 30 java_touch_gesture_(java_touch_gesture) { | |
| 31 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 32 RegisterNativesIfNeeded(env); | |
| 33 } | |
| 34 | |
| 35 GenericTouchGestureAndroid::~GenericTouchGestureAndroid() { | |
| 36 } | |
| 37 | |
| 38 bool GenericTouchGestureAndroid::ForwardInputEvents( | |
| 39 base::TimeTicks now, RenderWidgetHost* host) { | |
| 40 if (!has_started_) { | |
| 41 has_started_ = true; | |
| 42 JNIEnv* env = base::android::AttachCurrentThread(); | |
| 43 Java_GenericTouchGesture_start( | |
| 44 env, java_touch_gesture_.obj(), reinterpret_cast<intptr_t>(this)); | |
| 45 } | |
| 46 | |
| 47 return !has_finished_; | |
| 48 } | |
| 49 | |
| 50 float GenericTouchGestureAndroid::GetDelta( | |
| 51 JNIEnv* env, jobject obj, float scale) { | |
| 52 return synthetic_gesture_calculator_.GetDelta( | |
| 53 base::TimeTicks::Now(), | |
| 54 RenderWidgetHostImpl::From(rwh_)->GetSyntheticGestureMessageInterval()) * | |
| 55 scale; | |
| 56 } | |
| 57 | |
| 58 void GenericTouchGestureAndroid::SetHasFinished(JNIEnv* env, jobject obj) { | |
| 59 has_finished_ = true; | |
| 60 } | |
| 61 | |
| 62 } // namespace content | |
| OLD | NEW |