Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3812)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuViewPager.java

Issue 2959853002: Adding smarter resizing logic for the context menu on orientation changes (Closed)
Patch Set: comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/java/res/values/dimens.xml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index 55a3ad51463e8baa21ae31e467cace64f72fc229..dd76948cbbe1e9b0f01ef264b72dd508555bea10 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuViewPager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuViewPager.java
@@ -16,7 +16,8 @@ import org.chromium.chrome.R;
* pager.
*/
public class TabularContextMenuViewPager extends ViewPager {
- private static final double MAX_WIDTH_PROPORTION = 0.75;
+ private final int mContextMenuMinimumPaddingPx =
+ getResources().getDimensionPixelSize(R.dimen.context_menu_min_padding);
public TabularContextMenuViewPager(Context context) {
super(context);
@@ -38,13 +39,19 @@ public class TabularContextMenuViewPager extends ViewPager {
// getCurrentItem() does not take into account the tab layout unlike getChildCount().
int currentItemsIndex = getCurrentItem() + 1;
- // TODO(injae): Fix sizing on orientation changes (crbug.com/731173)
- int contextMenuWidth = (int) Math.min(
- getResources().getDisplayMetrics().widthPixels * MAX_WIDTH_PROPORTION,
+ // The width of the context menu is defined so that it leaves space between itself and the
+ // screen's edges. It is also bounded to a max size to prevent the menu from stretching
+ // across a large display (e.g. a tablet screen).
+ int deviceWidthPx = getResources().getDisplayMetrics().widthPixels;
+ int contextMenuWidth = Math.min(deviceWidthPx - 2 * mContextMenuMinimumPaddingPx,
getResources().getDimensionPixelSize(R.dimen.context_menu_max_width));
widthMeasureSpec = MeasureSpec.makeMeasureSpec(contextMenuWidth, MeasureSpec.EXACTLY);
+ // The height of the context menu is calculated as the sum of:
+ // 1. The tab bar's height, which is only visible when the context menu requires it
+ // (i.e. an ImageLink is clicked)
+ // 2. The height of the View being displayed for the current tab.
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
@@ -61,7 +68,12 @@ public class TabularContextMenuViewPager extends ViewPager {
break;
}
}
+
+ // Cap the height of the context menu so that it fits on the screen without touching the
+ // screen's edges.
int fullHeight = menuHeight + tabHeight;
+ int deviceHeightPx = getResources().getDisplayMetrics().heightPixels;
+ fullHeight = Math.min(fullHeight, deviceHeightPx - 2 * mContextMenuMinimumPaddingPx);
heightMeasureSpec = MeasureSpec.makeMeasureSpec(fullHeight, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
« no previous file with comments | « chrome/android/java/res/values/dimens.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698