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 <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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 #include "jni/DragEvent_jni.h" | 54 #include "jni/DragEvent_jni.h" |
55 #include "third_party/WebKit/public/web/WebInputEvent.h" | 55 #include "third_party/WebKit/public/web/WebInputEvent.h" |
56 #include "ui/android/view_android.h" | 56 #include "ui/android/view_android.h" |
57 #include "ui/android/window_android.h" | 57 #include "ui/android/window_android.h" |
58 #include "ui/base/clipboard/clipboard.h" | 58 #include "ui/base/clipboard/clipboard.h" |
59 #include "ui/base/ui_base_switches_util.h" | 59 #include "ui/base/ui_base_switches_util.h" |
60 #include "ui/events/android/motion_event_android.h" | 60 #include "ui/events/android/motion_event_android.h" |
61 #include "ui/events/blink/blink_event_util.h" | 61 #include "ui/events/blink/blink_event_util.h" |
62 #include "ui/events/blink/web_input_event_traits.h" | 62 #include "ui/events/blink/web_input_event_traits.h" |
63 #include "ui/events/event_utils.h" | 63 #include "ui/events/event_utils.h" |
64 #include "ui/events/gesture_detection/motion_event.h" | |
64 #include "ui/gfx/android/java_bitmap.h" | 65 #include "ui/gfx/android/java_bitmap.h" |
65 #include "ui/gfx/geometry/point_conversions.h" | 66 #include "ui/gfx/geometry/point_conversions.h" |
66 #include "ui/gfx/geometry/size_conversions.h" | 67 #include "ui/gfx/geometry/size_conversions.h" |
67 #include "ui/gfx/geometry/size_f.h" | 68 #include "ui/gfx/geometry/size_f.h" |
68 | 69 |
69 using base::android::AttachCurrentThread; | 70 using base::android::AttachCurrentThread; |
70 using base::android::ConvertJavaStringToUTF16; | 71 using base::android::ConvertJavaStringToUTF16; |
71 using base::android::ConvertJavaStringToUTF8; | 72 using base::android::ConvertJavaStringToUTF8; |
72 using base::android::ConvertUTF16ToJavaString; | 73 using base::android::ConvertUTF16ToJavaString; |
73 using base::android::ConvertUTF8ToJavaString; | 74 using base::android::ConvertUTF8ToJavaString; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 const JavaRef<jobject>& view_android_delegate, | 211 const JavaRef<jobject>& view_android_delegate, |
211 ui::WindowAndroid* window_android, | 212 ui::WindowAndroid* window_android, |
212 const JavaRef<jobject>& java_bridge_retained_object_set) | 213 const JavaRef<jobject>& java_bridge_retained_object_set) |
213 : WebContentsObserver(web_contents), | 214 : WebContentsObserver(web_contents), |
214 java_ref_(env, obj), | 215 java_ref_(env, obj), |
215 view_(view_android_delegate), | 216 view_(view_android_delegate), |
216 web_contents_(static_cast<WebContentsImpl*>(web_contents)), | 217 web_contents_(static_cast<WebContentsImpl*>(web_contents)), |
217 page_scale_(1), | 218 page_scale_(1), |
218 dpi_scale_(ui::GetScaleFactorForNativeView(&view_)), | 219 dpi_scale_(ui::GetScaleFactorForNativeView(&view_)), |
219 device_orientation_(0), | 220 device_orientation_(0), |
220 accessibility_enabled_(false) { | 221 accessibility_enabled_(false), |
222 button_state_(0) { | |
221 CHECK(web_contents) << | 223 CHECK(web_contents) << |
222 "A ContentViewCoreImpl should be created with a valid WebContents."; | 224 "A ContentViewCoreImpl should be created with a valid WebContents."; |
223 DCHECK(window_android); | 225 DCHECK(window_android); |
224 DCHECK(!view_android_delegate.is_null()); | 226 DCHECK(!view_android_delegate.is_null()); |
225 window_android->AddChild(&view_); | 227 window_android->AddChild(&view_); |
226 view_.SetLayer(cc::Layer::Create()); | 228 view_.SetLayer(cc::Layer::Create()); |
227 gfx::Size physical_size( | 229 gfx::Size physical_size( |
228 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), | 230 Java_ContentViewCore_getPhysicalBackingWidthPix(env, obj), |
229 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); | 231 Java_ContentViewCore_getPhysicalBackingHeightPix(env, obj)); |
230 view_.GetLayer()->SetBounds(physical_size); | 232 view_.GetLayer()->SetBounds(physical_size); |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
959 motion_event, | 961 motion_event, |
960 time_ms, | 962 time_ms, |
961 android_action, | 963 android_action, |
962 pointer_count, | 964 pointer_count, |
963 history_size, | 965 history_size, |
964 action_index, | 966 action_index, |
965 android_button_state, | 967 android_button_state, |
966 android_meta_state, | 968 android_meta_state, |
967 raw_pos_x - pos_x_0, | 969 raw_pos_x - pos_x_0, |
968 raw_pos_y - pos_y_0, | 970 raw_pos_y - pos_y_0, |
969 pointer0, | 971 &pointer0, |
970 pointer1); | 972 &pointer1); |
971 | 973 |
972 return is_touch_handle_event ? rwhv->OnTouchHandleEvent(event) | 974 return is_touch_handle_event ? rwhv->OnTouchHandleEvent(event) |
973 : rwhv->OnTouchEvent(event); | 975 : rwhv->OnTouchEvent(event); |
974 } | 976 } |
975 | 977 |
976 jboolean ContentViewCoreImpl::SendMouseMoveEvent( | 978 jboolean ContentViewCoreImpl::SendMouseEvent( |
977 JNIEnv* env, | 979 JNIEnv* env, |
978 const JavaParamRef<jobject>& obj, | 980 const JavaParamRef<jobject>& obj, |
979 jlong time_ms, | 981 jlong time_ms, |
982 jint android_action, | |
980 jfloat x, | 983 jfloat x, |
981 jfloat y, | 984 jfloat y, |
982 jint tool_type) { | 985 jint pointer_id, |
986 jfloat pressure, | |
987 jfloat orientation, | |
988 jfloat tilt, | |
989 jint android_button_state, | |
990 jint android_meta_state, | |
991 jint android_tool_type) { | |
992 | |
983 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 993 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
984 if (!rwhv) | 994 if (!rwhv) |
985 return false; | 995 return false; |
986 | 996 |
987 blink::WebMouseEvent event = WebMouseEventBuilder::Build( | 997 // Construct a motion_event object minimally, only to convert the raw |
988 WebInputEvent::MouseMove, | 998 // parameters to ui::MotionEvent values. Since we used only the cached values |
989 blink::WebMouseEvent::Button::NoButton, | 999 // at index=0, it is okay to even pass a null event to the constructor. |
990 time_ms / 1000.0, x / dpi_scale(), y / dpi_scale(), 0, 1, | 1000 ui::MotionEventAndroid::Pointer pointer0( |
991 ui::ToWebPointerType(static_cast<ui::MotionEvent::ToolType>(tool_type))); | 1001 pointer_id, x, y, 0.0f /* touch_major */, 0.0f /* touch_minor */, |
1002 orientation, tilt, android_tool_type); | |
992 | 1003 |
993 rwhv->SendMouseEvent(event); | 1004 ui::MotionEventAndroid motion_event(1.f / dpi_scale(), |
1005 env, | |
1006 nullptr /* event */, | |
1007 time_ms, | |
1008 android_action, | |
1009 1 /* pointer_count */, | |
1010 0 /* history_size */, | |
1011 0 /* action_index */, | |
1012 android_button_state, | |
1013 android_meta_state, | |
1014 0 /* raw_offset_x_pixels */, | |
1015 0 /* raw_offset_y_pixels */, | |
1016 &pointer0, | |
1017 nullptr); | |
1018 | |
1019 blink::WebInputEvent::Type webMouseEventType = | |
1020 ui::ToWebMouseEventType(motion_event.GetAction()); | |
1021 | |
1022 int old_button_state = button_state_; | |
1023 | |
1024 // Ignore button state in MouseMove events: we have seen cases that a | |
aelias_OOO_until_Jul13
2016/10/20 23:26:29
If the mouse is pressed outside the ContentViewCor
mustaq
2016/10/21 19:19:08
Right. I am not sure how to find the info correctl
aelias_OOO_until_Jul13
2016/10/21 21:26:54
Well, regardless of Samsung-specific or not, given
mustaq
2016/10/26 17:45:09
Looks like we were talking about two different thi
aelias_OOO_until_Jul13
2016/10/27 03:09:37
OK, thanks for the explanation. I really would pr
aelias_OOO_until_Jul13
2016/10/27 18:27:56
finger#2, stylus#1 etc), hence less "granular" tha
aelias_OOO_until_Jul13
2016/10/27 23:36:48
events (ACTION_BUTTON_PRESS & _RELEASE), and undef
| |
1025 // MouseMove with updated button state often precedes a MouseDown/MouseUp. | |
1026 if (webMouseEventType != blink::WebInputEvent::MouseMove) | |
1027 button_state_ = motion_event.GetButtonState(); | |
1028 | |
1029 blink::WebMouseEvent mouse_event = WebMouseEventBuilder::Build( | |
1030 webMouseEventType, | |
1031 time_ms / 1000.0, | |
1032 motion_event.GetX(0), | |
1033 motion_event.GetY(0), | |
1034 motion_event.GetFlags(), | |
1035 button_state_ ? 1 : 0 /* click count */, | |
1036 motion_event.GetPointerId(0), | |
1037 motion_event.GetPressure(0), | |
1038 motion_event.GetOrientation(0), | |
1039 motion_event.GetTilt(0), | |
1040 old_button_state, | |
1041 button_state_, | |
1042 motion_event.GetToolType(0)); | |
1043 | |
1044 rwhv->SendMouseEvent(mouse_event); | |
994 return true; | 1045 return true; |
995 } | 1046 } |
996 | 1047 |
997 jboolean ContentViewCoreImpl::SendMouseWheelEvent( | 1048 jboolean ContentViewCoreImpl::SendMouseWheelEvent( |
998 JNIEnv* env, | 1049 JNIEnv* env, |
999 const JavaParamRef<jobject>& obj, | 1050 const JavaParamRef<jobject>& obj, |
1000 jlong time_ms, | 1051 jlong time_ms, |
1001 jfloat x, | 1052 jfloat x, |
1002 jfloat y, | 1053 jfloat y, |
1003 jfloat ticks_x, | 1054 jfloat ticks_x, |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1601 return ScopedJavaLocalRef<jobject>(); | 1652 return ScopedJavaLocalRef<jobject>(); |
1602 | 1653 |
1603 return view->GetJavaObject(); | 1654 return view->GetJavaObject(); |
1604 } | 1655 } |
1605 | 1656 |
1606 bool RegisterContentViewCore(JNIEnv* env) { | 1657 bool RegisterContentViewCore(JNIEnv* env) { |
1607 return RegisterNativesImpl(env); | 1658 return RegisterNativesImpl(env); |
1608 } | 1659 } |
1609 | 1660 |
1610 } // namespace content | 1661 } // namespace content |
OLD | NEW |