Chromium Code Reviews| 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 // If there are no touch handlers and the touch queue is empty, touch | |
| 1136 // forwarding can be short-circuited completely. | |
|
tdresser
2014/03/28 17:55:27
It feels like this comment is breaking encapsulati
jdduke (slow)
2014/03/28 18:33:55
Yes, though in my mind those details are vital to
tdresser
2014/03/28 18:40:05
SGTM.
| |
| 1137 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( | |
| 1138 rwhv->GetRenderWidgetHost()); | |
| 1139 if (!host->ShouldForwardTouchEvent()) { | |
| 1140 ConfirmTouchEvent(INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | |
| 1141 return true; | |
| 1142 } | |
| 1143 | |
| 1144 rwhv->SendTouchEvent( | |
| 1145 CreateWebTouchEventFromMotionEvent(event, 1.f / dpi_scale())); | |
| 1146 return true; | |
| 1147 } | |
| 1148 | |
| 1134 void ContentViewCoreImpl::SendGestureEvent( | 1149 void ContentViewCoreImpl::SendGestureEvent( |
| 1135 const blink::WebGestureEvent& event) { | 1150 const blink::WebGestureEvent& event) { |
| 1136 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1151 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 1137 if (rwhv) | 1152 if (rwhv) |
| 1138 rwhv->SendGestureEvent(event); | 1153 rwhv->SendGestureEvent(event); |
| 1139 } | 1154 } |
| 1140 | 1155 |
| 1141 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, | 1156 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, |
| 1142 jobject obj, | 1157 jobject obj, |
| 1143 jlong time_ms, | 1158 jlong time_ms, |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1782 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1797 reinterpret_cast<ui::ViewAndroid*>(view_android), |
| 1783 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1798 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
| 1784 return reinterpret_cast<intptr_t>(view); | 1799 return reinterpret_cast<intptr_t>(view); |
| 1785 } | 1800 } |
| 1786 | 1801 |
| 1787 bool RegisterContentViewCore(JNIEnv* env) { | 1802 bool RegisterContentViewCore(JNIEnv* env) { |
| 1788 return RegisterNativesImpl(env); | 1803 return RegisterNativesImpl(env); |
| 1789 } | 1804 } |
| 1790 | 1805 |
| 1791 } // namespace content | 1806 } // namespace content |
| OLD | NEW |