diff options
author | George Mount <mount@google.com> | 2012-01-10 11:24:02 -0800 |
---|---|---|
committer | George Mount <mount@google.com> | 2012-01-18 14:59:21 -0800 |
commit | 3d09531f89238953be9065e0e2c1a755d424d392 (patch) | |
tree | 307f86ff0bc6402a2ff544818a377b3e018c5481 /core/java/android/webkit/SelectActionModeCallback.java | |
parent | ea77ed02e44ebd177e3c7e1797d9cb804820ce43 (diff) | |
download | frameworks_base-3d09531f89238953be9065e0e2c1a755d424d392.zip frameworks_base-3d09531f89238953be9065e0e2c1a755d424d392.tar.gz frameworks_base-3d09531f89238953be9065e0e2c1a755d424d392.tar.bz2 |
Add cut and paste to ContentEditable.
Bug 5806267
Use visual selection to determine the webkit selection.
The webkit selection can be used to cut text from an editable
area. It can also be used to do better complex character text
copy.
Webkit change: I194c6d9e2add67151b97092a1a54f5c081296000
Change-Id: I56543d17670a8c98484314c89c7fa6a94cb809e4
Diffstat (limited to 'core/java/android/webkit/SelectActionModeCallback.java')
-rw-r--r-- | core/java/android/webkit/SelectActionModeCallback.java | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/core/java/android/webkit/SelectActionModeCallback.java b/core/java/android/webkit/SelectActionModeCallback.java index 8c174aa..cdf20f6 100644 --- a/core/java/android/webkit/SelectActionModeCallback.java +++ b/core/java/android/webkit/SelectActionModeCallback.java @@ -17,6 +17,7 @@ package android.webkit; import android.app.SearchManager; +import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; import android.provider.Browser; @@ -27,11 +28,16 @@ import android.view.MenuItem; class SelectActionModeCallback implements ActionMode.Callback { private WebView mWebView; private ActionMode mActionMode; + private boolean mIsTextSelected = true; void setWebView(WebView webView) { mWebView = webView; } + void setTextSelected(boolean isTextSelected) { + mIsTextSelected = isTextSelected; + } + void finish() { // It is possible that onCreateActionMode was never called, in the case // where there is no ActionBar, for example. @@ -52,17 +58,25 @@ class SelectActionModeCallback implements ActionMode.Callback { mode.setTitle(allowText ? context.getString(com.android.internal.R.string.textSelectionCABTitle) : null); - if (!mode.isUiFocusable()) { - // If the action mode UI we're running in isn't capable of taking window focus - // the user won't be able to type into the find on page UI. Disable this functionality. - // (Note that this should only happen in floating dialog windows.) - // This can be removed once we can handle multiple focusable windows at a time - // in a better way. - final MenuItem findOnPageItem = menu.findItem(com.android.internal.R.id.find); - if (findOnPageItem != null) { - findOnPageItem.setVisible(false); - } - } + // If the action mode UI we're running in isn't capable of taking window focus + // the user won't be able to type into the find on page UI. Disable this functionality. + // (Note that this should only happen in floating dialog windows.) + // This can be removed once we can handle multiple focusable windows at a time + // in a better way. + ClipboardManager cm = (ClipboardManager)(context + .getSystemService(Context.CLIPBOARD_SERVICE)); + boolean isFocusable = mode.isUiFocusable(); + boolean isEditable = mWebView.focusCandidateIsEditableText(); + boolean canPaste = isEditable && cm.hasPrimaryClip() && isFocusable; + boolean canFind = !isEditable && isFocusable; + boolean canCut = isEditable && mIsTextSelected && isFocusable; + boolean canCopy = mIsTextSelected; + boolean canWebSearch = mIsTextSelected; + setMenuVisibility(menu, canFind, com.android.internal.R.id.find); + setMenuVisibility(menu, canPaste, com.android.internal.R.id.paste); + setMenuVisibility(menu, canCut, com.android.internal.R.id.cut); + setMenuVisibility(menu, canCopy, com.android.internal.R.id.copy); + setMenuVisibility(menu, canWebSearch, com.android.internal.R.id.websearch); mActionMode = mode; return true; } @@ -75,11 +89,21 @@ class SelectActionModeCallback implements ActionMode.Callback { @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch(item.getItemId()) { + case android.R.id.cut: + mWebView.cutSelection(); + mode.finish(); + break; + case android.R.id.copy: mWebView.copySelection(); mode.finish(); break; + case android.R.id.paste: + mWebView.pasteFromClipboard(); + mode.finish(); + break; + case com.android.internal.R.id.share: String selection = mWebView.getSelection(); Browser.sendString(mWebView.getContext(), selection); @@ -113,4 +137,11 @@ class SelectActionModeCallback implements ActionMode.Callback { public void onDestroyActionMode(ActionMode mode) { mWebView.selectionDone(); } + + private void setMenuVisibility(Menu menu, boolean visible, int resourceId) { + final MenuItem item = menu.findItem(resourceId); + if (item != null) { + item.setVisible(visible); + } + } } |