summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorLeon Scroggins <scroggo@google.com>2009-07-30 16:33:56 -0400
committerLeon Scroggins <scroggo@google.com>2009-07-31 10:54:38 -0400
commit010582885cbd5e1becadd6c53816c399465b459d (patch)
tree244f84ea4be91fc1af3f380c281502baf56d2426 /core
parented9584068144adedfdd6d119e2f928da595a1953 (diff)
downloadframeworks_base-010582885cbd5e1becadd6c53816c399465b459d.zip
frameworks_base-010582885cbd5e1becadd6c53816c399465b459d.tar.gz
frameworks_base-010582885cbd5e1becadd6c53816c399465b459d.tar.bz2
Allow the user to jump to the next textfield.
Requires a change to external/webkit. Set ImeActions for textfields, depending on the existence of other textfields on the page, and react accordingly.
Diffstat (limited to 'core')
-rw-r--r--core/java/android/webkit/WebTextView.java60
-rw-r--r--core/java/android/webkit/WebView.java10
2 files changed, 63 insertions, 7 deletions
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java
index 7bc154b..f22adb7 100644
--- a/core/java/android/webkit/WebTextView.java
+++ b/core/java/android/webkit/WebTextView.java
@@ -81,6 +81,10 @@ 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 when the the IME jumps to the next textfield. When this
+ // happens, the next time the user hits a key it is okay for the focus
+ // pointer to not match the WebTextView's node pointer
+ private boolean mOkayForFocusNotToMatch;
// Array to store the final character added in onTextChanged, so that its
// KeyEvents may be determined.
private char[] mCharacter = new char[1];
@@ -99,7 +103,6 @@ import java.util.ArrayList;
super(context);
mWebView = webView;
mMaxLength = -1;
- setImeOptions(EditorInfo.IME_ACTION_NONE);
}
@Override
@@ -125,8 +128,8 @@ import java.util.ArrayList;
isArrowKey = true;
break;
}
-
- if (!isArrowKey && mWebView.nativeFocusNodePointer() != mNodePointer) {
+ if (!isArrowKey && !mOkayForFocusNotToMatch
+ && mWebView.nativeFocusNodePointer() != mNodePointer) {
mWebView.nativeClearCursor();
// Do not call remove() here, which hides the soft keyboard. If
// the soft keyboard is being displayed, the user will still want
@@ -135,6 +138,9 @@ import java.util.ArrayList;
mWebView.requestFocus();
return mWebView.dispatchKeyEvent(event);
}
+ // After a jump to next textfield and the first key press, the cursor
+ // and focus will once again match, so reset this value.
+ mOkayForFocusNotToMatch = false;
Spannable text = (Spannable) getText();
int oldLength = text.length();
@@ -305,6 +311,36 @@ import java.util.ArrayList;
}
@Override
+ public void onEditorAction(int actionCode) {
+ switch (actionCode) {
+ case EditorInfo.IME_ACTION_NEXT:
+ mWebView.nativeMoveCursorToNextTextInput();
+ // Preemptively rebuild the WebTextView, so that the action will
+ // be set properly.
+ mWebView.rebuildWebTextView();
+ // Since the cursor will no longer be in the same place as the
+ // focus, set the focus controller back to inactive
+ mWebView.setFocusControllerInactive();
+ mOkayForFocusNotToMatch = true;
+ break;
+ case EditorInfo.IME_ACTION_DONE:
+ super.onEditorAction(actionCode);
+ break;
+ case EditorInfo.IME_ACTION_GO:
+ // Send an enter and hide the soft keyboard
+ InputMethodManager.getInstance(mContext)
+ .hideSoftInputFromWindow(getWindowToken(), 0);
+ sendDomEvent(new KeyEvent(KeyEvent.ACTION_DOWN,
+ KeyEvent.KEYCODE_ENTER));
+ sendDomEvent(new KeyEvent(KeyEvent.ACTION_UP,
+ KeyEvent.KEYCODE_ENTER));
+
+ default:
+ break;
+ }
+ }
+
+ @Override
protected void onSelectionChanged(int selStart, int selEnd) {
if (mWebView != null) {
if (DebugFlags.WEB_TEXT_VIEW) {
@@ -659,10 +695,26 @@ import java.util.ArrayList;
public void setSingleLine(boolean single) {
int inputType = EditorInfo.TYPE_CLASS_TEXT
| EditorInfo.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT;
- if (!single) {
+ if (single) {
+ int action = mWebView.nativeTextFieldAction();
+ switch (action) {
+ // Keep in sync with CachedRoot::ImeAction
+ case 0: // NEXT
+ setImeOptions(EditorInfo.IME_ACTION_NEXT);
+ break;
+ case 1: // GO
+ setImeOptions(EditorInfo.IME_ACTION_GO);
+ break;
+ case -1: // FAILURE
+ case 2: // DONE
+ setImeOptions(EditorInfo.IME_ACTION_DONE);
+ break;
+ }
+ } else {
inputType |= EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE
| EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES
| EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
+ setImeOptions(EditorInfo.IME_ACTION_NONE);
}
mSingle = single;
setHorizontallyScrolling(single);
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 05a7806..adb585d 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -3123,7 +3123,7 @@ public class WebView extends AbsoluteLayout
* mWebTextView to have the appropriate properties, such as password,
* multiline, and what text it contains. It also removes it if necessary.
*/
- private void rebuildWebTextView() {
+ /* package */ void rebuildWebTextView() {
// If the WebView does not have focus, do nothing until it gains focus.
if (!hasFocus() && (null == mWebTextView || !mWebTextView.hasFocus())
|| (mTouchMode >= FIRST_SCROLL_ZOOM
@@ -3385,7 +3385,8 @@ public class WebView extends AbsoluteLayout
} else if (nativeCursorIsTextInput()) {
// This message will put the node in focus, for the DOM's notion
// of focus, and make the focuscontroller active
- mWebViewCore.sendMessage(EventHub.CLICK);
+ mWebViewCore.sendMessage(EventHub.CLICK, nativeCursorFramePointer(),
+ nativeCursorNodePointer());
// This will bring up the WebTextView and put it in focus, for
// our view system's notion of focus
rebuildWebTextView();
@@ -3626,7 +3627,7 @@ public class WebView extends AbsoluteLayout
* not draw the blinking cursor. It gets set to "active" to draw the cursor
* in WebViewCore.cpp, when the WebCore thread receives key events/clicks.
*/
- private void setFocusControllerInactive() {
+ /* package */ void setFocusControllerInactive() {
// Do not need to also check whether mWebViewCore is null, because
// mNativeClass is only set if mWebViewCore is non null
if (mNativeClass == 0) return;
@@ -5627,6 +5628,7 @@ public class WebView extends AbsoluteLayout
private native void nativeHideCursor();
private native String nativeImageURI(int x, int y);
private native void nativeInstrumentReport();
+ /* package */ native void nativeMoveCursorToNextTextInput();
// return true if the page has been scrolled
private native boolean nativeMotionUp(int x, int y, int slop);
// returns false if it handled the key
@@ -5644,6 +5646,8 @@ public class WebView extends AbsoluteLayout
private native void nativeSetFindIsDown();
private native void nativeSetFollowedLink(boolean followed);
private native void nativeSetHeightCanMeasure(boolean measure);
+ // Returns a value corresponding to CachedFrame::ImeAction
+ /* package */ native int nativeTextFieldAction();
private native int nativeTextGeneration();
// Never call this version except by updateCachedTextfield(String) -
// we always want to pass in our generation number.