| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/gfx/android/view_configuration.h" | 5 #include "ui/gfx/android/view_configuration.h" |
| 6 | 6 |
| 7 #include "base/android/context_utils.h" | 7 #include "base/android/context_utils.h" |
| 8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
| 12 #include "jni/ViewConfigurationHelper_jni.h" | 12 #include "jni/ViewConfigurationHelper_jni.h" |
| 13 | 13 |
| 14 using base::android::AttachCurrentThread; | 14 using base::android::AttachCurrentThread; |
| 15 using base::android::GetApplicationContext; | 15 using base::android::GetApplicationContext; |
| 16 using base::android::JavaParamRef; | 16 using base::android::JavaParamRef; |
| 17 | 17 |
| 18 namespace gfx { | 18 namespace gfx { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 struct ViewConfigurationData { | 22 struct ViewConfigurationData { |
| 23 ViewConfigurationData() | 23 ViewConfigurationData() |
| 24 : double_tap_timeout_in_ms_(0), | 24 : double_tap_timeout_in_ms_(0), |
| 25 long_press_timeout_in_ms_(0), | 25 long_press_timeout_in_ms_(0), |
| 26 tap_timeout_in_ms_(0), | 26 tap_timeout_in_ms_(0), |
| 27 scroll_friction_(1.f), | |
| 28 max_fling_velocity_in_dips_s_(0), | 27 max_fling_velocity_in_dips_s_(0), |
| 29 min_fling_velocity_in_dips_s_(0), | 28 min_fling_velocity_in_dips_s_(0), |
| 30 touch_slop_in_dips_(0), | 29 touch_slop_in_dips_(0), |
| 31 double_tap_slop_in_dips_(0), | 30 double_tap_slop_in_dips_(0), |
| 32 min_scaling_span_in_dips_(0) { | 31 min_scaling_span_in_dips_(0) { |
| 33 JNIEnv* env = AttachCurrentThread(); | 32 JNIEnv* env = AttachCurrentThread(); |
| 34 j_view_configuration_helper_.Reset( | 33 j_view_configuration_helper_.Reset( |
| 35 Java_ViewConfigurationHelper_createWithListener( | 34 Java_ViewConfigurationHelper_createWithListener( |
| 36 env, base::android::GetApplicationContext())); | 35 env, base::android::GetApplicationContext())); |
| 37 | 36 |
| 38 double_tap_timeout_in_ms_ = | 37 double_tap_timeout_in_ms_ = |
| 39 Java_ViewConfigurationHelper_getDoubleTapTimeout(env); | 38 Java_ViewConfigurationHelper_getDoubleTapTimeout(env); |
| 40 long_press_timeout_in_ms_ = | 39 long_press_timeout_in_ms_ = |
| 41 Java_ViewConfigurationHelper_getLongPressTimeout(env); | 40 Java_ViewConfigurationHelper_getLongPressTimeout(env); |
| 42 tap_timeout_in_ms_ = Java_ViewConfigurationHelper_getTapTimeout(env); | 41 tap_timeout_in_ms_ = Java_ViewConfigurationHelper_getTapTimeout(env); |
| 43 scroll_friction_ = Java_ViewConfigurationHelper_getScrollFriction(env); | |
| 44 | 42 |
| 45 jobject obj = j_view_configuration_helper_.obj(); | 43 jobject obj = j_view_configuration_helper_.obj(); |
| 46 Update(Java_ViewConfigurationHelper_getMaximumFlingVelocity(env, obj), | 44 Update(Java_ViewConfigurationHelper_getMaximumFlingVelocity(env, obj), |
| 47 Java_ViewConfigurationHelper_getMinimumFlingVelocity(env, obj), | 45 Java_ViewConfigurationHelper_getMinimumFlingVelocity(env, obj), |
| 48 Java_ViewConfigurationHelper_getTouchSlop(env, obj), | 46 Java_ViewConfigurationHelper_getTouchSlop(env, obj), |
| 49 Java_ViewConfigurationHelper_getDoubleTapSlop(env, obj), | 47 Java_ViewConfigurationHelper_getDoubleTapSlop(env, obj), |
| 50 Java_ViewConfigurationHelper_getMinScalingSpan(env, obj)); | 48 Java_ViewConfigurationHelper_getMinScalingSpan(env, obj)); |
| 51 } | 49 } |
| 52 | 50 |
| 53 ~ViewConfigurationData() {} | 51 ~ViewConfigurationData() {} |
| 54 | 52 |
| 55 void SynchronizedUpdate(float maximum_fling_velocity, | 53 void SynchronizedUpdate(float maximum_fling_velocity, |
| 56 float minimum_fling_velocity, | 54 float minimum_fling_velocity, |
| 57 float touch_slop, | 55 float touch_slop, |
| 58 float double_tap_slop, | 56 float double_tap_slop, |
| 59 float min_scaling_span) { | 57 float min_scaling_span) { |
| 60 base::AutoLock autolock(lock_); | 58 base::AutoLock autolock(lock_); |
| 61 Update(maximum_fling_velocity, minimum_fling_velocity, touch_slop, | 59 Update(maximum_fling_velocity, minimum_fling_velocity, touch_slop, |
| 62 double_tap_slop, min_scaling_span); | 60 double_tap_slop, min_scaling_span); |
| 63 } | 61 } |
| 64 | 62 |
| 65 int double_tap_timeout_in_ms() const { return double_tap_timeout_in_ms_; } | 63 int double_tap_timeout_in_ms() const { return double_tap_timeout_in_ms_; } |
| 66 int long_press_timeout_in_ms() const { return long_press_timeout_in_ms_; } | 64 int long_press_timeout_in_ms() const { return long_press_timeout_in_ms_; } |
| 67 int tap_timeout_in_ms() const { return tap_timeout_in_ms_; } | 65 int tap_timeout_in_ms() const { return tap_timeout_in_ms_; } |
| 68 float scroll_friction() const { return scroll_friction_; } | |
| 69 | 66 |
| 70 int max_fling_velocity_in_dips_s() { | 67 int max_fling_velocity_in_dips_s() { |
| 71 base::AutoLock autolock(lock_); | 68 base::AutoLock autolock(lock_); |
| 72 return max_fling_velocity_in_dips_s_; | 69 return max_fling_velocity_in_dips_s_; |
| 73 } | 70 } |
| 74 | 71 |
| 75 int min_fling_velocity_in_dips_s() { | 72 int min_fling_velocity_in_dips_s() { |
| 76 base::AutoLock autolock(lock_); | 73 base::AutoLock autolock(lock_); |
| 77 return min_fling_velocity_in_dips_s_; | 74 return min_fling_velocity_in_dips_s_; |
| 78 } | 75 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 107 } | 104 } |
| 108 | 105 |
| 109 base::Lock lock_; | 106 base::Lock lock_; |
| 110 base::android::ScopedJavaGlobalRef<jobject> j_view_configuration_helper_; | 107 base::android::ScopedJavaGlobalRef<jobject> j_view_configuration_helper_; |
| 111 | 108 |
| 112 // These values will remain constant throughout the lifetime of the app, so | 109 // These values will remain constant throughout the lifetime of the app, so |
| 113 // read-access needn't be synchronized. | 110 // read-access needn't be synchronized. |
| 114 int double_tap_timeout_in_ms_; | 111 int double_tap_timeout_in_ms_; |
| 115 int long_press_timeout_in_ms_; | 112 int long_press_timeout_in_ms_; |
| 116 int tap_timeout_in_ms_; | 113 int tap_timeout_in_ms_; |
| 117 float scroll_friction_; | |
| 118 | 114 |
| 119 // These values may vary as view-specific parameters change, so read/write | 115 // These values may vary as view-specific parameters change, so read/write |
| 120 // access must be synchronized. | 116 // access must be synchronized. |
| 121 int max_fling_velocity_in_dips_s_; | 117 int max_fling_velocity_in_dips_s_; |
| 122 int min_fling_velocity_in_dips_s_; | 118 int min_fling_velocity_in_dips_s_; |
| 123 int touch_slop_in_dips_; | 119 int touch_slop_in_dips_; |
| 124 int double_tap_slop_in_dips_; | 120 int double_tap_slop_in_dips_; |
| 125 int min_scaling_span_in_dips_; | 121 int min_scaling_span_in_dips_; |
| 126 | 122 |
| 127 private: | 123 private: |
| (...skipping 23 matching lines...) Expand all Loading... |
| 151 } | 147 } |
| 152 | 148 |
| 153 int ViewConfiguration::GetLongPressTimeoutInMs() { | 149 int ViewConfiguration::GetLongPressTimeoutInMs() { |
| 154 return g_view_configuration.Get().long_press_timeout_in_ms(); | 150 return g_view_configuration.Get().long_press_timeout_in_ms(); |
| 155 } | 151 } |
| 156 | 152 |
| 157 int ViewConfiguration::GetTapTimeoutInMs() { | 153 int ViewConfiguration::GetTapTimeoutInMs() { |
| 158 return g_view_configuration.Get().tap_timeout_in_ms(); | 154 return g_view_configuration.Get().tap_timeout_in_ms(); |
| 159 } | 155 } |
| 160 | 156 |
| 161 float ViewConfiguration::GetScrollFriction() { | |
| 162 return g_view_configuration.Get().scroll_friction(); | |
| 163 } | |
| 164 | |
| 165 int ViewConfiguration::GetMaximumFlingVelocityInDipsPerSecond() { | 157 int ViewConfiguration::GetMaximumFlingVelocityInDipsPerSecond() { |
| 166 return g_view_configuration.Get().max_fling_velocity_in_dips_s(); | 158 return g_view_configuration.Get().max_fling_velocity_in_dips_s(); |
| 167 } | 159 } |
| 168 | 160 |
| 169 int ViewConfiguration::GetMinimumFlingVelocityInDipsPerSecond() { | 161 int ViewConfiguration::GetMinimumFlingVelocityInDipsPerSecond() { |
| 170 return g_view_configuration.Get().min_fling_velocity_in_dips_s(); | 162 return g_view_configuration.Get().min_fling_velocity_in_dips_s(); |
| 171 } | 163 } |
| 172 | 164 |
| 173 int ViewConfiguration::GetTouchSlopInDips() { | 165 int ViewConfiguration::GetTouchSlopInDips() { |
| 174 return g_view_configuration.Get().touch_slop_in_dips(); | 166 return g_view_configuration.Get().touch_slop_in_dips(); |
| 175 } | 167 } |
| 176 | 168 |
| 177 int ViewConfiguration::GetDoubleTapSlopInDips() { | 169 int ViewConfiguration::GetDoubleTapSlopInDips() { |
| 178 return g_view_configuration.Get().double_tap_slop_in_dips(); | 170 return g_view_configuration.Get().double_tap_slop_in_dips(); |
| 179 } | 171 } |
| 180 | 172 |
| 181 int ViewConfiguration::GetMinScalingSpanInDips() { | 173 int ViewConfiguration::GetMinScalingSpanInDips() { |
| 182 return g_view_configuration.Get().min_scaling_span_in_dips(); | 174 return g_view_configuration.Get().min_scaling_span_in_dips(); |
| 183 } | 175 } |
| 184 | 176 |
| 185 bool ViewConfiguration::RegisterViewConfiguration(JNIEnv* env) { | 177 bool ViewConfiguration::RegisterViewConfiguration(JNIEnv* env) { |
| 186 return RegisterNativesImpl(env); | 178 return RegisterNativesImpl(env); |
| 187 } | 179 } |
| 188 | 180 |
| 189 } // namespace gfx | 181 } // namespace gfx |
| OLD | NEW |