diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 14:04:24 -0800 |
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 14:04:24 -0800 |
| commit | 076357b8567458d4b6dfdcf839ef751634cd2bfb (patch) | |
| tree | efbb2fd6f1dc67d2d606382fc3b82983e7cb2e1f /core/java/android/webkit | |
| parent | 3dec7d563a2f3e1eb967ce2054a00b6620e3558c (diff) | |
| download | frameworks_base-076357b8567458d4b6dfdcf839ef751634cd2bfb.zip frameworks_base-076357b8567458d4b6dfdcf839ef751634cd2bfb.tar.gz frameworks_base-076357b8567458d4b6dfdcf839ef751634cd2bfb.tar.bz2 | |
auto import from //depot/cupcake/@132589
Diffstat (limited to 'core/java/android/webkit')
| -rw-r--r-- | core/java/android/webkit/CallbackProxy.java | 8 | ||||
| -rw-r--r-- | core/java/android/webkit/TextDialog.java | 103 | ||||
| -rw-r--r-- | core/java/android/webkit/WebView.java | 100 | ||||
| -rw-r--r-- | core/java/android/webkit/WebViewCore.java | 4 |
4 files changed, 93 insertions, 122 deletions
diff --git a/core/java/android/webkit/CallbackProxy.java b/core/java/android/webkit/CallbackProxy.java index 84aeb83..4f8e5e4 100644 --- a/core/java/android/webkit/CallbackProxy.java +++ b/core/java/android/webkit/CallbackProxy.java @@ -907,12 +907,10 @@ class CallbackProxy extends Handler { } public void onReceivedIcon(Bitmap icon) { - // The current item might be null if the icon was already stored in the - // database and this is a new WebView. - WebHistoryItem i = mBackForwardList.getCurrentItem(); - if (i != null) { - i.setFavicon(icon); + if (Config.DEBUG && mBackForwardList.getCurrentItem() == null) { + throw new AssertionError(); } + mBackForwardList.getCurrentItem().setFavicon(icon); // Do an unsynchronized quick check to avoid posting if no callback has // been set. if (mWebChromeClient == null) { diff --git a/core/java/android/webkit/TextDialog.java b/core/java/android/webkit/TextDialog.java index 8a82411..c2620a5 100644 --- a/core/java/android/webkit/TextDialog.java +++ b/core/java/android/webkit/TextDialog.java @@ -25,6 +25,8 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.RectShape; +import android.os.Handler; +import android.os.Message; import android.text.Editable; import android.text.InputFilter; import android.text.Selection; @@ -41,6 +43,7 @@ import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewConfiguration; import android.widget.AbsoluteLayout.LayoutParams; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; @@ -79,6 +82,22 @@ import java.util.ArrayList; // FIXME: This can be replaced with TextView.NO_FILTERS if that // is made public/protected. private static final InputFilter[] NO_FILTERS = new InputFilter[0]; + // The time of the last enter down, so we know whether to perform a long + // press. + private long mDownTime; + + private boolean mTrackballDown = false; + private static int LONGPRESS = 1; + private Handler mHandler = new Handler() { + public void handleMessage(Message msg) { + if (msg.what == LONGPRESS) { + if (mTrackballDown) { + performLongClick(); + mTrackballDown = false; + } + } + } + }; /** * Create a new TextDialog. @@ -116,13 +135,6 @@ import java.util.ArrayList; } @Override - protected boolean shouldAdvanceFocusOnEnter() { - // In the browser, single line textfields use enter as a form submit, - // so we never want to advance the focus on enter. - return false; - } - - @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.isSystem()) { return super.dispatchKeyEvent(event); @@ -140,33 +152,43 @@ import java.util.ArrayList; return true; } - if ((mSingle && KeyEvent.KEYCODE_ENTER == keyCode)) { + // For single-line textfields, return key should not be handled + // here. Instead, the WebView is passed the key up, so it may fire a + // submit/onClick. + // Center key should always be passed to a potential onClick + if ((mSingle && KeyEvent.KEYCODE_ENTER == keyCode) + || KeyEvent.KEYCODE_DPAD_CENTER == keyCode) { if (isPopupShowing()) { - return super.dispatchKeyEvent(event); + super.dispatchKeyEvent(event); + return true; } - if (!down) { - // Hide the keyboard, since the user has just submitted this - // form. The submission happens thanks to the two calls - // to sendDomEvent. + if (down) { + if (event.getRepeatCount() == 0) { + mGotEnterDown = true; + mDownTime = event.getEventTime(); + // Send the keydown when the up comes, so that we have + // a chance to handle a long press. + } else if (mGotEnterDown && event.getEventTime() - mDownTime > + ViewConfiguration.getLongPressTimeout()) { + performLongClick(); + mGotEnterDown = false; + } + } else if (mGotEnterDown) { + mGotEnterDown = false; + if (KeyEvent.KEYCODE_DPAD_CENTER == keyCode) { + mWebView.shortPressOnTextField(); + return true; + } + // If we reached here, then this is a single line textfield, and + // the user pressed ENTER. In this case, we want to hide the + // soft input method. InputMethodManager.getInstance(mContext) .hideSoftInputFromWindow(getWindowToken(), 0); sendDomEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode)); sendDomEvent(event); } - return super.dispatchKeyEvent(event); - } else if (KeyEvent.KEYCODE_DPAD_CENTER == keyCode) { - // Note that this handles center key and trackball. - if (isPopupShowing()) { - return super.dispatchKeyEvent(event); - } - // Center key should be passed to a potential onClick - if (!down) { - mWebView.shortPressOnTextField(); - } - // Pass to super to handle longpress. - return super.dispatchKeyEvent(event); + return true; } - // Ensure there is a layout so arrow keys are handled properly. if (getLayout() == null) { measure(mWidthSpec, mHeightSpec); @@ -203,8 +225,9 @@ import java.util.ArrayList; case KeyEvent.KEYCODE_DPAD_DOWN: isArrowKey = true; break; + case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: - // For multi-line text boxes, newlines will + // For multi-line text boxes, newlines and dpad center will // trigger onTextChanged for key down (which will send both // key up and key down) but not key up. mGotEnterDown = true; @@ -246,7 +269,7 @@ import java.util.ArrayList; // with WebCore's notion of the current selection, reset the selection // to what it was before the key event. Selection.setSelection(text, oldStart, oldEnd); - // Ignore the key up event for newlines. This prevents + // Ignore the key up event for newlines or dpad center. This prevents // multiple newlines in the native textarea. if (mGotEnterDown && !down) { return true; @@ -368,8 +391,27 @@ import java.util.ArrayList; if (isPopupShowing()) { return super.onTrackballEvent(event); } - if (event.getAction() != MotionEvent.ACTION_MOVE) { - return false; + int action = event.getAction(); + switch (action) { + case MotionEvent.ACTION_DOWN: + if (!mTrackballDown) { + mTrackballDown = true; + mHandler.sendEmptyMessageDelayed(LONGPRESS, + ViewConfiguration.getLongPressTimeout()); + } + return true; + case MotionEvent.ACTION_UP: + if (mTrackballDown) { + mWebView.shortPressOnTextField(); + mTrackballDown = false; + mHandler.removeMessages(LONGPRESS); + } + return true; + case MotionEvent.ACTION_CANCEL: + mTrackballDown = false; + return true; + case MotionEvent.ACTION_MOVE: + // fall through } Spannable text = (Spannable) getText(); MovementMethod move = getMovementMethod(); @@ -400,6 +442,7 @@ import java.util.ArrayList; // hide the soft keyboard when the edit text is out of focus InputMethodManager.getInstance(mContext).hideSoftInputFromWindow( getWindowToken(), 0); + mHandler.removeMessages(LONGPRESS); mWebView.removeView(this); mWebView.requestFocus(); mScrollToAccommodateCursor = false; diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 5126ef0..417b657 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -71,7 +71,6 @@ import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.Scroller; import android.widget.Toast; -import android.widget.ZoomButtonsController; import android.widget.ZoomControls; import android.widget.ZoomRingController; import android.widget.FrameLayout; @@ -285,10 +284,8 @@ public class WebView extends AbsoluteLayout /** * Customizable constant */ - // pre-computed square of ViewConfiguration.getScaledTouchSlop() + // pre-computed square of ViewConfiguration.getTouchSlop() private int mTouchSlopSquare; - // pre-computed square of ViewConfiguration.getScaledDoubleTapSlop() - private int mDoubleTapSlopSquare; // This should be ViewConfiguration.getTapTimeout() // But system time out is 100ms, which is too short for the browser. // In the browser, if it switches out of tap too soon, jump tap won't work. @@ -324,8 +321,6 @@ public class WebView extends AbsoluteLayout private int mContentHeight; // cache of value from WebViewCore static int MAX_FLOAT_CONTENT_WIDTH = 480; - // the calculated minimum content width for calculating the minimum scale. - // If it is 0, it means don't use it. private int mMinContentWidth; // Need to have the separate control for horizontal and vertical scrollbar @@ -558,9 +553,7 @@ public class WebView extends AbsoluteLayout return mExtra; } } - - private ZoomButtonsController mZoomButtonsController; - + private ZoomRingController mZoomRingController; private ImageView mZoomRingOverview; private Animation mZoomRingOverviewExitAnimation; @@ -624,9 +617,6 @@ public class WebView extends AbsoluteLayout / ZOOM_RING_STEPS; } mZoomRingController.setThumbAngle(angle * MAX_ZOOM_RING_ANGLE); - - // Don't show a thumb if the user cannot zoom - mZoomRingController.setThumbVisible(mMinZoomScale != mMaxZoomScale); // Show the zoom overview tab on the ring setZoomOverviewVisible(true); @@ -743,26 +733,6 @@ public class WebView extends AbsoluteLayout mZoomRingController.setPannerAcceleration(160); mZoomRingController.setPannerStartAcceleratingDuration(700); createZoomRingOverviewTab(); - mZoomButtonsController = new ZoomButtonsController(context, this); - mZoomButtonsController.setOverviewVisible(true); - mZoomButtonsController.setCallback(new ZoomButtonsController.OnZoomListener() { - public void onCenter(int x, int y) { - mZoomListener.onCenter(x, y); - } - - public void onOverview() { - mZoomButtonsController.setVisible(false); - zoomScrollOut(); - } - - public void onVisibilityChanged(boolean visible) { - mZoomListener.onVisibilityChanged(visible); - } - - public void onZoom(boolean zoomIn) { - mZoomListener.onSimpleZoom(zoomIn); - } - }); } private void init() { @@ -775,9 +745,6 @@ public class WebView extends AbsoluteLayout final int slop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); mTouchSlopSquare = slop * slop; mMinLockSnapReverseDistance = slop; - final int doubleTapslop = ViewConfiguration.get(getContext()) - .getScaledDoubleTapSlop(); - mDoubleTapSlopSquare = doubleTapslop * doubleTapslop; } private void createZoomRingOverviewTab() { @@ -796,7 +763,7 @@ public class WebView extends AbsoluteLayout FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER); // TODO: magic constant that's based on the zoom ring radius + some offset - lp.topMargin = 200; + lp.topMargin = 208; mZoomRingOverview.setLayoutParams(lp); mZoomRingOverview.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { @@ -2338,19 +2305,8 @@ public class WebView extends AbsoluteLayout /** * Use this function to bind an object to Javascript so that the * methods can be accessed from Javascript. - * <p><strong>IMPORTANT:</strong> - * <ul> - * <li> Using addJavascriptInterface() allows JavaScript to control your - * application. This can be a very useful feature or a dangerous security - * issue. When the HTML in the WebView is untrustworthy (for example, part - * or all of the HTML is provided by some person or process), then an - * attacker could inject HTML that will execute your code and possibly any - * code of the attacker's choosing.<br> - * Do not use addJavascriptInterface() unless all of the HTML in this - * WebView was written by you.</li> - * <li> The Java object that is bound runs in another thread and not in - * the thread that it was constructed in.</li> - * </ul></p> + * IMPORTANT, the object that is bound runs in another thread and + * not in the thread that it was constructed in. * @param obj The class instance to bind to Javascript * @param interfaceName The name to used to expose the class in Javascript */ @@ -3013,8 +2969,8 @@ public class WebView extends AbsoluteLayout if (lp != null) { // Take the last touch and adjust for the location of the // TextDialog. - float x = mLastTouchX + (float) (mScrollX - lp.x); - float y = mLastTouchY + (float) (mScrollY - lp.y); + float x = mLastTouchX - lp.x; + float y = mLastTouchY - lp.y; mTextEntry.fakeTouchEvent(x, y); } } @@ -3208,9 +3164,6 @@ public class WebView extends AbsoluteLayout mSelectX = mScrollX + (int) mLastTouchX; mSelectY = mScrollY + (int) mLastTouchY; } - int contentX = viewToContent((int) mLastTouchX + mScrollX); - int contentY = viewToContent((int) mLastTouchY + mScrollY); - nativeClearFocus(contentX, contentY); } if (keyCode >= KeyEvent.KEYCODE_DPAD_UP @@ -3402,9 +3355,6 @@ public class WebView extends AbsoluteLayout public void emulateShiftHeld() { mExtendSelection = false; mShiftIsPressed = true; - int contentX = viewToContent((int) mLastTouchX + mScrollX); - int contentY = viewToContent((int) mLastTouchY + mScrollY); - nativeClearFocus(contentX, contentY); } private boolean commitCopy() { @@ -3451,7 +3401,6 @@ public class WebView extends AbsoluteLayout // Clean up the zoom ring mZoomRingController.setVisible(false); - mZoomButtonsController.setVisible(false); } // Implementation for OnHierarchyChangeListener @@ -3500,17 +3449,8 @@ public class WebView extends AbsoluteLayout // false for the first parameter } } else { - if (!mZoomButtonsController.isVisible()) { - /* - * The zoom controls come in their own window, so our window - * loses focus. Our policy is to not draw the focus ring if - * our window is not focused, but this is an exception since - * the user can still navigate the web page with the zoom - * controls showing. - */ - // If our window has lost focus, stop drawing the focus ring - mDrawFocusRing = false; - } + // If our window has lost focus, stop drawing the focus ring + mDrawFocusRing = false; mGotKeyDown = false; mShiftIsPressed = false; if (mNativeClass != 0) { @@ -3652,8 +3592,7 @@ public class WebView extends AbsoluteLayout + mTouchMode); } - if ((mZoomRingController.isVisible() || mZoomButtonsController.isVisible()) - && mInZoomTapDragMode) { + if (mZoomRingController.isVisible() && mInZoomTapDragMode) { if (ev.getAction() == MotionEvent.ACTION_UP) { // Just released the second tap, no longer in tap-drag mode mInZoomTapDragMode = false; @@ -3691,9 +3630,6 @@ public class WebView extends AbsoluteLayout mLastSentTouchTime = eventTime; } - int deltaX = (int) (mLastTouchX - x); - int deltaY = (int) (mLastTouchY - y); - switch (action) { case MotionEvent.ACTION_DOWN: { if (mTouchMode == SCROLL_ZOOM_ANIMATION_IN @@ -3719,23 +3655,16 @@ public class WebView extends AbsoluteLayout , viewToContent(mSelectY), false); mTouchSelection = mExtendSelection = true; } else if (!ZoomRingController.useOldZoom(mContext) && - mPrivateHandler.hasMessages(RELEASE_SINGLE_TAP) && - (deltaX * deltaX + deltaY * deltaY < mDoubleTapSlopSquare)) { + mPrivateHandler.hasMessages(RELEASE_SINGLE_TAP)) { // Found doubletap, invoke the zoom controller mPrivateHandler.removeMessages(RELEASE_SINGLE_TAP); - int contentX = viewToContent((int) mLastTouchX + mScrollX); - int contentY = viewToContent((int) mLastTouchY + mScrollY); - if (inEditingMode()) { - mTextEntry.updateCachedTextfield(); - } - nativeClearFocus(contentX, contentY); + mZoomRingController.setVisible(true); mInZoomTapDragMode = true; if (mLogEvent) { EventLog.writeEvent(EVENT_LOG_DOUBLE_TAP_DURATION, (eventTime - mLastTouchUpTime), eventTime); } - return mZoomRingController.handleDoubleTapEvent(ev) || - mZoomButtonsController.handleDoubleTapEvent(ev); + return mZoomRingController.handleDoubleTapEvent(ev); } else { mTouchMode = TOUCH_INIT_MODE; mPreventDrag = mForwardTouchEvents; @@ -3772,6 +3701,9 @@ public class WebView extends AbsoluteLayout } mVelocityTracker.addMovement(ev); + int deltaX = (int) (mLastTouchX - x); + int deltaY = (int) (mLastTouchY - y); + if (mTouchMode != TOUCH_DRAG_MODE) { if (mTouchMode == TOUCH_SELECT_MODE) { mSelectX = mScrollX + (int) x; diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index 6ab088d..a7261c5 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -1294,9 +1294,7 @@ final class WebViewCore { draw.mViewPoint = new Point(mCurrentViewWidth, mCurrentViewHeight); if (LOGV_ENABLED) Log.v(LOGTAG, "webkitDraw NEW_PICTURE_MSG_ID"); Message.obtain(mWebView.mPrivateHandler, - WebView.NEW_PICTURE_MSG_ID, - mViewportMinimumScale == 0 ? nativeGetContentMinPrefWidth() - : 0, + WebView.NEW_PICTURE_MSG_ID, nativeGetContentMinPrefWidth(), 0, draw).sendToTarget(); nativeCheckNavCache(); if (mWebkitScrollX != 0 || mWebkitScrollY != 0) { |
