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 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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, |
dtapuska
2016/09/20 20:56:16
Can we pass const JavaParamRef<jobject>& motion_ev
mustaq
2016/09/21 19:31:29
- Done adding meta state.
- Skipped passing motio
| |
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_tool_type) { | |
991 | |
983 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 992 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
984 if (!rwhv) | 993 if (!rwhv) |
985 return false; | 994 return false; |
986 | 995 |
987 blink::WebMouseEvent event = WebMouseEventBuilder::Build( | 996 // Construct a motion_event object minimally, only to convert the raw |
988 WebInputEvent::MouseMove, | 997 // parameters to ui::MotionEvent values. Since we used only the cached values |
989 blink::WebMouseEvent::Button::NoButton, | 998 // 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, | 999 ui::MotionEventAndroid::Pointer pointer0( |
991 ui::ToWebPointerType(static_cast<ui::MotionEvent::ToolType>(tool_type))); | 1000 pointer_id, x, y, 0.0f /* touch_major */, 0.0f /* touch_minor */, |
1001 orientation, tilt, android_tool_type); | |
992 | 1002 |
993 rwhv->SendMouseEvent(event); | 1003 ui::MotionEventAndroid motion_event(1.f / dpi_scale(), |
1004 env, | |
1005 0 /* event */, | |
1006 time_ms, | |
1007 android_action, | |
1008 1 /* pointer_count */, | |
1009 0 /* history_size */, | |
1010 0 /* action_index */, | |
1011 android_button_state, | |
1012 0 /* meta_state */, | |
1013 0 /* raw_offset_x_pixels */, | |
1014 0 /* raw_offset_y_pixels */, | |
1015 pointer0, | |
1016 pointer0 /* pointer1 */); | |
1017 | |
1018 blink::WebInputEvent::Type webMouseEventType = | |
1019 ui::ToWebMouseEventType(motion_event.GetAction()); | |
1020 | |
1021 int old_button_state = button_state_; | |
1022 | |
1023 // Ignore button state in MouseMove events: we have seen cases that a | |
1024 // MouseMove with updated button state often precedes a MouseDown/MouseUp. | |
1025 if (webMouseEventType != blink::WebInputEvent::MouseMove) | |
1026 button_state_ = motion_event.GetButtonState(); | |
1027 | |
1028 blink::WebMouseEvent mouse_event = WebMouseEventBuilder::Build( | |
1029 webMouseEventType, | |
1030 time_ms / 1000.0, | |
1031 motion_event.GetX(0), | |
1032 motion_event.GetY(0), | |
1033 button_state_ /* modifiers */, | |
1034 button_state_ ? 1 : 0 /* click count */, | |
1035 motion_event.GetPointerId(0), | |
1036 motion_event.GetPressure(0), | |
1037 motion_event.GetOrientation(0), | |
1038 motion_event.GetTilt(0), | |
1039 old_button_state, | |
1040 button_state_, | |
1041 motion_event.GetToolType(0)); | |
1042 // TODO(mustaq): mouse_event.modifiers should include fields from | |
1043 // MotionEvent.getMetaState(). | |
1044 | |
1045 rwhv->SendMouseEvent(mouse_event); | |
994 return true; | 1046 return true; |
995 } | 1047 } |
996 | 1048 |
997 jboolean ContentViewCoreImpl::SendMouseWheelEvent( | 1049 jboolean ContentViewCoreImpl::SendMouseWheelEvent( |
998 JNIEnv* env, | 1050 JNIEnv* env, |
999 const JavaParamRef<jobject>& obj, | 1051 const JavaParamRef<jobject>& obj, |
1000 jlong time_ms, | 1052 jlong time_ms, |
1001 jfloat x, | 1053 jfloat x, |
1002 jfloat y, | 1054 jfloat y, |
1003 jfloat ticks_x, | 1055 jfloat ticks_x, |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1601 return ScopedJavaLocalRef<jobject>(); | 1653 return ScopedJavaLocalRef<jobject>(); |
1602 | 1654 |
1603 return view->GetJavaObject(); | 1655 return view->GetJavaObject(); |
1604 } | 1656 } |
1605 | 1657 |
1606 bool RegisterContentViewCore(JNIEnv* env) { | 1658 bool RegisterContentViewCore(JNIEnv* env) { |
1607 return RegisterNativesImpl(env); | 1659 return RegisterNativesImpl(env); |
1608 } | 1660 } |
1609 | 1661 |
1610 } // namespace content | 1662 } // namespace content |
OLD | NEW |