From fcf577665bb7ad029e41fd31d5f582f3c98d3026 Mon Sep 17 00:00:00 2001 From: Leon Scroggins Date: Tue, 14 Dec 2010 18:09:23 -0500 Subject: Make a long press on a textfield work. Bug:3268584 Even if the WebTextView has not been set up yet. Change-Id: I8ec2c4ef8146006d6ee84d08e1ddbdb099125047 --- core/java/android/webkit/WebTextView.java | 12 ++++++++++++ core/java/android/webkit/WebView.java | 12 ++++++++++++ 2 files changed, 24 insertions(+) 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 -- cgit v1.2.3-59-g8ed1b