Commit 3613d36b authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Fix <select> popups on Android.

Due to a recent refactoring, we were not creating the internal
plumbing needed to show popups anymore.

BUG=868238

Change-Id: I9ffcdff49a2c3a5f4de9dbda741986de765ad6a6
Reviewed-on: https://chromium-review.googlesource.com/1154039
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578942}
parent b83bba97
......@@ -27,11 +27,13 @@ import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.Context
import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost;
import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.components.embedder_support.view.ContentView;
import org.chromium.content.browser.test.util.TestSelectionPopupController;
import org.chromium.content_public.browser.SelectionClient;
import org.chromium.content_public.browser.SelectionPopupController;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.ActivityWindowAndroid;
import org.chromium.ui.base.ViewAndroidDelegate;
import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
import org.chromium.ui.touch_selection.SelectionEventType;
......@@ -81,7 +83,9 @@ public class ContextualSearchTapEventTest {
super(activity, null);
setSelectionController(new MockCSSelectionController(activity, this));
WebContents webContents = WebContentsFactory.createWebContents(false, false);
webContents.initialize(null, null, null, new ActivityWindowAndroid(activity),
ContentView cv = ContentView.createContentView(activity, webContents);
webContents.initialize(null, ViewAndroidDelegate.createBasicDelegate(cv), null,
new ActivityWindowAndroid(activity),
WebContents.createDefaultInternalsHolder());
SelectionPopupController selectionPopupController =
SelectionPopupController.createForTesting(webContents);
......
......@@ -13,7 +13,6 @@
#include "content/public/common/menu_item.h"
#include "content/public/common/use_zoom_for_dsf_policy.h"
#include "jni/SelectPopup_jni.h"
#include "ui/android/window_android.h"
#include "ui/gfx/geometry/rect_f.h"
using base::android::AttachCurrentThread;
......@@ -162,11 +161,4 @@ void SelectPopup::SelectMenuItems(JNIEnv* env,
rfhi->DidSelectPopupMenuItems(selected_indices);
}
base::android::ScopedJavaLocalRef<jobject> SelectPopup::GetWindowAndroid(
JNIEnv* env,
const JavaParamRef<jobject>& obj) {
auto* window = web_contents_->GetNativeView()->GetWindowAndroid();
return window ? window->GetJavaObject() : ScopedJavaLocalRef<jobject>();
}
} // namespace content
......@@ -26,9 +26,6 @@ class SelectPopup {
SelectPopup(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj,
WebContentsImpl* web_contents);
base::android::ScopedJavaLocalRef<jobject> GetWindowAndroid(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);
~SelectPopup();
// Creates a popup menu with |items|.
......
......@@ -46,7 +46,6 @@ public class SelectPopup
}
private final WebContentsImpl mWebContents;
private final Context mContext;
private View mContainerView;
private Ui mPopupView;
private long mNativeSelectPopup;
......@@ -57,11 +56,9 @@ public class SelectPopup
}
/**
* Get {@link SelectPopup} object used for the give WebContents. {@link #create()} should
* precede any calls to this.
* Get {@link SelectPopup} object used for the give WebContents.
* @param webContents {@link WebContents} object.
* @return {@link SelectPopup} object. {@code null} if not available because
* {@link #create()} is not called yet.
* @return {@link SelectPopup} object.
*/
public static SelectPopup fromWebContents(WebContents webContents) {
return webContents.getOrSetUserData(SelectPopup.class, UserDataFactoryLazyHolder.INSTANCE);
......@@ -73,7 +70,6 @@ public class SelectPopup
*/
public SelectPopup(WebContents webContents) {
mWebContents = (WebContentsImpl) webContents;
mContext = mWebContents.getContext();
ViewAndroidDelegate viewDelegate = mWebContents.getViewAndroidDelegate();
assert viewDelegate != null;
mContainerView = viewDelegate.getContainerView();
......@@ -135,6 +131,9 @@ public class SelectPopup
PopupController.hidePopupsAndClearSelection(mWebContents);
assert mNativeSelectPopupSourceFrame == 0 : "Zombie popup did not clear the frame source";
Context context = mWebContents.getContext();
if (context == null) return;
assert items.length == enabled.length;
List<SelectPopupItem> popupItems = new ArrayList<SelectPopupItem>();
for (int i = 0; i < items.length; i++) {
......@@ -144,14 +143,10 @@ public class SelectPopup
WebContentsAccessibilityImpl.fromWebContents(mWebContents);
if (DeviceFormFactor.isTablet() && !multiple && !wcax.isTouchExplorationEnabled()) {
mPopupView = new SelectPopupDropdown(
this, mContext, anchorView, popupItems, selectedIndices, rightAligned);
this, context, anchorView, popupItems, selectedIndices, rightAligned);
} else {
WindowAndroid window = getWindowAndroid();
if (window == null) return;
Context windowContext = window.getContext().get();
if (windowContext == null) return;
mPopupView = new SelectPopupDialog(
this, windowContext, popupItems, multiple, selectedIndices);
mPopupView =
new SelectPopupDialog(this, context, popupItems, multiple, selectedIndices);
}
mNativeSelectPopupSourceFrame = nativeSelectPopupSourceFrame;
mPopupView.show();
......@@ -181,10 +176,6 @@ public class SelectPopup
return mPopupView != null;
}
private WindowAndroid getWindowAndroid() {
return (mNativeSelectPopup != 0) ? nativeGetWindowAndroid(mNativeSelectPopup) : null;
}
/**
* Notifies that items were selected in the currently showing select popup.
* @param indices Array of indices of the selected items.
......@@ -200,5 +191,4 @@ public class SelectPopup
private native long nativeInit(WebContents webContents);
private native void nativeSelectMenuItems(
long nativeSelectPopup, long nativeSelectPopupSourceFrame, int[] indices);
private native WindowAndroid nativeGetWindowAndroid(long nativeSelectPopup);
}
......@@ -205,6 +205,9 @@ public class WebContentsImpl implements WebContents, RenderFrameHostDelegate, Wi
setViewAndroidDelegate(viewDelegate);
setTopLevelNativeWindow(windowAndroid);
// Internally registers the handler that controls showing <select> HTML elements.
SelectPopup.fromWebContents(this);
ViewEventSinkImpl.from(this).setAccessDelegate(accessDelegate);
getRenderCoordinates().setDeviceScaleFactor(windowAndroid.getDisplay().getDipScale());
}
......
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