diff options
author | Leon Scroggins <scroggo@google.com> | 2009-07-01 10:57:47 -0400 |
---|---|---|
committer | Leon Scroggins <scroggo@google.com> | 2009-07-01 10:57:47 -0400 |
commit | 409812691def88027dc16ac930646eb260536c69 (patch) | |
tree | 876601fcab9f707624547d1850491964778710a3 /core/java/android/webkit | |
parent | 3ccd3655a09633794f4d815ff85f35fa986a10d4 (diff) | |
download | frameworks_base-409812691def88027dc16ac930646eb260536c69.zip frameworks_base-409812691def88027dc16ac930646eb260536c69.tar.gz frameworks_base-409812691def88027dc16ac930646eb260536c69.tar.bz2 |
Fixes for moving a focused textfield on screen when entering a character.
When the focused node is a textfield, but the WebView has focus
(for example if the page had an initial focus) and the cursor
is not over a plugin or textfield, rebuild the WebTextView
to handle the keys. Also, remove mScrollToAccommodateCursor,
since now the WebTextView is only showing when we want to
scroll.
Diffstat (limited to 'core/java/android/webkit')
-rw-r--r-- | core/java/android/webkit/WebTextView.java | 26 | ||||
-rw-r--r-- | core/java/android/webkit/WebView.java | 11 |
2 files changed, 8 insertions, 29 deletions
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java index d1904b7..25a20f2 100644 --- a/core/java/android/webkit/WebTextView.java +++ b/core/java/android/webkit/WebTextView.java @@ -17,7 +17,6 @@ package android.webkit; import android.content.Context; -import android.graphics.Rect; import android.text.Editable; import android.text.InputFilter; import android.text.Selection; @@ -58,9 +57,6 @@ import java.util.ArrayList; // on the enter key. The method for blocking unmatched key ups prevents // the shift key from working properly. private boolean mGotEnterDown; - // mScrollToAccommodateCursor being set to false prevents us from scrolling - // the cursor on screen when using the trackball to select a textfield. - private boolean mScrollToAccommodateCursor; private int mMaxLength; // Keep track of the text before the change so we know whether we actually // need to send down the DOM events. @@ -189,7 +185,6 @@ import java.util.ArrayList; if (maxedOut && !isArrowKey && keyCode != KeyEvent.KEYCODE_DEL) { if (oldEnd == oldStart) { // Return true so the key gets dropped. - mScrollToAccommodateCursor = true; return true; } else if (!oldText.equals(getText().toString())) { // FIXME: This makes the text work properly, but it @@ -203,7 +198,6 @@ import java.util.ArrayList; int newEnd = Selection.getSelectionEnd(span); mWebView.replaceTextfieldText(0, oldLength, span.toString(), newStart, newEnd); - mScrollToAccommodateCursor = true; return true; } } @@ -219,7 +213,6 @@ import java.util.ArrayList; sendDomEvent(event); } */ - mScrollToAccommodateCursor = true; return true; } // Ignore the key up event for newlines. This prevents @@ -373,12 +366,6 @@ import java.util.ArrayList; // Selection is changed in onSelectionChanged return true; } - // If the user is in a textfield, and the movement method is not - // handling the trackball events, it means they are at the end of the - // field and continuing to move the trackball. In this case, we should - // not scroll the cursor on screen bc the user may be attempting to - // scroll the page, possibly in the opposite direction of the cursor. - mScrollToAccommodateCursor = false; return false; } @@ -392,11 +379,6 @@ import java.util.ArrayList; getWindowToken(), 0); mWebView.removeView(this); mWebView.requestFocus(); - mScrollToAccommodateCursor = false; - } - - /* package */ void enableScrollOnScreen(boolean enable) { - mScrollToAccommodateCursor = enable; } /* package */ void bringIntoView() { @@ -405,14 +387,6 @@ import java.util.ArrayList; } } - @Override - public boolean requestRectangleOnScreen(Rect rectangle) { - if (mScrollToAccommodateCursor) { - return super.requestRectangleOnScreen(rectangle); - } - return false; - } - /** * Send the DOM events for the specified event. * @param event KeyEvent to be translated into a DOM event. diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index ddcec3c..e061a4c 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -3029,7 +3029,6 @@ public class WebView extends AbsoluteLayout if (isTextView) { imm.showSoftInput(mWebTextView, 0); - mWebTextView.enableScrollOnScreen(true); // Now we need to fake a touch event to place the cursor where the // user touched. AbsoluteLayout.LayoutParams lp = (AbsoluteLayout.LayoutParams) @@ -3090,8 +3089,7 @@ public class WebView extends AbsoluteLayout // should be in content coordinates. Rect bounds = nativeFocusCandidateNodeBounds(); if (!Rect.intersects(bounds, visibleRect)) { - // Node is not on screen, so do not bother. - return; + mWebTextView.bringIntoView(); } String text = nativeFocusCandidateText(); int nodePointer = nativeFocusCandidatePointer(); @@ -3329,6 +3327,13 @@ public class WebView extends AbsoluteLayout rebuildWebTextView(); // Now we need to pass the event to it return mWebTextView.onKeyDown(keyCode, event); + } else if (nativeHasFocusNode()) { + // In this case, the cursor is not on a text input, but the focus + // might be. Check it, and if so, hand over to the WebTextView. + rebuildWebTextView(); + if (inEditingMode()) { + return mWebTextView.onKeyDown(keyCode, event); + } } // TODO: should we pass all the keys to DOM or check the meta tag |