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

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

Issue 10828098: Upstreaming Select Action (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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/ContentViewCore.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
index 1d6364b5d1da54889e7efa43249db29d31e6f433..2b68c4412ee07600b3e1e356b79d6a80dc248181 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
@@ -9,6 +9,7 @@ import android.content.res.Configuration;
import android.graphics.Canvas;
import android.os.Bundle;
import android.util.Log;
+import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
@@ -146,6 +147,16 @@ public class ContentViewCore implements MotionEventDelegate {
// will be mistakenly fired.
private boolean mIgnoreSingleTap;
+ // Only valid when focused on a text / password field.
+ private ImeAdapter mImeAdapter;
+
+ // Tracks whether a selection is currently active. When applied to selected text, indicates
+ // whether the last selected text is still highlighted.
+ private boolean mHasSelection;
+ private String mLastSelectedText;
+ private boolean mSelectionEditable;
+ private ActionMode mActionMode;
+
// The legacy webview DownloadListener.
private DownloadListener mDownloadListener;
// ContentViewDownloadDelegate adds support for authenticated downloads
@@ -472,6 +483,10 @@ public class ContentViewCore implements MotionEventDelegate {
if (mNativeContentViewCore != 0) nativeClearHistory(mNativeContentViewCore);
}
+ String getSelectedText() {
+ return mHasSelection ? mLastSelectedText : "";
+ }
+
// End FrameLayout overrides.
@@ -718,6 +733,63 @@ public class ContentViewCore implements MotionEventDelegate {
return mDownloadDelegate;
}
+ private void showSelectActionBar() {
+ if (mActionMode != null) {
+ mActionMode.invalidate();
+ return;
+ }
+
+ // Start a new action mode with a SelectActionModeCallback.
+ SelectActionModeCallback.ActionHandler actionHandler =
+ new SelectActionModeCallback.ActionHandler() {
+ @Override
+ public boolean selectAll() {
+ return mImeAdapter.selectAll();
+ }
+
+ @Override
+ public boolean cut() {
+ return mImeAdapter.cut();
+ }
+
+ @Override
+ public boolean copy() {
+ return mImeAdapter.copy();
+ }
+
+ @Override
+ public boolean paste() {
+ return mImeAdapter.paste();
+ }
+
+ @Override
+ public boolean isSelectionEditable() {
+ return mSelectionEditable;
+ }
+
+ @Override
+ public String getSelectedText() {
+ return ContentViewCore.this.getSelectedText();
+ }
+
+ @Override
+ public void onDestroyActionMode() {
+ mActionMode = null;
+ mImeAdapter.unselect();
+ getContentViewClient().onContextualActionBarHidden();
+ }
+ };
+ mActionMode = mContainerView.startActionMode(
+ getContentViewClient().getSelectActionModeCallback(getContext(), actionHandler,
+ nativeIsIncognito(mNativeContentViewCore)));
+ if (mActionMode == null) {
+ // There is no ActionMode, so remove the selection.
+ mImeAdapter.unselect();
+ } else {
+ getContentViewClient().onContextualActionBarShown();
+ }
+ }
+
/**
* @return Whether the native ContentView has crashed.
*/

Powered by Google App Engine
This is Rietveld 408576698