Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: content/browser/android/content_view_core_impl.cc

Issue 335943002: [Android] Composited selection handle rendering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@input_native_handles_final
Patch Set: Fix animation tests Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/accessibility/browser_accessibility_state_impl.h" 20 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
21 #include "content/browser/android/gesture_event_type.h" 21 #include "content/browser/android/gesture_event_type.h"
22 #include "content/browser/android/interstitial_page_delegate_android.h" 22 #include "content/browser/android/interstitial_page_delegate_android.h"
23 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h" 23 #include "content/browser/android/java/gin_java_bridge_dispatcher_host.h"
24 #include "content/browser/android/load_url_params.h" 24 #include "content/browser/android/load_url_params.h"
25 #include "content/browser/android/popup_touch_handle_drawable.h"
25 #include "content/browser/frame_host/interstitial_page_impl.h" 26 #include "content/browser/frame_host/interstitial_page_impl.h"
26 #include "content/browser/frame_host/navigation_controller_impl.h" 27 #include "content/browser/frame_host/navigation_controller_impl.h"
27 #include "content/browser/frame_host/navigation_entry_impl.h" 28 #include "content/browser/frame_host/navigation_entry_impl.h"
28 #include "content/browser/geolocation/geolocation_dispatcher_host.h" 29 #include "content/browser/geolocation/geolocation_dispatcher_host.h"
29 #include "content/browser/media/media_web_contents_observer.h" 30 #include "content/browser/media/media_web_contents_observer.h"
30 #include "content/browser/renderer_host/compositor_impl_android.h" 31 #include "content/browser/renderer_host/compositor_impl_android.h"
31 #include "content/browser/renderer_host/input/motion_event_android.h" 32 #include "content/browser/renderer_host/input/motion_event_android.h"
32 #include "content/browser/renderer_host/input/web_input_event_builders_android.h " 33 #include "content/browser/renderer_host/input/web_input_event_builders_android.h "
33 #include "content/browser/renderer_host/input/web_input_event_util.h" 34 #include "content/browser/renderer_host/input/web_input_event_util.h"
34 #include "content/browser/renderer_host/render_view_host_impl.h" 35 #include "content/browser/renderer_host/render_view_host_impl.h"
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 Java_ContentViewCore_onPinchEndEventAck(env, j_obj.obj()); 535 Java_ContentViewCore_onPinchEndEventAck(env, j_obj.obj());
535 break; 536 break;
536 case WebInputEvent::GestureTap: 537 case WebInputEvent::GestureTap:
537 Java_ContentViewCore_onSingleTapEventAck( 538 Java_ContentViewCore_onSingleTapEventAck(
538 env, 539 env,
539 j_obj.obj(), 540 j_obj.obj(),
540 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED, 541 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED,
541 event.x * dpi_scale(), 542 event.x * dpi_scale(),
542 event.y * dpi_scale()); 543 event.y * dpi_scale());
543 break; 544 break;
544 case WebInputEvent::GestureDoubleTap:
545 Java_ContentViewCore_onDoubleTapEventAck(env, j_obj.obj());
546 break;
547 default: 545 default:
548 break; 546 break;
549 } 547 }
550 } 548 }
551 549
552 bool ContentViewCoreImpl::FilterInputEvent(const blink::WebInputEvent& event) { 550 bool ContentViewCoreImpl::FilterInputEvent(const blink::WebInputEvent& event) {
553 if (event.type != WebInputEvent::GestureTap && 551 if (event.type != WebInputEvent::GestureTap &&
554 event.type != WebInputEvent::GestureDoubleTap && 552 event.type != WebInputEvent::GestureDoubleTap &&
555 event.type != WebInputEvent::GestureLongTap && 553 event.type != WebInputEvent::GestureLongTap &&
556 event.type != WebInputEvent::GestureLongPress) 554 event.type != WebInputEvent::GestureLongPress)
(...skipping 26 matching lines...) Expand all
583 581
584 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { 582 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) {
585 JNIEnv* env = AttachCurrentThread(); 583 JNIEnv* env = AttachCurrentThread();
586 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 584 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
587 if (obj.is_null()) 585 if (obj.is_null())
588 return; 586 return;
589 ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text); 587 ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text);
590 Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj()); 588 Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj());
591 } 589 }
592 590
593 void ContentViewCoreImpl::OnSelectionBoundsChanged( 591 void ContentViewCoreImpl::OnSelectionEvent(SelectionEventType event,
594 const ViewHostMsg_SelectionBounds_Params& params) { 592 const gfx::PointF& position) {
593 JNIEnv* env = AttachCurrentThread();
594 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
595 if (j_obj.is_null())
596 return;
597 Java_ContentViewCore_onSelectionEvent(
598 env, j_obj.obj(), event, position.x(), position.y());
599 }
600
601 scoped_ptr<TouchHandleDrawable>
602 ContentViewCoreImpl::CreatePopupTouchHandleDrawable() {
595 JNIEnv* env = AttachCurrentThread(); 603 JNIEnv* env = AttachCurrentThread();
596 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 604 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
597 if (obj.is_null()) 605 if (obj.is_null()) {
598 return; 606 NOTREACHED();
599 ScopedJavaLocalRef<jobject> anchor_rect_dip( 607 return scoped_ptr<TouchHandleDrawable>();
600 CreateJavaRect(env, params.anchor_rect)); 608 }
601 ScopedJavaLocalRef<jobject> focus_rect_dip( 609 return scoped_ptr<TouchHandleDrawable>(new PopupTouchHandleDrawable(
602 CreateJavaRect(env, params.focus_rect)); 610 Java_ContentViewCore_createPopupTouchHandleDrawable(env, obj.obj()),
603 Java_ContentViewCore_onSelectionBoundsChanged(env, obj.obj(), 611 dpi_scale_));
604 anchor_rect_dip.obj(),
605 params.anchor_dir,
606 focus_rect_dip.obj(),
607 params.focus_dir,
608 params.is_anchor_first);
609 } 612 }
610 613
611 void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) { 614 void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) {
612 JNIEnv* env = AttachCurrentThread(); 615 JNIEnv* env = AttachCurrentThread();
613 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 616 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
614 if (obj.is_null()) 617 if (obj.is_null())
615 return; 618 return;
616 Java_ContentViewCore_showPastePopup(env, obj.obj(), 619 Java_ContentViewCore_showPastePopup(env, obj.obj(),
617 static_cast<jint>(x_dip), 620 static_cast<jint>(x_dip),
618 static_cast<jint>(y_dip)); 621 static_cast<jint>(y_dip));
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 float ContentViewCoreImpl::GetOverdrawBottomHeightDip() const { 767 float ContentViewCoreImpl::GetOverdrawBottomHeightDip() const {
765 JNIEnv* env = AttachCurrentThread(); 768 JNIEnv* env = AttachCurrentThread();
766 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 769 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
767 if (j_obj.is_null()) 770 if (j_obj.is_null())
768 return 0.f; 771 return 0.f;
769 return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj()) 772 return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj())
770 / dpi_scale(); 773 / dpi_scale();
771 } 774 }
772 775
773 void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) { 776 void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) {
774 root_layer_->AddChild(layer); 777 root_layer_->InsertChild(layer, 0);
775 root_layer_->SetIsDrawable(false); 778 root_layer_->SetIsDrawable(false);
776 } 779 }
777 780
778 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { 781 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) {
779 layer->RemoveFromParent(); 782 layer->RemoveFromParent();
780 783
781 if (!root_layer_->children().size()) 784 if (!root_layer_->children().size())
782 root_layer_->SetIsDrawable(true); 785 root_layer_->SetIsDrawable(true);
783 } 786 }
784 787
788 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& start,
789 const gfx::PointF& end) {
790 if (!web_contents_)
791 return;
792
793 gfx::Point start_point = gfx::Point(start.x(), start.y());
794 gfx::Point end_point = gfx::Point(end.x(), end.y());
795 if (start_point == end_point)
796 return;
797
798 web_contents_->SelectRange(start_point, end_point);
799 }
800
785 void ContentViewCoreImpl::LoadUrl( 801 void ContentViewCoreImpl::LoadUrl(
786 NavigationController::LoadURLParams& params) { 802 NavigationController::LoadURLParams& params) {
787 GetWebContents()->GetController().LoadURLWithParams(params); 803 GetWebContents()->GetController().LoadURLWithParams(params);
788 } 804 }
789 805
790 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { 806 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const {
791 return view_android_; 807 return view_android_;
792 } 808 }
793 809
794 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { 810 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const {
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 jfloat pos_x_1, 944 jfloat pos_x_1,
929 jfloat pos_y_1, 945 jfloat pos_y_1,
930 jint pointer_id_0, 946 jint pointer_id_0,
931 jint pointer_id_1, 947 jint pointer_id_1,
932 jfloat touch_major_0, 948 jfloat touch_major_0,
933 jfloat touch_major_1, 949 jfloat touch_major_1,
934 jfloat raw_pos_x, 950 jfloat raw_pos_x,
935 jfloat raw_pos_y, 951 jfloat raw_pos_y,
936 jint android_tool_type_0, 952 jint android_tool_type_0,
937 jint android_tool_type_1, 953 jint android_tool_type_1,
938 jint android_button_state) { 954 jint android_button_state,
955 jboolean is_touch_handle_event) {
939 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 956 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
940 // Avoid synthesizing a touch event if it cannot be forwarded. 957 // Avoid synthesizing a touch event if it cannot be forwarded.
941 if (!rwhv) 958 if (!rwhv)
942 return false; 959 return false;
943 960
944 MotionEventAndroid event(1.f / dpi_scale(), 961 MotionEventAndroid event(1.f / dpi_scale(),
945 env, 962 env,
946 motion_event, 963 motion_event,
947 time_ms, 964 time_ms,
948 android_action, 965 android_action,
949 pointer_count, 966 pointer_count,
950 history_size, 967 history_size,
951 action_index, 968 action_index,
952 pos_x_0, 969 pos_x_0,
953 pos_y_0, 970 pos_y_0,
954 pos_x_1, 971 pos_x_1,
955 pos_y_1, 972 pos_y_1,
956 pointer_id_0, 973 pointer_id_0,
957 pointer_id_1, 974 pointer_id_1,
958 touch_major_0, 975 touch_major_0,
959 touch_major_1, 976 touch_major_1,
960 raw_pos_x, 977 raw_pos_x,
961 raw_pos_y, 978 raw_pos_y,
962 android_tool_type_0, 979 android_tool_type_0,
963 android_tool_type_1, 980 android_tool_type_1,
964 android_button_state); 981 android_button_state);
965 982
966 return rwhv->OnTouchEvent(event); 983 return is_touch_handle_event ? rwhv->OnTouchHandleEvent(event)
984 : rwhv->OnTouchEvent(event);
967 } 985 }
968 986
969 float ContentViewCoreImpl::GetDpiScale() const { 987 float ContentViewCoreImpl::GetDpiScale() const {
970 return dpi_scale_; 988 return dpi_scale_;
971 } 989 }
972 990
973 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, 991 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env,
974 jobject obj, 992 jobject obj,
975 jlong time_ms, 993 jlong time_ms,
976 jfloat x, 994 jfloat x,
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 WebGestureEvent event = MakeGestureEvent( 1138 WebGestureEvent event = MakeGestureEvent(
1121 WebInputEvent::GesturePinchUpdate, time_ms, anchor_x, anchor_y); 1139 WebInputEvent::GesturePinchUpdate, time_ms, anchor_x, anchor_y);
1122 event.data.pinchUpdate.scale = delta; 1140 event.data.pinchUpdate.scale = delta;
1123 1141
1124 SendGestureEvent(event); 1142 SendGestureEvent(event);
1125 } 1143 }
1126 1144
1127 void ContentViewCoreImpl::SelectBetweenCoordinates(JNIEnv* env, jobject obj, 1145 void ContentViewCoreImpl::SelectBetweenCoordinates(JNIEnv* env, jobject obj,
1128 jfloat x1, jfloat y1, 1146 jfloat x1, jfloat y1,
1129 jfloat x2, jfloat y2) { 1147 jfloat x2, jfloat y2) {
1130 if (!web_contents_) 1148 SelectBetweenCoordinates(gfx::PointF(x1 / dpi_scale(), y1 / dpi_scale()),
1131 return; 1149 gfx::PointF(x2 / dpi_scale(), y2 / dpi_scale()));
1132
1133 web_contents_->SelectRange(
1134 gfx::Point(x1 / dpi_scale(), y1 / dpi_scale()),
1135 gfx::Point(x2 / dpi_scale(), y2 / dpi_scale()));
1136 } 1150 }
1137 1151
1138 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, 1152 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj,
1139 jfloat x, jfloat y) { 1153 jfloat x, jfloat y) {
1140 if (GetRenderWidgetHostViewAndroid()) { 1154 if (GetRenderWidgetHostViewAndroid()) {
1141 GetRenderWidgetHostViewAndroid()->MoveCaret( 1155 GetRenderWidgetHostViewAndroid()->MoveCaret(
1142 gfx::Point(x / dpi_scale(), y / dpi_scale())); 1156 gfx::Point(x / dpi_scale_, y / dpi_scale_));
1143 } 1157 }
1144 } 1158 }
1145 1159
1160 void ContentViewCoreImpl::HideTextHandles(JNIEnv* env, jobject obj) {
1161 if (GetRenderWidgetHostViewAndroid())
1162 GetRenderWidgetHostViewAndroid()->HideTextHandles();
1163 }
1164
1146 void ContentViewCoreImpl::ResetGestureDetection(JNIEnv* env, jobject obj) { 1165 void ContentViewCoreImpl::ResetGestureDetection(JNIEnv* env, jobject obj) {
1147 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 1166 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
1148 if (rwhv) 1167 if (rwhv)
1149 rwhv->ResetGestureDetection(); 1168 rwhv->ResetGestureDetection();
1150 } 1169 }
1151 1170
1152 void ContentViewCoreImpl::SetDoubleTapSupportEnabled(JNIEnv* env, 1171 void ContentViewCoreImpl::SetDoubleTapSupportEnabled(JNIEnv* env,
1153 jobject obj, 1172 jobject obj,
1154 jboolean enabled) { 1173 jboolean enabled) {
1155 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 1174 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); 1437 static_cast<NavigationControllerImpl&>(web_contents_->GetController());
1419 controller.ReloadOriginalRequestURL(false); 1438 controller.ReloadOriginalRequestURL(false);
1420 } 1439 }
1421 } 1440 }
1422 1441
1423 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj, 1442 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj,
1424 bool enabled) { 1443 bool enabled) {
1425 SetAccessibilityEnabledInternal(enabled); 1444 SetAccessibilityEnabledInternal(enabled);
1426 } 1445 }
1427 1446
1428 void ContentViewCoreImpl::ShowSelectionHandlesAutomatically() const {
1429 JNIEnv* env = AttachCurrentThread();
1430 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env));
1431 if (obj.is_null())
1432 return;
1433 Java_ContentViewCore_showSelectionHandlesAutomatically(env, obj.obj());
1434 }
1435
1436 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const { 1447 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const {
1437 JNIEnv* env = AttachCurrentThread(); 1448 JNIEnv* env = AttachCurrentThread();
1438 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 1449 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
1439 if (obj.is_null()) 1450 if (obj.is_null())
1440 return true; 1451 return true;
1441 return Java_ContentViewCore_isFullscreenRequiredForOrientationLock(env, 1452 return Java_ContentViewCore_isFullscreenRequiredForOrientationLock(env,
1442 obj.obj()); 1453 obj.obj());
1443 } 1454 }
1444 1455
1445 void ContentViewCoreImpl::SetAccessibilityEnabledInternal(bool enabled) { 1456 void ContentViewCoreImpl::SetAccessibilityEnabledInternal(bool enabled) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 reinterpret_cast<ui::WindowAndroid*>(window_android), 1603 reinterpret_cast<ui::WindowAndroid*>(window_android),
1593 retained_objects_set); 1604 retained_objects_set);
1594 return reinterpret_cast<intptr_t>(view); 1605 return reinterpret_cast<intptr_t>(view);
1595 } 1606 }
1596 1607
1597 bool RegisterContentViewCore(JNIEnv* env) { 1608 bool RegisterContentViewCore(JNIEnv* env) {
1598 return RegisterNativesImpl(env); 1609 return RegisterNativesImpl(env);
1599 } 1610 }
1600 1611
1601 } // namespace content 1612 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/content_view_core_impl.h ('k') | content/browser/android/popup_touch_handle_drawable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698