| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.contextmenu; | 5 package org.chromium.chrome.browser.contextmenu; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.view.ContextMenu; | 8 import android.view.ContextMenu; |
| 9 import android.view.ContextMenu.ContextMenuInfo; | 9 import android.view.ContextMenu.ContextMenuInfo; |
| 10 import android.view.HapticFeedbackConstants; | |
| 11 import android.view.MenuItem; | 10 import android.view.MenuItem; |
| 12 import android.view.MenuItem.OnMenuItemClickListener; | 11 import android.view.MenuItem.OnMenuItemClickListener; |
| 13 import android.view.View; | 12 import android.view.View; |
| 14 import android.view.View.OnCreateContextMenuListener; | 13 import android.view.View.OnCreateContextMenuListener; |
| 15 | 14 |
| 16 import org.chromium.base.VisibleForTesting; | 15 import org.chromium.base.VisibleForTesting; |
| 17 import org.chromium.base.annotations.CalledByNative; | 16 import org.chromium.base.annotations.CalledByNative; |
| 18 import org.chromium.base.metrics.RecordHistogram; | 17 import org.chromium.base.metrics.RecordHistogram; |
| 19 import org.chromium.chrome.browser.share.ShareHelper; | 18 import org.chromium.chrome.browser.share.ShareHelper; |
| 20 import org.chromium.content.browser.ContentViewCore; | 19 import org.chromium.content.browser.ContentViewCore; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 54 |
| 56 /** | 55 /** |
| 57 * Starts showing a context menu for {@code view} based on {@code params}. | 56 * Starts showing a context menu for {@code view} based on {@code params}. |
| 58 * @param contentViewCore The {@link ContentViewCore} to show the menu to. | 57 * @param contentViewCore The {@link ContentViewCore} to show the menu to. |
| 59 * @param params The {@link ContextMenuParams} that indicate what m
enu items to show. | 58 * @param params The {@link ContextMenuParams} that indicate what m
enu items to show. |
| 60 */ | 59 */ |
| 61 @CalledByNative | 60 @CalledByNative |
| 62 private boolean showContextMenu(ContentViewCore contentViewCore, ContextMenu
Params params) { | 61 private boolean showContextMenu(ContentViewCore contentViewCore, ContextMenu
Params params) { |
| 63 final View view = contentViewCore.getContainerView(); | 62 final View view = contentViewCore.getContainerView(); |
| 64 | 63 |
| 65 if (!shouldShowMenu(params) | 64 if (view == null |
| 66 || view == null | |
| 67 || view.getVisibility() != View.VISIBLE | 65 || view.getVisibility() != View.VISIBLE |
| 68 || view.getParent() == null) { | 66 || view.getParent() == null) { |
| 69 return false; | 67 return false; |
| 70 } | 68 } |
| 71 | 69 |
| 72 mCurrentContextMenuParams = params; | 70 mCurrentContextMenuParams = params; |
| 73 | 71 |
| 74 view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); | |
| 75 view.setOnCreateContextMenuListener(this); | 72 view.setOnCreateContextMenuListener(this); |
| 76 if (view.showContextMenu()) { | 73 if (view.showContextMenu()) { |
| 77 WebContents webContents = contentViewCore.getWebContents(); | 74 WebContents webContents = contentViewCore.getWebContents(); |
| 78 RecordHistogram.recordBooleanHistogram( | 75 RecordHistogram.recordBooleanHistogram( |
| 79 "ContextMenu.Shown", webContents != null); | 76 "ContextMenu.Shown", webContents != null); |
| 80 if (webContents != null) webContents.onContextMenuOpened(); | 77 if (webContents != null) webContents.onContextMenuOpened(); |
| 81 return true; | 78 return true; |
| 82 } | 79 } |
| 83 return false; | 80 return false; |
| 84 } | 81 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 113 private void onShareImageReceived( | 110 private void onShareImageReceived( |
| 114 WindowAndroid windowAndroid, byte[] jpegImageData) { | 111 WindowAndroid windowAndroid, byte[] jpegImageData) { |
| 115 Activity activity = windowAndroid.getActivity().get(); | 112 Activity activity = windowAndroid.getActivity().get(); |
| 116 if (activity == null) return; | 113 if (activity == null) return; |
| 117 | 114 |
| 118 ShareHelper.shareImage(activity, jpegImageData); | 115 ShareHelper.shareImage(activity, jpegImageData); |
| 119 } | 116 } |
| 120 | 117 |
| 121 @Override | 118 @Override |
| 122 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo me
nuInfo) { | 119 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo me
nuInfo) { |
| 123 if (!shouldShowMenu(mCurrentContextMenuParams)) return; | |
| 124 | |
| 125 assert mPopulator != null; | 120 assert mPopulator != null; |
| 126 mPopulator.buildContextMenu(menu, v.getContext(), mCurrentContextMenuPar
ams); | 121 mPopulator.buildContextMenu(menu, v.getContext(), mCurrentContextMenuPar
ams); |
| 127 | 122 |
| 128 for (int i = 0; i < menu.size(); i++) { | 123 for (int i = 0; i < menu.size(); i++) { |
| 129 menu.getItem(i).setOnMenuItemClickListener(this); | 124 menu.getItem(i).setOnMenuItemClickListener(this); |
| 130 } | 125 } |
| 131 } | 126 } |
| 132 | 127 |
| 133 @Override | 128 @Override |
| 134 public boolean onMenuItemClick(MenuItem item) { | 129 public boolean onMenuItemClick(MenuItem item) { |
| 135 return mPopulator.onItemSelected(this, mCurrentContextMenuParams, item.g
etItemId()); | 130 return mPopulator.onItemSelected(this, mCurrentContextMenuParams, item.g
etItemId()); |
| 136 } | 131 } |
| 137 | 132 |
| 138 /** | 133 /** |
| 139 * @return The {@link ContextMenuPopulator} responsible for populating the c
ontext menu. | 134 * @return The {@link ContextMenuPopulator} responsible for populating the c
ontext menu. |
| 140 */ | 135 */ |
| 141 @VisibleForTesting | 136 @VisibleForTesting |
| 142 public ContextMenuPopulator getPopulator() { | 137 public ContextMenuPopulator getPopulator() { |
| 143 return mPopulator; | 138 return mPopulator; |
| 144 } | 139 } |
| 145 | 140 |
| 146 private boolean shouldShowMenu(ContextMenuParams params) { | |
| 147 return (mPopulator != null && mPopulator.shouldShowContextMenu(params)); | |
| 148 } | |
| 149 | |
| 150 private native void nativeOnStartDownload( | 141 private native void nativeOnStartDownload( |
| 151 long nativeContextMenuHelper, boolean isLink, boolean isDataReductio
nProxyEnabled); | 142 long nativeContextMenuHelper, boolean isLink, boolean isDataReductio
nProxyEnabled); |
| 152 private native void nativeSearchForImage(long nativeContextMenuHelper); | 143 private native void nativeSearchForImage(long nativeContextMenuHelper); |
| 153 private native void nativeShareImage(long nativeContextMenuHelper); | 144 private native void nativeShareImage(long nativeContextMenuHelper); |
| 154 } | 145 } |
| OLD | NEW |