Commit 19ba281e authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

[WebLayer] Fix autofill popup positioning

The autofill popup was not taking the top bar into account when
positioning near target input. This change creates a new view that will
be offset by the current top bar height, and uses that view as the
autofill container.

Bug: 1085294
Change-Id: I6bc8ce5dbeae2a00f16a9c01d39c5a8bee7e8d2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2218704Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772457}
parent 6a7f651b
......@@ -62,13 +62,13 @@ android_library("java") {
sources = [
"org/chromium/weblayer_private/ActionModeCallback.java",
"org/chromium/weblayer_private/AutocompleteSchemeClassifierImpl.java",
"org/chromium/weblayer_private/AutofillView.java",
"org/chromium/weblayer_private/BrowserControlsContainerView.java",
"org/chromium/weblayer_private/BrowserFragmentImpl.java",
"org/chromium/weblayer_private/BrowserImpl.java",
"org/chromium/weblayer_private/BrowserViewController.java",
"org/chromium/weblayer_private/ChildProcessServiceImpl.java",
"org/chromium/weblayer_private/ContentViewRenderView.java",
"org/chromium/weblayer_private/ContentViewWithAutofill.java",
"org/chromium/weblayer_private/CookieManagerImpl.java",
"org/chromium/weblayer_private/CrashReporterControllerImpl.java",
"org/chromium/weblayer_private/DownloadCallbackProxy.java",
......
......@@ -10,27 +10,16 @@ import android.util.SparseArray;
import android.view.View;
import android.view.ViewStructure;
import android.view.autofill.AutofillValue;
import org.chromium.components.embedder_support.view.ContentView;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.EventOffsetHandler;
import android.widget.FrameLayout;
/**
* API level 26 implementation that includes autofill.
* View which handles autofill support for a tab.
*/
public class ContentViewWithAutofill extends ContentView.ContentViewApi23 {
public static ContentView createContentView(
Context context, EventOffsetHandler eventOffsetHandler) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return new ContentViewWithAutofill(context, eventOffsetHandler);
}
return ContentView.createContentView(context, eventOffsetHandler, null /* webContents */);
}
public class AutofillView extends FrameLayout {
private TabImpl mTab;
private ContentViewWithAutofill(Context context, EventOffsetHandler eventOffsetHandler) {
super(context, eventOffsetHandler, null /* webContents */);
public AutofillView(Context context) {
super(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// The Autofill system-level infrastructure has heuristics for which Views it considers
......@@ -43,10 +32,8 @@ public class ContentViewWithAutofill extends ContentView.ContentViewApi23 {
}
}
@Override
public void setWebContents(WebContents webContents) {
mTab = TabImpl.fromWebContents(webContents);
super.setWebContents(webContents);
public void setTab(TabImpl tab) {
mTab = tab;
}
@Override
......
......@@ -118,6 +118,10 @@ public class BrowserImpl extends IBrowser.Stub {
return mViewController.getContentView();
}
public ViewGroup getAutofillView() {
return getViewController().getAutofillView();
}
// Called from constructor and onFragmentAttached() to configure state needed when attached.
private void createAttachmentState(
Context embedderAppContext, FragmentWindowAndroid windowAndroid) {
......
......@@ -46,6 +46,11 @@ public final class BrowserViewController
// Other child of mContentViewRenderView, which holds views that sit on top of the web contents,
// such as tab modal dialogs.
private final FrameLayout mWebContentsOverlayView;
// Child of mContentViewRenderView. This view has a top margin matching the current state of the
// top controls, which allows the autofill popup to be positioned correctly.
private final AutofillView mAutofillView;
private final RelativeLayout.LayoutParams mAutofillParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
private final FragmentWindowAndroid mWindowAndroid;
private final ModalDialogManager mModalDialogManager;
......@@ -74,8 +79,8 @@ public final class BrowserViewController
mBottomControlsContainerView =
new BrowserControlsContainerView(context, mContentViewRenderView, this, false);
mBottomControlsContainerView.setId(View.generateViewId());
mContentView = ContentViewWithAutofill.createContentView(
context, mTopControlsContainerView.getEventOffsetHandler());
mContentView = ContentView.createContentView(
context, mTopControlsContainerView.getEventOffsetHandler(), null /* webContents */);
mContentViewRenderView.addView(mContentView,
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT));
......@@ -103,6 +108,9 @@ public final class BrowserViewController
mModalDialogManager.registerPresenter(
new WebLayerTabModalPresenter(this, context), ModalDialogType.TAB);
mWindowAndroid.setModalDialogManager(mModalDialogManager);
mAutofillView = new AutofillView(context);
mContentViewRenderView.addView(mAutofillView, mAutofillParams);
}
public void destroy() {
......@@ -126,6 +134,10 @@ public final class BrowserViewController
return mWebContentsOverlayView;
}
public ViewGroup getAutofillView() {
return mAutofillView;
}
public void setActiveTab(TabImpl tab) {
if (tab == mTab) return;
......@@ -148,8 +160,9 @@ public final class BrowserViewController
mGestureStateTracker =
new WebContentsGestureStateTracker(mContentView, webContents, this);
}
mContentView.setWebContents(webContents);
mAutofillView.setTab(mTab);
mContentView.setWebContents(webContents);
mContentViewRenderView.setWebContents(webContents);
mTopControlsContainerView.setWebContents(webContents);
mBottomControlsContainerView.setWebContents(webContents);
......@@ -228,6 +241,9 @@ public final class BrowserViewController
mContentViewRenderView.setWebContentsHeightDelta(
mTopControlsContainerView.getContentHeightDelta()
+ mBottomControlsContainerView.getContentHeightDelta());
mAutofillParams.topMargin = mTopControlsContainerView.getContentHeightDelta();
mAutofillView.setLayoutParams(mAutofillParams);
}
public void setSupportsEmbedding(boolean enable, ValueCallback<Boolean> callback) {
......
......@@ -278,12 +278,11 @@ public final class TabImpl extends ITab.Stub {
// Set up |mAutofillProvider| to operate in the new Context. It's safe to assume
// the context won't change unless it is first nulled out, since the fragment
// must be detached before it can be reattached to a new Context.
mAutofillProvider = new AutofillProviderImpl(mBrowser.getContext(),
mBrowser.getViewAndroidDelegateContainerView(), "WebLayer");
mAutofillProvider = new AutofillProviderImpl(
mBrowser.getContext(), mBrowser.getAutofillView(), "WebLayer");
TabImplJni.get().onAutofillProviderChanged(mNativeTab, mAutofillProvider);
}
mAutofillProvider.onContainerViewChanged(
mBrowser.getViewAndroidDelegateContainerView());
mAutofillProvider.onContainerViewChanged(mBrowser.getAutofillView());
mAutofillProvider.setWebContents(mWebContents);
selectionController.setNonSelectionActionModeCallback(
......
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