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

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

Issue 2708613002: Add EventForwarder for routing touch events (Closed)
Patch Set: unittests 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 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 JNIEnv* env, 864 JNIEnv* env,
865 const JavaParamRef<jobject>& obj, 865 const JavaParamRef<jobject>& obj,
866 jint orientation) { 866 jint orientation) {
867 if (device_orientation_ != orientation) { 867 if (device_orientation_ != orientation) {
868 base::RecordAction(base::UserMetricsAction("ScreenOrientationChange")); 868 base::RecordAction(base::UserMetricsAction("ScreenOrientationChange"));
869 device_orientation_ = orientation; 869 device_orientation_ = orientation;
870 SendOrientationChangeEventInternal(); 870 SendOrientationChangeEventInternal();
871 } 871 }
872 } 872 }
873 873
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, 874 jboolean ContentViewCoreImpl::SendMouseEvent(JNIEnv* env,
boliu 2017/03/02 20:58:14 can be deleted as well?
Jinsuk Kim 2017/03/03 06:29:21 Done.
947 const JavaParamRef<jobject>& obj, 875 const JavaParamRef<jobject>& obj,
948 jlong time_ms, 876 jlong time_ms,
949 jint android_action, 877 jint android_action,
950 jfloat x, 878 jfloat x,
951 jfloat y, 879 jfloat y,
952 jint pointer_id, 880 jint pointer_id,
953 jfloat pressure, 881 jfloat pressure,
954 jfloat orientation, 882 jfloat orientation,
955 jfloat tilt, 883 jfloat tilt,
956 jint android_action_button, 884 jint android_action_button,
957 jint android_button_state, 885 jint android_button_state,
958 jint android_meta_state, 886 jint android_meta_state,
959 jint android_tool_type) { 887 jint android_tool_type) {
960 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 888 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
961 if (!rwhv) 889 if (!rwhv)
962 return false; 890 return false;
963 891
964 // Construct a motion_event object minimally, only to convert the raw 892 // Construct a motion_event object minimally, only to convert the raw
965 // parameters to ui::MotionEvent values. Since we used only the cached values 893 // 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. 894 // at index=0, it is okay to even pass a null event to the constructor.
967 MotionEventAndroid::Pointer pointer0( 895 MotionEventAndroid::Pointer pointer0(
968 pointer_id, x, y, 0.0f /* touch_major */, 0.0f /* touch_minor */, 896 pointer_id, x, y, 0.0f /* touch_major */, 0.0f /* touch_minor */,
969 orientation, tilt, android_tool_type); 897 orientation, tilt, android_tool_type);
970 898
971 MotionEventAndroid motion_event(1.f / dpi_scale(), 899 MotionEventAndroid motion_event(
972 env, 900 1.f / dpi_scale(), env, nullptr /* event */, time_ms, android_action,
973 nullptr /* event */, 901 1 /* pointer_count */, 0 /* history_size */, 0 /* action_index */,
974 time_ms, 902 android_button_state, android_meta_state, 0 /* raw_offset_x_pixels */,
975 android_action, 903 0 /* raw_offset_y_pixels */, &pointer0, nullptr);
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 904
986 RecordToolTypeForActionDown(motion_event); 905 RecordToolTypeForActionDown(motion_event);
987 906
988 // Note: This relies on identical button enum values in MotionEvent and 907 // Note: This relies on identical button enum values in MotionEvent and
989 // MotionEventAndroid. 908 // MotionEventAndroid.
990 rwhv->SendMouseEvent(motion_event, android_action_button); 909 rwhv->SendMouseEvent(motion_event, android_action_button);
991 910
992 return true; 911 return true;
993 } 912 }
994 913
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 const JavaParamRef<jobject>& jview_android_delegate, 1413 const JavaParamRef<jobject>& jview_android_delegate,
1495 jlong jwindow_android, 1414 jlong jwindow_android,
1496 jfloat dipScale, 1415 jfloat dipScale,
1497 const JavaParamRef<jobject>& retained_objects_set) { 1416 const JavaParamRef<jobject>& retained_objects_set) {
1498 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 1417 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
1499 WebContents::FromJavaWebContents(jweb_contents)); 1418 WebContents::FromJavaWebContents(jweb_contents));
1500 CHECK(web_contents) << 1419 CHECK(web_contents) <<
1501 "A ContentViewCoreImpl should be created with a valid WebContents."; 1420 "A ContentViewCoreImpl should be created with a valid WebContents.";
1502 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); 1421 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView();
1503 view_android->SetDelegate(jview_android_delegate); 1422 view_android->SetDelegate(jview_android_delegate);
1423 view_android->SetLayout(0, 0, 0, 0, true);
boliu 2017/03/02 20:58:14 /* match parent */
Jinsuk Kim 2017/03/03 06:29:21 Done.
1504 1424
1505 ui::WindowAndroid* window_android = 1425 ui::WindowAndroid* window_android =
1506 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); 1426 reinterpret_cast<ui::WindowAndroid*>(jwindow_android);
1507 DCHECK(window_android); 1427 DCHECK(window_android);
1508 window_android->AddChild(view_android); 1428 window_android->AddChild(view_android);
1509 1429
1510 // TODO: pass dipScale. 1430 // TODO: pass dipScale.
1511 ContentViewCoreImpl* view = new ContentViewCoreImpl( 1431 ContentViewCoreImpl* view = new ContentViewCoreImpl(
1512 env, obj, web_contents, dipScale, retained_objects_set); 1432 env, obj, web_contents, dipScale, retained_objects_set);
1513 return reinterpret_cast<intptr_t>(view); 1433 return reinterpret_cast<intptr_t>(view);
(...skipping 12 matching lines...) Expand all
1526 return ScopedJavaLocalRef<jobject>(); 1446 return ScopedJavaLocalRef<jobject>();
1527 1447
1528 return view->GetJavaObject(); 1448 return view->GetJavaObject();
1529 } 1449 }
1530 1450
1531 bool RegisterContentViewCore(JNIEnv* env) { 1451 bool RegisterContentViewCore(JNIEnv* env) {
1532 return RegisterNativesImpl(env); 1452 return RegisterNativesImpl(env);
1533 } 1453 }
1534 1454
1535 } // namespace content 1455 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698