Commit 3cd281c1 authored by Tao Bai's avatar Tao Bai Committed by Commit Bot

Aw Autofill: Send the bounds to autofill service.

Bounds are transformed to Android's coordinates with scroll offset.

Bug: 1064420
Change-Id: I8149e45a4de72f660a52466b7f1ca0505266f3b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2133239Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Commit-Queue: Tao Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756338}
parent 7621154c
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package org.chromium.android_webview.test; package org.chromium.android_webview.test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
...@@ -313,7 +314,23 @@ public class AwAutofillTest { ...@@ -313,7 +314,23 @@ public class AwAutofillTest {
public void setId(int id, String packageName, String typeName, String entryName) {} public void setId(int id, String packageName, String typeName, String entryName) {}
@Override @Override
public void setDimens(int left, int top, int scrollX, int scrollY, int width, int height) {} public void setDimens(int left, int top, int scrollX, int scrollY, int width, int height) {
mDimensRect = new Rect(left, top, width + left, height + top);
mDimensScrollX = scrollX;
mDimensScrollY = scrollY;
}
public Rect getDimensRect() {
return mDimensRect;
}
public int getDimensScrollX() {
return mDimensScrollX;
}
public int getDimensScrollY() {
return mDimensScrollY;
}
@Override @Override
public void setElevation(float elevation) {} public void setElevation(float elevation) {}
...@@ -423,6 +440,9 @@ public class AwAutofillTest { ...@@ -423,6 +440,9 @@ public class AwAutofillTest {
private boolean mDataIsSensitive; private boolean mDataIsSensitive;
private AwHtmlInfo mAwHtmlInfo; private AwHtmlInfo mAwHtmlInfo;
private boolean mChecked; private boolean mChecked;
private Rect mDimensRect;
private int mDimensScrollX;
private int mDimensScrollY;
} }
// crbug.com/776230: On Android L, declaring variables of unsupported classes causes an error. // crbug.com/776230: On Android L, declaring variables of unsupported classes causes an error.
...@@ -841,6 +861,10 @@ public class AwAutofillTest { ...@@ -841,6 +861,10 @@ public class AwAutofillTest {
assertEquals("placeholder@placeholder.com", child0.getHint()); assertEquals("placeholder@placeholder.com", child0.getHint());
assertEquals("name", child0.getAutofillHints()[0]); assertEquals("name", child0.getAutofillHints()[0]);
assertEquals("given-name", child0.getAutofillHints()[1]); assertEquals("given-name", child0.getAutofillHints()[1]);
assertFalse(child0.getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, child0.getDimensScrollX());
assertEquals(0, child0.getDimensScrollY());
TestViewStructure.AwHtmlInfo htmlInfo0 = child0.getHtmlInfo(); TestViewStructure.AwHtmlInfo htmlInfo0 = child0.getHtmlInfo();
assertEquals("text", htmlInfo0.getAttribute("type")); assertEquals("text", htmlInfo0.getAttribute("type"));
assertEquals("text1", htmlInfo0.getAttribute("id")); assertEquals("text1", htmlInfo0.getAttribute("id"));
...@@ -854,6 +878,10 @@ public class AwAutofillTest { ...@@ -854,6 +878,10 @@ public class AwAutofillTest {
assertEquals(View.AUTOFILL_TYPE_TOGGLE, child1.getAutofillType()); assertEquals(View.AUTOFILL_TYPE_TOGGLE, child1.getAutofillType());
assertEquals("", child1.getHint()); assertEquals("", child1.getHint());
assertNull(child1.getAutofillHints()); assertNull(child1.getAutofillHints());
assertFalse(child1.getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, child1.getDimensScrollX());
assertEquals(0, child1.getDimensScrollY());
TestViewStructure.AwHtmlInfo htmlInfo1 = child1.getHtmlInfo(); TestViewStructure.AwHtmlInfo htmlInfo1 = child1.getHtmlInfo();
assertEquals("checkbox", htmlInfo1.getAttribute("type")); assertEquals("checkbox", htmlInfo1.getAttribute("type"));
assertEquals("checkbox1", htmlInfo1.getAttribute("id")); assertEquals("checkbox1", htmlInfo1.getAttribute("id"));
...@@ -867,6 +895,10 @@ public class AwAutofillTest { ...@@ -867,6 +895,10 @@ public class AwAutofillTest {
assertEquals(View.AUTOFILL_TYPE_LIST, child2.getAutofillType()); assertEquals(View.AUTOFILL_TYPE_LIST, child2.getAutofillType());
assertEquals("", child2.getHint()); assertEquals("", child2.getHint());
assertNull(child2.getAutofillHints()); assertNull(child2.getAutofillHints());
assertFalse(child2.getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, child2.getDimensScrollX());
assertEquals(0, child2.getDimensScrollY());
TestViewStructure.AwHtmlInfo htmlInfo2 = child2.getHtmlInfo(); TestViewStructure.AwHtmlInfo htmlInfo2 = child2.getHtmlInfo();
assertEquals("month", htmlInfo2.getAttribute("name")); assertEquals("month", htmlInfo2.getAttribute("name"));
assertEquals("select1", htmlInfo2.getAttribute("id")); assertEquals("select1", htmlInfo2.getAttribute("id"));
...@@ -879,6 +911,10 @@ public class AwAutofillTest { ...@@ -879,6 +911,10 @@ public class AwAutofillTest {
assertEquals(View.AUTOFILL_TYPE_TEXT, child3.getAutofillType()); assertEquals(View.AUTOFILL_TYPE_TEXT, child3.getAutofillType());
assertEquals("", child3.getHint()); assertEquals("", child3.getHint());
assertNull(child3.getAutofillHints()); assertNull(child3.getAutofillHints());
assertFalse(child3.getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, child3.getDimensScrollX());
assertEquals(0, child3.getDimensScrollY());
TestViewStructure.AwHtmlInfo htmlInfo3 = child3.getHtmlInfo(); TestViewStructure.AwHtmlInfo htmlInfo3 = child3.getHtmlInfo();
assertEquals("textarea1", htmlInfo3.getAttribute("name")); assertEquals("textarea1", htmlInfo3.getAttribute("name"));
...@@ -1351,10 +1387,25 @@ public class AwAutofillTest { ...@@ -1351,10 +1387,25 @@ public class AwAutofillTest {
assertEquals(1, values.size()); assertEquals(1, values.size());
assertTrue(values.get(0).second.isList()); assertTrue(values.get(0).second.isList());
assertEquals(1, values.get(0).second.getListValue()); assertEquals(1, values.get(0).second.getListValue());
// Verify the autofill session started by select control has dimens filled.
invokeOnProvideAutoFillVirtualStructure();
TestViewStructure viewStructure = mTestValues.testViewStructure;
assertNotNull(viewStructure);
assertEquals(2, viewStructure.getChildCount());
assertFalse(viewStructure.getChild(0).getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, viewStructure.getChild(0).getDimensScrollX());
assertEquals(0, viewStructure.getChild(0).getDimensScrollY());
assertFalse(viewStructure.getChild(1).getDimensRect().isEmpty());
// The field has no scroll, should always be zero.
assertEquals(0, viewStructure.getChild(1).getDimensScrollX());
assertEquals(0, viewStructure.getChild(1).getDimensScrollY());
} finally { } finally {
webServer.shutdown(); webServer.shutdown();
} }
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView"}) @Feature({"AndroidWebView"})
......
...@@ -85,6 +85,12 @@ public class AutofillProviderImpl extends AutofillProvider { ...@@ -85,6 +85,12 @@ public class AutofillProviderImpl extends AutofillProvider {
child.setAutofillHints(field.mAutocompleteAttr.split(" +")); child.setAutofillHints(field.mAutocompleteAttr.split(" +"));
} }
child.setHint(field.mPlaceholder); child.setHint(field.mPlaceholder);
RectF bounds = field.getBoundsInContainerViewCoordinates();
// Field has no scroll.
child.setDimens((int) bounds.left, (int) bounds.top, 0 /* scrollX*/,
0 /* scrollY */, (int) bounds.width(), (int) bounds.height());
ViewStructure.HtmlInfo.Builder builder = ViewStructure.HtmlInfo.Builder builder =
child.newHtmlInfoBuilder("input") child.newHtmlInfoBuilder("input")
.addAttribute("name", field.mName) .addAttribute("name", field.mName)
...@@ -308,6 +314,7 @@ public class AutofillProviderImpl extends AutofillProvider { ...@@ -308,6 +314,7 @@ public class AutofillProviderImpl extends AutofillProvider {
mAutofillManager.notifyNewSessionStarted(); mAutofillManager.notifyNewSessionStarted();
Rect absBound = transformToWindowBounds(new RectF(x, y, x + width, y + height)); Rect absBound = transformToWindowBounds(new RectF(x, y, x + width, y + height));
if (mRequest != null) notifyViewExitBeforeDestoryRequest(); if (mRequest != null) notifyViewExitBeforeDestoryRequest();
transformFormFieldToContainViewCoordinates(formData);
mRequest = new AutofillRequest(formData, new FocusField((short) focus, absBound)); mRequest = new AutofillRequest(formData, new FocusField((short) focus, absBound));
int virtualId = mRequest.getVirtualId((short) focus); int virtualId = mRequest.getVirtualId((short) focus);
mAutofillManager.notifyVirtualViewEntered(mContainerView, virtualId, absBound); mAutofillManager.notifyVirtualViewEntered(mContainerView, virtualId, absBound);
...@@ -491,4 +498,25 @@ public class AutofillProviderImpl extends AutofillProvider { ...@@ -491,4 +498,25 @@ public class AutofillProviderImpl extends AutofillProvider {
return new Rect( return new Rect(
(int) bounds.left, (int) bounds.top, (int) bounds.right, (int) bounds.bottom); (int) bounds.left, (int) bounds.top, (int) bounds.right, (int) bounds.bottom);
} }
/**
* Transform FormFieldData's bounds to ContainView's coordinates and update the bounds with the
* transformed one.
*
* @param formData the form need to be transformed.
*/
private void transformFormFieldToContainViewCoordinates(FormData formData) {
WindowAndroid windowAndroid = mWebContents.getTopLevelNativeWindow();
DisplayAndroid displayAndroid = windowAndroid.getDisplay();
float dipScale = displayAndroid.getDipScale();
Matrix matrix = new Matrix();
matrix.setScale(dipScale, dipScale);
matrix.postTranslate(mContainerView.getScrollX(), mContainerView.getScrollY());
for (FormFieldData field : formData.mFields) {
RectF bounds = new RectF();
matrix.mapRect(bounds, field.getBounds());
field.setBoundsInContainerViewCoordinates(bounds);
}
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment