diff options
| -rw-r--r-- | core/java/android/webkit/WebView.java | 52 | ||||
| -rw-r--r-- | core/java/android/webkit/WebViewCore.java | 9 |
2 files changed, 47 insertions, 14 deletions
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 8f502470b00c..472ac09b2cc2 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -467,6 +467,7 @@ public class WebView extends AbsoluteLayout static final int WEBCORE_NEED_TOUCH_EVENTS = 25; // obj=Rect in doc coordinates static final int INVAL_RECT_MSG_ID = 26; + static final int REQUEST_KEYBOARD = 27; static final String[] HandlerDebugString = { "REMEMBER_PASSWORD", // = 1; @@ -494,7 +495,8 @@ public class WebView extends AbsoluteLayout "LONG_PRESS_CENTER", // = 23; "PREVENT_TOUCH_ID", // = 24; "WEBCORE_NEED_TOUCH_EVENTS", // = 25; - "INVAL_RECT_MSG_ID" // = 26; + "INVAL_RECT_MSG_ID", // = 26; + "REQUEST_KEYBOARD" // = 27; }; // width which view is considered to be fully zoomed out @@ -3002,24 +3004,38 @@ public class WebView extends AbsoluteLayout } // Called by JNI when a touch event puts a textfield into focus. - private void displaySoftKeyboard() { + private void displaySoftKeyboard(boolean isTextView) { InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - 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) - mWebTextView.getLayoutParams(); - if (lp != null) { - // Take the last touch and adjust for the location of the - // WebTextView. - float x = mLastTouchX + (float) (mScrollX - lp.x); - float y = mLastTouchY + (float) (mScrollY - lp.y); - mWebTextView.fakeTouchEvent(x, y); + + 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) + mWebTextView.getLayoutParams(); + if (lp != null) { + // Take the last touch and adjust for the location of the + // WebTextView. + float x = mLastTouchX + (float) (mScrollX - lp.x); + float y = mLastTouchY + (float) (mScrollY - lp.y); + mWebTextView.fakeTouchEvent(x, y); + } + } + else { // used by plugins + imm.showSoftInput(this, 0); } } + // Called by WebKit to instruct the UI to hide the keyboard + private void hideSoftKeyboard() { + InputMethodManager imm = (InputMethodManager) + getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + + imm.hideSoftInputFromWindow(this.getWindowToken(), 0); + } + /* * This method checks the current focus and cursor and potentially rebuilds * mWebTextView to have the appropriate properties, such as password, @@ -4920,6 +4936,14 @@ public class WebView extends AbsoluteLayout } break; + case REQUEST_KEYBOARD: + if (msg.arg1 == 0) { + hideSoftKeyboard(); + } else { + displaySoftKeyboard(false); + } + break; + default: super.handleMessage(msg); break; diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index b75ba94146ee..cfd6f6166a31 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -1780,6 +1780,15 @@ final class WebViewCore { } + // called by JNI + private void requestKeyboard(boolean showKeyboard) { + if (mWebView != null) { + Message.obtain(mWebView.mPrivateHandler, + WebView.REQUEST_KEYBOARD, showKeyboard ? 1 : 0, 0) + .sendToTarget(); + } + } + private native void nativePause(); private native void nativeResume(); private native void nativeFreeMemory(); |