OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/android/event_forwarder.h" | 5 #include "ui/android/event_forwarder.h" |
6 | 6 |
7 #include "base/android/jni_array.h" | |
8 #include "base/android/jni_string.h" | |
7 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
8 #include "jni/EventForwarder_jni.h" | 10 #include "jni/EventForwarder_jni.h" |
9 #include "ui/android/view_android.h" | 11 #include "ui/android/view_android.h" |
10 #include "ui/android/view_client.h" | 12 #include "ui/android/view_client.h" |
13 #include "ui/base/ui_base_switches_util.h" | |
14 #include "ui/events/android/drag_event_android.h" | |
11 #include "ui/events/android/motion_event_android.h" | 15 #include "ui/events/android/motion_event_android.h" |
12 #include "ui/events/base_event_utils.h" | 16 #include "ui/events/base_event_utils.h" |
13 | 17 |
14 namespace ui { | 18 namespace ui { |
15 | 19 |
20 using base::android::AppendJavaStringArrayToStringVector; | |
16 using base::android::JavaParamRef; | 21 using base::android::JavaParamRef; |
17 using base::android::ScopedJavaLocalRef; | 22 using base::android::ScopedJavaLocalRef; |
23 using base::android::ConvertJavaStringToUTF16; | |
18 | 24 |
19 EventForwarder::EventForwarder(ViewAndroid* view) : view_(view) {} | 25 EventForwarder::EventForwarder(ViewAndroid* view) : view_(view) {} |
20 | 26 |
21 EventForwarder::~EventForwarder() { | 27 EventForwarder::~EventForwarder() { |
22 if (!java_obj_.is_null()) { | 28 if (!java_obj_.is_null()) { |
23 Java_EventForwarder_destroy(base::android::AttachCurrentThread(), | 29 Java_EventForwarder_destroy(base::android::AttachCurrentThread(), |
24 java_obj_); | 30 java_obj_); |
25 java_obj_.Reset(); | 31 java_obj_.Reset(); |
26 } | 32 } |
27 } | 33 } |
28 | 34 |
29 ScopedJavaLocalRef<jobject> EventForwarder::GetJavaObject() { | 35 ScopedJavaLocalRef<jobject> EventForwarder::GetJavaObject() { |
30 if (java_obj_.is_null()) { | 36 if (java_obj_.is_null()) { |
37 JNIEnv* env = base::android::AttachCurrentThread(); | |
31 java_obj_.Reset( | 38 java_obj_.Reset( |
32 Java_EventForwarder_create(base::android::AttachCurrentThread(), | 39 Java_EventForwarder_create(env, reinterpret_cast<intptr_t>(this), |
33 reinterpret_cast<intptr_t>(this))); | 40 switches::IsTouchDragDropEnabled())); |
34 } | 41 } |
35 return ScopedJavaLocalRef<jobject>(java_obj_); | 42 return ScopedJavaLocalRef<jobject>(java_obj_); |
36 } | 43 } |
37 | 44 |
38 jboolean EventForwarder::OnTouchEvent(JNIEnv* env, | 45 jboolean EventForwarder::OnTouchEvent(JNIEnv* env, |
39 const JavaParamRef<jobject>& obj, | 46 const JavaParamRef<jobject>& obj, |
40 const JavaParamRef<jobject>& motion_event, | 47 const JavaParamRef<jobject>& motion_event, |
41 jlong time_ms, | 48 jlong time_ms, |
42 jint android_action, | 49 jint android_action, |
43 jint pointer_count, | 50 jint pointer_count, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 ui::MotionEventAndroid event(env, nullptr, 1.f / view_->GetDipScale(), | 137 ui::MotionEventAndroid event(env, nullptr, 1.f / view_->GetDipScale(), |
131 ticks_x, ticks_y, pixels_per_tick, time_ms, | 138 ticks_x, ticks_y, pixels_per_tick, time_ms, |
132 0 /* action */, 1 /* pointer_count */, | 139 0 /* action */, 1 /* pointer_count */, |
133 0 /* history_size */, 0 /* action_index */, 0, 0, | 140 0 /* history_size */, 0 /* action_index */, 0, 0, |
134 0, 0 /* raw_offset_x_pixels */, | 141 0, 0 /* raw_offset_x_pixels */, |
135 0 /* raw_offset_y_pixels */, &pointer, nullptr); | 142 0 /* raw_offset_y_pixels */, &pointer, nullptr); |
136 | 143 |
137 view_->OnMouseWheelEvent(event); | 144 view_->OnMouseWheelEvent(event); |
138 } | 145 } |
139 | 146 |
147 void EventForwarder::OnDragEvent(JNIEnv* env, | |
148 const JavaParamRef<jobject>& jobj, | |
149 jint action, | |
150 jint x, | |
151 jint y, | |
152 jint screen_x, | |
153 jint screen_y, | |
154 const JavaParamRef<jobjectArray>& j_mimeTypes, | |
155 const JavaParamRef<jstring>& j_content) { | |
156 base::string16 drop_content = ConvertJavaStringToUTF16(env, j_content); | |
boliu
2017/05/24 22:54:02
depending on how big the payload is, that's potent
Jinsuk Kim
2017/05/25 03:18:18
Done.
| |
157 float dip_scale = view_->GetDipScale(); | |
158 gfx::PointF location(x / dip_scale, y / dip_scale); | |
159 gfx::PointF root_location(screen_x / dip_scale, screen_y / dip_scale); | |
160 std::vector<base::string16> mime_types; | |
161 AppendJavaStringArrayToStringVector(env, j_mimeTypes, &mime_types); | |
162 | |
163 DragEventAndroid event(action, location, root_location, mime_types, | |
164 drop_content); | |
165 view_->OnDragEvent(event); | |
166 } | |
167 | |
140 bool RegisterEventForwarder(JNIEnv* env) { | 168 bool RegisterEventForwarder(JNIEnv* env) { |
141 return RegisterNativesImpl(env); | 169 return RegisterNativesImpl(env); |
142 } | 170 } |
143 | 171 |
144 } // namespace ui | 172 } // namespace ui |
OLD | NEW |