Commit b3cb099c authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Add Search item to Touchless NTP context menu.

Also adds support for showing the context menu on the All Apps button
with just the search entry.

Bug: 978458
Change-Id: I8c6a1229a84a7b60de2567c298ae1128096e9ae5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1677064Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avatarPavel Yatsuk <pavely@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672246}
parent 05ecc20f
......@@ -442,6 +442,11 @@ public abstract class AppHooks {
*/
public void performPrivateImeCommand(WebContents webContents, String action, Bundle data) {}
/**
* Called when the Search Context Menu Item is clicked.
*/
public void onSearchContextMenuClick() {}
/**
* @param registry The Chrome interface registry for the RenderFrameHost.
* @param renderFrameHost The RenderFrameHost the Interface Registry is for.
......
......@@ -30,24 +30,25 @@ import java.lang.annotation.RetentionPolicy;
* {@link Delegate#isItemSupported(int)}.
*/
public class ContextMenuManager implements OnCloseContextMenuListener {
@IntDef({ContextMenuItemId.OPEN_IN_NEW_TAB, ContextMenuItemId.OPEN_IN_INCOGNITO_TAB,
ContextMenuItemId.OPEN_IN_NEW_WINDOW, ContextMenuItemId.SAVE_FOR_OFFLINE,
ContextMenuItemId.ADD_TO_MY_APPS, ContextMenuItemId.REMOVE,
ContextMenuItemId.LEARN_MORE})
@IntDef({ContextMenuItemId.SEARCH, ContextMenuItemId.OPEN_IN_NEW_TAB,
ContextMenuItemId.OPEN_IN_INCOGNITO_TAB, ContextMenuItemId.OPEN_IN_NEW_WINDOW,
ContextMenuItemId.SAVE_FOR_OFFLINE, ContextMenuItemId.ADD_TO_MY_APPS,
ContextMenuItemId.REMOVE, ContextMenuItemId.LEARN_MORE})
@Retention(RetentionPolicy.SOURCE)
public @interface ContextMenuItemId {
// The order of the items will be based on the value of their ID. So if new items are added,
// the value of the existing ones should be modified so they stay in order.
// Values are also used for indexing - should start from 0 and can't have gaps.
int OPEN_IN_NEW_TAB = 0;
int OPEN_IN_INCOGNITO_TAB = 1;
int OPEN_IN_NEW_WINDOW = 2;
int SAVE_FOR_OFFLINE = 3;
int ADD_TO_MY_APPS = 4;
int REMOVE = 5;
int LEARN_MORE = 6;
int NUM_ENTRIES = 7;
int SEARCH = 0;
int OPEN_IN_NEW_TAB = 1;
int OPEN_IN_INCOGNITO_TAB = 2;
int OPEN_IN_NEW_WINDOW = 3;
int SAVE_FOR_OFFLINE = 4;
int ADD_TO_MY_APPS = 5;
int REMOVE = 6;
int LEARN_MORE = 7;
int NUM_ENTRIES = 8;
}
private final NativePageNavigationDelegate mNavigationDelegate;
......@@ -223,6 +224,8 @@ public class ContextMenuManager implements OnCloseContextMenuListener {
if (!delegate.isItemSupported(itemId)) return false;
switch (itemId) {
case ContextMenuItemId.SEARCH:
return false;
case ContextMenuItemId.OPEN_IN_NEW_TAB:
return true;
case ContextMenuItemId.OPEN_IN_INCOGNITO_TAB:
......
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
tools:ignore="NewApi">
<path
android:fillColor="@color/touchless_icon_color"
android:pathData="M20.49,19l-5.73,-5.73C15.53,12.2 16,10.91 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.41,0 2.7,-0.47 3.77,-1.24L19,20.49 20.49,19zM5,9.5C5,7.01 7.01,5 9.5,5S14,7.01 14,9.5 11.99,14 9.5,14 5,11.99 5,9.5z"/>
</vector>
......@@ -180,6 +180,8 @@ class SiteSuggestionsAdapter extends ForwardingListObservable<PropertyKey>
(view)
-> mNavDelegate.navigateToSuggestionUrl(
WindowOpenDisposition.CURRENT_TAB, UrlConstants.EXPLORE_URL));
ContextMenuManager.registerViewForTouchlessContextMenu(
tile, new ContextMenuManager.EmptyDelegate());
} else if (holder.getItemViewType() == ViewType.SUGGESTION_TYPE) {
// If site suggestion, attach context menu handler; clicks navigate to site url.
int itemCount = mModel.get(ITEM_COUNT_KEY);
......
......@@ -10,8 +10,10 @@ import android.support.annotation.StringRes;
import android.view.View;
import android.view.View.OnClickListener;
import org.chromium.chrome.browser.AppHooks;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.native_page.ContextMenuManager;
import org.chromium.chrome.browser.native_page.ContextMenuManager.ContextMenuItemId;
import org.chromium.chrome.browser.native_page.NativePageNavigationDelegate;
import org.chromium.chrome.browser.touchless.dialog.TouchlessDialogProperties;
import org.chromium.chrome.browser.touchless.dialog.TouchlessDialogProperties.ActionNames;
......@@ -105,6 +107,9 @@ public class TouchlessContextMenuManager extends ContextMenuManager {
@Override
protected @StringRes int getResourceIdForMenuItem(@ContextMenuItemId int id) {
if (id == ContextMenuItemId.SEARCH) {
return org.chromium.chrome.R.string.search_or_type_web_address;
}
if (id == ContextMenuItemId.ADD_TO_MY_APPS) {
return R.string.menu_add_to_apps;
}
......@@ -115,6 +120,10 @@ public class TouchlessContextMenuManager extends ContextMenuManager {
@Override
protected boolean handleMenuItemClick(
@ContextMenuItemId int itemId, ContextMenuManager.Delegate delegate) {
if (itemId == ContextMenuItemId.SEARCH) {
AppHooks.get().onSearchContextMenuClick();
return true;
}
if (itemId == ContextMenuItemId.ADD_TO_MY_APPS) {
Delegate touchlessDelegate = (Delegate) delegate;
TouchlessAddToHomescreenManager touchlessAddToHomescreenManager =
......@@ -122,7 +131,7 @@ public class TouchlessContextMenuManager extends ContextMenuManager {
touchlessDelegate.getUrl(), touchlessDelegate.getTitle(),
touchlessDelegate.getIconBitmap());
touchlessAddToHomescreenManager.start();
return false;
return true;
}
return super.handleMenuItemClick(itemId, delegate);
}
......@@ -132,6 +141,8 @@ public class TouchlessContextMenuManager extends ContextMenuManager {
@ContextMenuItemId int itemId, ContextMenuManager.Delegate delegate) {
// Here we filter out any item IDs that don't make sense in touchless.
switch (itemId) {
case ContextMenuItemId.SEARCH:
return true;
case ContextMenuItemId.REMOVE:
// fall through
case ContextMenuItemId.LEARN_MORE:
......@@ -202,6 +213,8 @@ public class TouchlessContextMenuManager extends ContextMenuManager {
*/
private @DrawableRes int getIconIdForMenuItem(@ContextMenuItemId int itemId) {
switch (itemId) {
case ContextMenuItemId.SEARCH:
return R.drawable.ic_search;
case ContextMenuItemId.REMOVE:
return R.drawable.ic_remove_circle_outline_24dp;
case ContextMenuItemId.LEARN_MORE:
......
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