am 108feca9: Merge "Change selection to use left/right instead of base/extent." into jb-dev
* commit '108feca9a02e7b5da705161660b76d4f356f5900': Change selection to use left/right instead of base/extent.
This commit is contained in:
@@ -88,7 +88,6 @@ import android.view.ViewConfiguration;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewParent;
|
import android.view.ViewParent;
|
||||||
import android.view.ViewRootImpl;
|
import android.view.ViewRootImpl;
|
||||||
import android.view.ViewTreeObserver;
|
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.accessibility.AccessibilityEvent;
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
@@ -888,20 +887,18 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
private Point mSelectHandleLeftOffset;
|
private Point mSelectHandleLeftOffset;
|
||||||
private Point mSelectHandleRightOffset;
|
private Point mSelectHandleRightOffset;
|
||||||
private Point mSelectHandleCenterOffset;
|
private Point mSelectHandleCenterOffset;
|
||||||
private Point mSelectCursorBase = new Point();
|
private Point mSelectCursorLeft = new Point();
|
||||||
private int mSelectCursorBaseLayerId;
|
private int mSelectCursorLeftLayerId;
|
||||||
private QuadF mSelectCursorBaseTextQuad = new QuadF();
|
private QuadF mSelectCursorLeftTextQuad = new QuadF();
|
||||||
private Point mSelectCursorExtent = new Point();
|
private Point mSelectCursorRight = new Point();
|
||||||
private int mSelectCursorExtentLayerId;
|
private int mSelectCursorRightLayerId;
|
||||||
private QuadF mSelectCursorExtentTextQuad = new QuadF();
|
private QuadF mSelectCursorRightTextQuad = new QuadF();
|
||||||
private Point mSelectDraggingCursor;
|
private Point mSelectDraggingCursor;
|
||||||
private Point mSelectDraggingOffset;
|
private Point mSelectDraggingOffset;
|
||||||
private QuadF mSelectDraggingTextQuad;
|
private QuadF mSelectDraggingTextQuad;
|
||||||
private boolean mIsCaretSelection;
|
private boolean mIsCaretSelection;
|
||||||
static final int HANDLE_ID_START = 0;
|
static final int HANDLE_ID_LEFT = 0;
|
||||||
static final int HANDLE_ID_END = 1;
|
static final int HANDLE_ID_RIGHT = 1;
|
||||||
static final int HANDLE_ID_BASE = 2;
|
|
||||||
static final int HANDLE_ID_EXTENT = 3;
|
|
||||||
|
|
||||||
// the color used to highlight the touch rectangles
|
// the color used to highlight the touch rectangles
|
||||||
static final int HIGHLIGHT_COLOR = 0x6633b5e5;
|
static final int HIGHLIGHT_COLOR = 0x6633b5e5;
|
||||||
@@ -3722,13 +3719,13 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mSelectingText) {
|
if (mSelectingText) {
|
||||||
if (mSelectCursorBaseLayerId == mCurrentScrollingLayerId) {
|
if (mSelectCursorLeftLayerId == mCurrentScrollingLayerId) {
|
||||||
mSelectCursorBase.offset(dx, dy);
|
mSelectCursorLeft.offset(dx, dy);
|
||||||
mSelectCursorBaseTextQuad.offset(dx, dy);
|
mSelectCursorLeftTextQuad.offset(dx, dy);
|
||||||
}
|
}
|
||||||
if (mSelectCursorExtentLayerId == mCurrentScrollingLayerId) {
|
if (mSelectCursorRightLayerId == mCurrentScrollingLayerId) {
|
||||||
mSelectCursorExtent.offset(dx, dy);
|
mSelectCursorRight.offset(dx, dy);
|
||||||
mSelectCursorExtentTextQuad.offset(dx, dy);
|
mSelectCursorRightTextQuad.offset(dx, dy);
|
||||||
}
|
}
|
||||||
} else if (mHandleAlpha.getAlpha() > 0) {
|
} else if (mHandleAlpha.getAlpha() > 0) {
|
||||||
// stop fading as we're not going to move with the layer.
|
// stop fading as we're not going to move with the layer.
|
||||||
@@ -3829,6 +3826,9 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
// reset the flag since we set to true in if need after
|
// reset the flag since we set to true in if need after
|
||||||
// loading is see onPageFinished(Url)
|
// loading is see onPageFinished(Url)
|
||||||
mAccessibilityScriptInjected = false;
|
mAccessibilityScriptInjected = false;
|
||||||
|
|
||||||
|
// Don't start out editing.
|
||||||
|
mIsEditingText = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -4589,18 +4589,10 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
* startX, startY, endX, endY
|
* startX, startY, endX, endY
|
||||||
*/
|
*/
|
||||||
private void getSelectionHandles(int[] handles) {
|
private void getSelectionHandles(int[] handles) {
|
||||||
handles[0] = mSelectCursorBase.x;
|
handles[0] = mSelectCursorLeft.x;
|
||||||
handles[1] = mSelectCursorBase.y;
|
handles[1] = mSelectCursorLeft.y;
|
||||||
handles[2] = mSelectCursorExtent.x;
|
handles[2] = mSelectCursorRight.x;
|
||||||
handles[3] = mSelectCursorExtent.y;
|
handles[3] = mSelectCursorRight.y;
|
||||||
if (!nativeIsBaseFirst(mNativeClass)) {
|
|
||||||
int swap = handles[0];
|
|
||||||
handles[0] = handles[2];
|
|
||||||
handles[2] = swap;
|
|
||||||
swap = handles[1];
|
|
||||||
handles[1] = handles[3];
|
|
||||||
handles[3] = swap;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw history
|
// draw history
|
||||||
@@ -5107,8 +5099,8 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
ClipboardManager cm = (ClipboardManager)(mContext
|
ClipboardManager cm = (ClipboardManager)(mContext
|
||||||
.getSystemService(Context.CLIPBOARD_SERVICE));
|
.getSystemService(Context.CLIPBOARD_SERVICE));
|
||||||
if (cm.hasPrimaryClip()) {
|
if (cm.hasPrimaryClip()) {
|
||||||
Point cursorPoint = new Point(contentToViewX(mSelectCursorBase.x),
|
Point cursorPoint = new Point(contentToViewX(mSelectCursorLeft.x),
|
||||||
contentToViewY(mSelectCursorBase.y));
|
contentToViewY(mSelectCursorLeft.y));
|
||||||
Point cursorTop = calculateCaretTop();
|
Point cursorTop = calculateCaretTop();
|
||||||
cursorTop.set(contentToViewX(cursorTop.x),
|
cursorTop.set(contentToViewX(cursorTop.x),
|
||||||
contentToViewY(cursorTop.y));
|
contentToViewY(cursorTop.y));
|
||||||
@@ -5158,12 +5150,12 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
* calculates the top of a caret.
|
* calculates the top of a caret.
|
||||||
*/
|
*/
|
||||||
private Point calculateCaretTop() {
|
private Point calculateCaretTop() {
|
||||||
float scale = scaleAlongSegment(mSelectCursorBase.x, mSelectCursorBase.y,
|
float scale = scaleAlongSegment(mSelectCursorLeft.x, mSelectCursorLeft.y,
|
||||||
mSelectCursorBaseTextQuad.p4, mSelectCursorBaseTextQuad.p3);
|
mSelectCursorLeftTextQuad.p4, mSelectCursorLeftTextQuad.p3);
|
||||||
int x = Math.round(scaleCoordinate(scale,
|
int x = Math.round(scaleCoordinate(scale,
|
||||||
mSelectCursorBaseTextQuad.p1.x, mSelectCursorBaseTextQuad.p2.x));
|
mSelectCursorLeftTextQuad.p1.x, mSelectCursorLeftTextQuad.p2.x));
|
||||||
int y = Math.round(scaleCoordinate(scale,
|
int y = Math.round(scaleCoordinate(scale,
|
||||||
mSelectCursorBaseTextQuad.p1.y, mSelectCursorBaseTextQuad.p2.y));
|
mSelectCursorLeftTextQuad.p1.y, mSelectCursorLeftTextQuad.p2.y));
|
||||||
return new Point(x, y);
|
return new Point(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5174,46 +5166,40 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void syncSelectionCursors() {
|
private void syncSelectionCursors() {
|
||||||
mSelectCursorBaseLayerId =
|
mSelectCursorLeftLayerId =
|
||||||
nativeGetHandleLayerId(mNativeClass, HANDLE_ID_BASE,
|
nativeGetHandleLayerId(mNativeClass, HANDLE_ID_LEFT,
|
||||||
mSelectCursorBase, mSelectCursorBaseTextQuad);
|
mSelectCursorLeft, mSelectCursorLeftTextQuad);
|
||||||
mSelectCursorExtentLayerId =
|
mSelectCursorRightLayerId =
|
||||||
nativeGetHandleLayerId(mNativeClass, HANDLE_ID_EXTENT,
|
nativeGetHandleLayerId(mNativeClass, HANDLE_ID_RIGHT,
|
||||||
mSelectCursorExtent, mSelectCursorExtentTextQuad);
|
mSelectCursorRight, mSelectCursorRightTextQuad);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void adjustSelectionCursors() {
|
private void adjustSelectionCursors() {
|
||||||
boolean wasDraggingStart = (mSelectDraggingCursor == mSelectCursorBase);
|
if (mIsCaretSelection) {
|
||||||
|
return; // no need to swap left and right handles.
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean wasDraggingLeft = (mSelectDraggingCursor == mSelectCursorLeft);
|
||||||
int oldX = mSelectDraggingCursor.x;
|
int oldX = mSelectDraggingCursor.x;
|
||||||
int oldY = mSelectDraggingCursor.y;
|
int oldY = mSelectDraggingCursor.y;
|
||||||
int oldStartX = mSelectCursorBase.x;
|
int oldLeftX = mSelectCursorLeft.x;
|
||||||
int oldStartY = mSelectCursorBase.y;
|
int oldLeftY = mSelectCursorLeft.y;
|
||||||
int oldEndX = mSelectCursorExtent.x;
|
int oldRightX = mSelectCursorRight.x;
|
||||||
int oldEndY = mSelectCursorExtent.y;
|
int oldRightY = mSelectCursorRight.y;
|
||||||
|
|
||||||
syncSelectionCursors();
|
syncSelectionCursors();
|
||||||
boolean dragChanged = oldX != mSelectDraggingCursor.x ||
|
|
||||||
oldY != mSelectDraggingCursor.y;
|
boolean rightChanged = (oldRightX != mSelectCursorRight.x
|
||||||
if (dragChanged && !mIsCaretSelection) {
|
|| oldRightY != mSelectCursorRight.y);
|
||||||
boolean draggingStart;
|
boolean leftChanged = (oldLeftX != mSelectCursorLeft.x
|
||||||
if (wasDraggingStart) {
|
|| oldLeftY != mSelectCursorLeft.y);
|
||||||
float endStart = distanceSquared(oldEndX, oldEndY,
|
if (leftChanged && rightChanged) {
|
||||||
mSelectCursorBase);
|
// Left and right switched places, so swap dragging cursor
|
||||||
float endEnd = distanceSquared(oldEndX, oldEndY,
|
boolean draggingLeft = !wasDraggingLeft;
|
||||||
mSelectCursorExtent);
|
mSelectDraggingCursor = (draggingLeft
|
||||||
draggingStart = endStart > endEnd;
|
? mSelectCursorLeft : mSelectCursorRight);
|
||||||
} else {
|
mSelectDraggingTextQuad = (draggingLeft
|
||||||
float startStart = distanceSquared(oldStartX, oldStartY,
|
? mSelectCursorLeftTextQuad : mSelectCursorRightTextQuad);
|
||||||
mSelectCursorBase);
|
mSelectDraggingOffset = (draggingLeft
|
||||||
float startEnd = distanceSquared(oldStartX, oldStartY,
|
|
||||||
mSelectCursorExtent);
|
|
||||||
draggingStart = startStart > startEnd;
|
|
||||||
}
|
|
||||||
mSelectDraggingCursor = (draggingStart
|
|
||||||
? mSelectCursorBase : mSelectCursorExtent);
|
|
||||||
mSelectDraggingTextQuad = (draggingStart
|
|
||||||
? mSelectCursorBaseTextQuad : mSelectCursorExtentTextQuad);
|
|
||||||
mSelectDraggingOffset = (draggingStart
|
|
||||||
? mSelectHandleLeftOffset : mSelectHandleRightOffset);
|
? mSelectHandleLeftOffset : mSelectHandleRightOffset);
|
||||||
}
|
}
|
||||||
mSelectDraggingCursor.set(oldX, oldY);
|
mSelectDraggingCursor.set(oldX, oldY);
|
||||||
@@ -5239,14 +5225,11 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
private void updateWebkitSelection() {
|
private void updateWebkitSelection() {
|
||||||
int[] handles = null;
|
int[] handles = null;
|
||||||
if (mIsCaretSelection) {
|
if (mIsCaretSelection) {
|
||||||
mSelectCursorExtent.set(mSelectCursorBase.x, mSelectCursorBase.y);
|
mSelectCursorRight.set(mSelectCursorLeft.x, mSelectCursorLeft.y);
|
||||||
}
|
}
|
||||||
if (mSelectingText) {
|
if (mSelectingText) {
|
||||||
handles = new int[4];
|
handles = new int[4];
|
||||||
handles[0] = mSelectCursorBase.x;
|
getSelectionHandles(handles);
|
||||||
handles[1] = mSelectCursorBase.y;
|
|
||||||
handles[2] = mSelectCursorExtent.x;
|
|
||||||
handles[3] = mSelectCursorExtent.y;
|
|
||||||
} else {
|
} else {
|
||||||
nativeSetTextSelection(mNativeClass, 0);
|
nativeSetTextSelection(mNativeClass, 0);
|
||||||
}
|
}
|
||||||
@@ -5610,21 +5593,21 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
Point caretTop = calculateCaretTop();
|
Point caretTop = calculateCaretTop();
|
||||||
if (visibleRect.width() < mEditTextContentBounds.width()) {
|
if (visibleRect.width() < mEditTextContentBounds.width()) {
|
||||||
// The whole edit won't fit in the width, so use the caret rect
|
// The whole edit won't fit in the width, so use the caret rect
|
||||||
if (mSelectCursorBase.x < caretTop.x) {
|
if (mSelectCursorLeft.x < caretTop.x) {
|
||||||
showRect.left = Math.max(0, mSelectCursorBase.x - buffer);
|
showRect.left = Math.max(0, mSelectCursorLeft.x - buffer);
|
||||||
showRect.right = caretTop.x + buffer;
|
showRect.right = caretTop.x + buffer;
|
||||||
} else {
|
} else {
|
||||||
showRect.left = Math.max(0, caretTop.x - buffer);
|
showRect.left = Math.max(0, caretTop.x - buffer);
|
||||||
showRect.right = mSelectCursorBase.x + buffer;
|
showRect.right = mSelectCursorLeft.x + buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (visibleRect.height() < mEditTextContentBounds.height()) {
|
if (visibleRect.height() < mEditTextContentBounds.height()) {
|
||||||
// The whole edit won't fit in the height, so use the caret rect
|
// The whole edit won't fit in the height, so use the caret rect
|
||||||
if (mSelectCursorBase.y > caretTop.y) {
|
if (mSelectCursorLeft.y > caretTop.y) {
|
||||||
showRect.top = Math.max(0, caretTop.y - buffer);
|
showRect.top = Math.max(0, caretTop.y - buffer);
|
||||||
showRect.bottom = mSelectCursorBase.y + buffer;
|
showRect.bottom = mSelectCursorLeft.y + buffer;
|
||||||
} else {
|
} else {
|
||||||
showRect.top = Math.max(0, mSelectCursorBase.y - buffer);
|
showRect.top = Math.max(0, mSelectCursorLeft.y - buffer);
|
||||||
showRect.bottom = caretTop.y + buffer;
|
showRect.bottom = caretTop.y + buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5885,25 +5868,25 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
if (mSelectHandleCenter != null && mSelectHandleCenter.getBounds()
|
if (mSelectHandleCenter != null && mSelectHandleCenter.getBounds()
|
||||||
.contains(shiftedX, shiftedY)) {
|
.contains(shiftedX, shiftedY)) {
|
||||||
mSelectionStarted = true;
|
mSelectionStarted = true;
|
||||||
mSelectDraggingCursor = mSelectCursorBase;
|
mSelectDraggingCursor = mSelectCursorLeft;
|
||||||
mSelectDraggingOffset = mSelectHandleCenterOffset;
|
mSelectDraggingOffset = mSelectHandleCenterOffset;
|
||||||
mSelectDraggingTextQuad = mSelectCursorBaseTextQuad;
|
mSelectDraggingTextQuad = mSelectCursorLeftTextQuad;
|
||||||
mPrivateHandler.removeMessages(CLEAR_CARET_HANDLE);
|
mPrivateHandler.removeMessages(CLEAR_CARET_HANDLE);
|
||||||
hidePasteButton();
|
hidePasteButton();
|
||||||
} else if (mSelectHandleLeft != null
|
} else if (mSelectHandleLeft != null
|
||||||
&& mSelectHandleLeft.getBounds()
|
&& mSelectHandleLeft.getBounds()
|
||||||
.contains(shiftedX, shiftedY)) {
|
.contains(shiftedX, shiftedY)) {
|
||||||
mSelectionStarted = true;
|
mSelectionStarted = true;
|
||||||
mSelectDraggingCursor = mSelectCursorBase;
|
mSelectDraggingOffset = mSelectHandleLeftOffset;
|
||||||
mSelectDraggingOffset = mSelectHandleLeftOffset;
|
mSelectDraggingCursor = mSelectCursorLeft;
|
||||||
mSelectDraggingTextQuad = mSelectCursorBaseTextQuad;
|
mSelectDraggingTextQuad = mSelectCursorLeftTextQuad;
|
||||||
} else if (mSelectHandleRight != null
|
} else if (mSelectHandleRight != null
|
||||||
&& mSelectHandleRight.getBounds()
|
&& mSelectHandleRight.getBounds()
|
||||||
.contains(shiftedX, shiftedY)) {
|
.contains(shiftedX, shiftedY)) {
|
||||||
mSelectionStarted = true;
|
mSelectionStarted = true;
|
||||||
mSelectDraggingCursor = mSelectCursorExtent;
|
|
||||||
mSelectDraggingOffset = mSelectHandleRightOffset;
|
mSelectDraggingOffset = mSelectHandleRightOffset;
|
||||||
mSelectDraggingTextQuad = mSelectCursorExtentTextQuad;
|
mSelectDraggingCursor = mSelectCursorRight;
|
||||||
|
mSelectDraggingTextQuad = mSelectCursorRightTextQuad;
|
||||||
} else if (mIsCaretSelection) {
|
} else if (mIsCaretSelection) {
|
||||||
selectionDone();
|
selectionDone();
|
||||||
}
|
}
|
||||||
@@ -8691,7 +8674,6 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
|
|||||||
private static native void nativeSetTextSelection(int instance, int selection);
|
private static native void nativeSetTextSelection(int instance, int selection);
|
||||||
private static native int nativeGetHandleLayerId(int instance, int handle,
|
private static native int nativeGetHandleLayerId(int instance, int handle,
|
||||||
Point cursorLocation, QuadF textQuad);
|
Point cursorLocation, QuadF textQuad);
|
||||||
private static native boolean nativeIsBaseFirst(int instance);
|
|
||||||
private static native void nativeMapLayerRect(int instance, int layerId,
|
private static native void nativeMapLayerRect(int instance, int layerId,
|
||||||
Rect rect);
|
Rect rect);
|
||||||
// Returns 1 if a layer sync is needed, else 0
|
// Returns 1 if a layer sync is needed, else 0
|
||||||
|
|||||||
Reference in New Issue
Block a user