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