OSDN Git Service

Pass selection data along with message to open the keyboard.
authorLeon Scroggins <scroggo@google.com>
Thu, 18 Mar 2010 16:43:35 +0000 (12:43 -0400)
committerLeon Scroggins <scroggo@google.com>
Thu, 18 Mar 2010 16:51:06 +0000 (12:51 -0400)
Fixes http://b/issue?id=2431351

Requires a change to frameworks/base

Change-Id: I7f703746bdd00aaae2607a6a41ac4916f43d37b1

WebKit/android/jni/WebViewCore.cpp
WebKit/android/jni/WebViewCore.h
WebKit/android/plugins/ANPWindowInterface.cpp

index 8556dd8..529f1d6 100644 (file)
@@ -214,6 +214,7 @@ struct WebViewCore::JavaGlue {
     jmethodID   m_restoreScreenWidthScale;
     jmethodID   m_needTouchEvents;
     jmethodID   m_requestKeyboard;
+    jmethodID   m_requestKeyboardWithSelection;
     jmethodID   m_exceededDatabaseQuota;
     jmethodID   m_reachedMaxAppCacheSize;
     jmethodID   m_populateVisitedLinks;
@@ -302,7 +303,8 @@ WebViewCore::WebViewCore(JNIEnv* env, jobject javaWebViewCore, WebCore::Frame* m
     m_javaGlue->m_restoreScale = GetJMethod(env, clazz, "restoreScale", "(I)V");
     m_javaGlue->m_restoreScreenWidthScale = GetJMethod(env, clazz, "restoreScreenWidthScale", "(I)V");
     m_javaGlue->m_needTouchEvents = GetJMethod(env, clazz, "needTouchEvents", "(Z)V");
-    m_javaGlue->m_requestKeyboard = GetJMethod(env, clazz, "requestKeyboard", "(ZZ)V");
+    m_javaGlue->m_requestKeyboard = GetJMethod(env, clazz, "requestKeyboard", "(Z)V");
+    m_javaGlue->m_requestKeyboardWithSelection = GetJMethod(env, clazz, "requestKeyboardWithSelection", "(IIII)V");
     m_javaGlue->m_exceededDatabaseQuota = GetJMethod(env, clazz, "exceededDatabaseQuota", "(Ljava/lang/String;Ljava/lang/String;JJ)V");
     m_javaGlue->m_reachedMaxAppCacheSize = GetJMethod(env, clazz, "reachedMaxAppCacheSize", "(J)V");
     m_javaGlue->m_populateVisitedLinks = GetJMethod(env, clazz, "populateVisitedLinks", "()V");
@@ -1047,14 +1049,27 @@ void WebViewCore::needTouchEvents(bool need)
 #endif
 }
 
-void WebViewCore::requestKeyboard(bool showKeyboard, bool isTextView)
+void WebViewCore::requestKeyboardWithSelection(const WebCore::Node* node,
+        int selStart, int selEnd)
 {
-    DBG_NAV_LOGD("showKeyboard=%d", showKeyboard);
+    DEBUG_NAV_UI_LOGD("%s", __FUNCTION__);
+    LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
+
+    JNIEnv* env = JSC::Bindings::getJNIEnv();
+    env->CallVoidMethod(m_javaGlue->object(env).get(),
+            m_javaGlue->m_requestKeyboardWithSelection,
+            reinterpret_cast<int>(node), selStart, selEnd, m_textGeneration);
+    checkException(env);
+}
+
+void WebViewCore::requestKeyboard(bool showKeyboard)
+{
+    DEBUG_NAV_UI_LOGD("%s", __FUNCTION__);
     LOG_ASSERT(m_javaGlue->m_obj, "A Java widget was not associated with this view bridge!");
 
     JNIEnv* env = JSC::Bindings::getJNIEnv();
-    env->CallVoidMethod(m_javaGlue->object(env).get(), m_javaGlue->m_requestKeyboard, showKeyboard,
-            isTextView);
+    env->CallVoidMethod(m_javaGlue->object(env).get(),
+            m_javaGlue->m_requestKeyboard, showKeyboard);
     checkException(env);
 }
 
@@ -2150,7 +2165,14 @@ bool WebViewCore::handleMouseClick(WebCore::Frame* framePtr, WebCore::Node* node
             bool ime = !(static_cast<WebCore::HTMLInputElement*>(focusNode))
                     ->readOnly();
             setFocusControllerActive(framePtr, ime);
-            requestKeyboard(ime, true);
+            if (ime) {
+                RenderTextControl* rtc
+                        = static_cast<RenderTextControl*> (renderer);
+                requestKeyboardWithSelection(focusNode, rtc->selectionStart(),
+                        rtc->selectionEnd());
+            } else {
+                requestKeyboard(false);
+            }
         }
     }
     return handled;
index 0ec8bed..abe0d8d 100644 (file)
@@ -388,8 +388,9 @@ namespace android {
         // Notify the Java side whether it needs to pass down the touch events
         void needTouchEvents(bool);
 
+        void requestKeyboardWithSelection(const WebCore::Node*, int selStart, int selEnd);
         // Notify the Java side that webkit is requesting a keyboard
-        void requestKeyboard(bool showKeyboard, bool isTextView);
+        void requestKeyboard(bool showKeyboard);
 
         // Generates a class loader that contains classes from the plugin's apk
         jclass getPluginClass(const WebCore::String& libName, const char* className);
index 0a31ed3..f086b44 100644 (file)
@@ -50,7 +50,7 @@ static void anp_showKeyboard(NPP instance, bool value) {
     PluginView* pluginView = pluginViewForInstance(instance);
     PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget();
     if(pluginWidget->hasFocus())
-        pluginWidget->webViewCore()->requestKeyboard(value, false);
+        pluginWidget->webViewCore()->requestKeyboard(value);
 }
 
 static void anp_requestFullScreen(NPP instance) {