| 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/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/threading/non_thread_safe.h" | 9 #include "base/threading/non_thread_safe.h" |
| 10 #include "jni/ViewConfigurationHelper_jni.h" | 10 #include "jni/ViewConfigurationHelper_jni.h" |
| 11 | 11 |
| 12 using base::android::AttachCurrentThread; | 12 using base::android::AttachCurrentThread; |
| 13 using base::android::GetApplicationContext; | 13 using base::android::GetApplicationContext; |
| 14 | 14 |
| 15 namespace gfx { | 15 namespace gfx { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 struct ViewConfigurationData { | 19 struct ViewConfigurationData { |
| 20 ViewConfigurationData() | 20 ViewConfigurationData() |
| 21 : double_tap_timeout_in_ms_(0), | 21 : double_tap_timeout_in_ms_(0), |
| 22 long_press_timeout_in_ms_(0), | 22 long_press_timeout_in_ms_(0), |
| 23 tap_timeout_in_ms_(0), | 23 tap_timeout_in_ms_(0), |
| 24 scroll_friction_(1.f), | 24 scroll_friction_(1.f), |
| 25 max_fling_velocity_in_pixels_s_(0), | 25 max_fling_velocity_in_pixels_s_(0), |
| 26 min_fling_velocity_in_pixels_s_(0), | 26 min_fling_velocity_in_pixels_s_(0), |
| 27 touch_slop_in_pixels_(0), | 27 touch_slop_in_pixels_(0), |
| 28 double_tap_slop_in_pixels_(0), | 28 double_tap_slop_in_pixels_(0) { |
| 29 min_scaling_span_in_pixels_(0), | |
| 30 min_scaling_touch_major_in_pixels_(0) { | |
| 31 JNIEnv* env = AttachCurrentThread(); | 29 JNIEnv* env = AttachCurrentThread(); |
| 32 j_view_configuration_helper_.Reset( | 30 j_view_configuration_helper_.Reset( |
| 33 Java_ViewConfigurationHelper_createWithListener( | 31 Java_ViewConfigurationHelper_createWithListener( |
| 34 env, base::android::GetApplicationContext())); | 32 env, base::android::GetApplicationContext())); |
| 35 | 33 |
| 36 double_tap_timeout_in_ms_ = | 34 double_tap_timeout_in_ms_ = |
| 37 Java_ViewConfigurationHelper_getDoubleTapTimeout(env); | 35 Java_ViewConfigurationHelper_getDoubleTapTimeout(env); |
| 38 long_press_timeout_in_ms_ = | 36 long_press_timeout_in_ms_ = |
| 39 Java_ViewConfigurationHelper_getLongPressTimeout(env); | 37 Java_ViewConfigurationHelper_getLongPressTimeout(env); |
| 40 tap_timeout_in_ms_ = Java_ViewConfigurationHelper_getTapTimeout(env); | 38 tap_timeout_in_ms_ = Java_ViewConfigurationHelper_getTapTimeout(env); |
| 41 scroll_friction_ = Java_ViewConfigurationHelper_getScrollFriction(env); | 39 scroll_friction_ = Java_ViewConfigurationHelper_getScrollFriction(env); |
| 42 | 40 |
| 43 jobject obj = j_view_configuration_helper_.obj(); | 41 jobject obj = j_view_configuration_helper_.obj(); |
| 44 Update( | 42 Update( |
| 45 Java_ViewConfigurationHelper_getScaledMaximumFlingVelocity(env, obj), | 43 Java_ViewConfigurationHelper_getScaledMaximumFlingVelocity(env, obj), |
| 46 Java_ViewConfigurationHelper_getScaledMinimumFlingVelocity(env, obj), | 44 Java_ViewConfigurationHelper_getScaledMinimumFlingVelocity(env, obj), |
| 47 Java_ViewConfigurationHelper_getScaledTouchSlop(env, obj), | 45 Java_ViewConfigurationHelper_getScaledTouchSlop(env, obj), |
| 48 Java_ViewConfigurationHelper_getScaledDoubleTapSlop(env, obj), | 46 Java_ViewConfigurationHelper_getScaledDoubleTapSlop(env, obj)); |
| 49 Java_ViewConfigurationHelper_getScaledMinScalingSpan(env, obj), | |
| 50 Java_ViewConfigurationHelper_getScaledMinScalingTouchMajor(env, obj)); | |
| 51 } | 47 } |
| 52 | 48 |
| 53 ~ViewConfigurationData() {} | 49 ~ViewConfigurationData() {} |
| 54 | 50 |
| 55 void SynchronizedUpdate(int scaled_maximum_fling_velocity, | 51 void SynchronizedUpdate(int scaled_maximum_fling_velocity, |
| 56 int scaled_minimum_fling_velocity, | 52 int scaled_minimum_fling_velocity, |
| 57 int scaled_touch_slop, | 53 int scaled_touch_slop, |
| 58 int scaled_double_tap_slop, | 54 int scaled_double_tap_slop) { |
| 59 int scaled_min_scaling_span, | |
| 60 int scaled_min_scaling_touch_major) { | |
| 61 base::AutoLock autolock(lock_); | 55 base::AutoLock autolock(lock_); |
| 62 Update(scaled_maximum_fling_velocity, | 56 Update(scaled_maximum_fling_velocity, |
| 63 scaled_minimum_fling_velocity, | 57 scaled_minimum_fling_velocity, |
| 64 scaled_touch_slop, | 58 scaled_touch_slop, |
| 65 scaled_double_tap_slop, | 59 scaled_double_tap_slop); |
| 66 scaled_min_scaling_span, | |
| 67 scaled_min_scaling_touch_major); | |
| 68 } | 60 } |
| 69 | 61 |
| 70 int double_tap_timeout_in_ms() const { return double_tap_timeout_in_ms_; } | 62 int double_tap_timeout_in_ms() const { return double_tap_timeout_in_ms_; } |
| 71 int long_press_timeout_in_ms() const { return long_press_timeout_in_ms_; } | 63 int long_press_timeout_in_ms() const { return long_press_timeout_in_ms_; } |
| 72 int tap_timeout_in_ms() const { return tap_timeout_in_ms_; } | 64 int tap_timeout_in_ms() const { return tap_timeout_in_ms_; } |
| 73 float scroll_friction() const { return scroll_friction_; } | 65 float scroll_friction() const { return scroll_friction_; } |
| 74 | 66 |
| 75 int max_fling_velocity_in_pixels_s() { | 67 int max_fling_velocity_in_pixels_s() { |
| 76 base::AutoLock autolock(lock_); | 68 base::AutoLock autolock(lock_); |
| 77 return max_fling_velocity_in_pixels_s_; | 69 return max_fling_velocity_in_pixels_s_; |
| 78 } | 70 } |
| 79 | 71 |
| 80 int min_fling_velocity_in_pixels_s() { | 72 int min_fling_velocity_in_pixels_s() { |
| 81 base::AutoLock autolock(lock_); | 73 base::AutoLock autolock(lock_); |
| 82 return min_fling_velocity_in_pixels_s_; | 74 return min_fling_velocity_in_pixels_s_; |
| 83 } | 75 } |
| 84 | 76 |
| 85 int touch_slop_in_pixels() { | 77 int touch_slop_in_pixels() { |
| 86 base::AutoLock autolock(lock_); | 78 base::AutoLock autolock(lock_); |
| 87 return touch_slop_in_pixels_; | 79 return touch_slop_in_pixels_; |
| 88 } | 80 } |
| 89 | 81 |
| 90 int double_tap_slop_in_pixels() { | 82 int double_tap_slop_in_pixels() { |
| 91 base::AutoLock autolock(lock_); | 83 base::AutoLock autolock(lock_); |
| 92 return double_tap_slop_in_pixels_; | 84 return double_tap_slop_in_pixels_; |
| 93 } | 85 } |
| 94 | 86 |
| 95 int min_scaling_span_in_pixels() { | |
| 96 base::AutoLock autolock(lock_); | |
| 97 return min_scaling_span_in_pixels_; | |
| 98 } | |
| 99 | |
| 100 int min_scaling_touch_major_in_pixels() { | |
| 101 base::AutoLock autolock(lock_); | |
| 102 return min_scaling_touch_major_in_pixels_; | |
| 103 } | |
| 104 | |
| 105 private: | 87 private: |
| 106 void Update(int scaled_maximum_fling_velocity, | 88 void Update(int scaled_maximum_fling_velocity, |
| 107 int scaled_minimum_fling_velocity, | 89 int scaled_minimum_fling_velocity, |
| 108 int scaled_touch_slop, | 90 int scaled_touch_slop, |
| 109 int scaled_double_tap_slop, | 91 int scaled_double_tap_slop) { |
| 110 int scaled_min_scaling_span, | |
| 111 int scaled_min_scaling_touch_major) { | |
| 112 DCHECK_LE(scaled_minimum_fling_velocity, scaled_maximum_fling_velocity); | 92 DCHECK_LE(scaled_minimum_fling_velocity, scaled_maximum_fling_velocity); |
| 113 max_fling_velocity_in_pixels_s_ = scaled_maximum_fling_velocity; | 93 max_fling_velocity_in_pixels_s_ = scaled_maximum_fling_velocity; |
| 114 min_fling_velocity_in_pixels_s_ = scaled_minimum_fling_velocity; | 94 min_fling_velocity_in_pixels_s_ = scaled_minimum_fling_velocity; |
| 115 touch_slop_in_pixels_ = scaled_touch_slop; | 95 touch_slop_in_pixels_ = scaled_touch_slop; |
| 116 double_tap_slop_in_pixels_ = scaled_double_tap_slop; | 96 double_tap_slop_in_pixels_ = scaled_double_tap_slop; |
| 117 min_scaling_span_in_pixels_ = scaled_min_scaling_span; | |
| 118 min_scaling_touch_major_in_pixels_ = scaled_min_scaling_touch_major; | |
| 119 } | 97 } |
| 120 | 98 |
| 121 base::Lock lock_; | 99 base::Lock lock_; |
| 122 base::android::ScopedJavaGlobalRef<jobject> j_view_configuration_helper_; | 100 base::android::ScopedJavaGlobalRef<jobject> j_view_configuration_helper_; |
| 123 | 101 |
| 124 // These values will remain constant throughout the lifetime of the app, so | 102 // These values will remain constant throughout the lifetime of the app, so |
| 125 // read-access needn't be synchronized. | 103 // read-access needn't be synchronized. |
| 126 int double_tap_timeout_in_ms_; | 104 int double_tap_timeout_in_ms_; |
| 127 int long_press_timeout_in_ms_; | 105 int long_press_timeout_in_ms_; |
| 128 int tap_timeout_in_ms_; | 106 int tap_timeout_in_ms_; |
| 129 float scroll_friction_; | 107 float scroll_friction_; |
| 130 | 108 |
| 131 // These values may vary as view-specific parameters (DPI scale) are changed, | 109 // These values may vary as view-specific parameters (DPI scale) are changed, |
| 132 // so read/write access must be synchronized. | 110 // so read/write access must be synchronized. |
| 133 int max_fling_velocity_in_pixels_s_; | 111 int max_fling_velocity_in_pixels_s_; |
| 134 int min_fling_velocity_in_pixels_s_; | 112 int min_fling_velocity_in_pixels_s_; |
| 135 int touch_slop_in_pixels_; | 113 int touch_slop_in_pixels_; |
| 136 int double_tap_slop_in_pixels_; | 114 int double_tap_slop_in_pixels_; |
| 137 int min_scaling_span_in_pixels_; | |
| 138 int min_scaling_touch_major_in_pixels_; | |
| 139 | 115 |
| 140 private: | 116 private: |
| 141 DISALLOW_COPY_AND_ASSIGN(ViewConfigurationData); | 117 DISALLOW_COPY_AND_ASSIGN(ViewConfigurationData); |
| 142 }; | 118 }; |
| 143 | 119 |
| 144 // Leaky to allow access from any thread. | 120 // Leaky to allow access from any thread. |
| 145 base::LazyInstance<ViewConfigurationData>::Leaky g_view_configuration = | 121 base::LazyInstance<ViewConfigurationData>::Leaky g_view_configuration = |
| 146 LAZY_INSTANCE_INITIALIZER; | 122 LAZY_INSTANCE_INITIALIZER; |
| 147 | 123 |
| 148 } // namespace | 124 } // namespace |
| 149 | 125 |
| 150 static void UpdateSharedViewConfiguration(JNIEnv* env, | 126 static void UpdateSharedViewConfiguration(JNIEnv* env, |
| 151 jobject obj, | 127 jobject obj, |
| 152 jint scaled_maximum_fling_velocity, | 128 jint scaled_maximum_fling_velocity, |
| 153 jint scaled_minimum_fling_velocity, | 129 jint scaled_minimum_fling_velocity, |
| 154 jint scaled_touch_slop, | 130 jint scaled_touch_slop, |
| 155 jint scaled_double_tap_slop, | 131 jint scaled_double_tap_slop) { |
| 156 jint scaled_min_scaling_span, | |
| 157 jint scaled_min_scaling_touch_major) { | |
| 158 g_view_configuration.Get().SynchronizedUpdate(scaled_maximum_fling_velocity, | 132 g_view_configuration.Get().SynchronizedUpdate(scaled_maximum_fling_velocity, |
| 159 scaled_minimum_fling_velocity, | 133 scaled_minimum_fling_velocity, |
| 160 scaled_touch_slop, | 134 scaled_touch_slop, |
| 161 scaled_double_tap_slop, | 135 scaled_double_tap_slop); |
| 162 scaled_min_scaling_span, | |
| 163 scaled_min_scaling_touch_major); | |
| 164 } | 136 } |
| 165 | 137 |
| 166 int ViewConfiguration::GetDoubleTapTimeoutInMs() { | 138 int ViewConfiguration::GetDoubleTapTimeoutInMs() { |
| 167 return g_view_configuration.Get().double_tap_timeout_in_ms(); | 139 return g_view_configuration.Get().double_tap_timeout_in_ms(); |
| 168 } | 140 } |
| 169 | 141 |
| 170 int ViewConfiguration::GetLongPressTimeoutInMs() { | 142 int ViewConfiguration::GetLongPressTimeoutInMs() { |
| 171 return g_view_configuration.Get().long_press_timeout_in_ms(); | 143 return g_view_configuration.Get().long_press_timeout_in_ms(); |
| 172 } | 144 } |
| 173 | 145 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 188 } | 160 } |
| 189 | 161 |
| 190 int ViewConfiguration::GetTouchSlopInPixels() { | 162 int ViewConfiguration::GetTouchSlopInPixels() { |
| 191 return g_view_configuration.Get().touch_slop_in_pixels(); | 163 return g_view_configuration.Get().touch_slop_in_pixels(); |
| 192 } | 164 } |
| 193 | 165 |
| 194 int ViewConfiguration::GetDoubleTapSlopInPixels() { | 166 int ViewConfiguration::GetDoubleTapSlopInPixels() { |
| 195 return g_view_configuration.Get().double_tap_slop_in_pixels(); | 167 return g_view_configuration.Get().double_tap_slop_in_pixels(); |
| 196 } | 168 } |
| 197 | 169 |
| 198 int ViewConfiguration::GetMinScalingSpanInPixels() { | |
| 199 return g_view_configuration.Get().min_scaling_span_in_pixels(); | |
| 200 } | |
| 201 | |
| 202 int ViewConfiguration::GetMinScalingTouchMajorInPixels() { | |
| 203 return g_view_configuration.Get().min_scaling_touch_major_in_pixels(); | |
| 204 } | |
| 205 | |
| 206 bool ViewConfiguration::RegisterViewConfiguration(JNIEnv* env) { | 170 bool ViewConfiguration::RegisterViewConfiguration(JNIEnv* env) { |
| 207 return RegisterNativesImpl(env); | 171 return RegisterNativesImpl(env); |
| 208 } | 172 } |
| 209 | 173 |
| 210 } // namespace gfx | 174 } // namespace gfx |
| OLD | NEW |