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 <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 Loading... |
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 Loading... |
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 params.source_type == ui::MENU_SOURCE_SELECT_ALL; |
| 588 if (!from_touch || (!params.is_editable && params.selection_text.empty())) |
584 return false; | 589 return false; |
585 | 590 |
586 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 591 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
587 if (!view) | 592 if (!view) |
588 return false; | 593 return false; |
589 | 594 |
590 JNIEnv* env = AttachCurrentThread(); | 595 JNIEnv* env = AttachCurrentThread(); |
591 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 596 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
592 if (obj.is_null()) | 597 if (obj.is_null()) |
593 return false; | 598 return false; |
594 | 599 |
595 const bool can_select_all = | 600 const bool can_select_all = |
596 !!(params.edit_flags & WebContextMenuData::kCanSelectAll); | 601 !!(params.edit_flags & WebContextMenuData::kCanSelectAll); |
597 const bool can_edit_richly = | 602 const bool can_edit_richly = |
598 !!(params.edit_flags & blink::WebContextMenuData::kCanEditRichly); | 603 !!(params.edit_flags & blink::WebContextMenuData::kCanEditRichly); |
| 604 int handle_height = GetRenderWidgetHostViewAndroid()->GetTouchHandleHeight(); |
| 605 const bool is_password_type = |
| 606 params.input_field_type == |
| 607 blink::WebContextMenuData::kInputFieldTypePassword; |
| 608 const ScopedJavaLocalRef<jstring> jselected_text = |
| 609 ConvertUTF16ToJavaString(env, params.selection_text); |
| 610 const bool should_suggest = |
| 611 !(params.source_type == ui::MENU_SOURCE_TOUCH_HANDLE || |
| 612 params.source_type == ui::MENU_SOURCE_SELECT_ALL); |
599 | 613 |
600 int handle_height = GetRenderWidgetHostViewAndroid()->GetTouchHandleHeight(); | 614 Java_ContentViewCore_showSelectionMenu( |
601 Java_ContentViewCore_showPastePopup( | |
602 env, obj, params.selection_rect.x(), params.selection_rect.y(), | 615 env, obj, params.selection_rect.x(), params.selection_rect.y(), |
603 params.selection_rect.right(), | 616 params.selection_rect.right(), |
604 params.selection_rect.bottom() + handle_height, can_select_all, | 617 params.selection_rect.bottom() + handle_height, params.is_editable, |
605 can_edit_richly); | 618 is_password_type, jselected_text, can_select_all, can_edit_richly, |
| 619 should_suggest); |
606 return true; | 620 return true; |
607 } | 621 } |
608 | 622 |
609 void ContentViewCoreImpl::ShowDisambiguationPopup( | 623 void ContentViewCoreImpl::ShowDisambiguationPopup( |
610 const gfx::Rect& rect_pixels, | 624 const gfx::Rect& rect_pixels, |
611 const SkBitmap& zoomed_bitmap) { | 625 const SkBitmap& zoomed_bitmap) { |
612 JNIEnv* env = AttachCurrentThread(); | 626 JNIEnv* env = AttachCurrentThread(); |
613 | 627 |
614 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 628 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
615 if (obj.is_null()) | 629 if (obj.is_null()) |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1289 return ScopedJavaLocalRef<jobject>(); | 1303 return ScopedJavaLocalRef<jobject>(); |
1290 | 1304 |
1291 return view->GetJavaObject(); | 1305 return view->GetJavaObject(); |
1292 } | 1306 } |
1293 | 1307 |
1294 bool RegisterContentViewCore(JNIEnv* env) { | 1308 bool RegisterContentViewCore(JNIEnv* env) { |
1295 return RegisterNativesImpl(env); | 1309 return RegisterNativesImpl(env); |
1296 } | 1310 } |
1297 | 1311 |
1298 } // namespace content | 1312 } // namespace content |
OLD | NEW |