diff options
| author | 2010-12-14 18:09:23 -0500 | |
|---|---|---|
| committer | 2010-12-15 09:50:53 -0500 | |
| commit | fcf577665bb7ad029e41fd31d5f582f3c98d3026 (patch) | |
| tree | 1bee3dcdb6400173fc2ec8810a9db1b0e9581664 | |
| parent | 96e6b8bfc82e04d06923c372657768b4866e4fb9 (diff) | |
Make a long press on a textfield work.
Bug:3268584
Even if the WebTextView has not been set up yet.
Change-Id: I8ec2c4ef8146006d6ee84d08e1ddbdb099125047
| -rw-r--r-- | core/java/android/webkit/WebTextView.java | 12 | ||||
| -rw-r--r-- | core/java/android/webkit/WebView.java | 12 |
2 files changed, 24 insertions, 0 deletions
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java index d83fc4285937..bb18270efa01 100644 --- a/core/java/android/webkit/WebTextView.java +++ b/core/java/android/webkit/WebTextView.java @@ -353,6 +353,18 @@ import junit.framework.Assert; return false; } + void ensureLayout() { + if (getLayout() == null) { + // Ensure we have a Layout + measure(mWidthSpec, mHeightSpec); + LayoutParams params = (LayoutParams) getLayoutParams(); + if (params != null) { + layout(params.x, params.y, params.x + params.width, + params.y + params.height); + } + } + } + /** * Determine whether this WebTextView currently represents the node * represented by ptr. diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 0959bfafd733..5b43953fd357 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -3750,6 +3750,18 @@ public class WebView extends AbsoluteLayout clearTextEntry(); } if (inEditingMode()) { + // Since we just called rebuildWebTextView, the layout is not set + // properly. Update it so it can correctly find the word to select. + mWebTextView.ensureLayout(); + // Provide a touch down event to WebTextView, which will allow it + // to store the location to use in performLongClick. + AbsoluteLayout.LayoutParams params + = (AbsoluteLayout.LayoutParams) mWebTextView.getLayoutParams(); + MotionEvent fake = MotionEvent.obtain(mLastTouchTime, + mLastTouchTime, MotionEvent.ACTION_DOWN, + mLastTouchX - params.x + mScrollX, + mLastTouchY - params.y + mScrollY, 0); + mWebTextView.dispatchTouchEvent(fake); return mWebTextView.performLongClick(); } if (mSelectingText) return false; // long click does nothing on selection |