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 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 const gfx::Rect& bounds, | 498 const gfx::Rect& bounds, |
499 const std::vector<MenuItem>& items, | 499 const std::vector<MenuItem>& items, |
500 int selected_item, | 500 int selected_item, |
501 bool multiple, | 501 bool multiple, |
502 bool right_aligned) { | 502 bool right_aligned) { |
503 JNIEnv* env = AttachCurrentThread(); | 503 JNIEnv* env = AttachCurrentThread(); |
504 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 504 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
505 if (j_obj.is_null()) | 505 if (j_obj.is_null()) |
506 return; | 506 return; |
507 | 507 |
508 ScopedJavaLocalRef<jobject> bounds_rect(CreateJavaRect(env, bounds)); | |
509 | |
510 // For multi-select list popups we find the list of previous selections by | 508 // For multi-select list popups we find the list of previous selections by |
511 // iterating through the items. But for single selection popups we take the | 509 // iterating through the items. But for single selection popups we take the |
512 // given |selected_item| as is. | 510 // given |selected_item| as is. |
513 ScopedJavaLocalRef<jintArray> selected_array; | 511 ScopedJavaLocalRef<jintArray> selected_array; |
514 if (multiple) { | 512 if (multiple) { |
515 std::unique_ptr<jint[]> native_selected_array(new jint[items.size()]); | 513 std::unique_ptr<jint[]> native_selected_array(new jint[items.size()]); |
516 size_t selected_count = 0; | 514 size_t selected_count = 0; |
517 for (size_t i = 0; i < items.size(); ++i) { | 515 for (size_t i = 0; i < items.size(); ++i) { |
518 if (items[i].checked) | 516 if (items[i].checked) |
519 native_selected_array[selected_count++] = i; | 517 native_selected_array[selected_count++] = i; |
(...skipping 16 matching lines...) Expand all Loading... |
536 for (size_t i = 0; i < items.size(); ++i) { | 534 for (size_t i = 0; i < items.size(); ++i) { |
537 labels.push_back(items[i].label); | 535 labels.push_back(items[i].label); |
538 jint enabled = | 536 jint enabled = |
539 (items[i].type == MenuItem::GROUP ? POPUP_ITEM_TYPE_GROUP : | 537 (items[i].type == MenuItem::GROUP ? POPUP_ITEM_TYPE_GROUP : |
540 (items[i].enabled ? POPUP_ITEM_TYPE_ENABLED : | 538 (items[i].enabled ? POPUP_ITEM_TYPE_ENABLED : |
541 POPUP_ITEM_TYPE_DISABLED)); | 539 POPUP_ITEM_TYPE_DISABLED)); |
542 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 540 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
543 } | 541 } |
544 ScopedJavaLocalRef<jobjectArray> items_array( | 542 ScopedJavaLocalRef<jobjectArray> items_array( |
545 base::android::ToJavaArrayOfStrings(env, labels)); | 543 base::android::ToJavaArrayOfStrings(env, labels)); |
| 544 select_popup_ = view_.AcquireAnchorView(); |
| 545 if (select_popup_.is_null()) |
| 546 return; |
| 547 view_.SetAnchorRect(select_popup_.view(env), |
| 548 gfx::ScaleRect(gfx::RectF(bounds), page_scale_)); |
546 Java_ContentViewCore_showSelectPopup( | 549 Java_ContentViewCore_showSelectPopup( |
547 env, j_obj.obj(), reinterpret_cast<intptr_t>(frame), bounds_rect.obj(), | 550 env, j_obj.obj(), select_popup_.view(env).obj(), |
| 551 bounds.width() * page_scale_, reinterpret_cast<intptr_t>(frame), |
548 items_array.obj(), enabled_array.obj(), multiple, selected_array.obj(), | 552 items_array.obj(), enabled_array.obj(), multiple, selected_array.obj(), |
549 right_aligned); | 553 right_aligned); |
550 } | 554 } |
551 | 555 |
552 void ContentViewCoreImpl::HideSelectPopupMenu() { | 556 void ContentViewCoreImpl::HideSelectPopupMenu() { |
553 JNIEnv* env = AttachCurrentThread(); | 557 JNIEnv* env = AttachCurrentThread(); |
554 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 558 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
555 if (!j_obj.is_null()) | 559 if (!j_obj.is_null()) |
556 Java_ContentViewCore_hideSelectPopup(env, j_obj.obj()); | 560 Java_ContentViewCore_hideSelectPopup(env, j_obj.obj()); |
| 561 if (!select_popup_.is_null()) |
| 562 select_popup_.Reset(); |
557 } | 563 } |
558 | 564 |
559 void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event, | 565 void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event, |
560 InputEventAckState ack_result) { | 566 InputEventAckState ack_result) { |
561 JNIEnv* env = AttachCurrentThread(); | 567 JNIEnv* env = AttachCurrentThread(); |
562 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 568 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
563 if (j_obj.is_null()) | 569 if (j_obj.is_null()) |
564 return; | 570 return; |
565 | 571 |
566 switch (event.type) { | 572 switch (event.type) { |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 return; | 864 return; |
859 | 865 |
860 gfx::Point base_point = gfx::ToRoundedPoint(base); | 866 gfx::Point base_point = gfx::ToRoundedPoint(base); |
861 gfx::Point extent_point = gfx::ToRoundedPoint(extent); | 867 gfx::Point extent_point = gfx::ToRoundedPoint(extent); |
862 if (base_point == extent_point) | 868 if (base_point == extent_point) |
863 return; | 869 return; |
864 | 870 |
865 web_contents_->SelectRange(base_point, extent_point); | 871 web_contents_->SelectRange(base_point, extent_point); |
866 } | 872 } |
867 | 873 |
868 const base::android::JavaRef<jobject>& | |
869 ContentViewCoreImpl::GetViewAndroidDelegate() const { | |
870 return view_.GetViewAndroidDelegate(); | |
871 } | |
872 | |
873 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { | 874 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { |
874 return view_.GetWindowAndroid(); | 875 return view_.GetWindowAndroid(); |
875 } | 876 } |
876 | 877 |
877 cc::Layer* ContentViewCoreImpl::GetLayer() const { | 878 cc::Layer* ContentViewCoreImpl::GetLayer() const { |
878 return view_.GetLayer(); | 879 return view_.GetLayer(); |
879 } | 880 } |
880 | 881 |
881 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() { | 882 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() { |
882 return &view_; | 883 return &view_; |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1648 return ScopedJavaLocalRef<jobject>(); | 1649 return ScopedJavaLocalRef<jobject>(); |
1649 | 1650 |
1650 return view->GetJavaObject(); | 1651 return view->GetJavaObject(); |
1651 } | 1652 } |
1652 | 1653 |
1653 bool RegisterContentViewCore(JNIEnv* env) { | 1654 bool RegisterContentViewCore(JNIEnv* env) { |
1654 return RegisterNativesImpl(env) && JNI_DragEvent::RegisterNativesImpl(env); | 1655 return RegisterNativesImpl(env) && JNI_DragEvent::RegisterNativesImpl(env); |
1655 } | 1656 } |
1656 | 1657 |
1657 } // namespace content | 1658 } // namespace content |
OLD | NEW |