| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.contextmenu; | 5 package org.chromium.chrome.browser.contextmenu; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.support.v4.view.ViewPager; | 8 import android.support.v4.view.ViewPager; |
| 9 import android.util.AttributeSet; | 9 import android.util.AttributeSet; |
| 10 import android.view.View; | 10 import android.view.View; |
| 11 | 11 |
| 12 import org.chromium.chrome.R; | 12 import org.chromium.chrome.R; |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * When there is more than one view for the context menu to display, it wraps th
e display in a view | 15 * When there is more than one view for the context menu to display, it wraps th
e display in a view |
| 16 * pager. | 16 * pager. |
| 17 */ | 17 */ |
| 18 public class TabularContextMenuViewPager extends ViewPager { | 18 public class TabularContextMenuViewPager extends ViewPager { |
| 19 private static final double MAX_WIDTH_PROPORTION = 0.75; |
| 20 |
| 19 public TabularContextMenuViewPager(Context context) { | 21 public TabularContextMenuViewPager(Context context) { |
| 20 super(context); | 22 super(context); |
| 21 } | 23 } |
| 22 | 24 |
| 23 public TabularContextMenuViewPager(Context context, AttributeSet attrs) { | 25 public TabularContextMenuViewPager(Context context, AttributeSet attrs) { |
| 24 super(context, attrs); | 26 super(context, attrs); |
| 25 } | 27 } |
| 26 | 28 |
| 27 /** | 29 /** |
| 28 * Used to show the full ViewPager dialog. Without this the dialog would hav
e no height or | 30 * Used to show the full ViewPager dialog. Without this the dialog would hav
e no height or |
| 29 * width. | 31 * width. |
| 30 */ | 32 */ |
| 31 @Override | 33 @Override |
| 32 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 34 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 33 int menuHeight = 0; | 35 int menuHeight = 0; |
| 34 int tabHeight = 0; | 36 int tabHeight = 0; |
| 37 |
| 35 // getCurrentItem() does not take into account the tab layout unlike get
ChildCount(). | 38 // getCurrentItem() does not take into account the tab layout unlike get
ChildCount(). |
| 36 int currentItemsIndex = getCurrentItem() + 1; | 39 int currentItemsIndex = getCurrentItem() + 1; |
| 37 | 40 |
| 41 // TODO(injae): Fix sizing on orientation changes (crbug.com/731173) |
| 42 int contextMenuWidth = (int) Math.min( |
| 43 getResources().getDisplayMetrics().widthPixels * MAX_WIDTH_PROPO
RTION, |
| 44 getResources().getDimensionPixelSize(R.dimen.context_menu_max_wi
dth)); |
| 45 |
| 46 widthMeasureSpec = MeasureSpec.makeMeasureSpec(contextMenuWidth, Measure
Spec.EXACTLY); |
| 47 |
| 38 for (int i = 0; i < getChildCount(); i++) { | 48 for (int i = 0; i < getChildCount(); i++) { |
| 39 View child = getChildAt(i); | 49 View child = getChildAt(i); |
| 50 |
| 40 child.measure( | 51 child.measure( |
| 41 widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec
.UNSPECIFIED)); | 52 widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec
.UNSPECIFIED)); |
| 42 int measuredHeight = child.getMeasuredHeight(); | 53 int measuredHeight = child.getMeasuredHeight(); |
| 43 | 54 |
| 44 // The ViewPager also considers the tab layout one of its children,
and needs to be | 55 // The ViewPager also considers the tab layout one of its children,
and needs to be |
| 45 // treated separately from getting the largest height. | 56 // treated separately from getting the largest height. |
| 46 if (child.getId() == R.id.tab_layout && child.getVisibility() != GON
E) { | 57 if (child.getId() == R.id.tab_layout && child.getVisibility() != GON
E) { |
| 47 tabHeight = measuredHeight; | 58 tabHeight = measuredHeight; |
| 48 } else if (i == currentItemsIndex) { | 59 } else if (i == currentItemsIndex) { |
| 49 menuHeight = child.getMeasuredHeight(); | 60 menuHeight = child.getMeasuredHeight(); |
| 50 break; | 61 break; |
| 51 } | 62 } |
| 52 } | 63 } |
| 53 int fullHeight = menuHeight + tabHeight; | 64 int fullHeight = menuHeight + tabHeight; |
| 54 | 65 |
| 55 heightMeasureSpec = MeasureSpec.makeMeasureSpec(fullHeight, MeasureSpec.
EXACTLY); | 66 heightMeasureSpec = MeasureSpec.makeMeasureSpec(fullHeight, MeasureSpec.
EXACTLY); |
| 56 super.onMeasure(widthMeasureSpec, heightMeasureSpec); | 67 super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 57 } | 68 } |
| 58 } | 69 } |
| OLD | NEW |