OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/renderer_host/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 SmoothScrollGestureAndroid::SmoothScrollGestureAndroid( |
| 25 int pixels_to_scroll, |
| 26 RenderWidgetHost* rwh, |
| 27 base::android::ScopedJavaLocalRef<jobject> java_scroller) |
| 28 : pixels_scrolled_(0), |
| 29 has_started_(false), |
| 30 pixels_to_scroll_(pixels_to_scroll), |
| 31 rwh_(rwh), |
| 32 java_scroller_(java_scroller) { |
| 33 JNIEnv* env = base::android::AttachCurrentThread(); |
| 34 RegisterNativesIfNeeded(env); |
| 35 } |
| 36 |
| 37 SmoothScrollGestureAndroid::~SmoothScrollGestureAndroid() { |
| 38 } |
| 39 |
| 40 bool SmoothScrollGestureAndroid::ForwardInputEvents( |
| 41 base::TimeTicks now, RenderWidgetHost* host) { |
| 42 if (!has_started_) { |
| 43 has_started_ = true; |
| 44 JNIEnv* env = base::android::AttachCurrentThread(); |
| 45 Java_SmoothScroller_start( |
| 46 env, java_scroller_.obj(), reinterpret_cast<int>(this)); |
| 47 } |
| 48 |
| 49 TRACE_COUNTER_ID1( |
| 50 "gpu", "smooth_scroll_by_pixels_scrolled", this, pixels_scrolled_); |
| 51 |
| 52 return pixels_scrolled_ < pixels_to_scroll_; |
| 53 } |
| 54 |
| 55 double SmoothScrollGestureAndroid::Tick(JNIEnv* env, jobject obj) { |
| 56 double delta = SmoothScrollGesture::Tick( |
| 57 base::TimeTicks::HighResNow(), |
| 58 RenderWidgetHostImpl::From(rwh_)->SyntheticScrollMessageInterval()); |
| 59 pixels_scrolled_ += delta; |
| 60 return delta; |
| 61 } |
| 62 |
| 63 bool SmoothScrollGestureAndroid::HasFinished(JNIEnv* env, jobject obj) { |
| 64 return pixels_scrolled_ >= pixels_to_scroll_; |
| 65 } |
| 66 |
| 67 } // namespace content |
| 68 |
OLD | NEW |