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") { ...@@ -62,13 +62,13 @@ android_library("java") {
sources = [ sources = [
"org/chromium/weblayer_private/ActionModeCallback.java", "org/chromium/weblayer_private/ActionModeCallback.java",
"org/chromium/weblayer_private/AutocompleteSchemeClassifierImpl.java", "org/chromium/weblayer_private/AutocompleteSchemeClassifierImpl.java",
"org/chromium/weblayer_private/AutofillView.java",
"org/chromium/weblayer_private/BrowserControlsContainerView.java", "org/chromium/weblayer_private/BrowserControlsContainerView.java",
"org/chromium/weblayer_private/BrowserFragmentImpl.java", "org/chromium/weblayer_private/BrowserFragmentImpl.java",
"org/chromium/weblayer_private/BrowserImpl.java", "org/chromium/weblayer_private/BrowserImpl.java",
"org/chromium/weblayer_private/BrowserViewController.java", "org/chromium/weblayer_private/BrowserViewController.java",
"org/chromium/weblayer_private/ChildProcessServiceImpl.java", "org/chromium/weblayer_private/ChildProcessServiceImpl.java",
"org/chromium/weblayer_private/ContentViewRenderView.java", "org/chromium/weblayer_private/ContentViewRenderView.java",
"org/chromium/weblayer_private/ContentViewWithAutofill.java",
"org/chromium/weblayer_private/CookieManagerImpl.java", "org/chromium/weblayer_private/CookieManagerImpl.java",
"org/chromium/weblayer_private/CrashReporterControllerImpl.java", "org/chromium/weblayer_private/CrashReporterControllerImpl.java",
"org/chromium/weblayer_private/DownloadCallbackProxy.java", "org/chromium/weblayer_private/DownloadCallbackProxy.java",
......
...@@ -10,27 +10,16 @@ import android.util.SparseArray; ...@@ -10,27 +10,16 @@ import android.util.SparseArray;
import android.view.View; import android.view.View;
import android.view.ViewStructure; import android.view.ViewStructure;
import android.view.autofill.AutofillValue; import android.view.autofill.AutofillValue;
import android.widget.FrameLayout;
import org.chromium.components.embedder_support.view.ContentView;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.EventOffsetHandler;
/** /**
* API level 26 implementation that includes autofill. * View which handles autofill support for a tab.
*/ */
public class ContentViewWithAutofill extends ContentView.ContentViewApi23 { public class AutofillView extends FrameLayout {
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 */);
}
private TabImpl mTab; private TabImpl mTab;
private ContentViewWithAutofill(Context context, EventOffsetHandler eventOffsetHandler) { public AutofillView(Context context) {
super(context, eventOffsetHandler, null /* webContents */); super(context);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// The Autofill system-level infrastructure has heuristics for which Views it considers // The Autofill system-level infrastructure has heuristics for which Views it considers
...@@ -43,10 +32,8 @@ public class ContentViewWithAutofill extends ContentView.ContentViewApi23 { ...@@ -43,10 +32,8 @@ public class ContentViewWithAutofill extends ContentView.ContentViewApi23 {
} }
} }
@Override public void setTab(TabImpl tab) {
public void setWebContents(WebContents webContents) { mTab = tab;
mTab = TabImpl.fromWebContents(webContents);
super.setWebContents(webContents);
} }
@Override @Override
......
...@@ -118,6 +118,10 @@ public class BrowserImpl extends IBrowser.Stub { ...@@ -118,6 +118,10 @@ public class BrowserImpl extends IBrowser.Stub {
return mViewController.getContentView(); return mViewController.getContentView();
} }
public ViewGroup getAutofillView() {
return getViewController().getAutofillView();
}
// Called from constructor and onFragmentAttached() to configure state needed when attached. // Called from constructor and onFragmentAttached() to configure state needed when attached.
private void createAttachmentState( private void createAttachmentState(
Context embedderAppContext, FragmentWindowAndroid windowAndroid) { Context embedderAppContext, FragmentWindowAndroid windowAndroid) {
......
...@@ -46,6 +46,11 @@ public final class BrowserViewController ...@@ -46,6 +46,11 @@ public final class BrowserViewController
// Other child of mContentViewRenderView, which holds views that sit on top of the web contents, // Other child of mContentViewRenderView, which holds views that sit on top of the web contents,
// such as tab modal dialogs. // such as tab modal dialogs.
private final FrameLayout mWebContentsOverlayView; 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 FragmentWindowAndroid mWindowAndroid;
private final ModalDialogManager mModalDialogManager; private final ModalDialogManager mModalDialogManager;
...@@ -74,8 +79,8 @@ public final class BrowserViewController ...@@ -74,8 +79,8 @@ public final class BrowserViewController
mBottomControlsContainerView = mBottomControlsContainerView =
new BrowserControlsContainerView(context, mContentViewRenderView, this, false); new BrowserControlsContainerView(context, mContentViewRenderView, this, false);
mBottomControlsContainerView.setId(View.generateViewId()); mBottomControlsContainerView.setId(View.generateViewId());
mContentView = ContentViewWithAutofill.createContentView( mContentView = ContentView.createContentView(
context, mTopControlsContainerView.getEventOffsetHandler()); context, mTopControlsContainerView.getEventOffsetHandler(), null /* webContents */);
mContentViewRenderView.addView(mContentView, mContentViewRenderView.addView(mContentView,
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT)); RelativeLayout.LayoutParams.MATCH_PARENT));
...@@ -103,6 +108,9 @@ public final class BrowserViewController ...@@ -103,6 +108,9 @@ public final class BrowserViewController
mModalDialogManager.registerPresenter( mModalDialogManager.registerPresenter(
new WebLayerTabModalPresenter(this, context), ModalDialogType.TAB); new WebLayerTabModalPresenter(this, context), ModalDialogType.TAB);
mWindowAndroid.setModalDialogManager(mModalDialogManager); mWindowAndroid.setModalDialogManager(mModalDialogManager);
mAutofillView = new AutofillView(context);
mContentViewRenderView.addView(mAutofillView, mAutofillParams);
} }
public void destroy() { public void destroy() {
...@@ -126,6 +134,10 @@ public final class BrowserViewController ...@@ -126,6 +134,10 @@ public final class BrowserViewController
return mWebContentsOverlayView; return mWebContentsOverlayView;
} }
public ViewGroup getAutofillView() {
return mAutofillView;
}
public void setActiveTab(TabImpl tab) { public void setActiveTab(TabImpl tab) {
if (tab == mTab) return; if (tab == mTab) return;
...@@ -148,8 +160,9 @@ public final class BrowserViewController ...@@ -148,8 +160,9 @@ public final class BrowserViewController
mGestureStateTracker = mGestureStateTracker =
new WebContentsGestureStateTracker(mContentView, webContents, this); new WebContentsGestureStateTracker(mContentView, webContents, this);
} }
mContentView.setWebContents(webContents); mAutofillView.setTab(mTab);
mContentView.setWebContents(webContents);
mContentViewRenderView.setWebContents(webContents); mContentViewRenderView.setWebContents(webContents);
mTopControlsContainerView.setWebContents(webContents); mTopControlsContainerView.setWebContents(webContents);
mBottomControlsContainerView.setWebContents(webContents); mBottomControlsContainerView.setWebContents(webContents);
...@@ -228,6 +241,9 @@ public final class BrowserViewController ...@@ -228,6 +241,9 @@ public final class BrowserViewController
mContentViewRenderView.setWebContentsHeightDelta( mContentViewRenderView.setWebContentsHeightDelta(
mTopControlsContainerView.getContentHeightDelta() mTopControlsContainerView.getContentHeightDelta()
+ mBottomControlsContainerView.getContentHeightDelta()); + mBottomControlsContainerView.getContentHeightDelta());
mAutofillParams.topMargin = mTopControlsContainerView.getContentHeightDelta();
mAutofillView.setLayoutParams(mAutofillParams);
} }
public void setSupportsEmbedding(boolean enable, ValueCallback<Boolean> callback) { public void setSupportsEmbedding(boolean enable, ValueCallback<Boolean> callback) {
......
...@@ -278,12 +278,11 @@ public final class TabImpl extends ITab.Stub { ...@@ -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 // 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 // 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. // must be detached before it can be reattached to a new Context.
mAutofillProvider = new AutofillProviderImpl(mBrowser.getContext(), mAutofillProvider = new AutofillProviderImpl(
mBrowser.getViewAndroidDelegateContainerView(), "WebLayer"); mBrowser.getContext(), mBrowser.getAutofillView(), "WebLayer");
TabImplJni.get().onAutofillProviderChanged(mNativeTab, mAutofillProvider); TabImplJni.get().onAutofillProviderChanged(mNativeTab, mAutofillProvider);
} }
mAutofillProvider.onContainerViewChanged( mAutofillProvider.onContainerViewChanged(mBrowser.getAutofillView());
mBrowser.getViewAndroidDelegateContainerView());
mAutofillProvider.setWebContents(mWebContents); mAutofillProvider.setWebContents(mWebContents);
selectionController.setNonSelectionActionModeCallback( 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