| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 return false; | 913 return false; |
| 914 } | 914 } |
| 915 WebKit::WebMouseWheelEvent event = WebInputEventFactory::mouseWheelEvent( | 915 WebKit::WebMouseWheelEvent event = WebInputEventFactory::mouseWheelEvent( |
| 916 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); | 916 type, time_ms / 1000.0, x / GetDpiScale(), y / GetDpiScale()); |
| 917 | 917 |
| 918 rwhv->SendMouseWheelEvent(event); | 918 rwhv->SendMouseWheelEvent(event); |
| 919 return true; | 919 return true; |
| 920 } | 920 } |
| 921 | 921 |
| 922 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( | 922 WebGestureEvent ContentViewCoreImpl::MakeGestureEvent( |
| 923 WebInputEvent::Type type, long time_ms, float x, float y, | 923 WebInputEvent::Type type, long time_ms, float x, float y) const { |
| 924 InputEventVSyncStatus vsync_status) const { | |
| 925 WebGestureEvent event; | 924 WebGestureEvent event; |
| 926 event.type = type; | 925 event.type = type; |
| 927 event.x = x / GetDpiScale(); | 926 event.x = x / GetDpiScale(); |
| 928 event.y = y / GetDpiScale(); | 927 event.y = y / GetDpiScale(); |
| 929 event.timeStampSeconds = time_ms / 1000.0; | 928 event.timeStampSeconds = time_ms / 1000.0; |
| 930 event.sourceDevice = WebGestureEvent::Touchscreen; | 929 event.sourceDevice = WebGestureEvent::Touchscreen; |
| 931 if (vsync_status == LAST_INPUT_EVENT_FOR_VSYNC) | |
| 932 event.modifiers |= WebInputEvent::IsLastInputEventForCurrentVSync; | |
| 933 return event; | 930 return event; |
| 934 } | 931 } |
| 935 | 932 |
| 936 void ContentViewCoreImpl::SendGestureEvent( | 933 void ContentViewCoreImpl::SendGestureEvent( |
| 937 const WebKit::WebGestureEvent& event) { | 934 const WebKit::WebGestureEvent& event) { |
| 938 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 935 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 939 if (rwhv) | 936 if (rwhv) |
| 940 rwhv->SendGestureEvent(event); | 937 rwhv->SendGestureEvent(event); |
| 941 } | 938 } |
| 942 | 939 |
| 943 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms, | 940 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms, |
| 944 jfloat x, jfloat y) { | 941 jfloat x, jfloat y) { |
| 945 WebGestureEvent event = MakeGestureEvent( | 942 WebGestureEvent event = MakeGestureEvent( |
| 946 WebInputEvent::GestureScrollBegin, time_ms, x, y, | 943 WebInputEvent::GestureScrollBegin, time_ms, x, y); |
| 947 NOT_LAST_INPUT_EVENT_FOR_VSYNC); | |
| 948 SendGestureEvent(event); | 944 SendGestureEvent(event); |
| 949 } | 945 } |
| 950 | 946 |
| 951 void ContentViewCoreImpl::ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms) { | 947 void ContentViewCoreImpl::ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms) { |
| 952 WebGestureEvent event = MakeGestureEvent( | 948 WebGestureEvent event = MakeGestureEvent( |
| 953 WebInputEvent::GestureScrollEnd, time_ms, 0, 0, | 949 WebInputEvent::GestureScrollEnd, time_ms, 0, 0); |
| 954 NOT_LAST_INPUT_EVENT_FOR_VSYNC); | |
| 955 SendGestureEvent(event); | 950 SendGestureEvent(event); |
| 956 } | 951 } |
| 957 | 952 |
| 958 void ContentViewCoreImpl::ScrollBy(JNIEnv* env, jobject obj, jlong time_ms, | 953 void ContentViewCoreImpl::ScrollBy(JNIEnv* env, jobject obj, jlong time_ms, |
| 959 jfloat x, jfloat y, jfloat dx, jfloat dy, | 954 jfloat x, jfloat y, jfloat dx, jfloat dy, |
| 960 jboolean last_input_event_for_vsync) { | 955 jboolean last_input_event_for_vsync) { |
| 961 InputEventVSyncStatus vsync_status = | |
| 962 last_input_event_for_vsync ? LAST_INPUT_EVENT_FOR_VSYNC | |
| 963 : NOT_LAST_INPUT_EVENT_FOR_VSYNC; | |
| 964 WebGestureEvent event = MakeGestureEvent( | 956 WebGestureEvent event = MakeGestureEvent( |
| 965 WebInputEvent::GestureScrollUpdate, time_ms, x, y, vsync_status); | 957 WebInputEvent::GestureScrollUpdate, time_ms, x, y); |
| 966 event.data.scrollUpdate.deltaX = -dx / GetDpiScale(); | 958 event.data.scrollUpdate.deltaX = -dx / GetDpiScale(); |
| 967 event.data.scrollUpdate.deltaY = -dy / GetDpiScale(); | 959 event.data.scrollUpdate.deltaY = -dy / GetDpiScale(); |
| 968 | 960 |
| 969 SendGestureEvent(event); | 961 SendGestureEvent(event); |
| 970 } | 962 } |
| 971 | 963 |
| 972 void ContentViewCoreImpl::FlingStart(JNIEnv* env, jobject obj, jlong time_ms, | 964 void ContentViewCoreImpl::FlingStart(JNIEnv* env, jobject obj, jlong time_ms, |
| 973 jfloat x, jfloat y, jfloat vx, jfloat vy) { | 965 jfloat x, jfloat y, jfloat vx, jfloat vy) { |
| 974 WebGestureEvent event = MakeGestureEvent( | 966 WebGestureEvent event = MakeGestureEvent( |
| 975 WebInputEvent::GestureFlingStart, time_ms, x, y, | 967 WebInputEvent::GestureFlingStart, time_ms, x, y); |
| 976 NOT_LAST_INPUT_EVENT_FOR_VSYNC); | |
| 977 | 968 |
| 978 // Velocity should not be scaled by DIP since that interacts poorly with the | 969 // Velocity should not be scaled by DIP since that interacts poorly with the |
| 979 // deceleration constants. The DIP scaling is done on the renderer. | 970 // deceleration constants. The DIP scaling is done on the renderer. |
| 980 event.data.flingStart.velocityX = vx; | 971 event.data.flingStart.velocityX = vx; |
| 981 event.data.flingStart.velocityY = vy; | 972 event.data.flingStart.velocityY = vy; |
| 982 | 973 |
| 983 SendGestureEvent(event); | 974 SendGestureEvent(event); |
| 984 } | 975 } |
| 985 | 976 |
| 986 void ContentViewCoreImpl::FlingCancel(JNIEnv* env, jobject obj, jlong time_ms) { | 977 void ContentViewCoreImpl::FlingCancel(JNIEnv* env, jobject obj, jlong time_ms) { |
| 987 WebGestureEvent event = MakeGestureEvent( | 978 WebGestureEvent event = MakeGestureEvent( |
| 988 WebInputEvent::GestureFlingCancel, time_ms, 0, 0, | 979 WebInputEvent::GestureFlingCancel, time_ms, 0, 0); |
| 989 NOT_LAST_INPUT_EVENT_FOR_VSYNC); | |
| 990 SendGestureEvent(event); | 980 SendGestureEvent(event); |
| 991 } | 981 } |
| 992 | 982 |
| 993 void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, | 983 void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, |
| 994 jfloat x, jfloat y, | 984 jfloat x, jfloat y, |
| 995 jboolean disambiguation_popup_tap) { | 985 jboolean disambiguation_popup_tap) { |
| 996 WebGestureEvent event = MakeGestureEvent( | 986 WebGestureEvent event = MakeGestureEvent( |
| 997 WebInputEvent::GestureTap, time_ms, x, y, | 987 WebInputEvent::GestureTap, time_ms, x, y); |
| 998 NOT_LAST_INPUT_EVENT_FOR_VSYNC); | |
| 999 | 988 |
| 1000 event.data.tap.tapCount = 1; | 989 event.data.tap.tapCount = 1; |
| 1001 if (!disambiguation_popup_tap) { | 990 if (!disambiguation_popup_tap) { |
| 1002 const float touch_padding_dip = GetTouchPaddingDip(); | 991 const float touch_padding_dip = GetTouchPaddingDip(); |
| 1003 event.data.tap.width = touch_padding_dip; | 992 event.data.tap.width = touch_padding_dip; |
| 1004 event.data.tap.height = touch_padding_dip; | 993 event.data.tap.height = touch_padding_dip; |
| 1005 } | 994 } |
| 1006 | 995 |
| 1007 SendGestureEvent(event); | 996 SendGestureEvent(event); |
| 1008 } | 997 } |
| 1009 | 998 |
| 1010 void ContentViewCoreImpl::SingleTapUnconfirmed(JNIEnv* env, jobject obj, | 999 void ContentViewCoreImpl::SingleTapUnconfirmed(JNIEnv* env, jobject obj, |
| 1011 jlong time_ms, | 1000 jlong time_ms, |
| 1012 jfloat x, jfloat y) { | 1001 jfloat x, jfloat y) { |
| 1013 WebGestureEvent event = MakeGestureEvent( | 1002 WebGestureEvent event = MakeGestureEvent( |
| 1014 WebInputEvent::GestureTapUnconfirmed, time_ms, x, y, | 1003 WebInputEvent::GestureTapUnconfirmed, time_ms, x, y); |
| 1015 NOT_LAST_INPUT_EVENT_FOR_VSYNC); | |
| 1016 | 1004 |
| 1017 event.data.tap.tapCount = 1; | 1005 event.data.tap.tapCount = 1; |
| 1018 | 1006 |
| 1019 const float touch_padding_dip = GetTouchPaddingDip(); | 1007 const float touch_padding_dip = GetTouchPaddingDip(); |
| 1020 event.data.tap.width = touch_padding_dip; | 1008 event.data.tap.width = touch_padding_dip; |
| 1021 event.data.tap.height = touch_padding_dip; | 1009 event.data.tap.height = touch_padding_dip; |
| 1022 | 1010 |
| 1023 SendGestureEvent(event); | 1011 SendGestureEvent(event); |
| 1024 } | 1012 } |
| 1025 | 1013 |
| 1026 void ContentViewCoreImpl::ShowPressState(JNIEnv* env, jobject obj, | 1014 void ContentViewCoreImpl::ShowPressState(JNIEnv* env, jobject obj, |
| 1027 jlong time_ms, | 1015 jlong time_ms, |
| 1028 jfloat x, jfloat y) { | 1016 jfloat x, jfloat y) { |
| 1029 WebGestureEvent event = MakeGestureEvent( | 1017 WebGestureEvent event = MakeGestureEvent( |
| 1030 WebInputEvent::GestureTapDown, time_ms, x, y, | 1018 WebInputEvent::GestureTapDown, time_ms, x, y); |
| 1031 NOT_LAST_INPUT_EVENT_FOR_VSYNC); | |
| 1032 SendGestureEvent(event); | 1019 SendGestureEvent(event); |
| 1033 } | 1020 } |
| 1034 | 1021 |
| 1035 void ContentViewCoreImpl::ShowPressCancel(JNIEnv* env, | 1022 void ContentViewCoreImpl::ShowPressCancel(JNIEnv* env, |
| 1036 jobject obj, | 1023 jobject obj, |
| 1037 jlong time_ms, | 1024 jlong time_ms, |
| 1038 jfloat x, | 1025 jfloat x, |
| 1039 jfloat y) { | 1026 jfloat y) { |
| 1040 WebGestureEvent event = MakeGestureEvent( | 1027 WebGestureEvent event = MakeGestureEvent( |
| 1041 WebInputEvent::GestureTapCancel, time_ms, x, y, | 1028 WebInputEvent::GestureTapCancel, time_ms, x, y); |
| 1042 NOT_LAST_INPUT_EVENT_FOR_VSYNC); | |
| 1043 SendGestureEvent(event); | 1029 SendGestureEvent(event); |
| 1044 } | 1030 } |
| 1045 | 1031 |
| 1046 void ContentViewCoreImpl::DoubleTap(JNIEnv* env, jobject obj, jlong time_ms, | 1032 void ContentViewCoreImpl::DoubleTap(JNIEnv* env, jobject obj, jlong time_ms, |
| 1047 jfloat x, jfloat y) { | 1033 jfloat x, jfloat y) { |
| 1048 WebGestureEvent event = MakeGestureEvent( | 1034 WebGestureEvent event = MakeGestureEvent( |
| 1049 WebInputEvent::GestureDoubleTap, time_ms, x, y, | 1035 WebInputEvent::GestureDoubleTap, time_ms, x, y); |
| 1050 NOT_LAST_INPUT_EVENT_FOR_VSYNC); | |
| 1051 SendGestureEvent(event); | 1036 SendGestureEvent(event); |
| 1052 } | 1037 } |
| 1053 | 1038 |
| 1054 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, | 1039 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, |
| 1055 jfloat x, jfloat y, | 1040 jfloat x, jfloat y, |
| 1056 jboolean disambiguation_popup_tap) { | 1041 jboolean disambiguation_popup_tap) { |
| 1057 WebGestureEvent event = MakeGestureEvent( | 1042 WebGestureEvent event = MakeGestureEvent( |
| 1058 WebInputEvent::GestureLongPress, time_ms, x, y, | 1043 WebInputEvent::GestureLongPress, time_ms, x, y); |
| 1059 NOT_LAST_INPUT_EVENT_FOR_VSYNC); | |
| 1060 | 1044 |
| 1061 if (!disambiguation_popup_tap) { | 1045 if (!disambiguation_popup_tap) { |
| 1062 const float touch_padding_dip = GetTouchPaddingDip(); | 1046 const float touch_padding_dip = GetTouchPaddingDip(); |
| 1063 event.data.longPress.width = touch_padding_dip; | 1047 event.data.longPress.width = touch_padding_dip; |
| 1064 event.data.longPress.height = touch_padding_dip; | 1048 event.data.longPress.height = touch_padding_dip; |
| 1065 } | 1049 } |
| 1066 | 1050 |
| 1067 SendGestureEvent(event); | 1051 SendGestureEvent(event); |
| 1068 } | 1052 } |
| 1069 | 1053 |
| 1070 void ContentViewCoreImpl::LongTap(JNIEnv* env, jobject obj, jlong time_ms, | 1054 void ContentViewCoreImpl::LongTap(JNIEnv* env, jobject obj, jlong time_ms, |
| 1071 jfloat x, jfloat y, | 1055 jfloat x, jfloat y, |
| 1072 jboolean disambiguation_popup_tap) { | 1056 jboolean disambiguation_popup_tap) { |
| 1073 WebGestureEvent event = MakeGestureEvent( | 1057 WebGestureEvent event = MakeGestureEvent( |
| 1074 WebInputEvent::GestureLongTap, time_ms, x, y, | 1058 WebInputEvent::GestureLongTap, time_ms, x, y); |
| 1075 NOT_LAST_INPUT_EVENT_FOR_VSYNC); | |
| 1076 | 1059 |
| 1077 if (!disambiguation_popup_tap) { | 1060 if (!disambiguation_popup_tap) { |
| 1078 const float touch_padding_dip = GetTouchPaddingDip(); | 1061 const float touch_padding_dip = GetTouchPaddingDip(); |
| 1079 event.data.longPress.width = touch_padding_dip; | 1062 event.data.longPress.width = touch_padding_dip; |
| 1080 event.data.longPress.height = touch_padding_dip; | 1063 event.data.longPress.height = touch_padding_dip; |
| 1081 } | 1064 } |
| 1082 | 1065 |
| 1083 SendGestureEvent(event); | 1066 SendGestureEvent(event); |
| 1084 } | 1067 } |
| 1085 | 1068 |
| 1086 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, | 1069 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, |
| 1087 jfloat x, jfloat y) { | 1070 jfloat x, jfloat y) { |
| 1088 WebGestureEvent event = MakeGestureEvent( | 1071 WebGestureEvent event = MakeGestureEvent( |
| 1089 WebInputEvent::GesturePinchBegin, time_ms, x, y, | 1072 WebInputEvent::GesturePinchBegin, time_ms, x, y); |
| 1090 NOT_LAST_INPUT_EVENT_FOR_VSYNC); | |
| 1091 SendGestureEvent(event); | 1073 SendGestureEvent(event); |
| 1092 } | 1074 } |
| 1093 | 1075 |
| 1094 void ContentViewCoreImpl::PinchEnd(JNIEnv* env, jobject obj, jlong time_ms) { | 1076 void ContentViewCoreImpl::PinchEnd(JNIEnv* env, jobject obj, jlong time_ms) { |
| 1095 WebGestureEvent event = MakeGestureEvent( | 1077 WebGestureEvent event = MakeGestureEvent( |
| 1096 WebInputEvent::GesturePinchEnd, time_ms, 0, 0, | 1078 WebInputEvent::GesturePinchEnd, time_ms, 0, 0); |
| 1097 NOT_LAST_INPUT_EVENT_FOR_VSYNC); | |
| 1098 SendGestureEvent(event); | 1079 SendGestureEvent(event); |
| 1099 } | 1080 } |
| 1100 | 1081 |
| 1101 void ContentViewCoreImpl::PinchBy(JNIEnv* env, jobject obj, jlong time_ms, | 1082 void ContentViewCoreImpl::PinchBy(JNIEnv* env, jobject obj, jlong time_ms, |
| 1102 jfloat anchor_x, jfloat anchor_y, | 1083 jfloat anchor_x, jfloat anchor_y, |
| 1103 jfloat delta, | 1084 jfloat delta, |
| 1104 jboolean last_input_event_for_vsync) { | 1085 jboolean last_input_event_for_vsync) { |
| 1105 InputEventVSyncStatus vsync_status = | |
| 1106 last_input_event_for_vsync ? LAST_INPUT_EVENT_FOR_VSYNC | |
| 1107 : NOT_LAST_INPUT_EVENT_FOR_VSYNC; | |
| 1108 WebGestureEvent event = MakeGestureEvent( | 1086 WebGestureEvent event = MakeGestureEvent( |
| 1109 WebInputEvent::GesturePinchUpdate, time_ms, anchor_x, anchor_y, | 1087 WebInputEvent::GesturePinchUpdate, time_ms, anchor_x, anchor_y); |
| 1110 vsync_status); | |
| 1111 event.data.pinchUpdate.scale = delta; | 1088 event.data.pinchUpdate.scale = delta; |
| 1112 | 1089 |
| 1113 SendGestureEvent(event); | 1090 SendGestureEvent(event); |
| 1114 } | 1091 } |
| 1115 | 1092 |
| 1116 void ContentViewCoreImpl::SelectBetweenCoordinates(JNIEnv* env, jobject obj, | 1093 void ContentViewCoreImpl::SelectBetweenCoordinates(JNIEnv* env, jobject obj, |
| 1117 jfloat x1, jfloat y1, | 1094 jfloat x1, jfloat y1, |
| 1118 jfloat x2, jfloat y2) { | 1095 jfloat x2, jfloat y2) { |
| 1119 if (GetRenderWidgetHostViewAndroid()) { | 1096 if (GetRenderWidgetHostViewAndroid()) { |
| 1120 GetRenderWidgetHostViewAndroid()->SelectRange( | 1097 GetRenderWidgetHostViewAndroid()->SelectRange( |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1568 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1545 reinterpret_cast<ui::ViewAndroid*>(view_android), |
| 1569 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1546 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
| 1570 return reinterpret_cast<jint>(view); | 1547 return reinterpret_cast<jint>(view); |
| 1571 } | 1548 } |
| 1572 | 1549 |
| 1573 bool RegisterContentViewCore(JNIEnv* env) { | 1550 bool RegisterContentViewCore(JNIEnv* env) { |
| 1574 return RegisterNativesImpl(env); | 1551 return RegisterNativesImpl(env); |
| 1575 } | 1552 } |
| 1576 | 1553 |
| 1577 } // namespace content | 1554 } // namespace content |
| OLD | NEW |