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

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

Issue 2855353002: Make Paste Popup use selection rect for positioning (Closed)
Patch Set: Created 3 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/SelectionPopupController.java
diff --git a/content/public/android/java/src/org/chromium/content/browser/SelectionPopupController.java b/content/public/android/java/src/org/chromium/content/browser/SelectionPopupController.java
index 6493e4abb98f9cef067f2f883888a7c320db3d72..7437870f5f45b87450709d27f841cd4bb75b64ce 100644
--- a/content/public/android/java/src/org/chromium/content/browser/SelectionPopupController.java
+++ b/content/public/android/java/src/org/chromium/content/browser/SelectionPopupController.java
@@ -268,13 +268,15 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
return actionMode;
}
- void createAndShowPastePopup(int x, int y, boolean canSelectAll, boolean canEditRichly) {
+ void createAndShowPastePopup(
+ int left, int top, int right, int bottom, boolean canSelectAll, boolean canEditRichly) {
if (mView.getParent() == null || mView.getVisibility() != View.VISIBLE) {
return;
}
if (!supportsFloatingActionMode() && !canPaste()) return;
destroyPastePopup();
+ setSelectionRect(left, top, right, bottom);
mCanSelectAllForPastePopup = canSelectAll;
mCanEditRichlyForPastePopup = canEditRichly;
PastePopupMenuDelegate delegate = new PastePopupMenuDelegate() {
@@ -317,17 +319,12 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
} else {
mPastePopupMenu = new LegacyPastePopupMenu(windowContext, mView, delegate);
}
- showPastePopup(x, y);
+ showPastePopup();
}
- private void showPastePopup(int x, int y) {
- // Coordinates are in DIP.
- final float deviceScale = mRenderCoordinates.getDeviceScaleFactor();
- final int xPix = (int) (x * deviceScale);
- final int yPix = (int) (y * deviceScale);
- final float browserControlsShownPix = mRenderCoordinates.getContentOffsetYPix();
+ private void showPastePopup() {
try {
- mPastePopupMenu.show(xPix, (int) (yPix + browserControlsShownPix));
+ mPastePopupMenu.show(mSelectionRect);
} catch (WindowManager.BadTokenException e) {
}
}
@@ -678,15 +675,16 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
*/
@Override
public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
- float deviceScale = mRenderCoordinates.getDeviceScaleFactor();
- outRect.set((int) (mSelectionRect.left * deviceScale),
- (int) (mSelectionRect.top * deviceScale),
- (int) (mSelectionRect.right * deviceScale),
- (int) (mSelectionRect.bottom * deviceScale));
+ outRect.set(mSelectionRect);
+ }
+ private void setSelectionRect(int left, int top, int right, int bottom) {
+ float deviceScale = mRenderCoordinates.getDeviceScaleFactor();
+ mSelectionRect.set((int) (left * deviceScale), (int) (top * deviceScale),
+ (int) (right * deviceScale), (int) (bottom * deviceScale));
// The selection coordinates are relative to the content viewport, but we need
// coordinates relative to the containing View.
- outRect.offset(0, (int) mRenderCoordinates.getContentOffsetYPix());
+ mSelectionRect.offset(0, (int) mRenderCoordinates.getContentOffsetYPix());
}
/**
@@ -916,15 +914,14 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
// All coordinates are in DIP.
@CalledByNative
- private void onSelectionEvent(
- int eventType, int xAnchor, int yAnchor, int left, int top, int right, int bottom) {
+ private void onSelectionEvent(int eventType, int left, int top, int right, int bottom) {
// Ensure the provided selection coordinates form a non-empty rect, as required by
// the selection action mode.
if (left == right) ++right;
if (top == bottom) ++bottom;
switch (eventType) {
case SelectionEventType.SELECTION_HANDLES_SHOWN:
- mSelectionRect.set(left, top, right, bottom);
+ setSelectionRect(left, top, right, bottom);
mHasSelection = true;
mUnselectAllOnDismiss = true;
if (mSelectionClient == null || !mSelectionClient.sendsSelectionPopupUpdates()) {
@@ -937,7 +934,7 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
break;
case SelectionEventType.SELECTION_HANDLES_MOVED:
- mSelectionRect.set(left, top, right, bottom);
+ setSelectionRect(left, top, right, bottom);
if (mPendingShowActionMode) {
showActionModeOrClearOnFailure();
} else {
@@ -965,14 +962,14 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
break;
case SelectionEventType.INSERTION_HANDLE_SHOWN:
- mSelectionRect.set(left, top, right, bottom);
+ setSelectionRect(left, top, right, bottom);
mIsInsertion = true;
break;
case SelectionEventType.INSERTION_HANDLE_MOVED:
- mSelectionRect.set(left, top, right, bottom);
+ setSelectionRect(left, top, right, bottom);
if (!mScrollInProgress && isPastePopupShowing()) {
- showPastePopup(xAnchor, yAnchor);
+ showPastePopup();
} else {
destroyPastePopup();
}
@@ -982,7 +979,8 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
if (mWasPastePopupShowingOnInsertionDragStart) {
destroyPastePopup();
} else {
- mWebContents.showContextMenuAtPoint(xAnchor, yAnchor);
+ mWebContents.showContextMenuAtPoint(
+ mSelectionRect.centerX(), mSelectionRect.centerY());
boliu 2017/05/04 20:36:11 from the xAnchorPix computation below, seems like
amaralp 2017/05/05 01:14:32 Changed it back to bottom left and css pixel
}
mWasPastePopupShowingOnInsertionDragStart = false;
break;
@@ -1000,7 +998,8 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
case SelectionEventType.INSERTION_HANDLE_DRAG_STOPPED:
if (mWasPastePopupShowingOnInsertionDragStart) {
- mWebContents.showContextMenuAtPoint(xAnchor, yAnchor);
+ mWebContents.showContextMenuAtPoint(
+ mSelectionRect.centerX(), mSelectionRect.centerY());
}
mWasPastePopupShowingOnInsertionDragStart = false;
break;
@@ -1011,8 +1010,8 @@ public class SelectionPopupController extends ActionModeCallbackHelper {
if (mSelectionClient != null) {
final float deviceScale = mRenderCoordinates.getDeviceScaleFactor();
- int xAnchorPix = (int) (xAnchor * deviceScale);
- int yAnchorPix = (int) (yAnchor * deviceScale);
+ int xAnchorPix = (int) (mSelectionRect.left * deviceScale);
boliu 2017/05/04 20:36:11 isn't mSelectionRect already multiplied by scale?
amaralp 2017/05/05 01:14:32 Yeah, made it not be multiplied by scale.
+ int yAnchorPix = (int) (mSelectionRect.bottom * deviceScale);
mSelectionClient.onSelectionEvent(eventType, xAnchorPix, yAnchorPix);
}
}

Powered by Google App Engine
This is Rietveld 408576698