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 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 Java_ContentViewCore_onPinchEndEventAck(env, j_obj.obj()); | 552 Java_ContentViewCore_onPinchEndEventAck(env, j_obj.obj()); |
552 break; | 553 break; |
553 case WebInputEvent::GestureTap: | 554 case WebInputEvent::GestureTap: |
554 Java_ContentViewCore_onSingleTapEventAck( | 555 Java_ContentViewCore_onSingleTapEventAck( |
555 env, | 556 env, |
556 j_obj.obj(), | 557 j_obj.obj(), |
557 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED, | 558 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED, |
558 event.x * dpi_scale(), | 559 event.x * dpi_scale(), |
559 event.y * dpi_scale()); | 560 event.y * dpi_scale()); |
560 break; | 561 break; |
561 case WebInputEvent::GestureDoubleTap: | |
562 Java_ContentViewCore_onDoubleTapEventAck(env, j_obj.obj()); | |
563 break; | |
564 default: | 562 default: |
565 break; | 563 break; |
566 } | 564 } |
567 } | 565 } |
568 | 566 |
569 bool ContentViewCoreImpl::FilterInputEvent(const blink::WebInputEvent& event) { | 567 bool ContentViewCoreImpl::FilterInputEvent(const blink::WebInputEvent& event) { |
570 if (event.type != WebInputEvent::GestureTap && | 568 if (event.type != WebInputEvent::GestureTap && |
571 event.type != WebInputEvent::GestureDoubleTap && | 569 event.type != WebInputEvent::GestureDoubleTap && |
572 event.type != WebInputEvent::GestureLongTap && | 570 event.type != WebInputEvent::GestureLongTap && |
573 event.type != WebInputEvent::GestureLongPress) | 571 event.type != WebInputEvent::GestureLongPress) |
(...skipping 26 matching lines...) Expand all Loading... |
600 | 598 |
601 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { | 599 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { |
602 JNIEnv* env = AttachCurrentThread(); | 600 JNIEnv* env = AttachCurrentThread(); |
603 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 601 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
604 if (obj.is_null()) | 602 if (obj.is_null()) |
605 return; | 603 return; |
606 ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text); | 604 ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text); |
607 Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj()); | 605 Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj()); |
608 } | 606 } |
609 | 607 |
610 void ContentViewCoreImpl::OnSelectionBoundsChanged(const gfx::PointF& start, | 608 void ContentViewCoreImpl::OnSelectionEvent(SelectionEventType event, |
611 const gfx::PointF& end, | 609 const gfx::PointF& position) { |
612 int start_dir, | 610 JNIEnv* env = AttachCurrentThread(); |
613 int end_dir) { | 611 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 612 if (j_obj.is_null()) |
| 613 return; |
| 614 Java_ContentViewCore_onSelectionEvent( |
| 615 env, j_obj.obj(), event, position.x(), position.y()); |
| 616 } |
| 617 |
| 618 scoped_ptr<TouchHandleDrawable> |
| 619 ContentViewCoreImpl::CreatePopupTouchHandleDrawable() { |
614 JNIEnv* env = AttachCurrentThread(); | 620 JNIEnv* env = AttachCurrentThread(); |
615 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 621 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
616 if (obj.is_null()) | 622 if (obj.is_null()) { |
617 return; | 623 NOTREACHED(); |
618 Java_ContentViewCore_onSelectionBoundsChanged(env, | 624 return scoped_ptr<TouchHandleDrawable>(); |
619 obj.obj(), | 625 } |
620 start.x(), | 626 return scoped_ptr<TouchHandleDrawable>(new PopupTouchHandleDrawable( |
621 start.y(), | 627 Java_ContentViewCore_createPopupTouchHandleDrawable(env, obj.obj()), |
622 end.x(), | 628 dpi_scale_)); |
623 end.y(), | |
624 start_dir, | |
625 end_dir); | |
626 } | 629 } |
627 | 630 |
628 void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) { | 631 void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) { |
629 JNIEnv* env = AttachCurrentThread(); | 632 JNIEnv* env = AttachCurrentThread(); |
630 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 633 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
631 if (obj.is_null()) | 634 if (obj.is_null()) |
632 return; | 635 return; |
633 Java_ContentViewCore_showPastePopup(env, obj.obj(), | 636 Java_ContentViewCore_showPastePopup(env, obj.obj(), |
634 static_cast<jint>(x_dip), | 637 static_cast<jint>(x_dip), |
635 static_cast<jint>(y_dip)); | 638 static_cast<jint>(y_dip)); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 float ContentViewCoreImpl::GetOverdrawBottomHeightDip() const { | 784 float ContentViewCoreImpl::GetOverdrawBottomHeightDip() const { |
782 JNIEnv* env = AttachCurrentThread(); | 785 JNIEnv* env = AttachCurrentThread(); |
783 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 786 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
784 if (j_obj.is_null()) | 787 if (j_obj.is_null()) |
785 return 0.f; | 788 return 0.f; |
786 return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj()) | 789 return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj()) |
787 / dpi_scale(); | 790 / dpi_scale(); |
788 } | 791 } |
789 | 792 |
790 void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) { | 793 void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) { |
791 root_layer_->AddChild(layer); | 794 root_layer_->InsertChild(layer, 0); |
792 root_layer_->SetIsDrawable(false); | 795 root_layer_->SetIsDrawable(false); |
793 } | 796 } |
794 | 797 |
795 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { | 798 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { |
796 layer->RemoveFromParent(); | 799 layer->RemoveFromParent(); |
797 | 800 |
798 if (!root_layer_->children().size()) | 801 if (!root_layer_->children().size()) |
799 root_layer_->SetIsDrawable(true); | 802 root_layer_->SetIsDrawable(true); |
800 } | 803 } |
801 | 804 |
| 805 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& start, |
| 806 const gfx::PointF& end) { |
| 807 if (!web_contents_) |
| 808 return; |
| 809 |
| 810 gfx::Point start_point = gfx::Point(start.x(), start.y()); |
| 811 gfx::Point end_point = gfx::Point(end.x(), end.y()); |
| 812 if (start_point == end_point) |
| 813 return; |
| 814 |
| 815 web_contents_->SelectRange(start_point, end_point); |
| 816 } |
| 817 |
802 void ContentViewCoreImpl::LoadUrl( | 818 void ContentViewCoreImpl::LoadUrl( |
803 NavigationController::LoadURLParams& params) { | 819 NavigationController::LoadURLParams& params) { |
804 GetWebContents()->GetController().LoadURLWithParams(params); | 820 GetWebContents()->GetController().LoadURLWithParams(params); |
805 } | 821 } |
806 | 822 |
807 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { | 823 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { |
808 return view_android_; | 824 return view_android_; |
809 } | 825 } |
810 | 826 |
811 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { | 827 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 jfloat pos_x_1, | 961 jfloat pos_x_1, |
946 jfloat pos_y_1, | 962 jfloat pos_y_1, |
947 jint pointer_id_0, | 963 jint pointer_id_0, |
948 jint pointer_id_1, | 964 jint pointer_id_1, |
949 jfloat touch_major_0, | 965 jfloat touch_major_0, |
950 jfloat touch_major_1, | 966 jfloat touch_major_1, |
951 jfloat raw_pos_x, | 967 jfloat raw_pos_x, |
952 jfloat raw_pos_y, | 968 jfloat raw_pos_y, |
953 jint android_tool_type_0, | 969 jint android_tool_type_0, |
954 jint android_tool_type_1, | 970 jint android_tool_type_1, |
955 jint android_button_state) { | 971 jint android_button_state, |
| 972 jboolean is_touch_handle_event) { |
956 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 973 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
957 // Avoid synthesizing a touch event if it cannot be forwarded. | 974 // Avoid synthesizing a touch event if it cannot be forwarded. |
958 if (!rwhv) | 975 if (!rwhv) |
959 return false; | 976 return false; |
960 | 977 |
961 MotionEventAndroid event(1.f / dpi_scale(), | 978 MotionEventAndroid event(1.f / dpi_scale(), |
962 env, | 979 env, |
963 motion_event, | 980 motion_event, |
964 time_ms, | 981 time_ms, |
965 android_action, | 982 android_action, |
966 pointer_count, | 983 pointer_count, |
967 history_size, | 984 history_size, |
968 action_index, | 985 action_index, |
969 pos_x_0, | 986 pos_x_0, |
970 pos_y_0, | 987 pos_y_0, |
971 pos_x_1, | 988 pos_x_1, |
972 pos_y_1, | 989 pos_y_1, |
973 pointer_id_0, | 990 pointer_id_0, |
974 pointer_id_1, | 991 pointer_id_1, |
975 touch_major_0, | 992 touch_major_0, |
976 touch_major_1, | 993 touch_major_1, |
977 raw_pos_x, | 994 raw_pos_x, |
978 raw_pos_y, | 995 raw_pos_y, |
979 android_tool_type_0, | 996 android_tool_type_0, |
980 android_tool_type_1, | 997 android_tool_type_1, |
981 android_button_state); | 998 android_button_state); |
982 | 999 |
983 return rwhv->OnTouchEvent(event); | 1000 return is_touch_handle_event ? rwhv->OnTouchHandleEvent(event) |
| 1001 : rwhv->OnTouchEvent(event); |
984 } | 1002 } |
985 | 1003 |
986 float ContentViewCoreImpl::GetDpiScale() const { | 1004 float ContentViewCoreImpl::GetDpiScale() const { |
987 return dpi_scale_; | 1005 return dpi_scale_; |
988 } | 1006 } |
989 | 1007 |
990 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, | 1008 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, |
991 jobject obj, | 1009 jobject obj, |
992 jlong time_ms, | 1010 jlong time_ms, |
993 jfloat x, | 1011 jfloat x, |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 WebGestureEvent event = MakeGestureEvent( | 1155 WebGestureEvent event = MakeGestureEvent( |
1138 WebInputEvent::GesturePinchUpdate, time_ms, anchor_x, anchor_y); | 1156 WebInputEvent::GesturePinchUpdate, time_ms, anchor_x, anchor_y); |
1139 event.data.pinchUpdate.scale = delta; | 1157 event.data.pinchUpdate.scale = delta; |
1140 | 1158 |
1141 SendGestureEvent(event); | 1159 SendGestureEvent(event); |
1142 } | 1160 } |
1143 | 1161 |
1144 void ContentViewCoreImpl::SelectBetweenCoordinates(JNIEnv* env, jobject obj, | 1162 void ContentViewCoreImpl::SelectBetweenCoordinates(JNIEnv* env, jobject obj, |
1145 jfloat x1, jfloat y1, | 1163 jfloat x1, jfloat y1, |
1146 jfloat x2, jfloat y2) { | 1164 jfloat x2, jfloat y2) { |
1147 if (!web_contents_) | 1165 SelectBetweenCoordinates(gfx::PointF(x1 / dpi_scale(), y1 / dpi_scale()), |
1148 return; | 1166 gfx::PointF(x2 / dpi_scale(), y2 / dpi_scale())); |
1149 | |
1150 web_contents_->SelectRange( | |
1151 gfx::Point(x1 / dpi_scale(), y1 / dpi_scale()), | |
1152 gfx::Point(x2 / dpi_scale(), y2 / dpi_scale())); | |
1153 } | 1167 } |
1154 | 1168 |
1155 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, | 1169 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, |
1156 jfloat x, jfloat y) { | 1170 jfloat x, jfloat y) { |
1157 if (GetRenderWidgetHostViewAndroid()) { | 1171 if (GetRenderWidgetHostViewAndroid()) { |
1158 GetRenderWidgetHostViewAndroid()->MoveCaret( | 1172 GetRenderWidgetHostViewAndroid()->MoveCaret( |
1159 gfx::Point(x / dpi_scale(), y / dpi_scale())); | 1173 gfx::Point(x / dpi_scale_, y / dpi_scale_)); |
1160 } | 1174 } |
1161 } | 1175 } |
1162 | 1176 |
| 1177 void ContentViewCoreImpl::HideTextHandles(JNIEnv* env, jobject obj) { |
| 1178 if (GetRenderWidgetHostViewAndroid()) |
| 1179 GetRenderWidgetHostViewAndroid()->HideTextHandles(); |
| 1180 } |
| 1181 |
1163 void ContentViewCoreImpl::ResetGestureDetection(JNIEnv* env, jobject obj) { | 1182 void ContentViewCoreImpl::ResetGestureDetection(JNIEnv* env, jobject obj) { |
1164 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1183 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
1165 if (rwhv) | 1184 if (rwhv) |
1166 rwhv->ResetGestureDetection(); | 1185 rwhv->ResetGestureDetection(); |
1167 } | 1186 } |
1168 | 1187 |
1169 void ContentViewCoreImpl::SetDoubleTapSupportEnabled(JNIEnv* env, | 1188 void ContentViewCoreImpl::SetDoubleTapSupportEnabled(JNIEnv* env, |
1170 jobject obj, | 1189 jobject obj, |
1171 jboolean enabled) { | 1190 jboolean enabled) { |
1172 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | 1191 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); | 1506 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); |
1488 controller.ReloadOriginalRequestURL(false); | 1507 controller.ReloadOriginalRequestURL(false); |
1489 } | 1508 } |
1490 } | 1509 } |
1491 | 1510 |
1492 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj, | 1511 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj, |
1493 bool enabled) { | 1512 bool enabled) { |
1494 SetAccessibilityEnabledInternal(enabled); | 1513 SetAccessibilityEnabledInternal(enabled); |
1495 } | 1514 } |
1496 | 1515 |
1497 void ContentViewCoreImpl::ShowSelectionHandlesAutomatically() const { | |
1498 JNIEnv* env = AttachCurrentThread(); | |
1499 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env)); | |
1500 if (obj.is_null()) | |
1501 return; | |
1502 Java_ContentViewCore_showSelectionHandlesAutomatically(env, obj.obj()); | |
1503 } | |
1504 | |
1505 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const { | 1516 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const { |
1506 JNIEnv* env = AttachCurrentThread(); | 1517 JNIEnv* env = AttachCurrentThread(); |
1507 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 1518 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
1508 if (obj.is_null()) | 1519 if (obj.is_null()) |
1509 return true; | 1520 return true; |
1510 return Java_ContentViewCore_isFullscreenRequiredForOrientationLock(env, | 1521 return Java_ContentViewCore_isFullscreenRequiredForOrientationLock(env, |
1511 obj.obj()); | 1522 obj.obj()); |
1512 } | 1523 } |
1513 | 1524 |
1514 void ContentViewCoreImpl::SetAccessibilityEnabledInternal(bool enabled) { | 1525 void ContentViewCoreImpl::SetAccessibilityEnabledInternal(bool enabled) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1664 reinterpret_cast<ui::WindowAndroid*>(window_android), | 1675 reinterpret_cast<ui::WindowAndroid*>(window_android), |
1665 retained_objects_set); | 1676 retained_objects_set); |
1666 return reinterpret_cast<intptr_t>(view); | 1677 return reinterpret_cast<intptr_t>(view); |
1667 } | 1678 } |
1668 | 1679 |
1669 bool RegisterContentViewCore(JNIEnv* env) { | 1680 bool RegisterContentViewCore(JNIEnv* env) { |
1670 return RegisterNativesImpl(env); | 1681 return RegisterNativesImpl(env); |
1671 } | 1682 } |
1672 | 1683 |
1673 } // namespace content | 1684 } // namespace content |
OLD | NEW |