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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/SelectionPopupController.java

Issue 2721813002: Make SelectionPopupController.ShowPastePopup only be triggered by Blink (Closed)
Patch Set: Rebased for Bo Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 return isActionModeValid(); 216 return isActionModeValid();
217 } 217 }
218 218
219 @TargetApi(Build.VERSION_CODES.M) 219 @TargetApi(Build.VERSION_CODES.M)
220 private ActionMode startFloatingActionMode() { 220 private ActionMode startFloatingActionMode() {
221 ActionMode actionMode = mView.startActionMode( 221 ActionMode actionMode = mView.startActionMode(
222 new FloatingActionModeCallback(this, mCallback), ActionMode.TYPE _FLOATING); 222 new FloatingActionModeCallback(this, mCallback), ActionMode.TYPE _FLOATING);
223 return actionMode; 223 return actionMode;
224 } 224 }
225 225
226 void showPastePopup(int x, int y) { 226 void createAndShowPastePopup(int x, int y) {
227 if (mView.getParent() == null || mView.getVisibility() != View.VISIBLE) { 227 if (mView.getParent() == null || mView.getVisibility() != View.VISIBLE) {
228 return; 228 return;
229 } 229 }
230 230
231 if (!supportsFloatingActionMode() && !canPaste()) return; 231 if (!supportsFloatingActionMode() && !canPaste()) return;
232 PastePopupMenuDelegate delegate = new PastePopupMenuDelegate() {
boliu 2017/03/17 22:54:20 does it matter if mPastePopupMenu already exists h
amaralp 2017/03/21 00:26:24 Addressed in crrev.com/2757313003.
233 @Override
234 public void paste() {
235 mWebContents.paste();
236 mWebContents.dismissTextHandles();
237 }
232 238
233 PastePopupMenu pastePopupMenu = getPastePopup(); 239 @Override
234 if (pastePopupMenu == null) return; 240 public boolean canPaste() {
241 return SelectionPopupController.this.canPaste();
242 }
243 };
244 Context windowContext = mWindowAndroid.getContext().get();
245 if (windowContext == null) return;
246 if (supportsFloatingActionMode()) {
247 mPastePopupMenu = new FloatingPastePopupMenu(windowContext, mView, d elegate);
248 } else {
249 mPastePopupMenu = new LegacyPastePopupMenu(windowContext, mView, del egate);
250 }
251 showPastePopup(x, y);
252 }
235 253
254 private void showPastePopup(int x, int y) {
255 if (mPastePopupMenu == null) return;
236 // Coordinates are in DIP. 256 // Coordinates are in DIP.
237 final float deviceScale = mRenderCoordinates.getDeviceScaleFactor(); 257 final float deviceScale = mRenderCoordinates.getDeviceScaleFactor();
238 final int xPix = (int) (x * deviceScale); 258 final int xPix = (int) (x * deviceScale);
239 final int yPix = (int) (y * deviceScale); 259 final int yPix = (int) (y * deviceScale);
240 final float browserControlsShownPix = mRenderCoordinates.getContentOffse tYPix(); 260 final float browserControlsShownPix = mRenderCoordinates.getContentOffse tYPix();
241 try { 261 try {
242 pastePopupMenu.show(xPix, (int) (yPix + browserControlsShownPix)); 262 mPastePopupMenu.show(xPix, (int) (yPix + browserControlsShownPix));
243 } catch (WindowManager.BadTokenException e) { 263 } catch (WindowManager.BadTokenException e) {
244 } 264 }
245 } 265 }
246 266
247 @Override 267 @Override
248 public boolean supportsFloatingActionMode() { 268 public boolean supportsFloatingActionMode() {
249 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; 269 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
250 } 270 }
251 271
252 void hidePastePopup() { 272 void hidePastePopup() {
253 if (mPastePopupMenu != null) mPastePopupMenu.hide(); 273 if (mPastePopupMenu != null) mPastePopupMenu.hide();
254 } 274 }
255 275
256 private PastePopupMenu getPastePopup() {
257 if (mPastePopupMenu == null) {
258 PastePopupMenuDelegate delegate = new PastePopupMenuDelegate() {
259 @Override
260 public void paste() {
261 mWebContents.paste();
262 mWebContents.dismissTextHandles();
263 }
264
265 @Override
266 public boolean canPaste() {
267 return SelectionPopupController.this.canPaste();
268 }
269 };
270 Context windowContext = mWindowAndroid.getContext().get();
271 if (windowContext == null) return null;
272 if (supportsFloatingActionMode()) {
273 mPastePopupMenu = new FloatingPastePopupMenu(windowContext, mVie w, delegate);
274 } else {
275 mPastePopupMenu = new LegacyPastePopupMenu(windowContext, mView, delegate);
276 }
277 }
278 return mPastePopupMenu;
279 }
280
281 void destroyPastePopup() { 276 void destroyPastePopup() {
282 hidePastePopup(); 277 hidePastePopup();
283 mPastePopupMenu = null; 278 mPastePopupMenu = null;
284 } 279 }
285 280
286 @VisibleForTesting 281 @VisibleForTesting
287 public boolean isPastePopupShowing() { 282 public boolean isPastePopupShowing() {
288 return mPastePopupMenu != null && mPastePopupMenu.isShowing(); 283 return mPastePopupMenu != null && mPastePopupMenu.isShowing();
289 } 284 }
290 285
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 break; 786 break;
792 787
793 case SelectionEventType.INSERTION_HANDLE_SHOWN: 788 case SelectionEventType.INSERTION_HANDLE_SHOWN:
794 mSelectionRect.set(left, top, right, bottom); 789 mSelectionRect.set(left, top, right, bottom);
795 setIsInsertion(true); 790 setIsInsertion(true);
796 break; 791 break;
797 792
798 case SelectionEventType.INSERTION_HANDLE_MOVED: 793 case SelectionEventType.INSERTION_HANDLE_MOVED:
799 mSelectionRect.set(left, top, right, bottom); 794 mSelectionRect.set(left, top, right, bottom);
800 if (!isScrollInProgress && isPastePopupShowing()) { 795 if (!isScrollInProgress && isPastePopupShowing()) {
801 mWebContents.showContextMenuAtPoint(xAnchor, yAnchor); 796 showPastePopup(xAnchor, yAnchor);
802 } else { 797 } else {
803 hidePastePopup(); 798 hidePastePopup();
804 } 799 }
805 break; 800 break;
806 801
807 case SelectionEventType.INSERTION_HANDLE_TAPPED: 802 case SelectionEventType.INSERTION_HANDLE_TAPPED:
808 if (mWasPastePopupShowingOnInsertionDragStart) { 803 if (mWasPastePopupShowingOnInsertionDragStart) {
809 hidePastePopup(); 804 hidePastePopup();
810 } else { 805 } else {
811 mWebContents.showContextMenuAtPoint(xAnchor, yAnchor); 806 mWebContents.showContextMenuAtPoint(xAnchor, yAnchor);
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 mIsInsertion = insertion; 905 mIsInsertion = insertion;
911 } 906 }
912 907
913 private boolean isShareAvailable() { 908 private boolean isShareAvailable() {
914 Intent intent = new Intent(Intent.ACTION_SEND); 909 Intent intent = new Intent(Intent.ACTION_SEND);
915 intent.setType("text/plain"); 910 intent.setType("text/plain");
916 return mContext.getPackageManager().queryIntentActivities(intent, 911 return mContext.getPackageManager().queryIntentActivities(intent,
917 PackageManager.MATCH_DEFAULT_ONLY).size() > 0; 912 PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
918 } 913 }
919 } 914 }
OLDNEW
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698