Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 package org.chromium.chrome.browser.autofill; | 5 package org.chromium.chrome.browser.autofill; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
| 10 import android.os.Handler; | 10 import android.os.Handler; |
| 11 import android.support.v7.app.AlertDialog; | 11 import android.support.v7.app.AlertDialog; |
| 12 import android.view.View; | 12 import android.view.View; |
| 13 | 13 |
| 14 import org.chromium.base.annotations.CalledByNative; | 14 import org.chromium.base.annotations.CalledByNative; |
| 15 import org.chromium.base.annotations.JNINamespace; | 15 import org.chromium.base.annotations.JNINamespace; |
| 16 import org.chromium.chrome.R; | 16 import org.chromium.chrome.R; |
| 17 import org.chromium.chrome.browser.ChromeActivity; | |
| 17 import org.chromium.chrome.browser.ResourceId; | 18 import org.chromium.chrome.browser.ResourceId; |
| 18 import org.chromium.components.autofill.AutofillDelegate; | 19 import org.chromium.components.autofill.AutofillDelegate; |
| 19 import org.chromium.components.autofill.AutofillPopup; | 20 import org.chromium.components.autofill.AutofillPopup; |
| 20 import org.chromium.components.autofill.AutofillSuggestion; | 21 import org.chromium.components.autofill.AutofillSuggestion; |
| 22 import org.chromium.content.browser.accessibility.BrowserAccessibilityManager; | |
| 23 import org.chromium.content.browser.ContentViewCore; | |
| 21 import org.chromium.ui.DropdownItem; | 24 import org.chromium.ui.DropdownItem; |
| 22 import org.chromium.ui.base.WindowAndroid; | 25 import org.chromium.ui.base.WindowAndroid; |
| 23 | 26 |
| 24 /** | 27 /** |
| 25 * JNI call glue for AutofillExternalDelagate C++ and Java objects. | 28 * JNI call glue for AutofillExternalDelagate C++ and Java objects. |
| 26 */ | 29 */ |
| 27 @JNINamespace("autofill") | 30 @JNINamespace("autofill") |
| 28 public class AutofillPopupBridge implements AutofillDelegate, DialogInterface.On ClickListener { | 31 public class AutofillPopupBridge implements AutofillDelegate, DialogInterface.On ClickListener { |
| 29 private final long mNativeAutofillPopup; | 32 private final long mNativeAutofillPopup; |
| 30 private final AutofillPopup mAutofillPopup; | 33 private final AutofillPopup mAutofillPopup; |
| 31 private AlertDialog mDeletionDialog; | 34 private AlertDialog mDeletionDialog; |
| 32 private final Context mContext; | 35 private final Context mContext; |
| 36 private BrowserAccessibilityManager mBrowserAccessibilityManager = null; | |
| 33 | 37 |
| 34 public AutofillPopupBridge(View anchorView, long nativeAutofillPopupViewAndr oid, | 38 public AutofillPopupBridge(View anchorView, long nativeAutofillPopupViewAndr oid, |
| 35 WindowAndroid windowAndroid) { | 39 WindowAndroid windowAndroid) { |
| 36 mNativeAutofillPopup = nativeAutofillPopupViewAndroid; | 40 mNativeAutofillPopup = nativeAutofillPopupViewAndroid; |
| 37 Activity activity = windowAndroid.getActivity().get(); | 41 Activity activity = windowAndroid.getActivity().get(); |
| 38 if (activity == null) { | 42 if (activity == null) { |
| 39 mAutofillPopup = null; | 43 mAutofillPopup = null; |
| 40 mContext = null; | 44 mContext = null; |
| 41 // Clean up the native counterpart. This is posted to allow the nat ive counterpart | 45 // Clean up the native counterpart. This is posted to allow the nat ive counterpart |
| 42 // to fully finish the construction of this glue object before we at tempt to delete it. | 46 // to fully finish the construction of this glue object before we at tempt to delete it. |
| 43 new Handler().post(new Runnable() { | 47 new Handler().post(new Runnable() { |
| 44 @Override | 48 @Override |
| 45 public void run() { | 49 public void run() { |
| 46 dismissed(); | 50 dismissed(); |
| 47 } | 51 } |
| 48 }); | 52 }); |
| 49 } else { | 53 } else { |
| 50 mAutofillPopup = new AutofillPopup(activity, anchorView, this); | 54 mAutofillPopup = new AutofillPopup(activity, anchorView, this); |
| 51 mContext = activity; | 55 mContext = activity; |
| 56 ChromeActivity chromeActivity = (ChromeActivity) activity; | |
| 57 ContentViewCore contentViewCore = chromeActivity.getCurrentContentVi ewCore(); | |
| 58 mBrowserAccessibilityManager = contentViewCore.getBrowserAccessibili tyManager(); | |
| 52 } | 59 } |
| 53 } | 60 } |
| 54 | 61 |
| 55 @CalledByNative | 62 @CalledByNative |
| 56 private static AutofillPopupBridge create(View anchorView, long nativeAutofi llPopupViewAndroid, | 63 private static AutofillPopupBridge create(View anchorView, long nativeAutofi llPopupViewAndroid, |
| 57 WindowAndroid windowAndroid) { | 64 WindowAndroid windowAndroid) { |
| 58 return new AutofillPopupBridge(anchorView, nativeAutofillPopupViewAndroi d, | 65 return new AutofillPopupBridge(anchorView, nativeAutofillPopupViewAndroi d, |
| 59 windowAndroid); | 66 windowAndroid); |
| 60 } | 67 } |
| 61 | 68 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 80 nativeDeletionConfirmed(mNativeAutofillPopup); | 87 nativeDeletionConfirmed(mNativeAutofillPopup); |
| 81 } | 88 } |
| 82 | 89 |
| 83 /** | 90 /** |
| 84 * Hides the Autofill Popup and removes its anchor from the ContainerView. | 91 * Hides the Autofill Popup and removes its anchor from the ContainerView. |
| 85 */ | 92 */ |
| 86 @CalledByNative | 93 @CalledByNative |
| 87 private void dismiss() { | 94 private void dismiss() { |
| 88 if (mAutofillPopup != null) mAutofillPopup.dismiss(); | 95 if (mAutofillPopup != null) mAutofillPopup.dismiss(); |
| 89 if (mDeletionDialog != null) mDeletionDialog.dismiss(); | 96 if (mDeletionDialog != null) mDeletionDialog.dismiss(); |
| 97 if (mBrowserAccessibilityManager != null) { | |
| 98 mBrowserAccessibilityManager.OnAutofillPopupDismissed(); | |
| 99 } | |
| 90 } | 100 } |
| 91 | 101 |
| 92 /** | 102 /** |
| 93 * Shows an Autofill popup with specified suggestions. | 103 * Shows an Autofill popup with specified suggestions. |
| 94 * @param suggestions Autofill suggestions to be displayed. | 104 * @param suggestions Autofill suggestions to be displayed. |
| 95 * @param isRtl @code true if right-to-left text. | 105 * @param isRtl @code true if right-to-left text. |
| 96 * @param backgroundColor popup background color, or {@code Color.TRANSPAREN T} if not specified | 106 * @param backgroundColor popup background color, or {@code Color.TRANSPAREN T} if not specified |
| 97 * in experiment. | 107 * in experiment. |
| 98 * @param dividerColor color for divider between popup items, or {@code Colo r.TRANSPARENT} if | 108 * @param dividerColor color for divider between popup items, or {@code Colo r.TRANSPARENT} if |
| 99 * not specified in experiment. | 109 * not specified in experiment. |
| 100 * @param dropdownItemHeight height of each dropdown item in dimension indep endent pixel units, | 110 * @param dropdownItemHeight height of each dropdown item in dimension indep endent pixel units, |
| 101 * 0 if not specified in experiment. | 111 * 0 if not specified in experiment. |
| 102 * @param margin Margin for icon, label and between icon and label in dimens ion independent | 112 * @param margin Margin for icon, label and between icon and label in dimens ion independent |
| 103 * pixel units, 0 if not specified in experiment. | 113 * pixel units, 0 if not specified in experiment. |
| 104 */ | 114 */ |
| 105 @CalledByNative | 115 @CalledByNative |
| 106 private void show(AutofillSuggestion[] suggestions, boolean isRtl, int backg roundColor, | 116 private void show(AutofillSuggestion[] suggestions, boolean isRtl, int backg roundColor, |
| 107 int dividerColor, int dropdownItemHeight, int margin) { | 117 int dividerColor, int dropdownItemHeight, int margin) { |
| 108 if (mAutofillPopup != null) mAutofillPopup.filterAndShow(suggestions, is Rtl, | 118 if (mAutofillPopup != null) { |
| 109 backgroundColor, dividerColor, dropdownItemHeight, margin); | 119 mAutofillPopup.filterAndShow( |
| 120 suggestions, isRtl, backgroundColor, dividerColor, dropdownI temHeight, margin); | |
| 121 if (mBrowserAccessibilityManager != null) { | |
| 122 mBrowserAccessibilityManager.OnAutofillPopupDisplayed(); | |
|
dmazzoni
2017/03/22 16:13:54
Would it make sense to pass the pop-up View to Bro
csashi
2017/03/24 01:32:23
Done.
| |
| 123 } | |
| 124 } | |
| 110 } | 125 } |
| 111 | 126 |
| 112 @CalledByNative | 127 @CalledByNative |
| 113 private void confirmDeletion(String title, String body) { | 128 private void confirmDeletion(String title, String body) { |
| 114 mDeletionDialog = new AlertDialog.Builder(mContext, R.style.AlertDialogT heme) | 129 mDeletionDialog = new AlertDialog.Builder(mContext, R.style.AlertDialogT heme) |
| 115 .setTitle(title) | 130 .setTitle(title) |
| 116 .setMessage(body) | 131 .setMessage(body) |
| 117 .setNegativeButton(R.string.cancel, null) | 132 .setNegativeButton(R.string.cancel, null) |
| 118 .setPositiveButton(R.string.ok, this) | 133 .setPositiveButton(R.string.ok, this) |
| 119 .create(); | 134 .create(); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 149 suggestionId, isDeletable, isLabelMultiline, isLabelBold); | 164 suggestionId, isDeletable, isLabelMultiline, isLabelBold); |
| 150 } | 165 } |
| 151 | 166 |
| 152 private native void nativeSuggestionSelected(long nativeAutofillPopupViewAnd roid, | 167 private native void nativeSuggestionSelected(long nativeAutofillPopupViewAnd roid, |
| 153 int listIndex); | 168 int listIndex); |
| 154 private native void nativeDeletionRequested(long nativeAutofillPopupViewAndr oid, | 169 private native void nativeDeletionRequested(long nativeAutofillPopupViewAndr oid, |
| 155 int listIndex); | 170 int listIndex); |
| 156 private native void nativeDeletionConfirmed(long nativeAutofillPopupViewAndr oid); | 171 private native void nativeDeletionConfirmed(long nativeAutofillPopupViewAndr oid); |
| 157 private native void nativePopupDismissed(long nativeAutofillPopupViewAndroid ); | 172 private native void nativePopupDismissed(long nativeAutofillPopupViewAndroid ); |
| 158 } | 173 } |
| OLD | NEW |