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

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: Clean up paste popup interaction 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/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/java_bound_object.h" 22 #include "content/browser/android/java/java_bound_object.h"
23 #include "content/browser/android/java/java_bridge_dispatcher_host_manager.h" 23 #include "content/browser/android/java/java_bridge_dispatcher_host_manager.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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 Java_ContentViewCore_onPinchEndEventAck(env, j_obj.obj()); 545 Java_ContentViewCore_onPinchEndEventAck(env, j_obj.obj());
545 break; 546 break;
546 case WebInputEvent::GestureTap: 547 case WebInputEvent::GestureTap:
547 Java_ContentViewCore_onSingleTapEventAck( 548 Java_ContentViewCore_onSingleTapEventAck(
548 env, 549 env,
549 j_obj.obj(), 550 j_obj.obj(),
550 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED, 551 ack_result == INPUT_EVENT_ACK_STATE_CONSUMED,
551 event.x * dpi_scale(), 552 event.x * dpi_scale(),
552 event.y * dpi_scale()); 553 event.y * dpi_scale());
553 break; 554 break;
554 case WebInputEvent::GestureDoubleTap:
555 Java_ContentViewCore_onDoubleTapEventAck(env, j_obj.obj());
556 break;
557 default: 555 default:
558 break; 556 break;
559 } 557 }
560 } 558 }
561 559
562 bool ContentViewCoreImpl::FilterInputEvent(const blink::WebInputEvent& event) { 560 bool ContentViewCoreImpl::FilterInputEvent(const blink::WebInputEvent& event) {
563 if (event.type != WebInputEvent::GestureTap && 561 if (event.type != WebInputEvent::GestureTap &&
564 event.type != WebInputEvent::GestureDoubleTap && 562 event.type != WebInputEvent::GestureDoubleTap &&
565 event.type != WebInputEvent::GestureLongTap && 563 event.type != WebInputEvent::GestureLongTap &&
566 event.type != WebInputEvent::GestureLongPress) 564 event.type != WebInputEvent::GestureLongPress)
(...skipping 26 matching lines...) Expand all
593 591
594 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { 592 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) {
595 JNIEnv* env = AttachCurrentThread(); 593 JNIEnv* env = AttachCurrentThread();
596 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 594 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
597 if (obj.is_null()) 595 if (obj.is_null())
598 return; 596 return;
599 ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text); 597 ScopedJavaLocalRef<jstring> jtext = ConvertUTF8ToJavaString(env, text);
600 Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj()); 598 Java_ContentViewCore_onSelectionChanged(env, obj.obj(), jtext.obj());
601 } 599 }
602 600
603 void ContentViewCoreImpl::OnSelectionBoundsChanged(const gfx::PointF& anchor, 601 void ContentViewCoreImpl::OnSelectionEvent(SelectionEventType event,
604 const gfx::PointF& focus, 602 const gfx::PointF& position) {
605 int anchor_dir, 603 JNIEnv* env = AttachCurrentThread();
606 int focus_dir, 604 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
607 bool is_anchor_visible, 605 if (j_obj.is_null())
608 bool is_focus_visible) { 606 return;
607 Java_ContentViewCore_onSelectionEvent(
608 env, j_obj.obj(), event, position.x(), position.y());
609 }
610
611 scoped_ptr<TouchHandleDrawable>
612 ContentViewCoreImpl::CreatePopupTouchHandleDrawable() {
609 JNIEnv* env = AttachCurrentThread(); 613 JNIEnv* env = AttachCurrentThread();
610 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 614 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
611 if (obj.is_null()) 615 if (obj.is_null()) {
612 return; 616 NOTREACHED();
613 Java_ContentViewCore_onSelectionBoundsChanged(env, 617 return scoped_ptr<TouchHandleDrawable>();
614 obj.obj(), 618 }
615 anchor.x(), 619 return scoped_ptr<TouchHandleDrawable>(new PopupTouchHandleDrawable(
616 anchor.y(), 620 Java_ContentViewCore_createPopupTouchHandleDrawable(env, obj.obj()),
617 focus.x(), 621 dpi_scale_));
618 focus.y(),
619 anchor_dir,
620 focus_dir,
621 is_anchor_visible,
622 is_focus_visible);
623 } 622 }
624 623
625 void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) { 624 void ContentViewCoreImpl::ShowPastePopup(int x_dip, int y_dip) {
626 JNIEnv* env = AttachCurrentThread(); 625 JNIEnv* env = AttachCurrentThread();
627 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 626 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
628 if (obj.is_null()) 627 if (obj.is_null())
629 return; 628 return;
630 Java_ContentViewCore_showPastePopup(env, obj.obj(), 629 Java_ContentViewCore_showPastePopup(env, obj.obj(),
631 static_cast<jint>(x_dip), 630 static_cast<jint>(x_dip),
632 static_cast<jint>(y_dip)); 631 static_cast<jint>(y_dip));
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 float ContentViewCoreImpl::GetOverdrawBottomHeightDip() const { 777 float ContentViewCoreImpl::GetOverdrawBottomHeightDip() const {
779 JNIEnv* env = AttachCurrentThread(); 778 JNIEnv* env = AttachCurrentThread();
780 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 779 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
781 if (j_obj.is_null()) 780 if (j_obj.is_null())
782 return 0.f; 781 return 0.f;
783 return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj()) 782 return Java_ContentViewCore_getOverdrawBottomHeightPix(env, j_obj.obj())
784 / dpi_scale(); 783 / dpi_scale();
785 } 784 }
786 785
787 void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) { 786 void ContentViewCoreImpl::AttachLayer(scoped_refptr<cc::Layer> layer) {
788 root_layer_->AddChild(layer); 787 root_layer_->InsertChild(layer, 0);
789 root_layer_->SetIsDrawable(false); 788 root_layer_->SetIsDrawable(false);
790 } 789 }
791 790
792 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) { 791 void ContentViewCoreImpl::RemoveLayer(scoped_refptr<cc::Layer> layer) {
793 layer->RemoveFromParent(); 792 layer->RemoveFromParent();
794 793
795 if (!root_layer_->children().size()) 794 if (!root_layer_->children().size())
796 root_layer_->SetIsDrawable(true); 795 root_layer_->SetIsDrawable(true);
797 } 796 }
798 797
798 void ContentViewCoreImpl::SelectBetweenCoordinates(const gfx::PointF& start,
799 const gfx::PointF& end) {
800 if (!web_contents_)
801 return;
802
803 gfx::Point anchor = gfx::Point(start.x(), start.y());
804 gfx::Point focus = gfx::Point(end.x(), end.y());
805 if (anchor.x() == focus.x() && anchor.y() == focus.y())
cjhopman 2014/07/09 22:29:12 nit: if (anchor == focus) {
jdduke (slow) 2014/07/10 02:08:39 Done.
806 return;
807
808 web_contents_->SelectRange(anchor, focus);
809 }
810
799 void ContentViewCoreImpl::LoadUrl( 811 void ContentViewCoreImpl::LoadUrl(
800 NavigationController::LoadURLParams& params) { 812 NavigationController::LoadURLParams& params) {
801 GetWebContents()->GetController().LoadURLWithParams(params); 813 GetWebContents()->GetController().LoadURLWithParams(params);
802 } 814 }
803 815
804 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const { 816 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() const {
805 // view_android_ should never be null for Chrome. 817 // view_android_ should never be null for Chrome.
806 DCHECK(view_android_); 818 DCHECK(view_android_);
807 return view_android_; 819 return view_android_;
808 } 820 }
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 touch_major_1, 989 touch_major_1,
978 raw_pos_x, 990 raw_pos_x,
979 raw_pos_y, 991 raw_pos_y,
980 android_tool_type_0, 992 android_tool_type_0,
981 android_tool_type_1, 993 android_tool_type_1,
982 android_button_state); 994 android_button_state);
983 995
984 return rwhv->OnTouchEvent(event); 996 return rwhv->OnTouchEvent(event);
985 } 997 }
986 998
999 jboolean ContentViewCoreImpl::OnTouchHandleEvent(JNIEnv* env,
1000 jobject obj,
1001 jobject motion_event) {
1002 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
1003 // Avoid synthesizing a touch event if it cannot be forwarded.
1004 if (!rwhv)
1005 return false;
1006
1007 const bool recycle = false;
1008 MotionEventAndroid event(1.f / dpi_scale(), env, motion_event, recycle);
1009
1010 return rwhv->OnTouchHandleEvent(event);
1011 }
1012
987 float ContentViewCoreImpl::GetDpiScale() const { 1013 float ContentViewCoreImpl::GetDpiScale() const {
988 return dpi_scale_; 1014 return dpi_scale_;
989 } 1015 }
990 1016
991 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env, 1017 jboolean ContentViewCoreImpl::SendMouseMoveEvent(JNIEnv* env,
992 jobject obj, 1018 jobject obj,
993 jlong time_ms, 1019 jlong time_ms,
994 jfloat x, 1020 jfloat x,
995 jfloat y) { 1021 jfloat y) {
996 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 1022 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 WebGestureEvent event = MakeGestureEvent( 1164 WebGestureEvent event = MakeGestureEvent(
1139 WebInputEvent::GesturePinchUpdate, time_ms, anchor_x, anchor_y); 1165 WebInputEvent::GesturePinchUpdate, time_ms, anchor_x, anchor_y);
1140 event.data.pinchUpdate.scale = delta; 1166 event.data.pinchUpdate.scale = delta;
1141 1167
1142 SendGestureEvent(event); 1168 SendGestureEvent(event);
1143 } 1169 }
1144 1170
1145 void ContentViewCoreImpl::SelectBetweenCoordinates(JNIEnv* env, jobject obj, 1171 void ContentViewCoreImpl::SelectBetweenCoordinates(JNIEnv* env, jobject obj,
1146 jfloat x1, jfloat y1, 1172 jfloat x1, jfloat y1,
1147 jfloat x2, jfloat y2) { 1173 jfloat x2, jfloat y2) {
1148 if (!web_contents_) 1174 SelectBetweenCoordinates(gfx::PointF(x1 / dpi_scale(), y1 / dpi_scale()),
1149 return; 1175 gfx::PointF(x2 / dpi_scale(), y2 / dpi_scale()));
1150
1151 web_contents_->SelectRange(
1152 gfx::Point(x1 / dpi_scale(), y1 / dpi_scale()),
1153 gfx::Point(x2 / dpi_scale(), y2 / dpi_scale()));
1154 } 1176 }
1155 1177
1156 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj, 1178 void ContentViewCoreImpl::MoveCaret(JNIEnv* env, jobject obj,
1157 jfloat x, jfloat y) { 1179 jfloat x, jfloat y) {
1158 if (GetRenderWidgetHostViewAndroid()) { 1180 if (GetRenderWidgetHostViewAndroid()) {
1159 GetRenderWidgetHostViewAndroid()->MoveCaret( 1181 GetRenderWidgetHostViewAndroid()->MoveCaret(
1160 gfx::Point(x / dpi_scale(), y / dpi_scale())); 1182 gfx::Point(x / dpi_scale_, y / dpi_scale_));
1161 } 1183 }
1162 } 1184 }
1163 1185
1186 void ContentViewCoreImpl::HideTextHandles(JNIEnv* env, jobject obj) {
1187 if (GetRenderWidgetHostViewAndroid())
1188 GetRenderWidgetHostViewAndroid()->HideTextHandles();
1189 }
1190
1164 void ContentViewCoreImpl::ResetGestureDetection(JNIEnv* env, jobject obj) { 1191 void ContentViewCoreImpl::ResetGestureDetection(JNIEnv* env, jobject obj) {
1165 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 1192 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
1166 if (rwhv) 1193 if (rwhv)
1167 rwhv->ResetGestureDetection(); 1194 rwhv->ResetGestureDetection();
1168 } 1195 }
1169 1196
1170 void ContentViewCoreImpl::SetDoubleTapSupportEnabled(JNIEnv* env, 1197 void ContentViewCoreImpl::SetDoubleTapSupportEnabled(JNIEnv* env,
1171 jobject obj, 1198 jobject obj,
1172 jboolean enabled) { 1199 jboolean enabled) {
1173 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); 1200 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid();
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 static_cast<NavigationControllerImpl&>(web_contents_->GetController()); 1555 static_cast<NavigationControllerImpl&>(web_contents_->GetController());
1529 controller.ReloadOriginalRequestURL(false); 1556 controller.ReloadOriginalRequestURL(false);
1530 } 1557 }
1531 } 1558 }
1532 1559
1533 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj, 1560 void ContentViewCoreImpl::SetAccessibilityEnabled(JNIEnv* env, jobject obj,
1534 bool enabled) { 1561 bool enabled) {
1535 SetAccessibilityEnabledInternal(enabled); 1562 SetAccessibilityEnabledInternal(enabled);
1536 } 1563 }
1537 1564
1538 void ContentViewCoreImpl::ShowSelectionHandlesAutomatically() const {
1539 JNIEnv* env = AttachCurrentThread();
1540 ScopedJavaLocalRef<jobject> obj(java_ref_.get(env));
1541 if (obj.is_null())
1542 return;
1543 Java_ContentViewCore_showSelectionHandlesAutomatically(env, obj.obj());
1544 }
1545
1546 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const { 1565 bool ContentViewCoreImpl::IsFullscreenRequiredForOrientationLock() const {
1547 JNIEnv* env = AttachCurrentThread(); 1566 JNIEnv* env = AttachCurrentThread();
1548 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 1567 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
1549 if (obj.is_null()) 1568 if (obj.is_null())
1550 return true; 1569 return true;
1551 return Java_ContentViewCore_isFullscreenRequiredForOrientationLock(env, 1570 return Java_ContentViewCore_isFullscreenRequiredForOrientationLock(env,
1552 obj.obj()); 1571 obj.obj());
1553 } 1572 }
1554 1573
1555 void ContentViewCoreImpl::SetAccessibilityEnabledInternal(bool enabled) { 1574 void ContentViewCoreImpl::SetAccessibilityEnabledInternal(bool enabled) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 reinterpret_cast<ui::WindowAndroid*>(window_android), 1722 reinterpret_cast<ui::WindowAndroid*>(window_android),
1704 retained_objects_set); 1723 retained_objects_set);
1705 return reinterpret_cast<intptr_t>(view); 1724 return reinterpret_cast<intptr_t>(view);
1706 } 1725 }
1707 1726
1708 bool RegisterContentViewCore(JNIEnv* env) { 1727 bool RegisterContentViewCore(JNIEnv* env) {
1709 return RegisterNativesImpl(env); 1728 return RegisterNativesImpl(env);
1710 } 1729 }
1711 1730
1712 } // namespace content 1731 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698