| Index: ui/android/java/src/org/chromium/ui/base/ViewAndroidDelegate.java
|
| diff --git a/ui/android/java/src/org/chromium/ui/base/ViewAndroidDelegate.java b/ui/android/java/src/org/chromium/ui/base/ViewAndroidDelegate.java
|
| index 6d3694cc9bfe1304dd81fce41b8c3691be883f0a..e9b6a3ee2ab4a1828631a4f068ab6dc80deade67 100644
|
| --- a/ui/android/java/src/org/chromium/ui/base/ViewAndroidDelegate.java
|
| +++ b/ui/android/java/src/org/chromium/ui/base/ViewAndroidDelegate.java
|
| @@ -5,30 +5,59 @@
|
| package org.chromium.ui.base;
|
|
|
| import android.view.View;
|
| +import android.view.ViewGroup;
|
| +import android.widget.FrameLayout.LayoutParams;
|
| +
|
| +import org.chromium.base.ApiCompatibilityUtils;
|
| +import org.chromium.base.annotations.CalledByNative;
|
| +import org.chromium.base.annotations.JNINamespace;
|
|
|
| /**
|
| - * Interface to acquire and release anchor views from the implementing View.
|
| + * Class to acquire, position, and remove anchor views from the implementing View.
|
| */
|
| -public interface ViewAndroidDelegate {
|
| -
|
| - /**
|
| - * @return An anchor view that can be used to anchor decoration views like Autofill popup.
|
| - */
|
| - View acquireAnchorView();
|
| -
|
| - /**
|
| - * Set the anchor view to specified position and width (all units in dp).
|
| - * @param view The anchor view that needs to be positioned.
|
| - * @param x X coordinate of the top left corner of the anchor view.
|
| - * @param y Y coordinate of the top left corner of the anchor view.
|
| - * @param width The width of the anchor view.
|
| - * @param height The height of the anchor view.
|
| - */
|
| - void setAnchorViewPosition(View view, float x, float y, float width, float height);
|
| -
|
| - /**
|
| - * Release given anchor view.
|
| - * @param anchorView The anchor view that needs to be released.
|
| - */
|
| - void releaseAnchorView(View anchorView);
|
| +@JNINamespace("ui")
|
| +public abstract class ViewAndroidDelegate {
|
| +
|
| + @CalledByNative
|
| + public View acquireView() {
|
| + View anchorView = new View(getContainerView().getContext());
|
| + getContainerView().addView(anchorView);
|
| + return anchorView;
|
| + }
|
| +
|
| + @CalledByNative
|
| + public void removeView(View anchorView) {
|
| + getContainerView().removeView(anchorView);
|
| + }
|
| +
|
| + @CalledByNative
|
| + public void setViewPosition(View view, float x, float y,
|
| + float width, float height, float scale, int leftMargin, int topMargin) {
|
| + if (view.getParent() == null) {
|
| + // Ignore. setAnchorViewPosition has been called after the anchor view has
|
| + // already been released.
|
| + return;
|
| + }
|
| + ViewGroup containerView = getContainerView();
|
| + assert view.getParent() == containerView;
|
| +
|
| + int scaledWidth = Math.round(width * scale);
|
| + int scaledHeight = Math.round(height * scale);
|
| + int startMargin;
|
| + if (ApiCompatibilityUtils.isLayoutRtl(containerView)) {
|
| + startMargin = containerView.getMeasuredWidth() - Math.round((width + x) * scale);
|
| + } else {
|
| + startMargin = leftMargin;
|
| + }
|
| + if (scaledWidth + startMargin > containerView.getWidth()) {
|
| + scaledWidth = containerView.getWidth() - startMargin;
|
| + }
|
| + LayoutParams lp = new LayoutParams(scaledWidth, scaledHeight);
|
| + ApiCompatibilityUtils.setMarginStart(lp, startMargin);
|
| + lp.topMargin = topMargin;
|
| + view.setLayoutParams(lp);
|
| + }
|
| +
|
| + // Override to return the container view the views are added to.
|
| + protected abstract ViewGroup getContainerView();
|
| }
|
|
|