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

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

Issue 2751333006: Create the base Custom Context Menu Dialog. (Closed)
Patch Set: git rebase Created 3 years, 9 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
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..640aabe91a27fc70069f04302a0b1facb4ccb1db
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuViewPager.java
@@ -0,0 +1,53 @@
+// 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;
+ 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);
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698