Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/ContentViewAndroidDelegate.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewAndroidDelegate.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewAndroidDelegate.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..77d788d5488f22e73e872f0b1120aff00d6f23d9 |
| --- /dev/null |
| +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewAndroidDelegate.java |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.content.browser; |
| + |
| +import android.view.View; |
| +import android.view.ViewGroup; |
| +import android.widget.FrameLayout.LayoutParams; |
| + |
| +import org.chromium.base.ApiCompatibilityUtils; |
| +import org.chromium.ui.base.ViewAndroidDelegate; |
|
no sievers
2016/07/14 23:14:31
Actually there are no more content dependencies no
Jinsuk Kim
2016/07/15 05:46:26
Sounds better. Made it an inner class of AndroidVi
no sievers
2016/07/15 18:35:00
Sorry there was a typo. I meant to say just put it
Jinsuk Kim
2016/07/18 06:45:46
Should have seen that :) Done.
|
| + |
| +/** |
| + * A {@link ViewAndroidDelegate} that delegates to the current container view. |
| + * |
| + * <p>This delegate handles the replacement of container views transparently so |
| + * that clients can safely hold to instances of this class. |
| + */ |
| +public class ContentViewAndroidDelegate implements ViewAndroidDelegate { |
| + private static final String TAG = "cr.ContentViewAndroidDelegate"; |
| + |
| + private final ViewGroup mContainerView; |
| + |
| + public ContentViewAndroidDelegate(ViewGroup containerView) { |
| + mContainerView = containerView; |
| + } |
| + |
| + @Override |
| + public void addView(View anchorView) { |
| + mContainerView.addView(anchorView); |
| + } |
| + |
| + @Override |
| + 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); |
| + } |
| + |
| + // Can be overriden by the inherited class to return its own container view in case |
| + // it allows dynamic container view switching. |
| + protected ViewGroup getContainerView() { |
| + return mContainerView; |
| + } |
| + |
| + @Override |
| + public void removeView(View anchorView) { |
| + mContainerView.removeView(anchorView); |
| + } |
| +} |