diff options
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/ViewPropertyAnimator.java | 142 | ||||
| -rw-r--r-- | core/java/android/webkit/WebView.java | 390 | ||||
| -rw-r--r-- | core/java/android/webkit/WebViewCore.java | 32 | ||||
| -rw-r--r-- | core/java/android/widget/NumberPicker.java | 10 |
4 files changed, 324 insertions, 250 deletions
diff --git a/core/java/android/view/ViewPropertyAnimator.java b/core/java/android/view/ViewPropertyAnimator.java index 89a1ef2..0fdcd0f 100644 --- a/core/java/android/view/ViewPropertyAnimator.java +++ b/core/java/android/view/ViewPropertyAnimator.java @@ -113,6 +113,10 @@ public class ViewPropertyAnimator { * on that list are added to the list of properties associated with that animator. */ ArrayList<NameValuesHolder> mPendingAnimations = new ArrayList<NameValuesHolder>(); + private Runnable mPendingSetupAction; + private Runnable mPendingCleanupAction; + private Runnable mPendingOnStartAction; + private Runnable mPendingOnEndAction; /** * Constants used to associate a property being requested and the mechanism used to set @@ -199,6 +203,10 @@ public class ViewPropertyAnimator { */ private HashMap<Animator, PropertyBundle> mAnimatorMap = new HashMap<Animator, PropertyBundle>(); + private HashMap<Animator, Runnable> mAnimatorSetupMap; + private HashMap<Animator, Runnable> mAnimatorCleanupMap; + private HashMap<Animator, Runnable> mAnimatorOnStartMap; + private HashMap<Animator, Runnable> mAnimatorOnEndMap; /** * This is the information we need to set each property during the animation. @@ -614,6 +622,93 @@ public class ViewPropertyAnimator { } /** + * The View associated with this ViewPropertyAnimator will have its + * {@link View#setLayerType(int, android.graphics.Paint) layer type} set to + * {@link View#LAYER_TYPE_HARDWARE} for the duration of the next animation. This state + * is not persistent, either on the View or on this ViewPropertyAnimator: the layer type + * of the View will be restored when the animation ends to what it was when this method was + * called, and this setting on ViewPropertyAnimator is only valid for the next animation. + * Note that calling this method and then independently setting the layer type of the View + * (by a direct call to {@link View#setLayerType(int, android.graphics.Paint)}) will result + * in some inconsistency, including having the layer type restored to its pre-withLayer() + * value when the animation ends. + * + * @see View#setLayerType(int, android.graphics.Paint) + * @return This object, allowing calls to methods in this class to be chained. + */ + public ViewPropertyAnimator withLayer() { + mPendingSetupAction= new Runnable() { + @Override + public void run() { + mView.setLayerType(View.LAYER_TYPE_HARDWARE, null); + } + }; + final int currentLayerType = mView.getLayerType(); + mPendingCleanupAction = new Runnable() { + @Override + public void run() { + mView.setLayerType(currentLayerType, null); + } + }; + if (mAnimatorSetupMap == null) { + mAnimatorSetupMap = new HashMap<Animator, Runnable>(); + } + if (mAnimatorCleanupMap == null) { + mAnimatorCleanupMap = new HashMap<Animator, Runnable>(); + } + + return this; + } + + /** + * Specifies an action to take place when the next animation runs. If there is a + * {@link #setStartDelay(long) startDelay} set on this ViewPropertyAnimator, then the + * action will run after that startDelay expires, when the actual animation begins. + * This method, along with {@link #withEndAction(Runnable)}, is intended to help facilitate + * choreographing ViewPropertyAnimator animations with other animations or actions + * in the application. + * + * @param runnable The action to run when the next animation starts. + * @return This object, allowing calls to methods in this class to be chained. + */ + public ViewPropertyAnimator withStartAction(Runnable runnable) { + mPendingOnStartAction = runnable; + if (runnable != null && mAnimatorOnStartMap == null) { + mAnimatorOnStartMap = new HashMap<Animator, Runnable>(); + } + return this; + } + + /** + * Specifies an action to take place when the next animation ends. The action is only + * run if the animation ends normally; if the ViewPropertyAnimator is canceled during + * that animation, the runnable will not run. + * This method, along with {@link #withStartAction(Runnable)}, is intended to help facilitate + * choreographing ViewPropertyAnimator animations with other animations or actions + * in the application. + * + * <p>For example, the following code animates a view to x=200 and then back to 0:</p> + * <pre> + * Runnable endAction = new Runnable() { + * public void run() { + * view.animate().x(0); + * } + * }; + * view.animate().x(200).onEnd(endAction); + * </pre> + * + * @param runnable The action to run when the next animation ends. + * @return This object, allowing calls to methods in this class to be chained. + */ + public ViewPropertyAnimator withEndAction(Runnable runnable) { + mPendingOnEndAction = runnable; + if (runnable != null && mAnimatorOnEndMap == null) { + mAnimatorOnEndMap = new HashMap<Animator, Runnable>(); + } + return this; + } + + /** * Starts the underlying Animator for a set of properties. We use a single animator that * simply runs from 0 to 1, and then use that fractional value to set each property * value accordingly. @@ -630,6 +725,22 @@ public class ViewPropertyAnimator { propertyMask |= nameValuesHolder.mNameConstant; } mAnimatorMap.put(animator, new PropertyBundle(propertyMask, nameValueList)); + if (mPendingSetupAction != null) { + mAnimatorSetupMap.put(animator, mPendingSetupAction); + mPendingSetupAction = null; + } + if (mPendingCleanupAction != null) { + mAnimatorCleanupMap.put(animator, mPendingCleanupAction); + mPendingCleanupAction = null; + } + if (mPendingOnStartAction != null) { + mAnimatorOnStartMap.put(animator, mPendingOnStartAction); + mPendingOnStartAction = null; + } + if (mPendingOnEndAction != null) { + mAnimatorOnEndMap.put(animator, mPendingOnEndAction); + mPendingOnEndAction = null; + } animator.addUpdateListener(mAnimatorEventListener); animator.addListener(mAnimatorEventListener); if (mStartDelaySet) { @@ -800,6 +911,20 @@ public class ViewPropertyAnimator { implements Animator.AnimatorListener, ValueAnimator.AnimatorUpdateListener { @Override public void onAnimationStart(Animator animation) { + if (mAnimatorSetupMap != null) { + Runnable r = mAnimatorSetupMap.get(animation); + if (r != null) { + r.run(); + } + mAnimatorSetupMap.remove(animation); + } + if (mAnimatorOnStartMap != null) { + Runnable r = mAnimatorOnStartMap.get(animation); + if (r != null) { + r.run(); + } + mAnimatorOnStartMap.remove(animation); + } if (mListener != null) { mListener.onAnimationStart(animation); } @@ -810,6 +935,9 @@ public class ViewPropertyAnimator { if (mListener != null) { mListener.onAnimationCancel(animation); } + if (mAnimatorOnEndMap != null) { + mAnimatorOnEndMap.remove(animation); + } } @Override @@ -824,6 +952,20 @@ public class ViewPropertyAnimator { if (mListener != null) { mListener.onAnimationEnd(animation); } + if (mAnimatorOnEndMap != null) { + Runnable r = mAnimatorOnEndMap.get(animation); + if (r != null) { + r.run(); + } + mAnimatorOnEndMap.remove(animation); + } + if (mAnimatorCleanupMap != null) { + Runnable r = mAnimatorCleanupMap.get(animation); + if (r != null) { + r.run(); + } + mAnimatorCleanupMap.remove(animation); + } mAnimatorMap.remove(animation); } diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index cc8eef2..c9123e9 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -789,12 +789,18 @@ public class WebView extends AbsoluteLayout // know to handle Shift and arrows natively first private boolean mAccessibilityScriptInjected; - static final boolean USE_JAVA_TEXT_SELECTION = true; - static final boolean DEBUG_TEXT_HANDLES = false; - private Region mTextSelectionRegion = new Region(); - private Paint mTextSelectionPaint; private Drawable mSelectHandleLeft; private Drawable mSelectHandleRight; + private Rect mSelectCursorBase = new Rect(); + private int mSelectCursorBaseLayerId; + private Rect mSelectCursorExtent = new Rect(); + private int mSelectCursorExtentLayerId; + private Rect mSelectDraggingCursor; + private Point mSelectDraggingOffset = new Point(); + static final int HANDLE_ID_START = 0; + static final int HANDLE_ID_END = 1; + static final int HANDLE_ID_BASE = 2; + static final int HANDLE_ID_EXTENT = 3; static boolean sDisableNavcache = false; // the color used to highlight the touch rectangles @@ -2656,12 +2662,6 @@ public class WebView extends AbsoluteLayout return mZoomManager.getScale(); } - // Called by JNI. Returns the scale to apply to the text selection handles - /* package */ float getTextHandleScale() { - float density = mContext.getResources().getDisplayMetrics().density; - return density / getScale(); - } - /** * Compute the reading level scale of the WebView * @param scale The current scale. @@ -3852,6 +3852,16 @@ public class WebView extends AbsoluteLayout if (x == mScrollingLayerRect.left && y == mScrollingLayerRect.top) { return; } + if (mSelectingText) { + int dx = mScrollingLayerRect.left - x; + int dy = mScrollingLayerRect.top - y; + if (mSelectCursorBaseLayerId == mCurrentScrollingLayerId) { + mSelectCursorBase.offset(dx, dy); + } + if (mSelectCursorExtentLayerId == mCurrentScrollingLayerId) { + mSelectCursorExtent.offset(dx, dy); + } + } nativeScrollLayer(mCurrentScrollingLayerId, x, y); mScrollingLayerRect.left = x; mScrollingLayerRect.top = y; @@ -4624,12 +4634,7 @@ public class WebView extends AbsoluteLayout * Select the word at the indicated content coordinates. */ boolean selectText(int x, int y) { - if (!setUpSelect(true, x, y)) { - return false; - } - nativeSetExtendSelection(); - mDrawSelectionPointer = false; - mTouchMode = TOUCH_DRAG_MODE; + mWebViewCore.sendMessage(EventHub.SELECT_WORD_AT, x, y); return true; } @@ -4830,11 +4835,8 @@ public class WebView extends AbsoluteLayout int extras = DRAW_EXTRAS_NONE; if (mFindIsUp) { extras = DRAW_EXTRAS_FIND; - } else if (mSelectingText && (!USE_JAVA_TEXT_SELECTION || DEBUG_TEXT_HANDLES)) { + } else if (mSelectingText) { extras = DRAW_EXTRAS_SELECTION; - nativeSetSelectionPointer(mNativeClass, - mDrawSelectionPointer, - mZoomManager.getInvScale(), mSelectX, mSelectY - getTitleHeight()); } else if (drawCursorRing) { extras = DRAW_EXTRAS_CURSOR_RING; } @@ -4879,7 +4881,7 @@ public class WebView extends AbsoluteLayout } canvas.restoreToCount(saveCount); - if (mSelectingText && USE_JAVA_TEXT_SELECTION) { + if (mSelectingText) { drawTextSelectionHandles(canvas); } @@ -4901,30 +4903,12 @@ public class WebView extends AbsoluteLayout } private void drawTextSelectionHandles(Canvas canvas) { - if (mTextSelectionPaint == null) { - mTextSelectionPaint = new Paint(); - mTextSelectionPaint.setColor(HIGHLIGHT_COLOR); - } - mTextSelectionRegion.setEmpty(); - nativeGetTextSelectionRegion(mNativeClass, mTextSelectionRegion); - Rect r = new Rect(); - RegionIterator iter = new RegionIterator(mTextSelectionRegion); - Rect clip = canvas.getClipBounds(); - while (iter.next(r)) { - r.set(contentToViewDimension(r.left), - contentToViewDimension(r.top), - contentToViewDimension(r.right), - contentToViewDimension(r.bottom)); - if (r.intersect(clip)) { - canvas.drawRect(r, mTextSelectionPaint); - } - } if (mSelectHandleLeft == null) { mSelectHandleLeft = mContext.getResources().getDrawable( com.android.internal.R.drawable.text_select_handle_left); } int[] handles = new int[4]; - nativeGetSelectionHandles(mNativeClass, handles); + getSelectionHandles(handles); int start_x = contentToViewDimension(handles[0]); int start_y = contentToViewDimension(handles[1]); int end_x = contentToViewDimension(handles[2]); @@ -4942,14 +4926,31 @@ public class WebView extends AbsoluteLayout mSelectHandleRight.setBounds(end_x, end_y, end_x + mSelectHandleRight.getIntrinsicWidth(), end_y + mSelectHandleRight.getIntrinsicHeight()); - if (DEBUG_TEXT_HANDLES) { - mSelectHandleLeft.setAlpha(125); - mSelectHandleRight.setAlpha(125); - } mSelectHandleLeft.draw(canvas); mSelectHandleRight.draw(canvas); } + /** + * Takes an int[4] array as an output param with the values being + * startX, startY, endX, endY + */ + private void getSelectionHandles(int[] handles) { + handles[0] = mSelectCursorBase.right; + handles[1] = mSelectCursorBase.bottom - + (mSelectCursorBase.height() / 4); + handles[2] = mSelectCursorExtent.left; + handles[3] = mSelectCursorExtent.bottom + - (mSelectCursorExtent.height() / 4); + 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 private boolean mDrawHistory = false; private Picture mHistoryPicture = null; @@ -5009,7 +5010,7 @@ public class WebView extends AbsoluteLayout /* package */ void deleteSelection(int start, int end) { mTextGeneration++; WebViewCore.TextSelectionData data - = new WebViewCore.TextSelectionData(start, end); + = new WebViewCore.TextSelectionData(start, end, 0); mWebViewCore.sendMessage(EventHub.DELETE_SELECTION, mTextGeneration, 0, data); } @@ -5462,15 +5463,6 @@ public class WebView extends AbsoluteLayout return pinScrollTo(mContentWidth, mScrollY, true, 0); } } - if (mSelectingText) { - int xRate = keyCode == KeyEvent.KEYCODE_DPAD_LEFT - ? -1 : keyCode == KeyEvent.KEYCODE_DPAD_RIGHT ? 1 : 0; - int yRate = keyCode == KeyEvent.KEYCODE_DPAD_UP ? - -1 : keyCode == KeyEvent.KEYCODE_DPAD_DOWN ? 1 : 0; - int multiplier = event.getRepeatCount() + 1; - moveSelection(xRate * multiplier, yRate * multiplier); - return true; - } if (navHandledKey(keyCode, 1, false, event.getEventTime())) { playSoundEffect(keyCodeToSoundsEffect(keyCode)); return true; @@ -5623,14 +5615,8 @@ public class WebView extends AbsoluteLayout mGotCenterDown = false; if (mSelectingText) { - if (mExtendSelection) { - copySelection(); - selectionDone(); - } else { - mExtendSelection = true; - nativeSetExtendSelection(); - invalidate(); // draw the i-beam instead of the arrow - } + copySelection(); + selectionDone(); return true; // discard press if copy in progress } @@ -5676,21 +5662,7 @@ public class WebView extends AbsoluteLayout return false; } - /* - * Enter selecting text mode, and see if CAB should be shown. - * Returns true if the WebView is now in - * selecting text mode (including if it was already in that mode, and this - * method did nothing). - */ - private boolean setUpSelect(boolean selectWord, int x, int y) { - if (0 == mNativeClass) return false; // client isn't initialized - if (inFullScreenMode()) return false; - if (mSelectingText) return true; - nativeResetSelection(); - if (selectWord && !nativeWordSelection(x, y)) { - selectionDone(); - return false; - } + private boolean startSelectActionMode() { mSelectCallback = new SelectActionModeCallback(); mSelectCallback.setWebView(this); if (startActionMode(mSelectCallback) == null) { @@ -5699,52 +5671,41 @@ public class WebView extends AbsoluteLayout selectionDone(); return false; } - mExtendSelection = false; - mSelectingText = mDrawSelectionPointer = true; - if (DEBUG_TEXT_HANDLES) { - // Debugging text handles requires running in software mode - setLayerType(LAYER_TYPE_SOFTWARE, null); + performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); + return true; + } + + private void syncSelectionCursors() { + mSelectCursorBaseLayerId = + nativeGetHandleLayerId(mNativeClass, HANDLE_ID_BASE, mSelectCursorBase); + mSelectCursorExtentLayerId = + nativeGetHandleLayerId(mNativeClass, HANDLE_ID_EXTENT, mSelectCursorExtent); + } + + private boolean setupWebkitSelect() { + syncSelectionCursors(); + if (!startSelectActionMode()) { + selectionDone(); + return false; } - // don't let the picture change during text selection - WebViewCore.pauseUpdatePicture(mWebViewCore); - if (nativeHasCursorNode()) { - Rect rect = nativeCursorNodeBounds(); - mSelectX = contentToViewX(rect.left); - mSelectY = contentToViewY(rect.top); - } else if (mLastTouchY > getVisibleTitleHeightImpl()) { - mSelectX = mScrollX + mLastTouchX; - mSelectY = mScrollY + mLastTouchY; + mSelectingText = true; + mTouchMode = TOUCH_DRAG_MODE; + return true; + } + + private void updateWebkitSelection() { + int[] handles = null; + if (mSelectingText) { + handles = new int[4]; + handles[0] = mSelectCursorBase.centerX(); + handles[1] = mSelectCursorBase.centerY(); + handles[2] = mSelectCursorExtent.centerX(); + handles[3] = mSelectCursorExtent.centerY(); } else { - mSelectX = mScrollX + getViewWidth() / 2; - mSelectY = mScrollY + getViewHeightWithTitle() / 2; + nativeSetTextSelection(mNativeClass, 0); } - nativeHideCursor(); - mMinAutoScrollX = 0; - mMaxAutoScrollX = getViewWidth(); - mMinAutoScrollY = 0; - mMaxAutoScrollY = getViewHeightWithTitle(); - mCurrentScrollingLayerId = nativeScrollableLayer(viewToContentX(mSelectX), - viewToContentY(mSelectY), mScrollingLayerRect, - mScrollingLayerBounds); - if (mCurrentScrollingLayerId != 0) { - if (mScrollingLayerRect.left != mScrollingLayerRect.right) { - mMinAutoScrollX = Math.max(mMinAutoScrollX, - contentToViewX(mScrollingLayerBounds.left)); - mMaxAutoScrollX = Math.min(mMaxAutoScrollX, - contentToViewX(mScrollingLayerBounds.right)); - } - if (mScrollingLayerRect.top != mScrollingLayerRect.bottom) { - mMinAutoScrollY = Math.max(mMinAutoScrollY, - contentToViewY(mScrollingLayerBounds.top)); - mMaxAutoScrollY = Math.min(mMaxAutoScrollY, - contentToViewY(mScrollingLayerBounds.bottom)); - } - } - mMinAutoScrollX += SELECT_SCROLL; - mMaxAutoScrollX -= SELECT_SCROLL; - mMinAutoScrollY += SELECT_SCROLL; - mMaxAutoScrollY -= SELECT_SCROLL; - return true; + mWebViewCore.removeMessages(EventHub.SELECT_TEXT); + mWebViewCore.sendMessageAtFrontOfQueue(EventHub.SELECT_TEXT, handles); } /** @@ -5755,7 +5716,6 @@ public class WebView extends AbsoluteLayout @Deprecated public void emulateShiftHeld() { checkThread(); - setUpSelect(false, 0, 0); } /** @@ -5764,17 +5724,8 @@ public class WebView extends AbsoluteLayout * @hide This is an implementation detail. */ public void selectAll() { - if (0 == mNativeClass) return; // client isn't initialized - if (inFullScreenMode()) return; - if (!mSelectingText) { - // retrieve a point somewhere within the text - Point select = nativeSelectableText(); - if (!selectText(select.x, select.y)) return; - } - nativeSelectAll(); - mDrawSelectionPointer = false; - mExtendSelection = true; - invalidate(); + // TODO + //mWebViewCore.sendMessage(EventHub.SELECT_ALL); } /** @@ -5783,17 +5734,11 @@ public class WebView extends AbsoluteLayout void selectionDone() { if (mSelectingText) { mSelectingText = false; - if (DEBUG_TEXT_HANDLES) { - // Debugging text handles required running in software mode, set - // back to default now - setLayerType(LAYER_TYPE_NONE, null); - } // finish is idempotent, so this is fine even if selectionDone was // called by mSelectCallback.onDestroyActionMode mSelectCallback.finish(); mSelectCallback = null; - WebViewCore.resumePriority(); - WebViewCore.resumeUpdatePicture(mWebViewCore); + updateWebkitSelection(); invalidate(); // redraw without selection mAutoScrollX = 0; mAutoScrollY = 0; @@ -5821,7 +5766,7 @@ public class WebView extends AbsoluteLayout .getSystemService(Context.CLIPBOARD_SERVICE); cm.setText(selection); int[] handles = new int[4]; - nativeGetSelectionHandles(mNativeClass, handles); + getSelectionHandles(handles); mWebViewCore.sendMessage(EventHub.COPY_TEXT, handles); } invalidate(); // remove selection region and pointer @@ -5836,7 +5781,7 @@ public class WebView extends AbsoluteLayout public void cutSelection() { copySelection(); int[] handles = new int[4]; - nativeGetSelectionHandles(mNativeClass, handles); + getSelectionHandles(handles); mWebViewCore.sendMessage(EventHub.DELETE_TEXT, handles); } @@ -5854,7 +5799,7 @@ public class WebView extends AbsoluteLayout CharSequence pasteText = clipItem.getText(); if (pasteText != null) { int[] handles = new int[4]; - nativeGetSelectionHandles(mNativeClass, handles); + getSelectionHandles(handles); mWebViewCore.sendMessage(EventHub.DELETE_TEXT, handles); mWebViewCore.sendMessage(EventHub.INSERT_TEXT, pasteText.toString()); @@ -6407,12 +6352,26 @@ public class WebView extends AbsoluteLayout (eventTime - mLastTouchUpTime), eventTime); } if (mSelectingText) { - mDrawSelectionPointer = false; - mSelectionStarted = nativeStartSelection(contentX, contentY); + mSelectionStarted = false; + int shiftedY = y - getTitleHeight() + mScrollY; + int shiftedX = x + mScrollX; + if (mSelectHandleLeft.getBounds() + .contains(shiftedX, shiftedY)) { + mSelectionStarted = true; + mSelectDraggingCursor = mSelectCursorBase; + } else if (mSelectHandleRight.getBounds() + .contains(shiftedX, shiftedY)) { + mSelectionStarted = true; + mSelectDraggingCursor = mSelectCursorExtent; + } + if (mSelectDraggingCursor != null) { + mSelectDraggingOffset.set( + mSelectDraggingCursor.left - contentX, + mSelectDraggingCursor.top - contentY); + } if (DebugFlags.WEB_VIEW) { Log.v(LOGTAG, "select=" + contentX + "," + contentY); } - invalidate(); } } // Trigger the link @@ -6478,6 +6437,26 @@ public class WebView extends AbsoluteLayout removeTouchHighlight(); } } + if (mSelectingText && mSelectionStarted) { + if (DebugFlags.WEB_VIEW) { + Log.v(LOGTAG, "extend=" + contentX + "," + contentY); + } + ViewParent parent = getParent(); + if (parent != null) { + parent.requestDisallowInterceptTouchEvent(true); + } + if (deltaX != 0 || deltaY != 0) { + mSelectDraggingCursor.offsetTo( + contentX + mSelectDraggingOffset.x, + contentY + mSelectDraggingOffset.y); + updateWebkitSelection(); + mLastTouchX = x; + mLastTouchY = y; + invalidate(); + } + break; + } + // pass the touch events from UI thread to WebCore thread if (shouldForwardTouchEvent() && mConfirmMove && (firstMove || eventTime - mLastSentTouchTime > mCurrentTouchInterval)) { @@ -6520,30 +6499,6 @@ public class WebView extends AbsoluteLayout } else { mVelocityTracker.addMovement(ev); } - if (mSelectingText && mSelectionStarted) { - if (DebugFlags.WEB_VIEW) { - Log.v(LOGTAG, "extend=" + contentX + "," + contentY); - } - ViewParent parent = getParent(); - if (parent != null) { - parent.requestDisallowInterceptTouchEvent(true); - } - mAutoScrollX = x <= mMinAutoScrollX ? -SELECT_SCROLL - : x >= mMaxAutoScrollX ? SELECT_SCROLL : 0; - mAutoScrollY = y <= mMinAutoScrollY ? -SELECT_SCROLL - : y >= mMaxAutoScrollY ? SELECT_SCROLL : 0; - if ((mAutoScrollX != 0 || mAutoScrollY != 0) - && !mSentAutoScrollMessage) { - mSentAutoScrollMessage = true; - mPrivateHandler.sendEmptyMessageDelayed( - SCROLL_SELECT_TEXT, SELECT_SCROLL_INTERVAL); - } - if (deltaX != 0 || deltaY != 0) { - nativeExtendSelection(contentX, contentY); - invalidate(); - } - break; - } if (mTouchMode != TOUCH_DRAG_MODE && mTouchMode != TOUCH_DRAG_LAYER_MODE) { @@ -6758,7 +6713,7 @@ public class WebView extends AbsoluteLayout } else { if (mSelectingText) { // tapping on selection or controls does nothing - if (!nativeHitSelection(contentX, contentY)) { + if (!mSelectionStarted) { selectionDone(); } break; @@ -7055,6 +7010,12 @@ public class WebView extends AbsoluteLayout if (mOverScrollGlow != null) { mOverScrollGlow.releaseAll(); } + + if (mSelectingText) { + mSelectionStarted = false; + syncSelectionCursors(); + invalidate(); + } } private void cancelTouch() { @@ -7119,8 +7080,6 @@ public class WebView extends AbsoluteLayout private int mTrackballYMove = 0; private boolean mSelectingText = false; private boolean mSelectionStarted = false; - private boolean mExtendSelection = false; - private boolean mDrawSelectionPointer = false; private static final int TRACKBALL_KEY_TIMEOUT = 1000; private static final int TRACKBALL_TIMEOUT = 200; private static final int TRACKBALL_WAIT = 100; @@ -7189,14 +7148,8 @@ public class WebView extends AbsoluteLayout mTrackballDown = false; mTrackballUpTime = time; if (mSelectingText) { - if (mExtendSelection) { - copySelection(); - selectionDone(); - } else { - mExtendSelection = true; - nativeSetExtendSelection(); - invalidate(); // draw the i-beam instead of the arrow - } + copySelection(); + selectionDone(); return true; // discard press if copy in progress } if (DebugFlags.WEB_VIEW) { @@ -7239,42 +7192,6 @@ public class WebView extends AbsoluteLayout return true; } - void moveSelection(float xRate, float yRate) { - if (mNativeClass == 0) - return; - int width = getViewWidth(); - int height = getViewHeight(); - mSelectX += xRate; - mSelectY += yRate; - int maxX = width + mScrollX; - int maxY = height + mScrollY; - mSelectX = Math.min(maxX, Math.max(mScrollX - SELECT_CURSOR_OFFSET - , mSelectX)); - mSelectY = Math.min(maxY, Math.max(mScrollY - SELECT_CURSOR_OFFSET - , mSelectY)); - if (DebugFlags.WEB_VIEW) { - Log.v(LOGTAG, "moveSelection" - + " mSelectX=" + mSelectX - + " mSelectY=" + mSelectY - + " mScrollX=" + mScrollX - + " mScrollY=" + mScrollY - + " xRate=" + xRate - + " yRate=" + yRate - ); - } - nativeMoveSelection(viewToContentX(mSelectX), viewToContentY(mSelectY)); - int scrollX = mSelectX < mScrollX ? -SELECT_CURSOR_OFFSET - : mSelectX > maxX - SELECT_CURSOR_OFFSET ? SELECT_CURSOR_OFFSET - : 0; - int scrollY = mSelectY < mScrollY ? -SELECT_CURSOR_OFFSET - : mSelectY > maxY - SELECT_CURSOR_OFFSET ? SELECT_CURSOR_OFFSET - : 0; - pinScrollBy(scrollX, scrollY, true, 0); - Rect select = new Rect(mSelectX, mSelectY, mSelectX + 1, mSelectY + 1); - requestRectangleOnScreen(select); - invalidate(); - } - private int scaleTrackballX(float xRate, int width) { int xMove = (int) (xRate / TRACKBALL_SCALE * width); int nextXMove = xMove; @@ -7328,21 +7245,6 @@ public class WebView extends AbsoluteLayout float yRate = mTrackballRemainsY * 1000 / elapsed; int viewWidth = getViewWidth(); int viewHeight = getViewHeight(); - if (mSelectingText) { - if (!mDrawSelectionPointer) { - // The last selection was made by touch, disabling drawing the - // selection pointer. Allow the trackball to adjust the - // position of the touch control. - mSelectX = contentToViewX(nativeSelectionX()); - mSelectY = contentToViewY(nativeSelectionY()); - mDrawSelectionPointer = mExtendSelection = true; - nativeSetExtendSelection(); - } - moveSelection(scaleTrackballX(xRate, viewWidth), - scaleTrackballY(yRate, viewHeight)); - mTrackballRemainsX = mTrackballRemainsY = 0; - return; - } float ax = Math.abs(xRate); float ay = Math.abs(yRate); float maxA = Math.max(ax, ay); @@ -9204,6 +9106,18 @@ public class WebView extends AbsoluteLayout mInputConnection.setSelection(data.mStart, data.mEnd); } } + + nativeSetTextSelection(mNativeClass, data.mSelectTextPtr); + if (data.mSelectTextPtr != 0) { + if (!mSelectingText) { + setupWebkitSelect(); + } else if (!mSelectionStarted) { + syncSelectionCursors(); + } + } else { + selectionDone(); + } + invalidate(); } // Class used to use a dropdown for a <select> element @@ -9952,7 +9866,6 @@ public class WebView extends AbsoluteLayout private native boolean nativeMoveCursor(int keyCode, int count, boolean noScroll); private native int nativeMoveGeneration(); - private native void nativeMoveSelection(int x, int y); /** * @return true if the page should get the shift and arrow keys, rather * than select text/navigation. @@ -9962,15 +9875,8 @@ public class WebView extends AbsoluteLayout */ private native boolean nativePageShouldHandleShiftAndArrows(); private native boolean nativePointInNavCache(int x, int y, int slop); - // Like many other of our native methods, you must make sure that - // mNativeClass is not null before calling this method. - private native void nativeResetSelection(); - private native Point nativeSelectableText(); - private native void nativeSelectAll(); private native void nativeSelectBestAt(Rect rect); private native void nativeSelectAt(int x, int y); - private native int nativeSelectionX(); - private native int nativeSelectionY(); private native int nativeFindIndex(); private native void nativeSetExtendSelection(); private native void nativeSetFindIsEmpty(); @@ -10026,12 +9932,14 @@ public class WebView extends AbsoluteLayout private native int nativeGetBackgroundColor(); native boolean nativeSetProperty(String key, String value); native String nativeGetProperty(String key); - private native void nativeGetTextSelectionRegion(int instance, Region region); - private native void nativeGetSelectionHandles(int instance, int[] handles); /** * See {@link ComponentCallbacks2} for the trim levels and descriptions */ private static native void nativeOnTrimMemory(int level); private static native void nativeSetPauseDrawing(int instance, boolean pause); private static native boolean nativeDisableNavcache(); + private static native void nativeSetTextSelection(int instance, int selection); + private static native int nativeGetHandleLayerId(int instance, int handle, + Rect cursorLocation); + private static native boolean nativeIsBaseFirst(int instance); } diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index 9c7bd34..67264de 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -835,12 +835,14 @@ public final class WebViewCore { } static class TextSelectionData { - public TextSelectionData(int start, int end) { + public TextSelectionData(int start, int end, int selectTextPtr) { mStart = start; mEnd = end; + mSelectTextPtr = selectTextPtr; } int mStart; int mEnd; + int mSelectTextPtr; } static class TouchUpData { @@ -1118,6 +1120,8 @@ public final class WebViewCore { static final int COPY_TEXT = 210; static final int DELETE_TEXT = 211; static final int INSERT_TEXT = 212; + static final int SELECT_TEXT = 213; + static final int SELECT_WORD_AT = 214; // Private handler for WebCore messages. private Handler mHandler; @@ -1746,6 +1750,22 @@ public final class WebViewCore { case INSERT_TEXT: nativeInsertText(mNativeClass, (String) msg.obj); break; + case SELECT_TEXT: { + int[] args = (int[]) msg.obj; + if (args == null) { + nativeClearTextSelection(mNativeClass); + } else { + nativeSelectText(mNativeClass, args[0], + args[1], args[2], args[3]); + } + break; + } + case SELECT_WORD_AT: { + int x = msg.arg1; + int y = msg.arg2; + nativeSelectWordAt(mNativeClass, x, y); + break; + } } } }; @@ -2699,11 +2719,11 @@ public final class WebViewCore { // called by JNI private void updateTextSelection(int pointer, int start, int end, - int textGeneration) { + int textGeneration, int selectionPtr) { if (mWebView != null) { Message.obtain(mWebView.mPrivateHandler, WebView.UPDATE_TEXT_SELECTION_MSG_ID, pointer, textGeneration, - new TextSelectionData(start, end)).sendToTarget(); + new TextSelectionData(start, end, selectionPtr)).sendToTarget(); } } @@ -2770,7 +2790,7 @@ public final class WebViewCore { if (mWebView != null) { Message.obtain(mWebView.mPrivateHandler, WebView.REQUEST_KEYBOARD_WITH_SELECTION_MSG_ID, pointer, - textGeneration, new TextSelectionData(selStart, selEnd)) + textGeneration, new TextSelectionData(selStart, selEnd, 0)) .sendToTarget(); } } @@ -3025,4 +3045,8 @@ public final class WebViewCore { */ private native String nativeGetText(int nativeClass, int startX, int startY, int endX, int endY); + private native void nativeSelectText(int nativeClass, + int startX, int startY, int endX, int endY); + private native void nativeClearTextSelection(int nativeClass); + private native void nativeSelectWordAt(int nativeClass, int x, int y); } diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java index d395fb2..84e86af 100644 --- a/core/java/android/widget/NumberPicker.java +++ b/core/java/android/widget/NumberPicker.java @@ -56,13 +56,13 @@ import com.android.internal.R; /** * A widget that enables the user to select a number form a predefined range. * The widget presents an input field and up and down buttons for selecting the - * current value. Pressing/long pressing the up and down buttons increments and + * current value. Pressing/long-pressing the up and down buttons increments and * decrements the current value respectively. Touching the input field shows a - * scroll wheel, tapping on which while shown and not moving allows direct edit - * of the current value. Sliding motions up or down hide the buttons and the - * input field, show the scroll wheel, and rotate the latter. Flinging is + * scroll wheel, which when touched allows direct edit + * of the current value. Sliding gestures up or down hide the buttons and the + * input filed, show and rotate the scroll wheel. Flinging is * also supported. The widget enables mapping from positions to strings such - * that instead the position index the corresponding string is displayed. + * that, instead of the position index, the corresponding string is displayed. * <p> * For an example of using this widget, see {@link android.widget.TimePicker}. * </p> |
