OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "content/browser/android/content_view_core_impl.h" | 5 #include "content/browser/android/content_view_core_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 if (!rwhv) | 1021 if (!rwhv) |
1022 return; | 1022 return; |
1023 | 1023 |
1024 const ui::MotionEvent* current_down_event = | 1024 const ui::MotionEvent* current_down_event = |
1025 gesture_provider_.GetCurrentDownEvent(); | 1025 gesture_provider_.GetCurrentDownEvent(); |
1026 if (!current_down_event) | 1026 if (!current_down_event) |
1027 return; | 1027 return; |
1028 | 1028 |
1029 scoped_ptr<ui::MotionEvent> cancel_event = current_down_event->Cancel(); | 1029 scoped_ptr<ui::MotionEvent> cancel_event = current_down_event->Cancel(); |
1030 DCHECK(cancel_event); | 1030 DCHECK(cancel_event); |
1031 if (!gesture_provider_.OnTouchEvent(*cancel_event)) | 1031 OnMotionEvent(*cancel_event); |
1032 return; | |
1033 | |
1034 rwhv->SendTouchEvent( | |
1035 CreateWebTouchEventFromMotionEvent(*cancel_event, 1.f / dpi_scale())); | |
1036 } | 1032 } |
1037 | 1033 |
1038 jboolean ContentViewCoreImpl::OnTouchEvent(JNIEnv* env, | 1034 jboolean ContentViewCoreImpl::OnTouchEvent(JNIEnv* env, |
1039 jobject obj, | 1035 jobject obj, |
1040 jobject motion_event, | 1036 jobject motion_event, |
1041 jlong time_ms, | 1037 jlong time_ms, |
1042 jint android_action, | 1038 jint android_action, |
1043 jint pointer_count, | 1039 jint pointer_count, |
1044 jint history_size, | 1040 jint history_size, |
1045 jint action_index, | 1041 jint action_index, |
1046 jfloat pos_x_0, | 1042 jfloat pos_x_0, |
1047 jfloat pos_y_0, | 1043 jfloat pos_y_0, |
1048 jfloat pos_x_1, | 1044 jfloat pos_x_1, |
1049 jfloat pos_y_1, | 1045 jfloat pos_y_1, |
1050 jint pointer_id_0, | 1046 jint pointer_id_0, |
1051 jint pointer_id_1, | 1047 jint pointer_id_1, |
1052 jfloat touch_major_0, | 1048 jfloat touch_major_0, |
1053 jfloat touch_major_1) { | 1049 jfloat touch_major_1) { |
1054 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1050 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 1051 // Avoid synthesizing a touch event if it cannot be forwarded. |
1055 if (!rwhv) | 1052 if (!rwhv) |
1056 return false; | 1053 return false; |
1057 | 1054 |
1058 MotionEventAndroid event(env, | 1055 MotionEventAndroid event(env, |
1059 motion_event, | 1056 motion_event, |
1060 time_ms, | 1057 time_ms, |
1061 android_action, | 1058 android_action, |
1062 pointer_count, | 1059 pointer_count, |
1063 history_size, | 1060 history_size, |
1064 action_index, | 1061 action_index, |
1065 pos_x_0, | 1062 pos_x_0, |
1066 pos_y_0, | 1063 pos_y_0, |
1067 pos_x_1, | 1064 pos_x_1, |
1068 pos_y_1, | 1065 pos_y_1, |
1069 pointer_id_0, | 1066 pointer_id_0, |
1070 pointer_id_1, | 1067 pointer_id_1, |
1071 touch_major_0, | 1068 touch_major_0, |
1072 touch_major_1); | 1069 touch_major_1); |
1073 | 1070 |
1074 if (!gesture_provider_.OnTouchEvent(event)) | 1071 return OnMotionEvent(event); |
1075 return false; | |
1076 | |
1077 rwhv->SendTouchEvent(WebTouchEventBuilder::Build(event, 1.f / dpi_scale())); | |
1078 return true; | |
1079 } | 1072 } |
1080 | 1073 |
1081 float ContentViewCoreImpl::GetDpiScale() const { | 1074 float ContentViewCoreImpl::GetDpiScale() const { |
1082 return dpi_scale_; | 1075 return dpi_scale_; |
1083 } | 1076 } |
1084 | 1077 |
1085 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, | 1078 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, |
1086 jobject obj, | 1079 jobject obj, |
1087 jlong time_ms, | 1080 jlong time_ms, |
1088 jfloat x, | 1081 jfloat x, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 rwhv->SendMouseWheelEvent(event); | 1117 rwhv->SendMouseWheelEvent(event); |
1125 return true; | 1118 return true; |
1126 } | 1119 } |
1127 | 1120 |
1128 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( | 1121 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( |
1129 WebInputEvent::Type type, int64 time_ms, float x, float y) const { | 1122 WebInputEvent::Type type, int64 time_ms, float x, float y) const { |
1130 return WebGestureEventBuilder::Build( | 1123 return WebGestureEventBuilder::Build( |
1131 type, time_ms / 1000.0, x / dpi_scale(), y / dpi_scale()); | 1124 type, time_ms / 1000.0, x / dpi_scale(), y / dpi_scale()); |
1132 } | 1125 } |
1133 | 1126 |
| 1127 bool ContentViewCoreImpl::OnMotionEvent(const ui::MotionEvent& event) { |
| 1128 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 1129 if (!rwhv) |
| 1130 return false; |
| 1131 |
| 1132 if (!gesture_provider_.OnTouchEvent(event)) |
| 1133 return false; |
| 1134 |
| 1135 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( |
| 1136 rwhv->GetRenderWidgetHost()); |
| 1137 if (!host->ShouldForwardTouchEvent()) { |
| 1138 ConfirmTouchEvent(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); |
| 1139 return true; |
| 1140 } |
| 1141 |
| 1142 rwhv->SendTouchEvent( |
| 1143 CreateWebTouchEventFromMotionEvent(event, 1.f / dpi_scale())); |
| 1144 return true; |
| 1145 } |
| 1146 |
1134 void ContentViewCoreImpl::SendGestureEvent( | 1147 void ContentViewCoreImpl::SendGestureEvent( |
1135 const blink::WebGestureEvent& event) { | 1148 const blink::WebGestureEvent& event) { |
1136 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1149 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
1137 if (rwhv) | 1150 if (rwhv) |
1138 rwhv->SendGestureEvent(event); | 1151 rwhv->SendGestureEvent(event); |
1139 } | 1152 } |
1140 | 1153 |
1141 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, | 1154 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, |
1142 jobject obj, | 1155 jobject obj, |
1143 jlong time_ms, | 1156 jlong time_ms, |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1782 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1795 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1783 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1796 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1784 return reinterpret_cast<intptr_t>(view); | 1797 return reinterpret_cast<intptr_t>(view); |
1785 } | 1798 } |
1786 | 1799 |
1787 bool RegisterContentViewCore(JNIEnv* env) { | 1800 bool RegisterContentViewCore(JNIEnv* env) { |
1788 return RegisterNativesImpl(env); | 1801 return RegisterNativesImpl(env); |
1789 } | 1802 } |
1790 | 1803 |
1791 } // namespace content | 1804 } // namespace content |
OLD | NEW |