diff options
author | Leon Scroggins <scroggo@google.com> | 2009-12-15 16:38:45 -0500 |
---|---|---|
committer | Leon Scroggins <scroggo@google.com> | 2010-01-04 09:43:57 -0500 |
commit | e26efa321c66716d58f3e338022caed8852af07e (patch) | |
tree | 0d0fce57cb48369886a22c47ac56b9e5d9a6014b /core/java/android/webkit | |
parent | 4bc95d19c9ccf9cfe4c51b1e697db8cc1d86a579 (diff) | |
download | frameworks_base-e26efa321c66716d58f3e338022caed8852af07e.zip frameworks_base-e26efa321c66716d58f3e338022caed8852af07e.tar.gz frameworks_base-e26efa321c66716d58f3e338022caed8852af07e.tar.bz2 |
If the DOM changes textfield focus, make the IME work properly.
Fix for http://b/issue?id=2219166
Requires a change to external/webkit
Remove the old change to update the WebTextView when a key is pressed,
since the IME does not generate key events. Instead, when the focus
changes, and the IME is serving the WebTextView, immediately clear
the cursor and update the WebTextView, so the user can continue
typing.
Diffstat (limited to 'core/java/android/webkit')
-rw-r--r-- | core/java/android/webkit/WebTextView.java | 23 | ||||
-rw-r--r-- | core/java/android/webkit/WebView.java | 32 |
2 files changed, 18 insertions, 37 deletions
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java index 92da456..9a36798 100644 --- a/core/java/android/webkit/WebTextView.java +++ b/core/java/android/webkit/WebTextView.java @@ -84,12 +84,6 @@ import java.util.ArrayList; // True if the most recent drag event has caused either the TextView to // scroll or the web page to scroll. Gets reset after a touch down. private boolean mScrolled; - // Gets set to true any time the WebTextView has focus, but the navigation - // cache does not yet know that the focus has been changed. This happens - // if the user presses "Next", if the user moves the cursor to a textfield - // and starts typing or clicks the trackball/center key, and when the user - // touches a textfield. - boolean mOkayForFocusNotToMatch; // Whether or not a selection change was generated from webkit. If it was, // we do not need to pass the selection back to webkit. private boolean mFromWebKit; @@ -151,22 +145,6 @@ import java.util.ArrayList; break; } - if (down) { - if (mOkayForFocusNotToMatch) { - if (mWebView.nativeFocusNodePointer() == mNodePointer) { - mOkayForFocusNotToMatch = false; - } - } else if (mWebView.nativeFocusNodePointer() != mNodePointer - && !isArrowKey) { - mWebView.nativeClearCursor(); - // Do not call remove() here, which hides the soft keyboard. If - // the soft keyboard is being displayed, the user will still want - // it there. - mWebView.removeView(this); - mWebView.requestFocus(); - return mWebView.dispatchKeyEvent(event); - } - } Spannable text = (Spannable) getText(); int oldLength = text.length(); // Normally the delete key's dom events are sent via onTextChanged. @@ -324,7 +302,6 @@ import java.util.ArrayList; // focus, set the focus controller back to inactive mWebView.setFocusControllerInactive(); mWebView.nativeMoveCursorToNextTextInput(); - mOkayForFocusNotToMatch = true; // Preemptively rebuild the WebTextView, so that the action will // be set properly. mWebView.rebuildWebTextView(); diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index fb8148b..28a3404 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -493,6 +493,7 @@ public class WebView extends AbsoluteLayout static final int DO_MOTION_UP = 28; static final int SHOW_FULLSCREEN = 29; static final int HIDE_FULLSCREEN = 30; + static final int DOM_FOCUS_CHANGED = 31; static final String[] HandlerDebugString = { "REMEMBER_PASSWORD", // = 1; @@ -524,7 +525,8 @@ public class WebView extends AbsoluteLayout "REQUEST_KEYBOARD", // = 27; "DO_MOTION_UP", // = 28; "SHOW_FULLSCREEN", // = 29; - "HIDE_FULLSCREEN" // = 30; + "HIDE_FULLSCREEN", // = 30; + "DOM_FOCUS_CHANGED" // = 31; }; // If the site doesn't use the viewport meta tag to specify the viewport, @@ -1726,6 +1728,13 @@ public class WebView extends AbsoluteLayout return result; } + // Called by JNI when the DOM has changed the focus. Clear the focus so + // that new keys will go to the newly focused field + private void domChangedFocus() { + if (inEditingMode()) { + mPrivateHandler.obtainMessage(DOM_FOCUS_CHANGED).sendToTarget(); + } + } /** * Request the href of an anchor element due to getFocusNodePath returning * "href." If hrefMsg is null, this method returns immediately and does not @@ -3191,16 +3200,6 @@ public class WebView extends AbsoluteLayout imm.hideSoftInputFromWindow(this.getWindowToken(), 0); } - /** - * Only for calling from JNI. Allows a click on an unfocused textfield to - * put the textfield in focus. - */ - private void setOkayNotToMatch() { - if (inEditingMode()) { - mWebTextView.mOkayForFocusNotToMatch = true; - } - } - /* * This method checks the current focus and cursor and potentially rebuilds * mWebTextView to have the appropriate properties, such as password, @@ -3462,7 +3461,6 @@ public class WebView extends AbsoluteLayout // Now we need to pass the event to it if (inEditingMode()) { mWebTextView.setDefaultSelection(); - mWebTextView.mOkayForFocusNotToMatch = true; return mWebTextView.dispatchKeyEvent(event); } } else if (nativeHasFocusNode()) { @@ -3559,7 +3557,6 @@ public class WebView extends AbsoluteLayout centerKeyPressOnTextField(); if (inEditingMode()) { mWebTextView.setDefaultSelection(); - mWebTextView.mOkayForFocusNotToMatch = true; } return true; } @@ -5311,7 +5308,7 @@ public class WebView extends AbsoluteLayout // exclude INVAL_RECT_MSG_ID since it is frequently output if (DebugFlags.WEB_VIEW && msg.what != INVAL_RECT_MSG_ID) { Log.v(LOGTAG, msg.what < REMEMBER_PASSWORD || msg.what - > HIDE_FULLSCREEN ? Integer.toString(msg.what) + > DOM_FOCUS_CHANGED ? Integer.toString(msg.what) : HandlerDebugString[msg.what - REMEMBER_PASSWORD]); } if (mWebViewCore == null) { @@ -5736,6 +5733,13 @@ public class WebView extends AbsoluteLayout } break; + case DOM_FOCUS_CHANGED: + if (inEditingMode()) { + nativeClearCursor(); + rebuildWebTextView(); + } + break; + default: super.handleMessage(msg); break; |