| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.app.Activity; | 8 import android.app.Activity; |
| 9 import android.app.SearchManager; | 9 import android.app.SearchManager; |
| 10 import android.content.ClipboardManager; | 10 import android.content.ClipboardManager; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 private ActionMode mActionMode; | 95 private ActionMode mActionMode; |
| 96 | 96 |
| 97 // Bit field for mappings from menu item to a flag indicating it is allowed. | 97 // Bit field for mappings from menu item to a flag indicating it is allowed. |
| 98 private int mAllowedMenuItems; | 98 private int mAllowedMenuItems; |
| 99 | 99 |
| 100 private boolean mHidden; | 100 private boolean mHidden; |
| 101 | 101 |
| 102 private boolean mEditable; | 102 private boolean mEditable; |
| 103 private boolean mIsPasswordType; | 103 private boolean mIsPasswordType; |
| 104 private boolean mIsInsertion; | 104 private boolean mIsInsertion; |
| 105 private boolean mCanSelectAllForPastePopup; |
| 105 | 106 |
| 106 private boolean mUnselectAllOnDismiss; | 107 private boolean mUnselectAllOnDismiss; |
| 107 private String mLastSelectedText; | 108 private String mLastSelectedText; |
| 108 | 109 |
| 109 // Tracks whether a selection is currently active. When applied to selected
text, indicates | 110 // Tracks whether a selection is currently active. When applied to selected
text, indicates |
| 110 // whether the last selected text is still highlighted. | 111 // whether the last selected text is still highlighted. |
| 111 private boolean mHasSelection; | 112 private boolean mHasSelection; |
| 112 | 113 |
| 113 // Lazily created paste popup menu, triggered either via long press in an | 114 // Lazily created paste popup menu, triggered either via long press in an |
| 114 // editable region or from tapping the insertion handle. | 115 // editable region or from tapping the insertion handle. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 if (!isActionModeValid()) clearSelection(); | 245 if (!isActionModeValid()) clearSelection(); |
| 245 } | 246 } |
| 246 | 247 |
| 247 @TargetApi(Build.VERSION_CODES.M) | 248 @TargetApi(Build.VERSION_CODES.M) |
| 248 private ActionMode startFloatingActionMode() { | 249 private ActionMode startFloatingActionMode() { |
| 249 ActionMode actionMode = mView.startActionMode( | 250 ActionMode actionMode = mView.startActionMode( |
| 250 new FloatingActionModeCallback(this, mCallback), ActionMode.TYPE
_FLOATING); | 251 new FloatingActionModeCallback(this, mCallback), ActionMode.TYPE
_FLOATING); |
| 251 return actionMode; | 252 return actionMode; |
| 252 } | 253 } |
| 253 | 254 |
| 254 void createAndShowPastePopup(int x, int y) { | 255 void createAndShowPastePopup(int x, int y, boolean canSelectAll) { |
| 255 if (mView.getParent() == null || mView.getVisibility() != View.VISIBLE)
{ | 256 if (mView.getParent() == null || mView.getVisibility() != View.VISIBLE)
{ |
| 256 return; | 257 return; |
| 257 } | 258 } |
| 258 | 259 |
| 259 if (!supportsFloatingActionMode() && !canPaste()) return; | 260 if (!supportsFloatingActionMode() && !canPaste()) return; |
| 260 destroyPastePopup(); | 261 destroyPastePopup(); |
| 262 mCanSelectAllForPastePopup = canSelectAll; |
| 261 PastePopupMenuDelegate delegate = new PastePopupMenuDelegate() { | 263 PastePopupMenuDelegate delegate = new PastePopupMenuDelegate() { |
| 262 @Override | 264 @Override |
| 263 public void paste() { | 265 public void paste() { |
| 264 mWebContents.paste(); | 266 mWebContents.paste(); |
| 265 mWebContents.dismissTextHandles(); | 267 mWebContents.dismissTextHandles(); |
| 266 } | 268 } |
| 267 | 269 |
| 268 @Override | 270 @Override |
| 269 public boolean canPaste() { | 271 public boolean canPaste() { |
| 270 return SelectionPopupController.this.canPaste(); | 272 return SelectionPopupController.this.canPaste(); |
| 271 } | 273 } |
| 274 |
| 275 @Override |
| 276 public void selectAll() { |
| 277 SelectionPopupController.this.selectAll(); |
| 278 } |
| 279 |
| 280 @Override |
| 281 public boolean canSelectAll() { |
| 282 return SelectionPopupController.this.canSelectAll(); |
| 283 } |
| 272 }; | 284 }; |
| 273 Context windowContext = mWindowAndroid.getContext().get(); | 285 Context windowContext = mWindowAndroid.getContext().get(); |
| 274 if (windowContext == null) return; | 286 if (windowContext == null) return; |
| 275 if (supportsFloatingActionMode()) { | 287 if (supportsFloatingActionMode()) { |
| 276 mPastePopupMenu = new FloatingPastePopupMenu(windowContext, mView, d
elegate); | 288 mPastePopupMenu = new FloatingPastePopupMenu(windowContext, mView, d
elegate); |
| 277 } else { | 289 } else { |
| 278 mPastePopupMenu = new LegacyPastePopupMenu(windowContext, mView, del
egate); | 290 mPastePopupMenu = new LegacyPastePopupMenu(windowContext, mView, del
egate); |
| 279 } | 291 } |
| 280 showPastePopup(x, y); | 292 showPastePopup(x, y); |
| 281 } | 293 } |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 | 746 |
| 735 /** | 747 /** |
| 736 * @return true if the current selection is an insertion point. | 748 * @return true if the current selection is an insertion point. |
| 737 */ | 749 */ |
| 738 @VisibleForTesting | 750 @VisibleForTesting |
| 739 public boolean isInsertion() { | 751 public boolean isInsertion() { |
| 740 return mIsInsertion; | 752 return mIsInsertion; |
| 741 } | 753 } |
| 742 | 754 |
| 743 /** | 755 /** |
| 756 * @return true if the current selection can select all. |
| 757 */ |
| 758 @VisibleForTesting |
| 759 public boolean canSelectAll() { |
| 760 return mCanSelectAllForPastePopup; |
| 761 } |
| 762 |
| 763 /** |
| 744 * @return true if the current selection is for incognito content. | 764 * @return true if the current selection is for incognito content. |
| 745 * Note: This should remain constant for the callback's lifetime. | 765 * Note: This should remain constant for the callback's lifetime. |
| 746 */ | 766 */ |
| 747 private boolean isIncognito() { | 767 private boolean isIncognito() { |
| 748 return mWebContents.isIncognito(); | 768 return mWebContents.isIncognito(); |
| 749 } | 769 } |
| 750 | 770 |
| 751 /** | 771 /** |
| 752 * @see ActionModeCallbackHelper#sanitizeQuery(String, int) | 772 * @see ActionModeCallbackHelper#sanitizeQuery(String, int) |
| 753 */ | 773 */ |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 | 1018 |
| 999 // Remain pending until SELECTION_HANDLES_MOVED arrives. | 1019 // Remain pending until SELECTION_HANDLES_MOVED arrives. |
| 1000 if (mPendingShowActionMode) return; | 1020 if (mPendingShowActionMode) return; |
| 1001 } | 1021 } |
| 1002 | 1022 |
| 1003 // Rely on this method to clear |mHidden| and unhide the action mode
. | 1023 // Rely on this method to clear |mHidden| and unhide the action mode
. |
| 1004 showActionModeOrClearOnFailure(); | 1024 showActionModeOrClearOnFailure(); |
| 1005 } | 1025 } |
| 1006 }; | 1026 }; |
| 1007 } | 1027 } |
| OLD | NEW |