| 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/layers/solid_color_layer.h" | 18 #include "cc/layers/solid_color_layer.h" |
| 19 #include "cc/output/begin_frame_args.h" | 19 #include "cc/output/begin_frame_args.h" |
| 20 #include "content/browser/android/gesture_event_type.h" | 20 #include "content/browser/android/gesture_event_type.h" |
| 21 #include "content/browser/android/interstitial_page_delegate_android.h" | 21 #include "content/browser/android/interstitial_page_delegate_android.h" |
| 22 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" | 22 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" |
| 23 #include "content/browser/android/load_url_params.h" | 23 #include "content/browser/android/load_url_params.h" |
| 24 #include "content/browser/android/popup_touch_handle_drawable.h" |
| 24 #include "content/browser/frame_host/interstitial_page_impl.h" | 25 #include "content/browser/frame_host/interstitial_page_impl.h" |
| 25 #include "content/browser/frame_host/navigation_controller_impl.h" | 26 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 26 #include "content/browser/frame_host/navigation_entry_impl.h" | 27 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 27 #include "content/browser/geolocation/geolocation_dispatcher_host.h" | 28 #include "content/browser/geolocation/geolocation_dispatcher_host.h" |
| 28 #include "content/browser/media/media_web_contents_observer.h" | 29 #include "content/browser/media/media_web_contents_observer.h" |
| 29 #include "content/browser/renderer_host/compositor_impl_android.h" | 30 #include "content/browser/renderer_host/compositor_impl_android.h" |
| 30 #include "content/browser/renderer_host/input/motion_event_android.h" | 31 #include "content/browser/renderer_host/input/motion_event_android.h" |
| 31 #include "content/browser/renderer_host/input/web_input_event_builders_android.h
" | 32 #include "content/browser/renderer_host/input/web_input_event_builders_android.h
" |
| 32 #include "content/browser/renderer_host/input/web_input_event_util.h" | 33 #include "content/browser/renderer_host/input/web_input_event_util.h" |
| 33 #include "content/browser/renderer_host/render_view_host_impl.h" | 34 #include "content/browser/renderer_host/render_view_host_impl.h" |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 Java_ContentViewCore_onPinchEndEventAck(env, j_obj.obj()); | 543 Java_ContentViewCore_onPinchEndEventAck(env, j_obj.obj()); |
| 543 break; | 544 break; |
| 544 case WebInputEvent::GestureTap: | 545 case WebInputEvent::GestureTap: |
| 545 Java_ContentViewCore_onSingleTapEventAck( | 546 Java_ContentViewCore_onSingleTapEventAck( |
| 546 env, | 547 env, |
| 547 j_obj.obj(), | 548 j_obj.obj(), |
| 548 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED, | 549 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED, |
| 549 event.x * dpi_scale(), | 550 event.x * dpi_scale(), |
| 550 event.y * dpi_scale()); | 551 event.y * dpi_scale()); |
| 551 break; | 552 break; |
| 552 case WebInputEvent::GestureDoubleTap: | |
| 553 Java_ContentViewCore_onDoubleTapEventAck(env, j_obj.obj()); | |
| 554 break; | |
| 555 default: | 553 default: |
| 556 break; | 554 break; |
| 557 } | 555 } |
| 558 } | 556 } |
| 559 | 557 |
| 560 bool ContentViewCoreImpl::FilterInputEvent(const blink::WebInputEvent& event) { | 558 bool ContentViewCoreImpl::FilterInputEvent(const blink::WebInputEvent& event) { |
| 561 if (event.type != WebInputEvent::GestureTap && | 559 if (event.type != WebInputEvent::GestureTap && |
| 562 event.type != WebInputEvent::GestureDoubleTap && | 560 event.type != WebInputEvent::GestureDoubleTap && |
| 563 event.type != WebInputEvent::GestureLongTap && | 561 event.type != WebInputEvent::GestureLongTap && |
| 564 event.type != WebInputEvent::GestureLongPress) | 562 event.type != WebInputEvent::GestureLongPress) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 591 | 589 |
| 592 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { | 590 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { |
| 593 JNIEnv* env = AttachCurrentThread(); | 591 JNIEnv* env = AttachCurrentThread(); |
| 594 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 592 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 595 if (obj.is_null()) | 593 if (obj.is_null()) |
| 596 return; | 594 return; |
| 597 ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text); | 595 ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text); |
| 598 Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj()); | 596 Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj()); |
| 599 } | 597 } |
| 600 | 598 |
| 601 void ContentViewCoreImpl::OnSelectionBoundsChanged(const gfx::PointF& start, | 599 void ContentViewCoreImpl::OnSelectionEvent(SelectionEventType event, |
| 602 const gfx::PointF& end, | 600 const gfx::PointF& position) { |
| 603 int start_dir, | 601 JNIEnv* env = AttachCurrentThread(); |
| 604 int end_dir) { | 602 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 603 if (j_obj.is_null()) |
| 604 return; |
| 605 Java_ContentViewCore_onSelectionEvent( |
| 606 env, j_obj.obj(), event, position.x(), position.y()); |
| 607 } |
| 608 |
| 609 scoped_ptr<TouchHandleDrawable> |
| 610 ContentViewCoreImpl::CreatePopupTouchHandleDrawable() { |
| 605 JNIEnv* env = AttachCurrentThread(); | 611 JNIEnv* env = AttachCurrentThread(); |
| 606 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 612 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 607 if (obj.is_null()) | 613 if (obj.is_null()) { |
| 608 return; | 614 NOTREACHED(); |
| 609 Java_ContentViewCore_onSelectionBoundsChanged(env, | 615 return scoped_ptr<TouchHandleDrawable>(); |
| 610 obj.obj(), | 616 } |
| 611 start.x(), | 617 return scoped_ptr<TouchHandleDrawable>(new PopupTouchHandleDrawable( |
| 612 start.y(), | 618 Java_ContentViewCore_createPopupTouchHandleDrawable(env, obj.obj()), |
| 613 end.x(), | 619 dpi_scale_)); |
| 614 end.y(), | |
| 615 start_dir, | |
| 616 end_dir); | |
| 617 } | 620 } |
| 618 | 621 |
| 619 void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) { | 622 void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) { |
| 620 JNIEnv* env = AttachCurrentThread(); | 623 JNIEnv* env = AttachCurrentThread(); |
| 621 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 624 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 622 if (obj.is_null()) | 625 if (obj.is_null()) |
| 623 return; | 626 return; |
| 624 Java_ContentViewCore_showPastePopup(env, obj.obj(), | 627 Java_ContentViewCore_showPastePopup(env, obj.obj(), |
| 625 static_cast<jint>(x_dip), | 628 static_cast<jint>(x_dip), |
| 626 static_cast<jint>(y_dip)); | 629 static_cast<jint>(y_dip)); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 float ContentViewCoreImpl::GetOverdrawBottomHeightDip() const { | 775 float ContentViewCoreImpl::GetOverdrawBottomHeightDip() const { |
| 773 JNIEnv* env = AttachCurrentThread(); | 776 JNIEnv* env = AttachCurrentThread(); |
| 774 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 777 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 775 if (j_obj.is_null()) | 778 if (j_obj.is_null()) |
| 776 return 0.f; | 779 return 0.f; |
| 777 return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj()) | 780 return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj()) |
| 778 / dpi_scale(); | 781 / dpi_scale(); |
| 779 } | 782 } |
| 780 | 783 |
| 781 void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) { | 784 void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) { |
| 782 root_layer_->AddChild(layer); | 785 root_layer_->InsertChild(layer, 0); |
| 783 root_layer_->SetIsDrawable(false); | 786 root_layer_->SetIsDrawable(false); |
| 784 } | 787 } |
| 785 | 788 |
| 786 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { | 789 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { |
| 787 layer->RemoveFromParent(); | 790 layer->RemoveFromParent(); |
| 788 | 791 |
| 789 if (!root_layer_->children().size()) | 792 if (!root_layer_->children().size()) |
| 790 root_layer_->SetIsDrawable(true); | 793 root_layer_->SetIsDrawable(true); |
| 791 } | 794 } |
| 792 | 795 |
| 796 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& start, |
| 797 const gfx::PointF& end) { |
| 798 if (!web_contents_) |
| 799 return; |
| 800 |
| 801 gfx::Point start_point = gfx::Point(start.x(), start.y()); |
| 802 gfx::Point end_point = gfx::Point(end.x(), end.y()); |
| 803 if (start_point == end_point) |
| 804 return; |
| 805 |
| 806 web_contents_->SelectRange(start_point, end_point); |
| 807 } |
| 808 |
| 793 void ContentViewCoreImpl::LoadUrl( | 809 void ContentViewCoreImpl::LoadUrl( |
| 794 NavigationController::LoadURLParams& params) { | 810 NavigationController::LoadURLParams& params) { |
| 795 GetWebContents()->GetController().LoadURLWithParams(params); | 811 GetWebContents()->GetController().LoadURLWithParams(params); |
| 796 } | 812 } |
| 797 | 813 |
| 798 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { | 814 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { |
| 799 // view_android_ should never be null for Chrome. | 815 // view_android_ should never be null for Chrome. |
| 800 DCHECK(view_android_); | 816 DCHECK(view_android_); |
| 801 return view_android_; | 817 return view_android_; |
| 802 } | 818 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 940 jfloat pos_x_1, | 956 jfloat pos_x_1, |
| 941 jfloat pos_y_1, | 957 jfloat pos_y_1, |
| 942 jint pointer_id_0, | 958 jint pointer_id_0, |
| 943 jint pointer_id_1, | 959 jint pointer_id_1, |
| 944 jfloat touch_major_0, | 960 jfloat touch_major_0, |
| 945 jfloat touch_major_1, | 961 jfloat touch_major_1, |
| 946 jfloat raw_pos_x, | 962 jfloat raw_pos_x, |
| 947 jfloat raw_pos_y, | 963 jfloat raw_pos_y, |
| 948 jint android_tool_type_0, | 964 jint android_tool_type_0, |
| 949 jint android_tool_type_1, | 965 jint android_tool_type_1, |
| 950 jint android_button_state) { | 966 jint android_button_state, |
| 967 jboolean is_touch_handle_event) { |
| 951 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 968 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 952 // Avoid synthesizing a touch event if it cannot be forwarded. | 969 // Avoid synthesizing a touch event if it cannot be forwarded. |
| 953 if (!rwhv) | 970 if (!rwhv) |
| 954 return false; | 971 return false; |
| 955 | 972 |
| 956 MotionEventAndroid event(1.f / dpi_scale(), | 973 MotionEventAndroid event(1.f / dpi_scale(), |
| 957 env, | 974 env, |
| 958 motion_event, | 975 motion_event, |
| 959 time_ms, | 976 time_ms, |
| 960 android_action, | 977 android_action, |
| 961 pointer_count, | 978 pointer_count, |
| 962 history_size, | 979 history_size, |
| 963 action_index, | 980 action_index, |
| 964 pos_x_0, | 981 pos_x_0, |
| 965 pos_y_0, | 982 pos_y_0, |
| 966 pos_x_1, | 983 pos_x_1, |
| 967 pos_y_1, | 984 pos_y_1, |
| 968 pointer_id_0, | 985 pointer_id_0, |
| 969 pointer_id_1, | 986 pointer_id_1, |
| 970 touch_major_0, | 987 touch_major_0, |
| 971 touch_major_1, | 988 touch_major_1, |
| 972 raw_pos_x, | 989 raw_pos_x, |
| 973 raw_pos_y, | 990 raw_pos_y, |
| 974 android_tool_type_0, | 991 android_tool_type_0, |
| 975 android_tool_type_1, | 992 android_tool_type_1, |
| 976 android_button_state); | 993 android_button_state); |
| 977 | 994 |
| 978 return rwhv->OnTouchEvent(event); | 995 return is_touch_handle_event ? rwhv->OnTouchHandleEvent(event) |
| 996 : rwhv->OnTouchEvent(event); |
| 979 } | 997 } |
| 980 | 998 |
| 981 float ContentViewCoreImpl::GetDpiScale() const { | 999 float ContentViewCoreImpl::GetDpiScale() const { |
| 982 return dpi_scale_; | 1000 return dpi_scale_; |
| 983 } | 1001 } |
| 984 | 1002 |
| 985 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, | 1003 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, |
| 986 jobject obj, | 1004 jobject obj, |
| 987 jlong time_ms, | 1005 jlong time_ms, |
| 988 jfloat x, | 1006 jfloat x, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 WebGestureEvent event = MakeGestureEvent( | 1150 WebGestureEvent event = MakeGestureEvent( |
| 1133 WebInputEvent::GesturePinchUpdate, time_ms, anchor_x, anchor_y); | 1151 WebInputEvent::GesturePinchUpdate, time_ms, anchor_x, anchor_y); |
| 1134 event.data.pinchUpdate.scale = delta; | 1152 event.data.pinchUpdate.scale = delta; |
| 1135 | 1153 |
| 1136 SendGestureEvent(event); | 1154 SendGestureEvent(event); |
| 1137 } | 1155 } |
| 1138 | 1156 |
| 1139 void ContentViewCoreImpl::SelectBetweenCoordinates(JNIEnv* env, jobject obj, | 1157 void ContentViewCoreImpl::SelectBetweenCoordinates(JNIEnv* env, jobject obj, |
| 1140 jfloat x1, jfloat y1, | 1158 jfloat x1, jfloat y1, |
| 1141 jfloat x2, jfloat y2) { | 1159 jfloat x2, jfloat y2) { |
| 1142 if (!web_contents_) | 1160 SelectBetweenCoordinates(gfx::PointF(x1 / dpi_scale(), y1 / dpi_scale()), |
| 1143 return; | 1161 gfx::PointF(x2 / dpi_scale(), y2 / dpi_scale())); |
| 1144 | |
| 1145 web_contents_->SelectRange( | |
| 1146 gfx::Point(x1 / dpi_scale(), y1 / dpi_scale()), | |
| 1147 gfx::Point(x2 / dpi_scale(), y2 / dpi_scale())); | |
| 1148 } | 1162 } |
| 1149 | 1163 |
| 1150 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, | 1164 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, |
| 1151 jfloat x, jfloat y) { | 1165 jfloat x, jfloat y) { |
| 1152 if (GetRenderWidgetHostViewAndroid()) { | 1166 if (GetRenderWidgetHostViewAndroid()) { |
| 1153 GetRenderWidgetHostViewAndroid()->MoveCaret( | 1167 GetRenderWidgetHostViewAndroid()->MoveCaret( |
| 1154 gfx::Point(x / dpi_scale(), y / dpi_scale())); | 1168 gfx::Point(x / dpi_scale_, y / dpi_scale_)); |
| 1155 } | 1169 } |
| 1156 } | 1170 } |
| 1157 | 1171 |
| 1172 void ContentViewCoreImpl::HideTextHandles(JNIEnv* env, jobject obj) { |
| 1173 if (GetRenderWidgetHostViewAndroid()) |
| 1174 GetRenderWidgetHostViewAndroid()->HideTextHandles(); |
| 1175 } |
| 1176 |
| 1158 void ContentViewCoreImpl::ResetGestureDetection(JNIEnv* env, jobject obj) { | 1177 void ContentViewCoreImpl::ResetGestureDetection(JNIEnv* env, jobject obj) { |
| 1159 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1178 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| 1160 if (rwhv) | 1179 if (rwhv) |
| 1161 rwhv->ResetGestureDetection(); | 1180 rwhv->ResetGestureDetection(); |
| 1162 } | 1181 } |
| 1163 | 1182 |
| 1164 void ContentViewCoreImpl::SetDoubleTapSupportEnabled(JNIEnv* env, | 1183 void ContentViewCoreImpl::SetDoubleTapSupportEnabled(JNIEnv* env, |
| 1165 jobject obj, | 1184 jobject obj, |
| 1166 jboolean enabled) { | 1185 jboolean enabled) { |
| 1167 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1186 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1482 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); | 1501 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); |
| 1483 controller.ReloadOriginalRequestURL(false); | 1502 controller.ReloadOriginalRequestURL(false); |
| 1484 } | 1503 } |
| 1485 } | 1504 } |
| 1486 | 1505 |
| 1487 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj, | 1506 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj, |
| 1488 bool enabled) { | 1507 bool enabled) { |
| 1489 SetAccessibilityEnabledInternal(enabled); | 1508 SetAccessibilityEnabledInternal(enabled); |
| 1490 } | 1509 } |
| 1491 | 1510 |
| 1492 void ContentViewCoreImpl::ShowSelectionHandlesAutomatically() const { | |
| 1493 JNIEnv* env = AttachCurrentThread(); | |
| 1494 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env)); | |
| 1495 if (obj.is_null()) | |
| 1496 return; | |
| 1497 Java_ContentViewCore_showSelectionHandlesAutomatically(env, obj.obj()); | |
| 1498 } | |
| 1499 | |
| 1500 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const { | 1511 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const { |
| 1501 JNIEnv* env = AttachCurrentThread(); | 1512 JNIEnv* env = AttachCurrentThread(); |
| 1502 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 1513 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 1503 if (obj.is_null()) | 1514 if (obj.is_null()) |
| 1504 return true; | 1515 return true; |
| 1505 return Java_ContentViewCore_isFullscreenRequiredForOrientationLock(env, | 1516 return Java_ContentViewCore_isFullscreenRequiredForOrientationLock(env, |
| 1506 obj.obj()); | 1517 obj.obj()); |
| 1507 } | 1518 } |
| 1508 | 1519 |
| 1509 void ContentViewCoreImpl::SetAccessibilityEnabledInternal(bool enabled) { | 1520 void ContentViewCoreImpl::SetAccessibilityEnabledInternal(bool enabled) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1657 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1668 reinterpret_cast<ui::WindowAndroid*>(window_android), |
| 1658 retained_objects_set); | 1669 retained_objects_set); |
| 1659 return reinterpret_cast<intptr_t>(view); | 1670 return reinterpret_cast<intptr_t>(view); |
| 1660 } | 1671 } |
| 1661 | 1672 |
| 1662 bool RegisterContentViewCore(JNIEnv* env) { | 1673 bool RegisterContentViewCore(JNIEnv* env) { |
| 1663 return RegisterNativesImpl(env); | 1674 return RegisterNativesImpl(env); |
| 1664 } | 1675 } |
| 1665 | 1676 |
| 1666 } // namespace content | 1677 } // namespace content |
| OLD | NEW |