| 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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 const gfx::Rect& bounds, | 491 const gfx::Rect& bounds, |
| 492 const std::vector<MenuItem>& items, | 492 const std::vector<MenuItem>& items, |
| 493 int selected_item, | 493 int selected_item, |
| 494 bool multiple, | 494 bool multiple, |
| 495 bool right_aligned) { | 495 bool right_aligned) { |
| 496 JNIEnv* env = AttachCurrentThread(); | 496 JNIEnv* env = AttachCurrentThread(); |
| 497 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 497 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 498 if (j_obj.is_null()) | 498 if (j_obj.is_null()) |
| 499 return; | 499 return; |
| 500 | 500 |
| 501 ScopedJavaLocalRef<jobject> bounds_rect(CreateJavaRect(env, bounds)); | |
| 502 | |
| 503 // For multi-select list popups we find the list of previous selections by | 501 // For multi-select list popups we find the list of previous selections by |
| 504 // iterating through the items. But for single selection popups we take the | 502 // iterating through the items. But for single selection popups we take the |
| 505 // given |selected_item| as is. | 503 // given |selected_item| as is. |
| 506 ScopedJavaLocalRef<jintArray> selected_array; | 504 ScopedJavaLocalRef<jintArray> selected_array; |
| 507 if (multiple) { | 505 if (multiple) { |
| 508 std::unique_ptr<jint[]> native_selected_array(new jint[items.size()]); | 506 std::unique_ptr<jint[]> native_selected_array(new jint[items.size()]); |
| 509 size_t selected_count = 0; | 507 size_t selected_count = 0; |
| 510 for (size_t i = 0; i < items.size(); ++i) { | 508 for (size_t i = 0; i < items.size(); ++i) { |
| 511 if (items[i].checked) | 509 if (items[i].checked) |
| 512 native_selected_array[selected_count++] = i; | 510 native_selected_array[selected_count++] = i; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 529 for (size_t i = 0; i < items.size(); ++i) { | 527 for (size_t i = 0; i < items.size(); ++i) { |
| 530 labels.push_back(items[i].label); | 528 labels.push_back(items[i].label); |
| 531 jint enabled = | 529 jint enabled = |
| 532 (items[i].type == MenuItem::GROUP ? POPUP_ITEM_TYPE_GROUP : | 530 (items[i].type == MenuItem::GROUP ? POPUP_ITEM_TYPE_GROUP : |
| 533 (items[i].enabled ? POPUP_ITEM_TYPE_ENABLED : | 531 (items[i].enabled ? POPUP_ITEM_TYPE_ENABLED : |
| 534 POPUP_ITEM_TYPE_DISABLED)); | 532 POPUP_ITEM_TYPE_DISABLED)); |
| 535 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 533 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
| 536 } | 534 } |
| 537 ScopedJavaLocalRef<jobjectArray> items_array( | 535 ScopedJavaLocalRef<jobjectArray> items_array( |
| 538 base::android::ToJavaArrayOfStrings(env, labels)); | 536 base::android::ToJavaArrayOfStrings(env, labels)); |
| 537 select_popup_ = view_.AcquireAnchorView(); |
| 538 const ScopedJavaLocalRef<jobject> popup_view = select_popup_.view(); |
| 539 if (popup_view.is_null()) |
| 540 return; |
| 541 view_.SetAnchorRect(popup_view, |
| 542 gfx::ScaleRect(gfx::RectF(bounds), page_scale_)); |
| 539 Java_ContentViewCore_showSelectPopup( | 543 Java_ContentViewCore_showSelectPopup( |
| 540 env, j_obj.obj(), reinterpret_cast<intptr_t>(frame), bounds_rect.obj(), | 544 env, j_obj.obj(), popup_view.obj(), reinterpret_cast<intptr_t>(frame), |
| 541 items_array.obj(), enabled_array.obj(), multiple, selected_array.obj(), | 545 items_array.obj(), enabled_array.obj(), multiple, selected_array.obj(), |
| 542 right_aligned); | 546 right_aligned); |
| 543 } | 547 } |
| 544 | 548 |
| 545 void ContentViewCoreImpl::HideSelectPopupMenu() { | 549 void ContentViewCoreImpl::HideSelectPopupMenu() { |
| 546 JNIEnv* env = AttachCurrentThread(); | 550 JNIEnv* env = AttachCurrentThread(); |
| 547 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 551 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 548 if (!j_obj.is_null()) | 552 if (!j_obj.is_null()) |
| 549 Java_ContentViewCore_hideSelectPopup(env, j_obj.obj()); | 553 Java_ContentViewCore_hideSelectPopup(env, j_obj.obj()); |
| 554 select_popup_.Reset(); |
| 550 } | 555 } |
| 551 | 556 |
| 552 void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event, | 557 void ContentViewCoreImpl::OnGestureEventAck(const blink::WebGestureEvent& event, |
| 553 InputEventAckState ack_result) { | 558 InputEventAckState ack_result) { |
| 554 JNIEnv* env = AttachCurrentThread(); | 559 JNIEnv* env = AttachCurrentThread(); |
| 555 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); | 560 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); |
| 556 if (j_obj.is_null()) | 561 if (j_obj.is_null()) |
| 557 return; | 562 return; |
| 558 | 563 |
| 559 switch (event.type) { | 564 switch (event.type) { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 return; | 856 return; |
| 852 | 857 |
| 853 gfx::Point base_point = gfx::ToRoundedPoint(base); | 858 gfx::Point base_point = gfx::ToRoundedPoint(base); |
| 854 gfx::Point extent_point = gfx::ToRoundedPoint(extent); | 859 gfx::Point extent_point = gfx::ToRoundedPoint(extent); |
| 855 if (base_point == extent_point) | 860 if (base_point == extent_point) |
| 856 return; | 861 return; |
| 857 | 862 |
| 858 web_contents_->SelectRange(base_point, extent_point); | 863 web_contents_->SelectRange(base_point, extent_point); |
| 859 } | 864 } |
| 860 | 865 |
| 861 const base::android::JavaRef<jobject>& | |
| 862 ContentViewCoreImpl::GetViewAndroidDelegate() const { | |
| 863 return view_.GetViewAndroidDelegate(); | |
| 864 } | |
| 865 | |
| 866 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { | 866 ui::WindowAndroid* ContentViewCoreImpl::GetWindowAndroid() const { |
| 867 return view_.GetWindowAndroid(); | 867 return view_.GetWindowAndroid(); |
| 868 } | 868 } |
| 869 | 869 |
| 870 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() { | 870 ui::ViewAndroid* ContentViewCoreImpl::GetViewAndroid() { |
| 871 return &view_; | 871 return &view_; |
| 872 } | 872 } |
| 873 | 873 |
| 874 | 874 |
| 875 // ---------------------------------------------------------------------------- | 875 // ---------------------------------------------------------------------------- |
| (...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1637 return ScopedJavaLocalRef<jobject>(); | 1637 return ScopedJavaLocalRef<jobject>(); |
| 1638 | 1638 |
| 1639 return view->GetJavaObject(); | 1639 return view->GetJavaObject(); |
| 1640 } | 1640 } |
| 1641 | 1641 |
| 1642 bool RegisterContentViewCore(JNIEnv* env) { | 1642 bool RegisterContentViewCore(JNIEnv* env) { |
| 1643 return RegisterNativesImpl(env) && JNI_DragEvent::RegisterNativesImpl(env); | 1643 return RegisterNativesImpl(env) && JNI_DragEvent::RegisterNativesImpl(env); |
| 1644 } | 1644 } |
| 1645 | 1645 |
| 1646 } // namespace content | 1646 } // namespace content |
| OLD | NEW |