OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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/touch_smooth_scroll_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/SmoothScroller_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 TouchSmoothScrollGestureAndroid::TouchSmoothScrollGestureAndroid( |
| 25 int pixels_to_scroll, |
| 26 RenderWidgetHost* rwh, |
| 27 base::android::ScopedJavaLocalRef<jobject> java_scroller) |
| 28 : pixels_scrolled_(0), |
| 29 has_started_(false), |
| 30 has_sent_motion_up_(false), |
| 31 pixels_to_scroll_(pixels_to_scroll), |
| 32 rwh_(rwh), |
| 33 java_scroller_(java_scroller) { |
| 34 JNIEnv* env = base::android::AttachCurrentThread(); |
| 35 RegisterNativesIfNeeded(env); |
| 36 } |
| 37 |
| 38 TouchSmoothScrollGestureAndroid::~TouchSmoothScrollGestureAndroid() { |
| 39 } |
| 40 |
| 41 bool TouchSmoothScrollGestureAndroid::ForwardInputEvents( |
| 42 base::TimeTicks now, RenderWidgetHost* host) { |
| 43 if (!has_started_) { |
| 44 has_started_ = true; |
| 45 JNIEnv* env = base::android::AttachCurrentThread(); |
| 46 Java_SmoothScroller_start( |
| 47 env, java_scroller_.obj(), reinterpret_cast<int>(this)); |
| 48 } |
| 49 |
| 50 TRACE_COUNTER_ID1( |
| 51 "gpu", "smooth_scroll_by_pixels_scrolled", this, pixels_scrolled_); |
| 52 |
| 53 return !has_sent_motion_up_; |
| 54 } |
| 55 |
| 56 double TouchSmoothScrollGestureAndroid::GetScrollDelta( |
| 57 JNIEnv* env, jobject obj, double scale) { |
| 58 double delta = smooth_scroll_calculator_.GetScrollDelta( |
| 59 base::TimeTicks::Now(), |
| 60 RenderWidgetHostImpl::From(rwh_)->GetSyntheticScrollMessageInterval()) |
| 61 * scale; |
| 62 pixels_scrolled_ += delta; |
| 63 return delta; |
| 64 } |
| 65 |
| 66 bool TouchSmoothScrollGestureAndroid::HasFinished(JNIEnv* env, jobject obj) { |
| 67 return pixels_scrolled_ >= pixels_to_scroll_; |
| 68 } |
| 69 |
| 70 void TouchSmoothScrollGestureAndroid::SetHasSentMotionUp( |
| 71 JNIEnv* env, jobject obj) { |
| 72 has_sent_motion_up_ = true; |
| 73 } |
| 74 |
| 75 } // namespace content |
OLD | NEW |