OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/android/jni_string.h" |
| 9 #include "base/lazy_instance.h" |
| 10 #include "jni/ResourcesHelper_jni.h" |
8 #include "jni/ViewConfiguration_jni.h" | 11 #include "jni/ViewConfiguration_jni.h" |
9 | 12 |
10 using namespace JNI_ViewConfiguration; | |
11 using base::android::AttachCurrentThread; | 13 using base::android::AttachCurrentThread; |
12 using base::android::GetApplicationContext; | 14 using base::android::GetApplicationContext; |
13 | 15 |
14 namespace gfx { | 16 namespace gfx { |
| 17 namespace { |
| 18 struct ViewConfigurationData { |
| 19 ViewConfigurationData() { |
| 20 using namespace JNI_ViewConfiguration; |
| 21 |
| 22 JNIEnv* env = AttachCurrentThread(); |
| 23 |
| 24 double_tap_timeout_in_ms = Java_ViewConfiguration_getDoubleTapTimeout(env); |
| 25 long_press_timeout_in_ms = Java_ViewConfiguration_getLongPressTimeout(env); |
| 26 tap_timeout_in_ms = Java_ViewConfiguration_getTapTimeout(env); |
| 27 |
| 28 ScopedJavaLocalRef<jobject> view = |
| 29 Java_ViewConfiguration_get(env, GetApplicationContext()); |
| 30 |
| 31 max_fling_velocity_in_pixels_s = |
| 32 Java_ViewConfiguration_getScaledMaximumFlingVelocity(env, view.obj()); |
| 33 min_fling_velocity_in_pixels_s = |
| 34 Java_ViewConfiguration_getScaledMinimumFlingVelocity(env, view.obj()); |
| 35 |
| 36 touch_slop_in_pixels = |
| 37 Java_ViewConfiguration_getScaledTouchSlop(env, view.obj()); |
| 38 double_tap_slop_in_pixels = |
| 39 Java_ViewConfiguration_getScaledDoubleTapSlop(env, view.obj()); |
| 40 |
| 41 ScopedJavaLocalRef<jstring> jidentifier = |
| 42 base::android::ConvertUTF8ToJavaString(env, "config_minScalingSpan"); |
| 43 min_scaling_span_in_pixels = |
| 44 Java_ResourcesHelper_getDimensionPixelSize(env, jidentifier.obj()); |
| 45 |
| 46 jidentifier = base::android::ConvertUTF8ToJavaString( |
| 47 env, "config_minScalingTouchMajor"); |
| 48 min_scaling_touch_major_in_pixels = |
| 49 Java_ResourcesHelper_getDimensionPixelSize(env, jidentifier.obj()); |
| 50 } |
| 51 |
| 52 int double_tap_timeout_in_ms; |
| 53 int long_press_timeout_in_ms; |
| 54 int tap_timeout_in_ms; |
| 55 int max_fling_velocity_in_pixels_s; |
| 56 int min_fling_velocity_in_pixels_s; |
| 57 int touch_slop_in_pixels; |
| 58 int double_tap_slop_in_pixels; |
| 59 int min_scaling_span_in_pixels; |
| 60 int min_scaling_touch_major_in_pixels; |
| 61 |
| 62 private: |
| 63 DISALLOW_COPY_AND_ASSIGN(ViewConfigurationData); |
| 64 }; |
| 65 |
| 66 base::LazyInstance<ViewConfigurationData> g_view_configuration = |
| 67 LAZY_INSTANCE_INITIALIZER; |
| 68 |
| 69 } // namespace |
15 | 70 |
16 int ViewConfiguration::GetDoubleTapTimeoutInMs() { | 71 int ViewConfiguration::GetDoubleTapTimeoutInMs() { |
17 JNIEnv* env = AttachCurrentThread(); | 72 return g_view_configuration.Get().double_tap_timeout_in_ms; |
18 return Java_ViewConfiguration_getDoubleTapTimeout(env); | |
19 } | 73 } |
20 | 74 |
21 int ViewConfiguration::GetLongPressTimeoutInMs() { | 75 int ViewConfiguration::GetLongPressTimeoutInMs() { |
22 JNIEnv* env = AttachCurrentThread(); | 76 return g_view_configuration.Get().long_press_timeout_in_ms; |
23 return Java_ViewConfiguration_getLongPressTimeout(env); | |
24 } | 77 } |
25 | 78 |
26 int ViewConfiguration::GetTapTimeoutInMs() { | 79 int ViewConfiguration::GetTapTimeoutInMs() { |
27 JNIEnv* env = AttachCurrentThread(); | 80 return g_view_configuration.Get().tap_timeout_in_ms; |
28 return Java_ViewConfiguration_getTapTimeout(env); | |
29 } | 81 } |
30 | 82 |
31 int ViewConfiguration::GetMaximumFlingVelocityInPixelsPerSecond() { | 83 int ViewConfiguration::GetMaximumFlingVelocityInPixelsPerSecond() { |
32 JNIEnv* env = AttachCurrentThread(); | 84 return g_view_configuration.Get().max_fling_velocity_in_pixels_s; |
33 ScopedJavaLocalRef<jobject> view = | |
34 Java_ViewConfiguration_get(env, GetApplicationContext()); | |
35 return Java_ViewConfiguration_getScaledMaximumFlingVelocity(env, view.obj()); | |
36 } | 85 } |
37 | 86 |
38 int ViewConfiguration::GetMinimumFlingVelocityInPixelsPerSecond() { | 87 int ViewConfiguration::GetMinimumFlingVelocityInPixelsPerSecond() { |
39 JNIEnv* env = AttachCurrentThread(); | 88 return g_view_configuration.Get().min_fling_velocity_in_pixels_s; |
40 ScopedJavaLocalRef<jobject> view = | |
41 Java_ViewConfiguration_get(env, GetApplicationContext()); | |
42 return Java_ViewConfiguration_getScaledMinimumFlingVelocity(env, view.obj()); | |
43 } | 89 } |
44 | 90 |
45 int ViewConfiguration::GetTouchSlopInPixels() { | 91 int ViewConfiguration::GetTouchSlopInPixels() { |
46 JNIEnv* env = AttachCurrentThread(); | 92 return g_view_configuration.Get().touch_slop_in_pixels; |
47 ScopedJavaLocalRef<jobject> view = | 93 } |
48 Java_ViewConfiguration_get(env, GetApplicationContext()); | 94 |
49 return Java_ViewConfiguration_getScaledTouchSlop(env, view.obj()); | 95 int ViewConfiguration::GetDoubleTapSlopInPixels() { |
| 96 return g_view_configuration.Get().double_tap_slop_in_pixels; |
| 97 } |
| 98 |
| 99 int ViewConfiguration::GetMinScalingSpanInPixels() { |
| 100 return g_view_configuration.Get().min_scaling_span_in_pixels; |
| 101 } |
| 102 |
| 103 int ViewConfiguration::GetMinScalingTouchMajorInPixels() { |
| 104 return g_view_configuration.Get().min_scaling_touch_major_in_pixels; |
50 } | 105 } |
51 | 106 |
52 bool ViewConfiguration::RegisterViewConfiguration(JNIEnv* env) { | 107 bool ViewConfiguration::RegisterViewConfiguration(JNIEnv* env) { |
53 return RegisterNativesImpl(env); | 108 return JNI_ViewConfiguration::RegisterNativesImpl(env) && |
| 109 RegisterNativesImpl(env); |
54 } | 110 } |
55 | 111 |
56 } // namespace gfx | 112 } // namespace gfx |
OLD | NEW |