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 "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" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "cc/layers/layer.h" | 17 #include "cc/layers/layer.h" |
18 #include "cc/output/begin_frame_args.h" | 18 #include "cc/output/begin_frame_args.h" |
19 #include "content/browser/android/gesture_event_type.h" | 19 #include "content/browser/android/gesture_event_type.h" |
20 #include "content/browser/android/interstitial_page_delegate_android.h" | 20 #include "content/browser/android/interstitial_page_delegate_android.h" |
21 #include "content/browser/android/load_url_params.h" | 21 #include "content/browser/android/load_url_params.h" |
22 #include "content/browser/frame_host/interstitial_page_impl.h" | 22 #include "content/browser/frame_host/interstitial_page_impl.h" |
23 #include "content/browser/frame_host/navigation_controller_impl.h" | 23 #include "content/browser/frame_host/navigation_controller_impl.h" |
24 #include "content/browser/frame_host/navigation_entry_impl.h" | 24 #include "content/browser/frame_host/navigation_entry_impl.h" |
25 #include "content/browser/media/android/browser_media_player_manager.h" | 25 #include "content/browser/media/android/browser_media_player_manager.h" |
26 #include "content/browser/renderer_host/compositor_impl_android.h" | 26 #include "content/browser/renderer_host/compositor_impl_android.h" |
27 #include "content/browser/renderer_host/input/motion_event_android.h" | 27 #include "content/browser/renderer_host/input/motion_event_android.h" |
28 #include "content/browser/renderer_host/input/web_input_event_builders_android.h
" | 28 #include "content/browser/renderer_host/input/web_input_event_builders_android.h
" |
| 29 #include "content/browser/renderer_host/input/web_input_event_util.h" |
29 #include "content/browser/renderer_host/java/java_bound_object.h" | 30 #include "content/browser/renderer_host/java/java_bound_object.h" |
30 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager
.h" | 31 #include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager
.h" |
31 #include "content/browser/renderer_host/render_view_host_impl.h" | 32 #include "content/browser/renderer_host/render_view_host_impl.h" |
32 #include "content/browser/renderer_host/render_widget_host_impl.h" | 33 #include "content/browser/renderer_host/render_widget_host_impl.h" |
33 #include "content/browser/renderer_host/render_widget_host_view_android.h" | 34 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
34 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.
h" | 35 #include "content/browser/screen_orientation/screen_orientation_dispatcher_host.
h" |
35 #include "content/browser/ssl/ssl_host_state.h" | 36 #include "content/browser/ssl/ssl_host_state.h" |
36 #include "content/browser/web_contents/web_contents_view_android.h" | 37 #include "content/browser/web_contents/web_contents_view_android.h" |
37 #include "content/common/input/web_input_event_traits.h" | 38 #include "content/common/input/web_input_event_traits.h" |
38 #include "content/common/input_messages.h" | 39 #include "content/common/input_messages.h" |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 | 988 |
988 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, | 989 void ContentViewCoreImpl::SendOrientationChangeEvent(JNIEnv* env, |
989 jobject obj, | 990 jobject obj, |
990 jint orientation) { | 991 jint orientation) { |
991 if (device_orientation_ != orientation) { | 992 if (device_orientation_ != orientation) { |
992 device_orientation_ = orientation; | 993 device_orientation_ = orientation; |
993 SendOrientationChangeEventInternal(); | 994 SendOrientationChangeEventInternal(); |
994 } | 995 } |
995 } | 996 } |
996 | 997 |
| 998 void ContentViewCoreImpl::CancelActiveTouchSequenceIfNecessary() { |
| 999 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 1000 // Avoid synthesizing a touch cancel event if it cannot be forwarded. |
| 1001 if (!rwhv) |
| 1002 return; |
| 1003 |
| 1004 const ui::MotionEvent* current_down_event = |
| 1005 gesture_provider_.GetCurrentDownEvent(); |
| 1006 if (!current_down_event) |
| 1007 return; |
| 1008 |
| 1009 scoped_ptr<ui::MotionEvent> cancel_event = current_down_event->Cancel(); |
| 1010 DCHECK(cancel_event); |
| 1011 if (!gesture_provider_.OnTouchEvent(*cancel_event)) |
| 1012 return; |
| 1013 |
| 1014 rwhv->SendTouchEvent( |
| 1015 CreateWebTouchEventFromMotionEvent(*cancel_event, 1.f / GetDpiScale())); |
| 1016 } |
| 1017 |
997 jboolean ContentViewCoreImpl::OnTouchEvent(JNIEnv* env, | 1018 jboolean ContentViewCoreImpl::OnTouchEvent(JNIEnv* env, |
998 jobject obj, | 1019 jobject obj, |
999 jobject motion_event) { | 1020 jobject motion_event) { |
1000 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1021 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
1001 if (!rwhv) | 1022 if (!rwhv) |
1002 return false; | 1023 return false; |
1003 | 1024 |
1004 MotionEventAndroid event(env, motion_event, false); | 1025 MotionEventAndroid event(env, motion_event, false); |
1005 | 1026 |
1006 if (!gesture_provider_.OnTouchEvent(event)) | 1027 if (!gesture_provider_.OnTouchEvent(event)) |
1007 return false; | 1028 return false; |
1008 | 1029 |
1009 rwhv->SendTouchEvent(WebTouchEventBuilder::Build(event, GetDpiScale())); | 1030 rwhv->SendTouchEvent(WebTouchEventBuilder::Build(event, 1.f / GetDpiScale())); |
1010 return true; | 1031 return true; |
1011 } | 1032 } |
1012 | 1033 |
1013 float ContentViewCoreImpl::GetDpiScale() const { | 1034 float ContentViewCoreImpl::GetDpiScale() const { |
1014 return dpi_scale_; | 1035 return dpi_scale_; |
1015 } | 1036 } |
1016 | 1037 |
1017 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, | 1038 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, |
1018 jobject obj, | 1039 jobject obj, |
1019 jlong time_ms, | 1040 jlong time_ms, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 GetRenderWidgetHostViewAndroid()->MoveCaret( | 1201 GetRenderWidgetHostViewAndroid()->MoveCaret( |
1181 gfx::Point(x / GetDpiScale(), y / GetDpiScale())); | 1202 gfx::Point(x / GetDpiScale(), y / GetDpiScale())); |
1182 } | 1203 } |
1183 } | 1204 } |
1184 | 1205 |
1185 void ContentViewCoreImpl::ResetGestureDetectors(JNIEnv* env, jobject obj) { | 1206 void ContentViewCoreImpl::ResetGestureDetectors(JNIEnv* env, jobject obj) { |
1186 gesture_provider_.ResetGestureDetectors(); | 1207 gesture_provider_.ResetGestureDetectors(); |
1187 } | 1208 } |
1188 | 1209 |
1189 void ContentViewCoreImpl::IgnoreRemainingTouchEvents(JNIEnv* env, jobject obj) { | 1210 void ContentViewCoreImpl::IgnoreRemainingTouchEvents(JNIEnv* env, jobject obj) { |
1190 gesture_provider_.CancelActiveTouchSequence(); | 1211 CancelActiveTouchSequenceIfNecessary(); |
1191 } | 1212 } |
1192 | 1213 |
1193 void ContentViewCoreImpl::OnWindowFocusLost(JNIEnv* env, jobject obj) { | 1214 void ContentViewCoreImpl::OnWindowFocusLost(JNIEnv* env, jobject obj) { |
1194 gesture_provider_.CancelActiveTouchSequence(); | 1215 CancelActiveTouchSequenceIfNecessary(); |
1195 } | 1216 } |
1196 | 1217 |
1197 void ContentViewCoreImpl::SetDoubleTapSupportForPageEnabled(JNIEnv* env, | 1218 void ContentViewCoreImpl::SetDoubleTapSupportForPageEnabled(JNIEnv* env, |
1198 jobject obj, | 1219 jobject obj, |
1199 jboolean enabled) { | 1220 jboolean enabled) { |
1200 gesture_provider_.SetDoubleTapSupportForPageEnabled(enabled); | 1221 gesture_provider_.SetDoubleTapSupportForPageEnabled(enabled); |
1201 } | 1222 } |
1202 | 1223 |
1203 void ContentViewCoreImpl::SetDoubleTapSupportEnabled(JNIEnv* env, | 1224 void ContentViewCoreImpl::SetDoubleTapSupportEnabled(JNIEnv* env, |
1204 jobject obj, | 1225 jobject obj, |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 reinterpret_cast<ui::ViewAndroid*>(view_android), | 1733 reinterpret_cast<ui::ViewAndroid*>(view_android), |
1713 reinterpret_cast<ui::WindowAndroid*>(window_android)); | 1734 reinterpret_cast<ui::WindowAndroid*>(window_android)); |
1714 return reinterpret_cast<intptr_t>(view); | 1735 return reinterpret_cast<intptr_t>(view); |
1715 } | 1736 } |
1716 | 1737 |
1717 bool RegisterContentViewCore(JNIEnv* env) { | 1738 bool RegisterContentViewCore(JNIEnv* env) { |
1718 return RegisterNativesImpl(env); | 1739 return RegisterNativesImpl(env); |
1719 } | 1740 } |
1720 | 1741 |
1721 } // namespace content | 1742 } // namespace content |
OLD | NEW |