| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 struct ViewConfigurationData { | 21 struct ViewConfigurationData { |
| 22 ViewConfigurationData() | 22 ViewConfigurationData() |
| 23 : double_tap_timeout_in_ms_(0), | 23 : double_tap_timeout_in_ms_(0), |
| 24 long_press_timeout_in_ms_(0), | 24 long_press_timeout_in_ms_(0), |
| 25 tap_timeout_in_ms_(0), | 25 tap_timeout_in_ms_(0), |
| 26 scroll_friction_(1.f), | 26 scroll_friction_(1.f), |
| 27 max_fling_velocity_in_dips_s_(0), | 27 max_fling_velocity_in_dips_s_(0), |
| 28 min_fling_velocity_in_dips_s_(0), | 28 min_fling_velocity_in_dips_s_(0), |
| 29 touch_slop_in_dips_(0), | 29 touch_slop_in_dips_(0), |
| 30 double_tap_slop_in_dips_(0), | 30 double_tap_slop_in_dips_(0), |
| 31 min_scaling_span_in_dips_(0), | 31 min_scaling_span_in_dips_(0) { |
| 32 min_scaling_touch_major_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); | 42 scroll_friction_ = Java_ViewConfigurationHelper_getScrollFriction(env); |
| 44 | 43 |
| 45 jobject obj = j_view_configuration_helper_.obj(); | 44 jobject obj = j_view_configuration_helper_.obj(); |
| 46 Update(Java_ViewConfigurationHelper_getMaximumFlingVelocity(env, obj), | 45 Update(Java_ViewConfigurationHelper_getMaximumFlingVelocity(env, obj), |
| 47 Java_ViewConfigurationHelper_getMinimumFlingVelocity(env, obj), | 46 Java_ViewConfigurationHelper_getMinimumFlingVelocity(env, obj), |
| 48 Java_ViewConfigurationHelper_getTouchSlop(env, obj), | 47 Java_ViewConfigurationHelper_getTouchSlop(env, obj), |
| 49 Java_ViewConfigurationHelper_getDoubleTapSlop(env, obj), | 48 Java_ViewConfigurationHelper_getDoubleTapSlop(env, obj), |
| 50 Java_ViewConfigurationHelper_getMinScalingSpan(env, obj), | 49 Java_ViewConfigurationHelper_getMinScalingSpan(env, obj)); |
| 51 Java_ViewConfigurationHelper_getMinScalingTouchMajor(env, obj)); | |
| 52 } | 50 } |
| 53 | 51 |
| 54 ~ViewConfigurationData() {} | 52 ~ViewConfigurationData() {} |
| 55 | 53 |
| 56 void SynchronizedUpdate(float maximum_fling_velocity, | 54 void SynchronizedUpdate(float maximum_fling_velocity, |
| 57 float minimum_fling_velocity, | 55 float minimum_fling_velocity, |
| 58 float touch_slop, | 56 float touch_slop, |
| 59 float double_tap_slop, | 57 float double_tap_slop, |
| 60 float min_scaling_span, | 58 float min_scaling_span) { |
| 61 float min_scaling_touch_major) { | |
| 62 base::AutoLock autolock(lock_); | 59 base::AutoLock autolock(lock_); |
| 63 Update(maximum_fling_velocity, minimum_fling_velocity, touch_slop, | 60 Update(maximum_fling_velocity, minimum_fling_velocity, touch_slop, |
| 64 double_tap_slop, min_scaling_span, min_scaling_touch_major); | 61 double_tap_slop, min_scaling_span); |
| 65 } | 62 } |
| 66 | 63 |
| 67 int double_tap_timeout_in_ms() const { return double_tap_timeout_in_ms_; } | 64 int double_tap_timeout_in_ms() const { return double_tap_timeout_in_ms_; } |
| 68 int long_press_timeout_in_ms() const { return long_press_timeout_in_ms_; } | 65 int long_press_timeout_in_ms() const { return long_press_timeout_in_ms_; } |
| 69 int tap_timeout_in_ms() const { return tap_timeout_in_ms_; } | 66 int tap_timeout_in_ms() const { return tap_timeout_in_ms_; } |
| 70 float scroll_friction() const { return scroll_friction_; } | 67 float scroll_friction() const { return scroll_friction_; } |
| 71 | 68 |
| 72 int max_fling_velocity_in_dips_s() { | 69 int max_fling_velocity_in_dips_s() { |
| 73 base::AutoLock autolock(lock_); | 70 base::AutoLock autolock(lock_); |
| 74 return max_fling_velocity_in_dips_s_; | 71 return max_fling_velocity_in_dips_s_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 87 int double_tap_slop_in_dips() { | 84 int double_tap_slop_in_dips() { |
| 88 base::AutoLock autolock(lock_); | 85 base::AutoLock autolock(lock_); |
| 89 return double_tap_slop_in_dips_; | 86 return double_tap_slop_in_dips_; |
| 90 } | 87 } |
| 91 | 88 |
| 92 int min_scaling_span_in_dips() { | 89 int min_scaling_span_in_dips() { |
| 93 base::AutoLock autolock(lock_); | 90 base::AutoLock autolock(lock_); |
| 94 return min_scaling_span_in_dips_; | 91 return min_scaling_span_in_dips_; |
| 95 } | 92 } |
| 96 | 93 |
| 97 int min_scaling_touch_major_in_dips() { | |
| 98 base::AutoLock autolock(lock_); | |
| 99 return min_scaling_touch_major_in_dips_; | |
| 100 } | |
| 101 | |
| 102 private: | 94 private: |
| 103 void Update(float maximum_fling_velocity, | 95 void Update(float maximum_fling_velocity, |
| 104 float minimum_fling_velocity, | 96 float minimum_fling_velocity, |
| 105 float touch_slop, | 97 float touch_slop, |
| 106 float double_tap_slop, | 98 float double_tap_slop, |
| 107 float min_scaling_span, | 99 float min_scaling_span) { |
| 108 float min_scaling_touch_major) { | |
| 109 DCHECK_LE(minimum_fling_velocity, maximum_fling_velocity); | 100 DCHECK_LE(minimum_fling_velocity, maximum_fling_velocity); |
| 110 max_fling_velocity_in_dips_s_ = maximum_fling_velocity; | 101 max_fling_velocity_in_dips_s_ = maximum_fling_velocity; |
| 111 min_fling_velocity_in_dips_s_ = minimum_fling_velocity; | 102 min_fling_velocity_in_dips_s_ = minimum_fling_velocity; |
| 112 touch_slop_in_dips_ = touch_slop; | 103 touch_slop_in_dips_ = touch_slop; |
| 113 double_tap_slop_in_dips_ = double_tap_slop; | 104 double_tap_slop_in_dips_ = double_tap_slop; |
| 114 min_scaling_span_in_dips_ = min_scaling_span; | 105 min_scaling_span_in_dips_ = min_scaling_span; |
| 115 min_scaling_touch_major_in_dips_ = min_scaling_touch_major; | |
| 116 } | 106 } |
| 117 | 107 |
| 118 base::Lock lock_; | 108 base::Lock lock_; |
| 119 base::android::ScopedJavaGlobalRef<jobject> j_view_configuration_helper_; | 109 base::android::ScopedJavaGlobalRef<jobject> j_view_configuration_helper_; |
| 120 | 110 |
| 121 // These values will remain constant throughout the lifetime of the app, so | 111 // These values will remain constant throughout the lifetime of the app, so |
| 122 // read-access needn't be synchronized. | 112 // read-access needn't be synchronized. |
| 123 int double_tap_timeout_in_ms_; | 113 int double_tap_timeout_in_ms_; |
| 124 int long_press_timeout_in_ms_; | 114 int long_press_timeout_in_ms_; |
| 125 int tap_timeout_in_ms_; | 115 int tap_timeout_in_ms_; |
| 126 float scroll_friction_; | 116 float scroll_friction_; |
| 127 | 117 |
| 128 // These values may vary as view-specific parameters change, so read/write | 118 // These values may vary as view-specific parameters change, so read/write |
| 129 // access must be synchronized. | 119 // access must be synchronized. |
| 130 int max_fling_velocity_in_dips_s_; | 120 int max_fling_velocity_in_dips_s_; |
| 131 int min_fling_velocity_in_dips_s_; | 121 int min_fling_velocity_in_dips_s_; |
| 132 int touch_slop_in_dips_; | 122 int touch_slop_in_dips_; |
| 133 int double_tap_slop_in_dips_; | 123 int double_tap_slop_in_dips_; |
| 134 int min_scaling_span_in_dips_; | 124 int min_scaling_span_in_dips_; |
| 135 int min_scaling_touch_major_in_dips_; | |
| 136 | 125 |
| 137 private: | 126 private: |
| 138 DISALLOW_COPY_AND_ASSIGN(ViewConfigurationData); | 127 DISALLOW_COPY_AND_ASSIGN(ViewConfigurationData); |
| 139 }; | 128 }; |
| 140 | 129 |
| 141 // Leaky to allow access from any thread. | 130 // Leaky to allow access from any thread. |
| 142 base::LazyInstance<ViewConfigurationData>::Leaky g_view_configuration = | 131 base::LazyInstance<ViewConfigurationData>::Leaky g_view_configuration = |
| 143 LAZY_INSTANCE_INITIALIZER; | 132 LAZY_INSTANCE_INITIALIZER; |
| 144 | 133 |
| 145 } // namespace | 134 } // namespace |
| 146 | 135 |
| 147 static void UpdateSharedViewConfiguration(JNIEnv* env, | 136 static void UpdateSharedViewConfiguration(JNIEnv* env, |
| 148 const JavaParamRef<jobject>& obj, | 137 const JavaParamRef<jobject>& obj, |
| 149 jfloat maximum_fling_velocity, | 138 jfloat maximum_fling_velocity, |
| 150 jfloat minimum_fling_velocity, | 139 jfloat minimum_fling_velocity, |
| 151 jfloat touch_slop, | 140 jfloat touch_slop, |
| 152 jfloat double_tap_slop, | 141 jfloat double_tap_slop, |
| 153 jfloat min_scaling_span, | 142 jfloat min_scaling_span) { |
| 154 jfloat min_scaling_touch_major) { | |
| 155 g_view_configuration.Get().SynchronizedUpdate( | 143 g_view_configuration.Get().SynchronizedUpdate( |
| 156 maximum_fling_velocity, minimum_fling_velocity, touch_slop, | 144 maximum_fling_velocity, minimum_fling_velocity, touch_slop, |
| 157 double_tap_slop, min_scaling_span, min_scaling_touch_major); | 145 double_tap_slop, min_scaling_span); |
| 158 } | 146 } |
| 159 | 147 |
| 160 int ViewConfiguration::GetDoubleTapTimeoutInMs() { | 148 int ViewConfiguration::GetDoubleTapTimeoutInMs() { |
| 161 return g_view_configuration.Get().double_tap_timeout_in_ms(); | 149 return g_view_configuration.Get().double_tap_timeout_in_ms(); |
| 162 } | 150 } |
| 163 | 151 |
| 164 int ViewConfiguration::GetLongPressTimeoutInMs() { | 152 int ViewConfiguration::GetLongPressTimeoutInMs() { |
| 165 return g_view_configuration.Get().long_press_timeout_in_ms(); | 153 return g_view_configuration.Get().long_press_timeout_in_ms(); |
| 166 } | 154 } |
| 167 | 155 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 186 } | 174 } |
| 187 | 175 |
| 188 int ViewConfiguration::GetDoubleTapSlopInDips() { | 176 int ViewConfiguration::GetDoubleTapSlopInDips() { |
| 189 return g_view_configuration.Get().double_tap_slop_in_dips(); | 177 return g_view_configuration.Get().double_tap_slop_in_dips(); |
| 190 } | 178 } |
| 191 | 179 |
| 192 int ViewConfiguration::GetMinScalingSpanInDips() { | 180 int ViewConfiguration::GetMinScalingSpanInDips() { |
| 193 return g_view_configuration.Get().min_scaling_span_in_dips(); | 181 return g_view_configuration.Get().min_scaling_span_in_dips(); |
| 194 } | 182 } |
| 195 | 183 |
| 196 int ViewConfiguration::GetMinScalingTouchMajorInDips() { | |
| 197 return g_view_configuration.Get().min_scaling_touch_major_in_dips(); | |
| 198 } | |
| 199 | |
| 200 bool ViewConfiguration::RegisterViewConfiguration(JNIEnv* env) { | 184 bool ViewConfiguration::RegisterViewConfiguration(JNIEnv* env) { |
| 201 return RegisterNativesImpl(env); | 185 return RegisterNativesImpl(env); |
| 202 } | 186 } |
| 203 | 187 |
| 204 } // namespace gfx | 188 } // namespace gfx |
| OLD | NEW |