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

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

Issue 2708613002: Add EventForwarder for routing touch events (Closed)
Patch Set: base::Bind (doesn't compile yet) 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 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 JNIEnv* env, 853 JNIEnv* env,
865 const JavaParamRef<jobject>& obj, 854 const JavaParamRef<jobject>& obj,
866 jint orientation) { 855 jint orientation) {
867 if (device_orientation_ != orientation) { 856 if (device_orientation_ != orientation) {
868 base::RecordAction(base::UserMetricsAction("ScreenOrientationChange")); 857 base::RecordAction(base::UserMetricsAction("ScreenOrientationChange"));
869 device_orientation_ = orientation; 858 device_orientation_ = orientation;
870 SendOrientationChangeEventInternal(); 859 SendOrientationChangeEventInternal();
871 } 860 }
872 } 861 }
873 862
874 jboolean ContentViewCoreImpl::OnTouchEvent(
875 JNIEnv* env,
876 const JavaParamRef<jobject>& obj,
877 const JavaParamRef<jobject>& motion_event,
878 jlong time_ms,
879 jint android_action,
880 jint pointer_count,
881 jint history_size,
882 jint action_index,
883 jfloat pos_x_0,
884 jfloat pos_y_0,
885 jfloat pos_x_1,
886 jfloat pos_y_1,
887 jint pointer_id_0,
888 jint pointer_id_1,
889 jfloat touch_major_0,
890 jfloat touch_major_1,
891 jfloat touch_minor_0,
892 jfloat touch_minor_1,
893 jfloat orientation_0,
894 jfloat orientation_1,
895 jfloat tilt_0,
896 jfloat tilt_1,
897 jfloat raw_pos_x,
898 jfloat raw_pos_y,
899 jint android_tool_type_0,
900 jint android_tool_type_1,
901 jint android_button_state,
902 jint android_meta_state,
903 jboolean is_touch_handle_event) {
904 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
905 // Avoid synthesizing a touch event if it cannot be forwarded.
906 if (!rwhv)
907 return false;
908
909 MotionEventAndroid::Pointer pointer0(pointer_id_0,
910 pos_x_0,
911 pos_y_0,
912 touch_major_0,
913 touch_minor_0,
914 orientation_0,
915 tilt_0,
916 android_tool_type_0);
917 MotionEventAndroid::Pointer pointer1(pointer_id_1,
918 pos_x_1,
919 pos_y_1,
920 touch_major_1,
921 touch_minor_1,
922 orientation_1,
923 tilt_1,
924 android_tool_type_1);
925 MotionEventAndroid event(1.f / dpi_scale(),
926 env,
927 motion_event,
928 time_ms,
929 android_action,
930 pointer_count,
931 history_size,
932 action_index,
933 android_button_state,
934 android_meta_state,
935 raw_pos_x - pos_x_0,
936 raw_pos_y - pos_y_0,
937 &pointer0,
938 &pointer1);
939
940 RecordToolTypeForActionDown(event);
941
942 return is_touch_handle_event ? rwhv->OnTouchHandleEvent(event)
943 : rwhv->OnTouchEvent(event);
944 }
945
946 jboolean ContentViewCoreImpl::SendMouseEvent(JNIEnv* env,
947 const JavaParamRef<jobject>& obj,
948 jlong time_ms,
949 jint android_action,
950 jfloat x,
951 jfloat y,
952 jint pointer_id,
953 jfloat pressure,
954 jfloat orientation,
955 jfloat tilt,
956 jint android_action_button,
957 jint android_button_state,
958 jint android_meta_state,
959 jint android_tool_type) {
960 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
961 if (!rwhv)
962 return false;
963
964 // Construct a motion_event object minimally, only to convert the raw
965 // parameters to ui::MotionEvent values. Since we used only the cached values
966 // at index=0, it is okay to even pass a null event to the constructor.
967 MotionEventAndroid::Pointer pointer0(
968 pointer_id, x, y, 0.0f /* touch_major */, 0.0f /* touch_minor */,
969 orientation, tilt, android_tool_type);
970
971 MotionEventAndroid motion_event(1.f / dpi_scale(),
972 env,
973 nullptr /* event */,
974 time_ms,
975 android_action,
976 1 /* pointer_count */,
977 0 /* history_size */,
978 0 /* action_index */,
979 android_button_state,
980 android_meta_state,
981 0 /* raw_offset_x_pixels */,
982 0 /* raw_offset_y_pixels */,
983 &pointer0,
984 nullptr);
985
986 RecordToolTypeForActionDown(motion_event);
987
988 // Note: This relies on identical button enum values in MotionEvent and
989 // MotionEventAndroid.
990 rwhv->SendMouseEvent(motion_event, android_action_button);
991
992 return true;
993 }
994
995 jboolean ContentViewCoreImpl::SendMouseWheelEvent( 863 jboolean ContentViewCoreImpl::SendMouseWheelEvent(
996 JNIEnv* env, 864 JNIEnv* env,
997 const JavaParamRef<jobject>& obj, 865 const JavaParamRef<jobject>& obj,
998 jlong time_ms, 866 jlong time_ms,
999 jfloat x, 867 jfloat x,
1000 jfloat y, 868 jfloat y,
1001 jfloat ticks_x, 869 jfloat ticks_x,
1002 jfloat ticks_y, 870 jfloat ticks_y,
1003 jfloat pixels_per_tick) { 871 jfloat pixels_per_tick) {
1004 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 872 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 1076
1209 void ContentViewCoreImpl::SetMultiTouchZoomSupportEnabled( 1077 void ContentViewCoreImpl::SetMultiTouchZoomSupportEnabled(
1210 JNIEnv* env, 1078 JNIEnv* env,
1211 const JavaParamRef<jobject>& obj, 1079 const JavaParamRef<jobject>& obj,
1212 jboolean enabled) { 1080 jboolean enabled) {
1213 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 1081 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
1214 if (rwhv) 1082 if (rwhv)
1215 rwhv->SetMultiTouchZoomSupportEnabled(enabled); 1083 rwhv->SetMultiTouchZoomSupportEnabled(enabled);
1216 } 1084 }
1217 1085
1086 void ContentViewCoreImpl::OnTouchDown(
1087 const base::android::ScopedJavaLocalRef<jobject>& event) {
1088 JNIEnv* env = AttachCurrentThread();
1089 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
1090 if (obj.is_null())
1091 return;
1092 Java_ContentViewCore_onTouchDown(env, obj, event);
1093 }
1094
1218 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection( 1095 void ContentViewCoreImpl::SetAllowJavascriptInterfacesInspection(
1219 JNIEnv* env, 1096 JNIEnv* env,
1220 const JavaParamRef<jobject>& obj, 1097 const JavaParamRef<jobject>& obj,
1221 jboolean allow) { 1098 jboolean allow) {
1222 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow); 1099 java_bridge_dispatcher_host_->SetAllowObjectContentsInspection(allow);
1223 } 1100 }
1224 1101
1225 void ContentViewCoreImpl::AddJavascriptInterface( 1102 void ContentViewCoreImpl::AddJavascriptInterface(
1226 JNIEnv* env, 1103 JNIEnv* env,
1227 const JavaParamRef<jobject>& /* obj */, 1104 const JavaParamRef<jobject>& /* obj */,
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 const JavaParamRef<jobject>& jview_android_delegate, 1371 const JavaParamRef<jobject>& jview_android_delegate,
1495 jlong jwindow_android, 1372 jlong jwindow_android,
1496 jfloat dipScale, 1373 jfloat dipScale,
1497 const JavaParamRef<jobject>& retained_objects_set) { 1374 const JavaParamRef<jobject>& retained_objects_set) {
1498 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 1375 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
1499 WebContents::FromJavaWebContents(jweb_contents)); 1376 WebContents::FromJavaWebContents(jweb_contents));
1500 CHECK(web_contents) << 1377 CHECK(web_contents) <<
1501 "A ContentViewCoreImpl should be created with a valid WebContents."; 1378 "A ContentViewCoreImpl should be created with a valid WebContents.";
1502 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); 1379 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView();
1503 view_android->SetDelegate(jview_android_delegate); 1380 view_android->SetDelegate(jview_android_delegate);
1381 view_android->SetLayout(ui::ViewAndroid::LayoutParams::MatchParent());
1504 1382
1505 ui::WindowAndroid* window_android = 1383 ui::WindowAndroid* window_android =
1506 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); 1384 reinterpret_cast<ui::WindowAndroid*>(jwindow_android);
1507 DCHECK(window_android); 1385 DCHECK(window_android);
1508 window_android->AddChild(view_android); 1386 window_android->AddChild(view_android);
1509 1387
1510 // TODO: pass dipScale. 1388 // TODO: pass dipScale.
1511 ContentViewCoreImpl* view = new ContentViewCoreImpl( 1389 ContentViewCoreImpl* view = new ContentViewCoreImpl(
1512 env, obj, web_contents, dipScale, retained_objects_set); 1390 env, obj, web_contents, dipScale, retained_objects_set);
1513 return reinterpret_cast<intptr_t>(view); 1391 return reinterpret_cast<intptr_t>(view);
(...skipping 12 matching lines...) Expand all
1526 return ScopedJavaLocalRef<jobject>(); 1404 return ScopedJavaLocalRef<jobject>();
1527 1405
1528 return view->GetJavaObject(); 1406 return view->GetJavaObject();
1529 } 1407 }
1530 1408
1531 bool RegisterContentViewCore(JNIEnv* env) { 1409 bool RegisterContentViewCore(JNIEnv* env) {
1532 return RegisterNativesImpl(env); 1410 return RegisterNativesImpl(env);
1533 } 1411 }
1534 1412
1535 } // namespace content 1413 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698