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

Side by Side Diff: webkit/glue/fling_animator_impl_android.cc

Issue 12638003: Replace hand-written JNI in fling_animator with generated bindings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/glue/fling_animator_impl_android.h ('k') | webkit/glue/webkit_glue.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/glue/fling_animator_impl_android.h" 5 #include "webkit/glue/fling_animator_impl_android.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/scoped_java_ref.h" 8 #include "base/android/scoped_java_ref.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "jni/OverScroller_jni.h"
10 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatSize.h" 11 #include "third_party/WebKit/Source/Platform/chromium/public/WebFloatSize.h"
11 #include "third_party/WebKit/Source/Platform/chromium/public/WebGestureCurveTarg et.h" 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebGestureCurveTarg et.h"
12 #include "ui/gfx/screen.h" 13 #include "ui/gfx/screen.h"
13 #include "ui/gfx/vector2d.h" 14 #include "ui/gfx/vector2d.h"
14 15
15 using base::android::AttachCurrentThread;
16 using base::android::CheckException;
17 using base::android::GetApplicationContext;
18 using base::android::GetClass;
19 using base::android::MethodID;
20 using base::android::ScopedJavaLocalRef;
21
22 namespace webkit_glue { 16 namespace webkit_glue {
23 17
24 FlingAnimatorImpl::FlingAnimatorImpl() 18 FlingAnimatorImpl::FlingAnimatorImpl()
25 : is_active_(false) { 19 : is_active_(false) {
26 // hold the global reference of the Java objects. 20 // hold the global reference of the Java objects.
27 JNIEnv* env = AttachCurrentThread(); 21 JNIEnv* env = base::android::AttachCurrentThread();
28 DCHECK(env); 22 java_scroller_.Reset(JNI_OverScroller::Java_OverScroller_ConstructorAWOS_ACC(
29 ScopedJavaLocalRef<jclass> cls(GetClass(env, "android/widget/OverScroller")); 23 env,
30 jmethodID constructor = MethodID::Get<MethodID::TYPE_INSTANCE>( 24 base::android::GetApplicationContext()));
31 env, cls.obj(), "<init>", "(Landroid/content/Context;)V");
32 ScopedJavaLocalRef<jobject> tmp(env, env->NewObject(cls.obj(), constructor,
33 GetApplicationContext()));
34 DCHECK(tmp.obj());
35 java_scroller_.Reset(tmp);
36
37 fling_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
38 env, cls.obj(), "fling", "(IIIIIIII)V");
39 abort_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
40 env, cls.obj(), "abortAnimation", "()V");
41 compute_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
42 env, cls.obj(), "computeScrollOffset", "()Z");
43 getX_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
44 env, cls.obj(), "getCurrX", "()I");
45 getY_method_id_ = MethodID::Get<MethodID::TYPE_INSTANCE>(
46 env, cls.obj(), "getCurrY", "()I");
47 } 25 }
48 26
49 FlingAnimatorImpl::~FlingAnimatorImpl() 27 FlingAnimatorImpl::~FlingAnimatorImpl()
50 { 28 {
51 } 29 }
52 30
31 //static
32 bool FlingAnimatorImpl::RegisterJni(JNIEnv* env) {
33 return JNI_OverScroller::RegisterNativesImpl(env);
34 }
35
53 void FlingAnimatorImpl::StartFling(const gfx::PointF& velocity) 36 void FlingAnimatorImpl::StartFling(const gfx::PointF& velocity)
54 { 37 {
55 // No bounds on the fling. See http://webkit.org/b/96403 38 // No bounds on the fling. See http://webkit.org/b/96403
56 // Instead, use the largest possible bounds for minX/maxX/minY/maxY. The 39 // Instead, use the largest possible bounds for minX/maxX/minY/maxY. The
57 // compositor will ignore any attempt to scroll beyond the end of the page. 40 // compositor will ignore any attempt to scroll beyond the end of the page.
58 41
59 DCHECK(velocity.x() || velocity.y()); 42 DCHECK(velocity.x() || velocity.y());
60 if (is_active_) 43 if (is_active_)
61 CancelFling(); 44 CancelFling();
62 45
63 is_active_ = true; 46 is_active_ = true;
64 47
65 JNIEnv* env = AttachCurrentThread(); 48 JNIEnv* env = base::android::AttachCurrentThread();
66 49
67 env->CallVoidMethod(java_scroller_.obj(), fling_method_id_, 0, 0, 50 JNI_OverScroller::Java_OverScroller_flingV_I_I_I_I_I_I_I_I(
68 static_cast<int>(velocity.x()), 51 env, java_scroller_.obj(), 0, 0,
69 static_cast<int>(velocity.y()), 52 static_cast<int>(velocity.x()),
70 INT_MIN, INT_MAX, INT_MIN, INT_MAX); 53 static_cast<int>(velocity.y()),
71 CheckException(env); 54 INT_MIN, INT_MAX, INT_MIN, INT_MAX);
72 } 55 }
73 56
74 void FlingAnimatorImpl::CancelFling() 57 void FlingAnimatorImpl::CancelFling()
75 { 58 {
76 if (!is_active_) 59 if (!is_active_)
77 return; 60 return;
78 61
79 is_active_ = false; 62 is_active_ = false;
80 JNIEnv* env = AttachCurrentThread(); 63 JNIEnv* env = base::android::AttachCurrentThread();
81 env->CallVoidMethod(java_scroller_.obj(), abort_method_id_); 64 JNI_OverScroller::Java_OverScroller_abortAnimation(env, java_scroller_.obj());
82 CheckException(env);
83 } 65 }
84 66
85 bool FlingAnimatorImpl::UpdatePosition() 67 bool FlingAnimatorImpl::UpdatePosition()
86 { 68 {
87 JNIEnv* env = AttachCurrentThread(); 69 JNIEnv* env = base::android::AttachCurrentThread();
88 bool result = env->CallBooleanMethod(java_scroller_.obj(), 70 bool result = JNI_OverScroller::Java_OverScroller_computeScrollOffset(
89 compute_method_id_); 71 env,
90 CheckException(env); 72 java_scroller_.obj());
91 return is_active_ = result; 73 return is_active_ = result;
92 } 74 }
93 75
94 gfx::Point FlingAnimatorImpl::GetCurrentPosition() 76 gfx::Point FlingAnimatorImpl::GetCurrentPosition()
95 { 77 {
96 JNIEnv* env = AttachCurrentThread(); 78 JNIEnv* env = base::android::AttachCurrentThread();
97 gfx::Point position( 79 gfx::Point position(
98 env->CallIntMethod(java_scroller_.obj(), getX_method_id_), 80 JNI_OverScroller::Java_OverScroller_getCurrX(env, java_scroller_.obj()),
99 env->CallIntMethod(java_scroller_.obj(), getY_method_id_)); 81 JNI_OverScroller::Java_OverScroller_getCurrY(env, java_scroller_.obj()));
100 CheckException(env);
101 return position; 82 return position;
102 } 83 }
103 84
104 bool FlingAnimatorImpl::apply(double time, 85 bool FlingAnimatorImpl::apply(double time,
105 WebKit::WebGestureCurveTarget* target) { 86 WebKit::WebGestureCurveTarget* target) {
106 if (!UpdatePosition()) 87 if (!UpdatePosition())
107 return false; 88 return false;
108 89
109 gfx::Point current_position = GetCurrentPosition(); 90 gfx::Point current_position = GetCurrentPosition();
110 gfx::Vector2d diff(current_position - last_position_); 91 gfx::Vector2d diff(current_position - last_position_);
(...skipping 10 matching lines...) Expand all
121 102
122 FlingAnimatorImpl* FlingAnimatorImpl::CreateAndroidGestureCurve( 103 FlingAnimatorImpl* FlingAnimatorImpl::CreateAndroidGestureCurve(
123 const WebKit::WebFloatPoint& velocity, 104 const WebKit::WebFloatPoint& velocity,
124 const WebKit::WebSize&) { 105 const WebKit::WebSize&) {
125 FlingAnimatorImpl* gesture_curve = new FlingAnimatorImpl(); 106 FlingAnimatorImpl* gesture_curve = new FlingAnimatorImpl();
126 gesture_curve->StartFling(velocity); 107 gesture_curve->StartFling(velocity);
127 return gesture_curve; 108 return gesture_curve;
128 } 109 }
129 110
130 } // namespace webkit_glue 111 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/fling_animator_impl_android.h ('k') | webkit/glue/webkit_glue.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698