Chromium Code Reviews| 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; | 19 private final int mContextMenuMinimumPaddingPx = |
| 20 getResources().getDimensionPixelSize(R.dimen.context_menu_min_paddin g); | |
| 20 | 21 |
| 21 public TabularContextMenuViewPager(Context context) { | 22 public TabularContextMenuViewPager(Context context) { |
| 22 super(context); | 23 super(context); |
| 23 } | 24 } |
| 24 | 25 |
| 25 public TabularContextMenuViewPager(Context context, AttributeSet attrs) { | 26 public TabularContextMenuViewPager(Context context, AttributeSet attrs) { |
| 26 super(context, attrs); | 27 super(context, attrs); |
| 27 } | 28 } |
| 28 | 29 |
| 29 /** | 30 /** |
| 30 * Used to show the full ViewPager dialog. Without this the dialog would hav e no height or | 31 * Used to show the full ViewPager dialog. Without this the dialog would hav e no height or |
| 31 * width. | 32 * width. |
| 32 */ | 33 */ |
| 33 @Override | 34 @Override |
| 34 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 35 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 35 int menuHeight = 0; | 36 int menuHeight = 0; |
| 36 int tabHeight = 0; | 37 int tabHeight = 0; |
| 37 | 38 |
| 38 // getCurrentItem() does not take into account the tab layout unlike get ChildCount(). | 39 // getCurrentItem() does not take into account the tab layout unlike get ChildCount(). |
| 39 int currentItemsIndex = getCurrentItem() + 1; | 40 int currentItemsIndex = getCurrentItem() + 1; |
| 40 | 41 |
| 41 // TODO(injae): Fix sizing on orientation changes (crbug.com/731173) | 42 // set the context menu width |
|
gone
2017/06/26 21:57:23
English sentences, capital letters and punctuation
Daniel Park
2017/06/29 18:22:58
Done.
| |
| 42 int contextMenuWidth = (int) Math.min( | 43 int deviceWidthPx = getResources().getDisplayMetrics().widthPixels; |
| 43 getResources().getDisplayMetrics().widthPixels * MAX_WIDTH_PROPO RTION, | 44 int contextMenuWidth = Math.min(deviceWidthPx - 2 * mContextMenuMinimumP addingPx, |
| 44 getResources().getDimensionPixelSize(R.dimen.context_menu_max_wi dth)); | 45 getResources().getDimensionPixelSize(R.dimen.context_menu_max_wi dth)); |
| 45 | 46 |
| 46 widthMeasureSpec = MeasureSpec.makeMeasureSpec(contextMenuWidth, Measure Spec.EXACTLY); | 47 widthMeasureSpec = MeasureSpec.makeMeasureSpec(contextMenuWidth, Measure Spec.EXACTLY); |
| 47 | 48 |
| 49 // figure out which view is about to displayed & measure that view's hei ght | |
|
gone
2017/06/26 21:57:23
This current only applies to the block at line 62,
Daniel Park
2017/06/29 18:22:58
Done.
| |
| 48 for (int i = 0; i < getChildCount(); i++) { | 50 for (int i = 0; i < getChildCount(); i++) { |
| 49 View child = getChildAt(i); | 51 View child = getChildAt(i); |
| 50 | 52 |
| 51 child.measure( | 53 child.measure( |
| 52 widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec .UNSPECIFIED)); | 54 widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec .UNSPECIFIED)); |
| 53 int measuredHeight = child.getMeasuredHeight(); | 55 int measuredHeight = child.getMeasuredHeight(); |
| 54 | 56 |
| 55 // The ViewPager also considers the tab layout one of its children, and needs to be | 57 // The ViewPager also considers the tab layout one of its children, and needs to be |
| 56 // treated separately from getting the largest height. | 58 // treated separately from getting the largest height. |
| 57 if (child.getId() == R.id.tab_layout && child.getVisibility() != GON E) { | 59 if (child.getId() == R.id.tab_layout && child.getVisibility() != GON E) { |
| 58 tabHeight = measuredHeight; | 60 tabHeight = measuredHeight; |
| 59 } else if (i == currentItemsIndex) { | 61 } else if (i == currentItemsIndex) { |
| 60 menuHeight = child.getMeasuredHeight(); | 62 menuHeight = child.getMeasuredHeight(); |
| 61 break; | 63 break; |
| 62 } | 64 } |
| 63 } | 65 } |
| 66 | |
| 67 // set the context menu height | |
| 64 int fullHeight = menuHeight + tabHeight; | 68 int fullHeight = menuHeight + tabHeight; |
| 69 int deviceHeightPx = getResources().getDisplayMetrics().heightPixels; | |
| 70 fullHeight = Math.min(fullHeight, deviceHeightPx - 2 * mContextMenuMinim umPaddingPx); | |
| 65 | 71 |
| 66 heightMeasureSpec = MeasureSpec.makeMeasureSpec(fullHeight, MeasureSpec. EXACTLY); | 72 heightMeasureSpec = MeasureSpec.makeMeasureSpec(fullHeight, MeasureSpec. EXACTLY); |
| 67 super.onMeasure(widthMeasureSpec, heightMeasureSpec); | 73 super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 68 } | 74 } |
| 69 } | 75 } |
| OLD | NEW |