Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: content/browser/android/content_view_core_impl.cc

Issue 2708613002: Add EventForwarder for routing touch events (Closed)
Patch Set: EventForwarder... Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 case WebInputEvent::GesturePinchUpdate: 155 case WebInputEvent::GesturePinchUpdate:
156 return GESTURE_EVENT_TYPE_PINCH_BY; 156 return GESTURE_EVENT_TYPE_PINCH_BY;
157 case WebInputEvent::GestureTwoFingerTap: 157 case WebInputEvent::GestureTwoFingerTap:
158 default: 158 default:
159 NOTREACHED() << "Invalid source gesture type: " 159 NOTREACHED() << "Invalid source gesture type: "
160 << WebInputEvent::GetName(type); 160 << WebInputEvent::GetName(type);
161 return -1; 161 return -1;
162 } 162 }
163 } 163 }
164 164
165 void RecordToolTypeForActionDown(MotionEventAndroid& event) {
166 MotionEventAndroid::Action action = event.GetAction();
167 if (action == MotionEventAndroid::ACTION_DOWN ||
168 action == MotionEventAndroid::ACTION_POINTER_DOWN ||
169 action == MotionEventAndroid::ACTION_BUTTON_PRESS) {
170 UMA_HISTOGRAM_ENUMERATION("Event.AndroidActionDown.ToolType",
171 event.GetToolType(0),
172 MotionEventAndroid::TOOL_TYPE_LAST + 1);
173 }
174 }
175
176 } // namespace 165 } // namespace
177 166
178 // Enables a callback when the underlying WebContents is destroyed, to enable 167 // Enables a callback when the underlying WebContents is destroyed, to enable
179 // nulling the back-pointer. 168 // nulling the back-pointer.
180 class ContentViewCoreImpl::ContentViewUserData 169 class ContentViewCoreImpl::ContentViewUserData
181 : public base::SupportsUserData::Data { 170 : public base::SupportsUserData::Data {
182 public: 171 public:
183 explicit ContentViewUserData(ContentViewCoreImpl* content_view_core) 172 explicit ContentViewUserData(ContentViewCoreImpl* content_view_core)
184 : content_view_core_(content_view_core) { 173 : content_view_core_(content_view_core) {
185 } 174 }
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 JNIEnv* env, 858 JNIEnv* env,
870 const JavaParamRef<jobject>& obj, 859 const JavaParamRef<jobject>& obj,
871 jint orientation) { 860 jint orientation) {
872 if (device_orientation_ != orientation) { 861 if (device_orientation_ != orientation) {
873 base::RecordAction(base::UserMetricsAction("ScreenOrientationChange")); 862 base::RecordAction(base::UserMetricsAction("ScreenOrientationChange"));
874 device_orientation_ = orientation; 863 device_orientation_ = orientation;
875 SendOrientationChangeEventInternal(); 864 SendOrientationChangeEventInternal();
876 } 865 }
877 } 866 }
878 867
879 jboolean ContentViewCoreImpl::OnTouchEvent(
880 JNIEnv* env,
881 const JavaParamRef<jobject>& obj,
882 const JavaParamRef<jobject>& motion_event,
883 jlong time_ms,
884 jint android_action,
885 jint pointer_count,
886 jint history_size,
887 jint action_index,
888 jfloat pos_x_0,
889 jfloat pos_y_0,
890 jfloat pos_x_1,
891 jfloat pos_y_1,
892 jint pointer_id_0,
893 jint pointer_id_1,
894 jfloat touch_major_0,
895 jfloat touch_major_1,
896 jfloat touch_minor_0,
897 jfloat touch_minor_1,
898 jfloat orientation_0,
899 jfloat orientation_1,
900 jfloat tilt_0,
901 jfloat tilt_1,
902 jfloat raw_pos_x,
903 jfloat raw_pos_y,
904 jint android_tool_type_0,
905 jint android_tool_type_1,
906 jint android_button_state,
907 jint android_meta_state,
908 jboolean is_touch_handle_event) {
909 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
910 // Avoid synthesizing a touch event if it cannot be forwarded.
911 if (!rwhv)
912 return false;
913
914 MotionEventAndroid::Pointer pointer0(pointer_id_0,
915 pos_x_0,
916 pos_y_0,
917 touch_major_0,
918 touch_minor_0,
919 orientation_0,
920 tilt_0,
921 android_tool_type_0);
922 MotionEventAndroid::Pointer pointer1(pointer_id_1,
923 pos_x_1,
924 pos_y_1,
925 touch_major_1,
926 touch_minor_1,
927 orientation_1,
928 tilt_1,
929 android_tool_type_1);
930 MotionEventAndroid event(1.f / dpi_scale(),
931 env,
932 motion_event,
933 time_ms,
934 android_action,
935 pointer_count,
936 history_size,
937 action_index,
938 android_button_state,
939 android_meta_state,
940 raw_pos_x - pos_x_0,
941 raw_pos_y - pos_y_0,
942 &pointer0,
943 &pointer1);
944
945 RecordToolTypeForActionDown(event);
946
947 return is_touch_handle_event ? rwhv->OnTouchHandleEvent(event)
948 : rwhv->OnTouchEvent(event);
949 }
950
951 jboolean ContentViewCoreImpl::SendMouseEvent(JNIEnv* env,
952 const JavaParamRef<jobject>& obj,
953 jlong time_ms,
954 jint android_action,
955 jfloat x,
956 jfloat y,
957 jint pointer_id,
958 jfloat pressure,
959 jfloat orientation,
960 jfloat tilt,
961 jint android_action_button,
962 jint android_button_state,
963 jint android_meta_state,
964 jint android_tool_type) {
965 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
966 if (!rwhv)
967 return false;
968
969 // Construct a motion_event object minimally, only to convert the raw
970 // parameters to ui::MotionEvent values. Since we used only the cached values
971 // at index=0, it is okay to even pass a null event to the constructor.
972 MotionEventAndroid::Pointer pointer0(
973 pointer_id, x, y, 0.0f /* touch_major */, 0.0f /* touch_minor */,
974 orientation, tilt, android_tool_type);
975
976 MotionEventAndroid motion_event(1.f / dpi_scale(),
977 env,
978 nullptr /* event */,
979 time_ms,
980 android_action,
981 1 /* pointer_count */,
982 0 /* history_size */,
983 0 /* action_index */,
984 android_button_state,
985 android_meta_state,
986 0 /* raw_offset_x_pixels */,
987 0 /* raw_offset_y_pixels */,
988 &pointer0,
989 nullptr);
990
991 RecordToolTypeForActionDown(motion_event);
992
993 // Note: This relies on identical button enum values in MotionEvent and
994 // MotionEventAndroid.
995 rwhv->SendMouseEvent(motion_event, android_action_button);
996
997 return true;
998 }
999
1000 jboolean ContentViewCoreImpl::SendMouseWheelEvent( 868 jboolean ContentViewCoreImpl::SendMouseWheelEvent(
1001 JNIEnv* env, 869 JNIEnv* env,
1002 const JavaParamRef<jobject>& obj, 870 const JavaParamRef<jobject>& obj,
1003 jlong time_ms, 871 jlong time_ms,
1004 jfloat x, 872 jfloat x,
1005 jfloat y, 873 jfloat y,
1006 jfloat ticks_x, 874 jfloat ticks_x,
1007 jfloat ticks_y, 875 jfloat ticks_y,
1008 jfloat pixels_per_tick) { 876 jfloat pixels_per_tick) {
1009 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 877 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 1081
1214 void ContentViewCoreImpl::SetMultiTouchZoomSupportEnabled( 1082 void ContentViewCoreImpl::SetMultiTouchZoomSupportEnabled(
1215 JNIEnv* env, 1083 JNIEnv* env,
1216 const JavaParamRef<jobject>& obj, 1084 const JavaParamRef<jobject>& obj,
1217 jboolean enabled) { 1085 jboolean enabled) {
1218 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 1086 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
1219 if (rwhv) 1087 if (rwhv)
1220 rwhv->SetMultiTouchZoomSupportEnabled(enabled); 1088 rwhv->SetMultiTouchZoomSupportEnabled(enabled);
1221 } 1089 }
1222 1090
1091 void ContentViewCoreImpl::OnTouchDown(
1092 const base::android::ScopedJavaLocalRef<jobject>& event) {
1093 JNIEnv* env = AttachCurrentThread();
1094 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
1095 if (obj.is_null())
1096 return;
1097 Java_ContentViewCore_onTouchDown(env, obj, event);
1098 }
1099
1223 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( 1100 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection(
1224 JNIEnv* env, 1101 JNIEnv* env,
1225 const JavaParamRef<jobject>& obj, 1102 const JavaParamRef<jobject>& obj,
1226 jboolean allow) { 1103 jboolean allow) {
1227 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow); 1104 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow);
1228 } 1105 }
1229 1106
1230 void ContentViewCoreImpl::AddJavascriptInterface( 1107 void ContentViewCoreImpl::AddJavascriptInterface(
1231 JNIEnv* env, 1108 JNIEnv* env,
1232 const JavaParamRef<jobject>& /* obj */, 1109 const JavaParamRef<jobject>& /* obj */,
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 const JavaParamRef<jobject>& jview_android_delegate, 1376 const JavaParamRef<jobject>& jview_android_delegate,
1500 jlong jwindow_android, 1377 jlong jwindow_android,
1501 jfloat dipScale, 1378 jfloat dipScale,
1502 const JavaParamRef<jobject>& retained_objects_set) { 1379 const JavaParamRef<jobject>& retained_objects_set) {
1503 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 1380 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
1504 WebContents::FromJavaWebContents(jweb_contents)); 1381 WebContents::FromJavaWebContents(jweb_contents));
1505 CHECK(web_contents) << 1382 CHECK(web_contents) <<
1506 "A ContentViewCoreImpl should be created with a valid WebContents."; 1383 "A ContentViewCoreImpl should be created with a valid WebContents.";
1507 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); 1384 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView();
1508 view_android->SetDelegate(jview_android_delegate); 1385 view_android->SetDelegate(jview_android_delegate);
1386 view_android->SetLayout(ui::ViewAndroid::LayoutParams::MatchParent());
1509 1387
1510 ui::WindowAndroid* window_android = 1388 ui::WindowAndroid* window_android =
1511 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); 1389 reinterpret_cast<ui::WindowAndroid*>(jwindow_android);
1512 DCHECK(window_android); 1390 DCHECK(window_android);
1513 window_android->AddChild(view_android); 1391 window_android->AddChild(view_android);
1514 1392
1515 // TODO: pass dipScale. 1393 // TODO: pass dipScale.
1516 ContentViewCoreImpl* view = new ContentViewCoreImpl( 1394 ContentViewCoreImpl* view = new ContentViewCoreImpl(
1517 env, obj, web_contents, dipScale, retained_objects_set); 1395 env, obj, web_contents, dipScale, retained_objects_set);
1518 return reinterpret_cast<intptr_t>(view); 1396 return reinterpret_cast<intptr_t>(view);
(...skipping 12 matching lines...) Expand all
1531 return ScopedJavaLocalRef<jobject>(); 1409 return ScopedJavaLocalRef<jobject>();
1532 1410
1533 return view->GetJavaObject(); 1411 return view->GetJavaObject();
1534 } 1412 }
1535 1413
1536 bool RegisterContentViewCore(JNIEnv* env) { 1414 bool RegisterContentViewCore(JNIEnv* env) {
1537 return RegisterNativesImpl(env); 1415 return RegisterNativesImpl(env);
1538 } 1416 }
1539 1417
1540 } // namespace content 1418 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/content_view_core_impl.h ('k') | content/browser/renderer_host/render_widget_host_view_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698