Commit c4070b69 authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

Make SelectPopupDialog and SelectPopupDrown reusable.

This change makes above classes independent of SelectPopup, which will
allow reuse of those widgets in other parts of Chrome.

Specifically, they will be used in autofill_assistant for the selection
of time slots and similar information.

This is a refactoring only; there are no user-facing changes.

Bug: b/147577012
Change-Id: Id2d981345640ecf3b201ad4b64e0b5e2c3145426
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2002620
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarMathias Carlen <mcarlen@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732833}
parent 8aca6649
......@@ -153,11 +153,11 @@ public class SelectPopup implements HideablePopup, ViewAndroidDelegate.Container
WebContentsAccessibilityImpl wcax =
WebContentsAccessibilityImpl.fromWebContents(mWebContents);
if (DeviceFormFactor.isTablet() && !multiple && !wcax.isTouchExplorationEnabled()) {
mPopupView = new SelectPopupDropdown(this, context, anchorView, popupItems,
selectedIndices, rightAligned, mWebContents);
mPopupView = new SelectPopupDropdown(context, this::selectMenuItems, anchorView,
popupItems, selectedIndices, rightAligned, mWebContents);
} else {
mPopupView =
new SelectPopupDialog(this, context, popupItems, multiple, selectedIndices);
mPopupView = new SelectPopupDialog(
context, this::selectMenuItems, popupItems, multiple, selectedIndices);
}
mNativeSelectPopupSourceFrame = nativeSelectPopupSourceFrame;
mPopupView.show();
......
......@@ -15,6 +15,7 @@ import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import org.chromium.base.Callback;
import org.chromium.content.R;
import org.chromium.ui.widget.UiWidgetFactory;
......@@ -31,13 +32,13 @@ public class SelectPopupDialog implements SelectPopup.Ui {
// The dialog hosting the popup list view.
private final AlertDialog mListBoxPopup;
private final SelectPopup mSelectPopup;
private final Callback<int[]> mSelectionChangedCallback;
private boolean mSelectionNotified;
public SelectPopupDialog(SelectPopup selectPopup, Context windowContext,
public SelectPopupDialog(Context windowContext, Callback<int[]> selectionChangedCallback,
List<SelectPopupItem> items, boolean multiple, int[] selected) {
mSelectPopup = selectPopup;
mSelectionChangedCallback = selectionChangedCallback;
final ListView listView = new ListView(windowContext);
// setCacheColorHint(0) is required to prevent a black background in WebView on Lollipop:
......@@ -136,7 +137,7 @@ public class SelectPopupDialog implements SelectPopup.Ui {
private void notifySelection(int[] indicies) {
if (mSelectionNotified) return;
mSelectPopup.selectMenuItems(indicies);
mSelectionChangedCallback.onResult(indicies);
mSelectionNotified = true;
}
......
......@@ -9,6 +9,7 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.PopupWindow;
import org.chromium.base.Callback;
import org.chromium.content_public.browser.GestureListenerManager;
import org.chromium.content_public.browser.GestureStateListener;
import org.chromium.content_public.browser.WebContents;
......@@ -21,15 +22,15 @@ import java.util.List;
* Handles the dropdown popup for the <select> HTML tag support.
*/
public class SelectPopupDropdown implements SelectPopup.Ui {
private final SelectPopup mSelectPopup;
private final Callback<int[]> mSelectionChangedCallback;
private final DropdownPopupWindow mDropdownPopupWindow;
private boolean mSelectionNotified;
public SelectPopupDropdown(SelectPopup selectPopup, Context context, View anchorView,
List<SelectPopupItem> items, int[] selected, boolean rightAligned,
public SelectPopupDropdown(Context context, Callback<int[]> selectionChangedCallback,
View anchorView, List<SelectPopupItem> items, int[] selected, boolean rightAligned,
WebContents webContents) {
mSelectPopup = selectPopup;
mSelectionChangedCallback = selectionChangedCallback;
mDropdownPopupWindow = new DropdownPopupWindow(context, anchorView);
mDropdownPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
......@@ -63,7 +64,7 @@ public class SelectPopupDropdown implements SelectPopup.Ui {
private void notifySelection(int[] indicies) {
if (mSelectionNotified) return;
mSelectPopup.selectMenuItems(indicies);
mSelectionChangedCallback.onResult(indicies);
mSelectionNotified = true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment