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

Unified Diff: content/public/android/java/src/org/chromium/content/browser/input/SelectPopupDropdown.java

Issue 231953003: Show Ash like <select> popup on Android tablets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@newpopupx
Patch Set: Rebased Created 6 years, 8 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: content/public/android/java/src/org/chromium/content/browser/input/SelectPopupDropdown.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/input/SelectPopupDropdown.java b/content/public/android/java/src/org/chromium/content/browser/input/SelectPopupDropdown.java
new file mode 100644
index 0000000000000000000000000000000000000000..97458f3099a5a625756eab22a49d69e48b70a2fb
--- /dev/null
+++ b/content/public/android/java/src/org/chromium/content/browser/input/SelectPopupDropdown.java
@@ -0,0 +1,74 @@
+// Copyright 2014 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.content.browser.input;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.view.View;
+import android.widget.AdapterView;
+
+import org.chromium.content.browser.ContentViewCore;
+import org.chromium.content.browser.RenderCoordinates;
+import org.chromium.ui.DropdownAdapter;
+import org.chromium.ui.DropdownItem;
+import org.chromium.ui.DropdownPopupWindow;
+
+import java.util.List;
+
+/**
+ * Handles the dropdown popup for the <select> HTML tag support.
+ */
+public class SelectPopupDropdown implements SelectPopup {
+
+ private final ContentViewCore mContentViewCore;
+ private final Context mContext;
+
+ private DropdownPopupWindow mDropdownPopupWindow;
+ private int mInitialSelection = -1;
+
+ public SelectPopupDropdown(ContentViewCore contentViewCore, List<SelectPopupItem> items,
+ Rect bounds, int[] selected) {
+ mContentViewCore = contentViewCore;
+ mContext = mContentViewCore.getContext();
+ mDropdownPopupWindow = new DropdownPopupWindow(mContext,
+ mContentViewCore.getViewAndroidDelegate());
+ mDropdownPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ int[] selectedIndices = {position};
+ mContentViewCore.selectPopupMenuItems(selectedIndices);
+ hide();
+ }
+ });
+ if (selected.length > 0) {
+ mInitialSelection = selected[0];
+ }
+ DropdownItem[] dropdownItems = items.toArray(new DropdownItem[items.size()]);
+ mDropdownPopupWindow.setAdapter(new DropdownAdapter(mContext, dropdownItems, null));
+ RenderCoordinates renderCoordinates = mContentViewCore.getRenderCoordinates();
+ float anchorX = renderCoordinates.fromPixToDip(
+ renderCoordinates.fromLocalCssToPix(bounds.left));
+ float anchorY = renderCoordinates.fromPixToDip(
+ renderCoordinates.fromLocalCssToPix(bounds.top));
+ float anchorWidth = renderCoordinates.fromPixToDip(
+ renderCoordinates.fromLocalCssToPix(bounds.right)) - anchorX;
+ float anchorHeight = renderCoordinates.fromPixToDip(
+ renderCoordinates.fromLocalCssToPix(bounds.bottom)) - anchorY;
+ mDropdownPopupWindow.setAnchorRect(anchorX, anchorY, anchorWidth, anchorHeight);
+ }
+
+ @Override
+ public void show() {
+ mDropdownPopupWindow.show();
+ if (mInitialSelection >= 0) {
+ mDropdownPopupWindow.getListView().setSelection(mInitialSelection);
+ }
+ }
+
+ @Override
+ public void hide() {
+ mDropdownPopupWindow.dismiss();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698