Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Unified Diff: content/public/android/java/src/org/chromium/content/browser/SelectActionModeCallback.java

Issue 1066053002: [Android] Allow custom ActionMode creation via ContentViewClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix null check Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/public/android/java/src/org/chromium/content/browser/SelectActionModeCallback.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/SelectActionModeCallback.java b/content/public/android/java/src/org/chromium/content/browser/SelectActionModeCallback.java
index 25459fbc1cd5f456c2493c905345c4de9cdc474a..7984cdc13ba5c34000aec5ae5acb428625f79cee 100644
--- a/content/public/android/java/src/org/chromium/content/browser/SelectActionModeCallback.java
+++ b/content/public/android/java/src/org/chromium/content/browser/SelectActionModeCallback.java
@@ -6,9 +6,11 @@ package org.chromium.content.browser;
import android.content.ClipboardManager;
import android.content.Context;
+import android.graphics.Rect;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.View;
import org.chromium.content.R;
@@ -63,6 +65,12 @@ public class SelectActionModeCallback implements ActionMode.Callback {
void onDestroyActionMode();
/**
+ * Called when the onGetContentRect of the SelectActionModeCallback is called.
+ * @param outRect The Rect to be populated with the content position.
+ */
+ void onGetContentRect(Rect outRect);
+
+ /**
* @return Whether or not share is available.
*/
boolean isShareAvailable();
@@ -76,19 +84,28 @@ public class SelectActionModeCallback implements ActionMode.Callback {
* @return true if the current selection is of password type.
*/
boolean isSelectionPassword();
+
+ /**
+ * @return true if the current selection is an insertion point.
+ */
+ boolean isInsertion();
+
+ /**
+ * @return true if the current selection is for incognito content.
+ * Note: This should remain constant for the callback's lifetime.
+ */
+ boolean isIncognito();
}
+ protected final ActionHandler mActionHandler;
private final Context mContext;
- private final ActionHandler mActionHandler;
- private final boolean mIncognito;
private boolean mEditable;
private boolean mIsPasswordType;
+ private boolean mIsInsertion;
- protected SelectActionModeCallback(
- Context context, ActionHandler actionHandler, boolean incognito) {
+ public SelectActionModeCallback(Context context, ActionHandler actionHandler) {
mContext = context;
mActionHandler = actionHandler;
- mIncognito = incognito;
}
protected Context getContext() {
@@ -101,6 +118,7 @@ public class SelectActionModeCallback implements ActionMode.Callback {
mode.setSubtitle(null);
mEditable = mActionHandler.isSelectionEditable();
mIsPasswordType = mActionHandler.isSelectionPassword();
+ mIsInsertion = mActionHandler.isInsertion();
createActionMenu(mode, menu);
return true;
}
@@ -109,9 +127,12 @@ public class SelectActionModeCallback implements ActionMode.Callback {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
boolean isEditableNow = mActionHandler.isSelectionEditable();
boolean isPasswordNow = mActionHandler.isSelectionPassword();
- if (mEditable != isEditableNow || mIsPasswordType != isPasswordNow) {
+ boolean isInsertionNow = mActionHandler.isInsertion();
+ if (mEditable != isEditableNow || mIsPasswordType != isPasswordNow
+ || mIsInsertion != isInsertionNow) {
mEditable = isEditableNow;
mIsPasswordType = isPasswordNow;
+ mIsInsertion = isInsertionNow;
menu.clear();
createActionMenu(mode, menu);
return true;
@@ -122,6 +143,15 @@ public class SelectActionModeCallback implements ActionMode.Callback {
private void createActionMenu(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.select_action_menu, menu);
+ if (mIsInsertion) {
+ menu.removeItem(R.id.select_action_menu_select_all);
+ menu.removeItem(R.id.select_action_menu_cut);
+ menu.removeItem(R.id.select_action_menu_copy);
+ menu.removeItem(R.id.select_action_menu_share);
+ menu.removeItem(R.id.select_action_menu_web_search);
+ return;
+ }
+
if (!mEditable || !canPaste()) {
menu.removeItem(R.id.select_action_menu_paste);
}
@@ -134,9 +164,10 @@ public class SelectActionModeCallback implements ActionMode.Callback {
menu.removeItem(R.id.select_action_menu_share);
}
- if (mEditable || mIncognito || !mActionHandler.isWebSearchAvailable()) {
+ if (mEditable || mActionHandler.isIncognito() || !mActionHandler.isWebSearchAvailable()) {
menu.removeItem(R.id.select_action_menu_web_search);
}
+
if (mIsPasswordType) {
menu.removeItem(R.id.select_action_menu_copy);
menu.removeItem(R.id.select_action_menu_cut);
@@ -175,6 +206,19 @@ public class SelectActionModeCallback implements ActionMode.Callback {
mActionHandler.onDestroyActionMode();
}
+ /**
+ * Called when an ActionMode needs to be positioned on screen, potentially occluding view
+ * content. Note this may be called on a per-frame basis.
+ *
+ * @param mode The ActionMode that requires positioning.
+ * @param view The View that originated the ActionMode, in whose coordinates the Rect should
+ * be provided.
+ * @param outRect The Rect to be populated with the content position.
+ */
+ public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
+ mActionHandler.onGetContentRect(outRect);
+ }
+
private boolean canPaste() {
ClipboardManager clipMgr = (ClipboardManager)
getContext().getSystemService(Context.CLIPBOARD_SERVICE);
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/SelectActionMode.java ('k') | ui/base/touch/selection_bound.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698