summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsgurun@chromium.org <sgurun@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-03 08:16:31 +0000
committersgurun@chromium.org <sgurun@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-03 08:16:31 +0000
commit6f09f204799ea321d06110f1ab612b8b3dad26fa (patch)
tree9751df7974c4aca1de736d0b0058ad16f9bb58c7
parent3e5d16303f43f646ceb37573de40d6a0dfde1859 (diff)
downloadchromium_src-6f09f204799ea321d06110f1ab612b8b3dad26fa.zip
chromium_src-6f09f204799ea321d06110f1ab612b8b3dad26fa.tar.gz
chromium_src-6f09f204799ea321d06110f1ab612b8b3dad26fa.tar.bz2
Combine ViewAndroidDelegate code.
The ViewAndroidDelegate code in AutofillManagerDelegate and ContentViewCore has a lot of redundancies. Combine. Review URL: https://chromiumcodereview.appspot.com/21969002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215497 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwAutofillManagerDelegate.java39
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContents.java2
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java34
3 files changed, 26 insertions, 49 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwAutofillManagerDelegate.java b/android_webview/java/src/org/chromium/android_webview/AwAutofillManagerDelegate.java
index 5310268..c3a74af 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwAutofillManagerDelegate.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwAutofillManagerDelegate.java
@@ -11,7 +11,6 @@ import android.view.ViewGroup;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.content.browser.ContentViewCore;
-import org.chromium.ui.ViewAndroidDelegate;
import org.chromium.ui.autofill.AutofillPopup;
import org.chromium.ui.autofill.AutofillSuggestion;
@@ -23,7 +22,6 @@ public class AwAutofillManagerDelegate {
private final int mNativeAwAutofillManagerDelegate;
private AutofillPopup mAutofillPopup;
private ViewGroup mContainerView;
- private double mDIPScale;
private ContentViewCore mContentViewCore;
@CalledByNative
@@ -35,10 +33,9 @@ public class AwAutofillManagerDelegate {
mNativeAwAutofillManagerDelegate = nativeAwAutofillManagerDelegate;
}
- public void init(ContentViewCore contentViewCore, double DIPScale) {
+ public void init(ContentViewCore contentViewCore) {
mContentViewCore = contentViewCore;
mContainerView = contentViewCore.getContainerView();
- mDIPScale = DIPScale;
}
@CalledByNative
@@ -50,7 +47,7 @@ public class AwAutofillManagerDelegate {
if (mAutofillPopup == null) {
mAutofillPopup = new AutofillPopup(
mContentViewCore.getContext(),
- getViewAndroidDelegate(),
+ mContentViewCore.getViewAndroidDelegate(),
new AutofillPopup.AutofillPopupDelegate() {
public void requestHide() { }
public void suggestionSelected(int listIndex) {
@@ -70,38 +67,6 @@ public class AwAutofillManagerDelegate {
mAutofillPopup = null;
}
- private ViewAndroidDelegate getViewAndroidDelegate() {
- return new ViewAndroidDelegate() {
- @Override
- public View acquireAnchorView() {
- View anchorView = new View(mContentViewCore.getContext());
- mContainerView.addView(anchorView);
- return anchorView;
- }
-
- @Override
- @SuppressWarnings("deprecation") // AbsoluteLayout.LayoutParams
- 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);
-
- android.widget.AbsoluteLayout.LayoutParams lp =
- new android.widget.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];
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 01127a6..a5f8983 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -1647,7 +1647,7 @@ public class AwContents {
@CalledByNative
private void setAwAutofillManagerDelegate(AwAutofillManagerDelegate delegate) {
mAwAutofillManagerDelegate = delegate;
- delegate.init(mContentViewCore, mDIPScale);
+ delegate.init(mContentViewCore);
}
@CalledByNative
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
index 8f44ba1..95ed270 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
@@ -43,6 +43,7 @@ import android.view.accessibility.AccessibilityNodeProvider;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
+import android.widget.AbsoluteLayout;
import android.widget.FrameLayout;
import com.google.common.annotations.VisibleForTesting;
@@ -508,24 +509,35 @@ import java.util.Map;
}
@Override
+ @SuppressWarnings("deprecation") // AbsoluteLayout.LayoutParams
public void setAnchorViewPosition(
View view, float x, float y, float width, float height) {
assert(view.getParent() == mContainerView);
+
float scale = (float) DeviceDisplayInfo.create(getContext()).getDIPScale();
// The anchor view should not go outside the bounds of the ContainerView.
- int scaledX = Math.round(x * scale);
- int scaledWidth = Math.round(width * scale);
- if (scaledWidth + scaledX > mContainerView.getWidth()) {
- scaledWidth = mContainerView.getWidth() - scaledX;
- }
-
- FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
+ int leftMargin = Math.round(x * scale);
+ int topMargin = Math.round(mRenderCoordinates.getContentOffsetYPix() + y * scale);
+ // ContentViewCore currently only supports these two container view types.
+ if (mContainerView instanceof FrameLayout) {
+ int scaledWidth = Math.round(width * scale);
+ if (scaledWidth + leftMargin > mContainerView.getWidth()) {
+ scaledWidth = mContainerView.getWidth() - leftMargin;
+ }
+ FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
scaledWidth, Math.round(height * scale));
- lp.leftMargin = scaledX;
- lp.topMargin = (int) mRenderCoordinates.getContentOffsetYPix() +
- Math.round(y * scale);
- view.setLayoutParams(lp);
+ lp.leftMargin = leftMargin;
+ lp.topMargin = topMargin;
+ view.setLayoutParams(lp);
+ } else if (mContainerView instanceof AbsoluteLayout) {
+ android.widget.AbsoluteLayout.LayoutParams lp =
+ new android.widget.AbsoluteLayout.LayoutParams((int)width,
+ (int)height, leftMargin, topMargin);
+ view.setLayoutParams(lp);
+ } else {
+ Log.e(TAG, "Unknown layout " + mContainerView.getClass().getName());
+ }
}
@Override