Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuViewPager.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuViewPager.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuViewPager.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1589c4e3692c6513c78e172cf58eaf2fa7d85f1f |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuViewPager.java |
| @@ -0,0 +1,55 @@ |
| +// 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 TabularContextMenuViewPager extends ViewPager { |
| + public TabularContextMenuViewPager(Context context) { |
| + super(context); |
| + } |
| + |
| + public TabularContextMenuViewPager(Context context, AttributeSet attrs) { |
| + super(context, attrs); |
| + } |
| + |
| + /** |
| + * Used to show the full ViewPager dialog. Without this the dialog would have no height or |
| + * width. |
| + */ |
| + @Override |
| + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| + int maxHeight = 0; |
| + int tabHeight = 0; |
| + if (getChildCount() > 0) { |
|
Ted C
2017/03/24 04:32:53
I don't think you need this check as the for loop
JJ
2017/03/25 01:40:26
Whoops you're right
|
| + 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 && child.getVisibility() != GONE) { |
| + tabHeight = measuredHeight; |
| + } else { |
| + maxHeight = Math.max(maxHeight, child.getMeasuredHeight()); |
| + } |
| + } |
| + } |
| + maxHeight += tabHeight; |
| + heightMeasureSpec = MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.EXACTLY); |
|
Ted C
2017/03/24 04:32:54
what happens if this is larger than the screen dim
JJ
2017/03/25 01:40:26
Again nothing. The Dialog does not go bigger than
|
| + super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
|
Ted C
2017/03/24 04:32:54
I wonder if we when we are creating the context me
JJ
2017/03/25 01:40:25
That's a good thought. I tried to something with t
Ted C
2017/03/27 20:53:33
In the design spec, it mentions the height never c
JJ
2017/03/28 00:09:27
Awesome, I'll keep that in mind. I'm not sure if t
|
| + } |
| +} |