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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 const gfx::Rect& bounds, | 492 const gfx::Rect& bounds, |
493 const std::vector<MenuItem>& items, | 493 const std::vector<MenuItem>& items, |
494 int selected_item, | 494 int selected_item, |
495 bool multiple, | 495 bool multiple, |
496 bool right_aligned) { | 496 bool right_aligned) { |
497 JNIEnv* env = AttachCurrentThread(); | 497 JNIEnv* env = AttachCurrentThread(); |
498 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 498 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
499 if (j_obj.is_null()) | 499 if (j_obj.is_null()) |
500 return; | 500 return; |
501 | 501 |
502 ScopedJavaLocalRef<jobject> bounds_rect(CreateJavaRect(env, bounds)); | |
503 | |
504 // For multi-select list popups we find the list of previous selections by | 502 // For multi-select list popups we find the list of previous selections by |
505 // iterating through the items. But for single selection popups we take the | 503 // iterating through the items. But for single selection popups we take the |
506 // given |selected_item| as is. | 504 // given |selected_item| as is. |
507 ScopedJavaLocalRef<jintArray> selected_array; | 505 ScopedJavaLocalRef<jintArray> selected_array; |
508 if (multiple) { | 506 if (multiple) { |
509 std::unique_ptr<jint[]> native_selected_array(new jint[items.size()]); | 507 std::unique_ptr<jint[]> native_selected_array(new jint[items.size()]); |
510 size_t selected_count = 0; | 508 size_t selected_count = 0; |
511 for (size_t i = 0; i < items.size(); ++i) { | 509 for (size_t i = 0; i < items.size(); ++i) { |
512 if (items[i].checked) | 510 if (items[i].checked) |
513 native_selected_array[selected_count++] = i; | 511 native_selected_array[selected_count++] = i; |
(...skipping 16 matching lines...) Expand all Loading... |
530 for (size_t i = 0; i < items.size(); ++i) { | 528 for (size_t i = 0; i < items.size(); ++i) { |
531 labels.push_back(items[i].label); | 529 labels.push_back(items[i].label); |
532 jint enabled = | 530 jint enabled = |
533 (items[i].type == MenuItem::GROUP ? POPUP_ITEM_TYPE_GROUP : | 531 (items[i].type == MenuItem::GROUP ? POPUP_ITEM_TYPE_GROUP : |
534 (items[i].enabled ? POPUP_ITEM_TYPE_ENABLED : | 532 (items[i].enabled ? POPUP_ITEM_TYPE_ENABLED : |
535 POPUP_ITEM_TYPE_DISABLED)); | 533 POPUP_ITEM_TYPE_DISABLED)); |
536 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 534 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
537 } | 535 } |
538 ScopedJavaLocalRef<jobjectArray> items_array( | 536 ScopedJavaLocalRef<jobjectArray> items_array( |
539 base::android::ToJavaArrayOfStrings(env, labels)); | 537 base::android::ToJavaArrayOfStrings(env, labels)); |
| 538 ScopedJavaLocalRef<jobject> anchor_view = AcquireAnchorView( |
| 539 gfx::RectF(bounds.x() * page_scale_, |
| 540 bounds.y() * page_scale_, |
| 541 bounds.width() * page_scale_, |
| 542 bounds.height() * page_scale_)); |
540 Java_ContentViewCore_showSelectPopup( | 543 Java_ContentViewCore_showSelectPopup( |
541 env, j_obj.obj(), reinterpret_cast<intptr_t>(frame), bounds_rect.obj(), | 544 env, j_obj.obj(), anchor_view.obj(), bounds.width() * page_scale_, |
| 545 reinterpret_cast<intptr_t>(frame), |
542 items_array.obj(), enabled_array.obj(), multiple, selected_array.obj(), | 546 items_array.obj(), enabled_array.obj(), multiple, selected_array.obj(), |
543 right_aligned); | 547 right_aligned); |
544 } | 548 } |
545 | 549 |
| 550 ScopedJavaLocalRef<jobject> |
| 551 ContentViewCoreImpl::AcquireAnchorView(const gfx::RectF& bounds) { |
| 552 JNIEnv* env = AttachCurrentThread(); |
| 553 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 554 if (j_obj.is_null()) |
| 555 return ScopedJavaLocalRef<jobject>(); |
| 556 return Java_ContentViewCore_acquireAnchorView( |
| 557 env, j_obj.obj(), bounds.x(), bounds.y(), bounds.width(), |
| 558 bounds.height()); |
| 559 } |
| 560 |
546 void ContentViewCoreImpl::HideSelectPopupMenu() { | 561 void ContentViewCoreImpl::HideSelectPopupMenu() { |
547 JNIEnv* env = AttachCurrentThread(); | 562 JNIEnv* env = AttachCurrentThread(); |
548 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 563 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
549 if (!j_obj.is_null()) | 564 if (!j_obj.is_null()) |
550 Java_ContentViewCore_hideSelectPopup(env, j_obj.obj()); | 565 Java_ContentViewCore_hideSelectPopup(env, j_obj.obj()); |
551 } | 566 } |
552 | 567 |
553 void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event, | 568 void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event, |
554 InputEventAckState ack_result) { | 569 InputEventAckState ack_result) { |
555 JNIEnv* env = AttachCurrentThread(); | 570 JNIEnv* env = AttachCurrentThread(); |
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1581 return ScopedJavaLocalRef<jobject>(); | 1596 return ScopedJavaLocalRef<jobject>(); |
1582 | 1597 |
1583 return view->GetJavaObject(); | 1598 return view->GetJavaObject(); |
1584 } | 1599 } |
1585 | 1600 |
1586 bool RegisterContentViewCore(JNIEnv* env) { | 1601 bool RegisterContentViewCore(JNIEnv* env) { |
1587 return RegisterNativesImpl(env); | 1602 return RegisterNativesImpl(env); |
1588 } | 1603 } |
1589 | 1604 |
1590 } // namespace content | 1605 } // namespace content |
OLD | NEW |