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

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

Issue 2785853002: Selection Action mode triggered like a context menu (Closed)
Patch Set: fixing tests Created 3 years, 7 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 using base::android::AttachCurrentThread; 72 using base::android::AttachCurrentThread;
73 using base::android::ConvertJavaStringToUTF16; 73 using base::android::ConvertJavaStringToUTF16;
74 using base::android::ConvertJavaStringToUTF8; 74 using base::android::ConvertJavaStringToUTF8;
75 using base::android::ConvertUTF16ToJavaString; 75 using base::android::ConvertUTF16ToJavaString;
76 using base::android::ConvertUTF8ToJavaString; 76 using base::android::ConvertUTF8ToJavaString;
77 using base::android::JavaParamRef; 77 using base::android::JavaParamRef;
78 using base::android::JavaRef; 78 using base::android::JavaRef;
79 using base::android::ScopedJavaLocalRef; 79 using base::android::ScopedJavaLocalRef;
80 using blink::WebContextMenuData; 80 using blink::WebContextMenuData;
81 using blink::WebGestureEvent; 81 using blink::WebGestureEvent;
82 using blink::WebContextMenuData;
82 using blink::WebInputEvent; 83 using blink::WebInputEvent;
83 using ui::MotionEventAndroid; 84 using ui::MotionEventAndroid;
84 85
85 namespace content { 86 namespace content {
86 87
87 namespace { 88 namespace {
88 89
89 // Describes the type and enabled state of a select popup item. 90 // Describes the type and enabled state of a select popup item.
90 // 91 //
91 // A Java counterpart will be generated for this enum. 92 // A Java counterpart will be generated for this enum.
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 return Java_ContentViewCore_hasFocus(env, obj); 572 return Java_ContentViewCore_hasFocus(env, obj);
572 } 573 }
573 574
574 void ContentViewCoreImpl::RequestDisallowInterceptTouchEvent() { 575 void ContentViewCoreImpl::RequestDisallowInterceptTouchEvent() {
575 JNIEnv* env = AttachCurrentThread(); 576 JNIEnv* env = AttachCurrentThread();
576 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 577 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
577 if (!obj.is_null()) 578 if (!obj.is_null())
578 Java_ContentViewCore_requestDisallowInterceptTouchEvent(env, obj); 579 Java_ContentViewCore_requestDisallowInterceptTouchEvent(env, obj);
579 } 580 }
580 581
581 bool ContentViewCoreImpl::ShowPastePopup(const ContextMenuParams& params) { 582 bool ContentViewCoreImpl::ShowSelectionMenu(const ContextMenuParams& params) {
582 // Display paste pop-up only when selection is empty and editable. 583 // Display paste pop-up only when selection is empty and editable.
583 if (!(params.is_editable && params.selection_text.empty())) 584 const bool from_touch = params.source_type == ui::MENU_SOURCE_TOUCH ||
585 params.source_type == ui::MENU_SOURCE_LONG_PRESS ||
586 params.source_type == ui::MENU_SOURCE_TOUCH_HANDLE;
587 if (!from_touch || (!params.is_editable && params.selection_text.empty()))
584 return false; 588 return false;
585 589
586 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); 590 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
587 if (!view) 591 if (!view)
588 return false; 592 return false;
589 593
590 JNIEnv* env = AttachCurrentThread(); 594 JNIEnv* env = AttachCurrentThread();
591 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 595 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
592 if (obj.is_null()) 596 if (obj.is_null())
593 return false; 597 return false;
594 598
595 const bool can_select_all = 599 const bool can_select_all =
596 !!(params.edit_flags & WebContextMenuData::kCanSelectAll); 600 !!(params.edit_flags & WebContextMenuData::kCanSelectAll);
597 const bool can_edit_richly = 601 const bool can_edit_richly =
598 !!(params.edit_flags & blink::WebContextMenuData::kCanEditRichly); 602 !!(params.edit_flags & blink::WebContextMenuData::kCanEditRichly);
603 int handle_height = GetRenderWidgetHostViewAndroid()->GetTouchHandleHeight();
604 const bool is_password_type =
605 params.input_field_type ==
606 blink::WebContextMenuData::kInputFieldTypePassword;
607 const ScopedJavaLocalRef<jstring> jselected_text =
608 ConvertUTF16ToJavaString(env, params.selection_text);
609 const bool should_suggest =
610 params.source_type != ui::MENU_SOURCE_TOUCH_HANDLE;
599 611
600 int handle_height = GetRenderWidgetHostViewAndroid()->GetTouchHandleHeight(); 612 Java_ContentViewCore_showSelectionMenu(
601 Java_ContentViewCore_showPastePopup(
602 env, obj, params.selection_rect.x(), params.selection_rect.y(), 613 env, obj, params.selection_rect.x(), params.selection_rect.y(),
603 params.selection_rect.right(), 614 params.selection_rect.right(),
604 params.selection_rect.bottom() + handle_height, can_select_all, 615 params.selection_rect.bottom() + handle_height, params.is_editable,
605 can_edit_richly); 616 is_password_type, jselected_text, can_select_all, can_edit_richly,
617 should_suggest);
606 return true; 618 return true;
607 } 619 }
608 620
609 void ContentViewCoreImpl::ShowDisambiguationPopup( 621 void ContentViewCoreImpl::ShowDisambiguationPopup(
610 const gfx::Rect& rect_pixels, 622 const gfx::Rect& rect_pixels,
611 const SkBitmap& zoomed_bitmap) { 623 const SkBitmap& zoomed_bitmap) {
612 JNIEnv* env = AttachCurrentThread(); 624 JNIEnv* env = AttachCurrentThread();
613 625
614 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 626 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
615 if (obj.is_null()) 627 if (obj.is_null())
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 return ScopedJavaLocalRef<jobject>(); 1301 return ScopedJavaLocalRef<jobject>();
1290 1302
1291 return view->GetJavaObject(); 1303 return view->GetJavaObject();
1292 } 1304 }
1293 1305
1294 bool RegisterContentViewCore(JNIEnv* env) { 1306 bool RegisterContentViewCore(JNIEnv* env) {
1295 return RegisterNativesImpl(env); 1307 return RegisterNativesImpl(env);
1296 } 1308 }
1297 1309
1298 } // namespace content 1310 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698