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

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

Issue 2751333006: Create the base Custom Context Menu Dialog. (Closed)
Patch Set: 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/CustomContextMenuViewPager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuViewPager.java b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuViewPager.java
new file mode 100644
index 0000000000000000000000000000000000000000..1e9c682985fccb0f8aebfc826063a0106d8e2121
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextmenu/CustomContextMenuViewPager.java
@@ -0,0 +1,54 @@
+// 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 CustomContextMenuViewPager extends ViewPager {
+ public CustomContextMenuViewPager(Context context) {
+ super(context);
+ }
+
+ public CustomContextMenuViewPager(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ /** Used to show the full ViewPager dialog. Without this the dialog would have no height or
David Trainor- moved to gerrit 2017/03/21 16:30:03 Fix javadoc?
JJ 2017/03/22 23:35:33 Done.
+ * width.
+ */
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ int maxHeight = 0;
+ int tabHeight = 0;
+ if (getChildCount() > 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) {
+ 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