Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1285)

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwContents.java

Issue 16212007: Implement the autofill UI for chromium powered android webview. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue15097004
Patch Set: move ui files Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/java/src/org/chromium/android_webview/AwContents.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java
index 9a0831470a30ff4e28a31905f8a52661138e3c59..1c5c8880e371eb285af42eb66f1225f74e6b92e0 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -28,6 +28,7 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.webkit.GeolocationPermissions;
import android.webkit.ValueCallback;
+import android.widget.AbsoluteLayout;
import com.google.common.annotations.VisibleForTesting;
@@ -38,6 +39,7 @@ import org.chromium.content.browser.ContentSettings;
import org.chromium.content.browser.ContentVideoView;
import org.chromium.content.browser.ContentViewClient;
import org.chromium.content.browser.ContentViewCore;
+import org.chromium.content.browser.RenderCoordinates;
import org.chromium.content.browser.ContentViewStatics;
import org.chromium.content.browser.LoadUrlParams;
import org.chromium.content.browser.NavigationHistory;
@@ -46,6 +48,9 @@ import org.chromium.content.common.CleanupReference;
import org.chromium.components.navigation_interception.InterceptNavigationDelegate;
import org.chromium.components.navigation_interception.NavigationParams;
import org.chromium.net.GURLUtils;
+import org.chromium.ui.ViewAndroidDelegate;
+import org.chromium.ui.autofill.AutofillPopup;
+import org.chromium.ui.autofill.AutofillSuggestion;
import org.chromium.ui.gfx.DeviceDisplayInfo;
import java.io.File;
@@ -140,6 +145,8 @@ public class AwContents {
private boolean mContainerViewFocused;
private boolean mWindowFocused;
+ private AutofillPopup mAutofillPopup;
+
private static final class DestroyRunnable implements Runnable {
private int mNativeAwContents;
private DestroyRunnable(int nativeAwContents) {
@@ -1253,6 +1260,13 @@ public class AwContents {
return mContentViewCore.performAccessibilityAction(action, arguments);
}
+ /**
+ * @see android.webkit.WebView#clearFormData()
benm (inactive) 2013/06/04 13:35:18 might be worth a note to say that this is poorly n
sgurun-gerrit only 2013/06/15 01:16:51 Done.
+ */
+ public void clearFormData() {
+ hideAutofillPopup();
+ }
+
//--------------------------------------------------------------------------------------------
// Methods called from native via JNI
//--------------------------------------------------------------------------------------------
@@ -1380,6 +1394,80 @@ public class AwContents {
mLayoutSizer.onPageScaleChanged(pageScaleFactor);
}
+ @CalledByNative
+ private void showAutofillPopup(float x, float y, float width, float height,
+ AutofillSuggestion[] suggestions) {
+ if (mAutofillPopup == null) {
+ mAutofillPopup = new AutofillPopup(
+ mContentViewCore.getContext(),
+ getViewAndroidDelegate(),
+ new AutofillPopup.AutofillPopupDelegate() {
+ public void requestHide() { }
+ public void suggestionSelected(int listIndex) {
+ nativeSuggestionSelected(mNativeAwContents, listIndex);
+ }
+ });
+ }
+ mAutofillPopup.setAnchorRect(x, y, width, height);
+ mAutofillPopup.show(suggestions);
+ }
+
+ @CalledByNative
+ private void hideAutofillPopup() {
+ if (mAutofillPopup == null)
+ return;
+ mAutofillPopup.hide();
+ mAutofillPopup = null;
+ }
+
+ private ViewAndroidDelegate getViewAndroidDelegate() {
+ return new ViewAndroidDelegate() {
+ @Override
+ public View acquireAnchorView() {
+ View anchorView = new View(mContentViewCore.getContext());
+ mContainerView.addView(anchorView);
+ return anchorView;
+ }
+
+ @Override
+ public void setAnchorViewPosition(
+ View view, float x, float y, float width, float height) {
+ assert(view.getParent() == mContainerView);
+
+ int leftMargin = (int)Math.round(x * mDIPScale);
+ int topMargin = (int)mContentViewCore.getRenderCoordinates().getContentOffsetYPix()
+ + (int)Math.round(y * mDIPScale);
+
+ AbsoluteLayout.LayoutParams lp = new AbsoluteLayout.LayoutParams((int)width,
+ (int)height, leftMargin, topMargin);
+ view.setLayoutParams(lp);
+ }
+
+ @Override
+ public void releaseAnchorView(View anchorView) {
+ mContainerView.removeView(anchorView);
+ }
+ };
+ }
+
+
+ @CalledByNative
+ private static AutofillSuggestion[] createAutofillSuggestionArray(int size) {
+ return new AutofillSuggestion[size];
+ }
+ /**
+ * @param array AutofillSuggestion array that should get a new suggestion added.
+ * @param index Index in the array where to place a new suggestion.
+ * @param name Name of the suggestion.
+ * @param label Label of the suggestion.
+ * @param uniqueId Unique suggestion id.
+ */
+ @CalledByNative
+ private static void addToAutofillSuggestionArray(AutofillSuggestion[] array, int index,
+ String name, String label, int uniqueId) {
+ array[index] = new AutofillSuggestion(name, label, uniqueId);
+ }
+
// -------------------------------------------------------------------------------------------
// Helper methods
// -------------------------------------------------------------------------------------------
@@ -1492,4 +1580,7 @@ public class AwContents {
private native void nativeInvokeGeolocationCallback(
int nativeAwContents, boolean value, String requestingFrame);
+
+
+ private native void nativeSuggestionSelected(int nativeAwContents, int position);
}

Powered by Google App Engine
This is Rietveld 408576698