Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/ContentView.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentView.java b/content/public/android/java/src/org/chromium/content/browser/ContentView.java |
| index 0886e4cb4effd1259e3271a72fd30b71bcebb808..bac8aaa9c2ef5d936319a9cbdee1acb11ed0b8c1 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/ContentView.java |
| +++ b/content/public/android/java/src/org/chromium/content/browser/ContentView.java |
| @@ -36,6 +36,13 @@ public class ContentView extends FrameLayout |
| protected final ContentViewCore mContentViewCore; |
| /** |
| + * The desired size of this view defined by the host when it is different from |
| + * that of the parent. Should be applied to {@link onMeasure} when it is non-null. |
| + */ |
| + private int mDesiredWidth; |
| + private int mDesiredHeight; |
| + |
| + /** |
| * Constructs a new ContentView for the appropriate Android version. |
| * @param context The Context the view is running in, through which it can |
| * access the current theme, resources, etc. |
| @@ -78,6 +85,39 @@ public class ContentView extends FrameLayout |
| return super.performAccessibilityAction(action, arguments); |
| } |
| + /** |
| + * Set the desired size of the view. |
| + * @param width The width of the content view. |
| + * @param height The height of the content view. |
| + */ |
| + public void setDesiredSize(int width, int height) { |
| + mDesiredWidth = width; |
| + mDesiredHeight = height; |
| + } |
| + |
| + /** |
| + * @return The desired width of the view. |
| + */ |
| + public int getDesiredWidth() { |
| + return mDesiredWidth; |
| + } |
| + |
| + /** |
| + * @return The desired height of the view. |
| + */ |
| + public int getDesiredHeight() { |
| + return mDesiredHeight; |
| + } |
| + |
| + @Override |
| + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| + if (mDesiredWidth != 0 && mDesiredHeight != 0) { |
|
boliu
2016/12/03 00:16:39
Use MeasureSpec.UNSPECIFIED instead of 0, this als
Jinsuk Kim
2016/12/05 01:24:33
I guess you meant MeasureSpec(0, MeasureSpec.UNSPE
|
| + widthMeasureSpec = MeasureSpec.makeMeasureSpec(mDesiredWidth, MeasureSpec.EXACTLY); |
| + heightMeasureSpec = MeasureSpec.makeMeasureSpec(mDesiredHeight, MeasureSpec.EXACTLY); |
| + } |
| + super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| + } |
| + |
| @Override |
| public AccessibilityNodeProvider getAccessibilityNodeProvider() { |
| AccessibilityNodeProvider provider = mContentViewCore.getAccessibilityNodeProvider(); |
| @@ -231,25 +271,6 @@ public class ContentView extends FrameLayout |
| return mContentViewCore.computeVerticalScrollRange(); |
| } |
| - @Override |
| - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| - ContentViewClient client = mContentViewCore.getContentViewClient(); |
| - |
| - // Allow the ContentViewClient to override the ContentView's width. |
| - int desiredWidthMeasureSpec = client.getDesiredWidthMeasureSpec(); |
| - if (MeasureSpec.getMode(desiredWidthMeasureSpec) != MeasureSpec.UNSPECIFIED) { |
| - widthMeasureSpec = desiredWidthMeasureSpec; |
| - } |
| - |
| - // Allow the ContentViewClient to override the ContentView's height. |
| - int desiredHeightMeasureSpec = client.getDesiredHeightMeasureSpec(); |
| - if (MeasureSpec.getMode(desiredHeightMeasureSpec) != MeasureSpec.UNSPECIFIED) { |
| - heightMeasureSpec = desiredHeightMeasureSpec; |
| - } |
| - |
| - super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| - } |
| - |
| // End FrameLayout overrides. |
| @Override |