Commit ef660c26 authored by Chris Blume's avatar Chris Blume Committed by Commit Bot

Show correct context menu given source type

Sometimes, an Android device is meant to behave like a desktop. For
example, when an external monitor and mouse are connected. When this
happens, things like a right mouse click should show a context menu
positioned at the click location (rather than showing a long-press modal
dialog).

BUG=687787

Change-Id: I8d42d248f69ee3e52b65ce93c5c2a5ce58786be4
Reviewed-on: https://chromium-review.googlesource.com/731509
Commit-Queue: Chris Blume <cblume@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512947}
parent 0aa10a8d
......@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.contextmenu;
import android.app.Activity;
import android.content.ComponentName;
import android.graphics.Bitmap;
import android.os.Build;
import android.util.Pair;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
......@@ -23,6 +24,7 @@ import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.share.ShareHelper;
import org.chromium.chrome.browser.share.ShareParams;
import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.MenuSourceType;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.base.WindowAndroid.OnCloseContextMenuListener;
......@@ -120,7 +122,8 @@ public class ContextMenuHelper implements OnCreateContextMenuListener {
}
};
if (ChromeFeatureList.isEnabled(ChromeFeatureList.CUSTOM_CONTEXT_MENU)) {
if (ChromeFeatureList.isEnabled(ChromeFeatureList.CUSTOM_CONTEXT_MENU)
&& params.getSourceType() != MenuSourceType.MENU_SOURCE_MOUSE) {
List<Pair<Integer, List<ContextMenuItem>>> items =
mPopulator.buildContextMenu(null, mActivity, mCurrentContextMenuParams);
if (items.isEmpty()) {
......@@ -160,7 +163,18 @@ public class ContextMenuHelper implements OnCreateContextMenuListener {
// The Platform Context Menu requires the listener within this helper since this helper and
// provides context menu for us to show.
view.setOnCreateContextMenuListener(this);
if (view.showContextMenu()) {
boolean wasContextMenuShown = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
&& params.getSourceType() == MenuSourceType.MENU_SOURCE_MOUSE) {
final float density = view.getResources().getDisplayMetrics().density;
final float touchPointXPx = params.getTriggeringTouchXDp() * density;
final float touchPointYPx =
(params.getTriggeringTouchYDp() * density) + topContentOffsetPx;
wasContextMenuShown = view.showContextMenu(touchPointXPx, touchPointYPx);
} else {
wasContextMenuShown = view.showContextMenu();
}
if (wasContextMenuShown) {
mOnMenuShown.run();
windowAndroid.addContextMenuCloseListener(new OnCloseContextMenuListener() {
@Override
......
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