| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 using base::android::AttachCurrentThread; | 68 using base::android::AttachCurrentThread; |
| 69 using base::android::ConvertJavaStringToUTF16; | 69 using base::android::ConvertJavaStringToUTF16; |
| 70 using base::android::ConvertJavaStringToUTF8; | 70 using base::android::ConvertJavaStringToUTF8; |
| 71 using base::android::ConvertUTF16ToJavaString; | 71 using base::android::ConvertUTF16ToJavaString; |
| 72 using base::android::ConvertUTF8ToJavaString; | 72 using base::android::ConvertUTF8ToJavaString; |
| 73 using base::android::JavaParamRef; | 73 using base::android::JavaParamRef; |
| 74 using base::android::JavaRef; | 74 using base::android::JavaRef; |
| 75 using base::android::ScopedJavaLocalRef; | 75 using base::android::ScopedJavaLocalRef; |
| 76 using blink::WebContextMenuData; | 76 using blink::WebContextMenuData; |
| 77 using blink::WebGestureEvent; | 77 using blink::WebGestureEvent; |
| 78 using blink::WebContextMenuData; |
| 78 using blink::WebInputEvent; | 79 using blink::WebInputEvent; |
| 79 | 80 |
| 80 namespace content { | 81 namespace content { |
| 81 | 82 |
| 82 namespace { | 83 namespace { |
| 83 | 84 |
| 84 // Describes the type and enabled state of a select popup item. | 85 // Describes the type and enabled state of a select popup item. |
| 85 // | 86 // |
| 86 // A Java counterpart will be generated for this enum. | 87 // A Java counterpart will be generated for this enum. |
| 87 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.content.browser.input | 88 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.content.browser.input |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 return Java_ContentViewCore_hasFocus(env, obj); | 567 return Java_ContentViewCore_hasFocus(env, obj); |
| 567 } | 568 } |
| 568 | 569 |
| 569 void ContentViewCoreImpl::RequestDisallowInterceptTouchEvent() { | 570 void ContentViewCoreImpl::RequestDisallowInterceptTouchEvent() { |
| 570 JNIEnv* env = AttachCurrentThread(); | 571 JNIEnv* env = AttachCurrentThread(); |
| 571 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 572 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 572 if (!obj.is_null()) | 573 if (!obj.is_null()) |
| 573 Java_ContentViewCore_requestDisallowInterceptTouchEvent(env, obj); | 574 Java_ContentViewCore_requestDisallowInterceptTouchEvent(env, obj); |
| 574 } | 575 } |
| 575 | 576 |
| 576 bool ContentViewCoreImpl::ShowPastePopup(const ContextMenuParams& params) { | 577 bool ContentViewCoreImpl::ShowSelectionMenu(const ContextMenuParams& params) { |
| 577 // Display paste pop-up only when selection is empty and editable. | 578 // Display paste pop-up only when selection is empty and editable. |
| 578 if (!(params.is_editable && params.selection_text.empty())) | 579 const bool from_touch = params.source_type == ui::MENU_SOURCE_TOUCH || |
| 580 params.source_type == ui::MENU_SOURCE_LONG_PRESS || |
| 581 params.source_type == ui::MENU_SOURCE_TOUCH_HANDLE || |
| 582 params.source_type == ui::MENU_SOURCE_STYLUS; |
| 583 if (!from_touch || (!params.is_editable && params.selection_text.empty())) |
| 579 return false; | 584 return false; |
| 580 | 585 |
| 581 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); | 586 RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid(); |
| 582 if (!view) | 587 if (!view) |
| 583 return false; | 588 return false; |
| 584 | 589 |
| 585 JNIEnv* env = AttachCurrentThread(); | 590 JNIEnv* env = AttachCurrentThread(); |
| 586 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 591 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 587 if (obj.is_null()) | 592 if (obj.is_null()) |
| 588 return false; | 593 return false; |
| 589 | 594 |
| 590 const bool can_select_all = | 595 const bool can_select_all = |
| 591 !!(params.edit_flags & WebContextMenuData::kCanSelectAll); | 596 !!(params.edit_flags & WebContextMenuData::kCanSelectAll); |
| 592 const bool can_edit_richly = | 597 const bool can_edit_richly = |
| 593 !!(params.edit_flags & blink::WebContextMenuData::kCanEditRichly); | 598 !!(params.edit_flags & blink::WebContextMenuData::kCanEditRichly); |
| 599 int handle_height = GetRenderWidgetHostViewAndroid()->GetTouchHandleHeight(); |
| 600 const bool is_password_type = |
| 601 params.input_field_type == |
| 602 blink::WebContextMenuData::kInputFieldTypePassword; |
| 603 const ScopedJavaLocalRef<jstring> jselected_text = |
| 604 ConvertUTF16ToJavaString(env, params.selection_text); |
| 605 const bool should_suggest = params.source_type == ui::MENU_SOURCE_TOUCH || |
| 606 params.source_type == ui::MENU_SOURCE_LONG_PRESS; |
| 594 | 607 |
| 595 int handle_height = GetRenderWidgetHostViewAndroid()->GetTouchHandleHeight(); | 608 Java_ContentViewCore_showSelectionMenu( |
| 596 Java_ContentViewCore_showPastePopup( | |
| 597 env, obj, params.selection_rect.x(), params.selection_rect.y(), | 609 env, obj, params.selection_rect.x(), params.selection_rect.y(), |
| 598 params.selection_rect.right(), | 610 params.selection_rect.right(), |
| 599 params.selection_rect.bottom() + handle_height, can_select_all, | 611 params.selection_rect.bottom() + handle_height, params.is_editable, |
| 600 can_edit_richly); | 612 is_password_type, jselected_text, can_select_all, can_edit_richly, |
| 613 should_suggest); |
| 601 return true; | 614 return true; |
| 602 } | 615 } |
| 603 | 616 |
| 604 void ContentViewCoreImpl::ShowDisambiguationPopup( | 617 void ContentViewCoreImpl::ShowDisambiguationPopup( |
| 605 const gfx::Rect& rect_pixels, | 618 const gfx::Rect& rect_pixels, |
| 606 const SkBitmap& zoomed_bitmap) { | 619 const SkBitmap& zoomed_bitmap) { |
| 607 JNIEnv* env = AttachCurrentThread(); | 620 JNIEnv* env = AttachCurrentThread(); |
| 608 | 621 |
| 609 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 622 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 610 if (obj.is_null()) | 623 if (obj.is_null()) |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 return ScopedJavaLocalRef<jobject>(); | 1229 return ScopedJavaLocalRef<jobject>(); |
| 1217 | 1230 |
| 1218 return view->GetJavaObject(); | 1231 return view->GetJavaObject(); |
| 1219 } | 1232 } |
| 1220 | 1233 |
| 1221 bool RegisterContentViewCore(JNIEnv* env) { | 1234 bool RegisterContentViewCore(JNIEnv* env) { |
| 1222 return RegisterNativesImpl(env); | 1235 return RegisterNativesImpl(env); |
| 1223 } | 1236 } |
| 1224 | 1237 |
| 1225 } // namespace content | 1238 } // namespace content |
| OLD | NEW |