Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuViewPager.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuViewPager.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuViewPager.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1e9c682985fccb0f8aebfc826063a0106d8e2121 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuViewPager.java |
| @@ -0,0 +1,54 @@ |
| +// Copyright 2017 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.chrome.browser.contextmenu; |
| + |
| +import android.content.Context; |
| +import android.support.v4.view.ViewPager; |
| +import android.util.AttributeSet; |
| +import android.view.View; |
| + |
| +import org.chromium.chrome.R; |
| + |
| +/** |
| + * When there is more than one view for the context menu to display, it wraps the display in a view |
| + * pager. |
| + */ |
| +public class CustomContextMenuViewPager extends ViewPager { |
| + public CustomContextMenuViewPager(Context context) { |
| + super(context); |
| + } |
| + |
| + public CustomContextMenuViewPager(Context context, AttributeSet attrs) { |
| + super(context, attrs); |
| + } |
| + |
| + /** Used to show the full ViewPager dialog. Without this the dialog would have no height or |
|
David Trainor- moved to gerrit
2017/03/21 16:30:03
Fix javadoc?
JJ
2017/03/22 23:35:33
Done.
|
| + * width. |
| + */ |
| + @Override |
| + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| + int maxHeight = 0; |
| + int tabHeight = 0; |
| + if (getChildCount() > 0) { |
| + for (int i = 0; i < getChildCount(); i++) { |
| + View child = getChildAt(i); |
| + child.measure(widthMeasureSpec, |
| + MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.UNSPECIFIED)); |
| + int measuredHeight = child.getMeasuredHeight(); |
| + |
| + // The ViewPager also considers the tab layout one of its children, and needs to be |
| + // treated separately from getting the largest height. |
| + if (child.getId() == R.id.tab_layout) { |
| + tabHeight = measuredHeight; |
| + } else { |
| + maxHeight = Math.max(maxHeight, child.getMeasuredHeight()); |
| + } |
| + } |
| + } |
| + maxHeight += tabHeight; |
| + heightMeasureSpec = MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.EXACTLY); |
| + super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| + } |
| +} |