1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.android_webview;
7 import android.view.ViewGroup;
9 import org.chromium.base.CalledByNative;
10 import org.chromium.base.JNINamespace;
11 import org.chromium.content.browser.ContentViewCore;
12 import org.chromium.ui.DropdownItem;
13 import org.chromium.ui.autofill.AutofillPopup;
14 import org.chromium.ui.autofill.AutofillSuggestion;
17 * Java counterpart to the AwAutofillClient. This class is owned by AwContents and has
18 * a weak reference from native side.
20 @JNINamespace("android_webview")
21 public class AwAutofillClient {
23 private final long mNativeAwAutofillClient;
24 private AutofillPopup mAutofillPopup;
25 private ViewGroup mContainerView;
26 private ContentViewCore mContentViewCore;
29 public static AwAutofillClient create(long nativeClient) {
30 return new AwAutofillClient(nativeClient);
33 private AwAutofillClient(long nativeAwAutofillClient) {
34 mNativeAwAutofillClient = nativeAwAutofillClient;
37 public void init(ContentViewCore contentViewCore) {
38 mContentViewCore = contentViewCore;
39 mContainerView = contentViewCore.getContainerView();
43 private void showAutofillPopup(float x, float y, float width, float height,
44 boolean isRtl, AutofillSuggestion[] suggestions) {
46 if (mContentViewCore == null) return;
48 if (mAutofillPopup == null) {
49 mAutofillPopup = new AutofillPopup(
50 mContentViewCore.getContext(),
51 mContentViewCore.getViewAndroidDelegate(),
52 new AutofillPopup.AutofillPopupDelegate() {
54 public void dismissed() { }
56 public void suggestionSelected(int listIndex) {
57 nativeSuggestionSelected(mNativeAwAutofillClient, listIndex);
61 mAutofillPopup.setAnchorRect(x, y, width, height);
62 mAutofillPopup.filterAndShow(suggestions, isRtl);
66 public void hideAutofillPopup() {
67 if (mAutofillPopup == null)
69 mAutofillPopup.hide();
70 mAutofillPopup = null;
74 private static AutofillSuggestion[] createAutofillSuggestionArray(int size) {
75 return new AutofillSuggestion[size];
79 * @param array AutofillSuggestion array that should get a new suggestion added.
80 * @param index Index in the array where to place a new suggestion.
81 * @param name Name of the suggestion.
82 * @param label Label of the suggestion.
83 * @param uniqueId Unique suggestion id.
86 private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index,
87 String name, String label, int uniqueId) {
88 array[index] = new AutofillSuggestion(name, label, DropdownItem.NO_ICON, uniqueId);
91 private native void nativeSuggestionSelected(long nativeAwAutofillClient,