OSDN Git Service

Improve dragging on WebTextView.
authorLeon Scroggins <scroggo@google.com>
Thu, 23 Jul 2009 20:03:42 +0000 (16:03 -0400)
committerLeon Scroggins <scroggo@google.com>
Thu, 23 Jul 2009 20:34:04 +0000 (16:34 -0400)
When the WebTextView scrolls, scroll the corresponding RenderTextControl
in webkit.  Requires a change in frameworks/base.

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

index 9f457f4..51293b8 100644 (file)
@@ -1517,6 +1517,26 @@ void WebViewCore::passToJs(int generation, const WebCore::String& current,
     updateTextfield(focus, false, test);
 }
 
+void WebViewCore::scrollFocusedTextInput(int x, int y)
+{
+    WebCore::Node* focus = currentFocus();
+    if (!focus) {
+        DBG_NAV_LOG("!focus");
+        clearTextEntry();
+        return;
+    }
+    WebCore::RenderObject* renderer = focus->renderer();
+    if (!renderer || (!renderer->isTextField() && !renderer->isTextArea())) {
+        DBG_NAV_LOGD("renderer==%p || not text", renderer);
+        clearTextEntry();
+        return;
+    }
+    WebCore::RenderTextControl* renderText =
+        static_cast<WebCore::RenderTextControl*>(renderer);
+    renderText->setScrollLeft(x);
+    renderText->setScrollTop(y);
+}
+
 void WebViewCore::setFocusControllerActive(bool active)
 {
     m_mainFrame->page()->focusController()->setActive(active);
@@ -2180,6 +2200,15 @@ static void PassToJs(JNIEnv *env, jobject obj,
         PlatformKeyboardEvent(keyCode, keyValue, 0, down, cap, fn, sym));
 }
 
+static void ScrollFocusedTextInput(JNIEnv *env, jobject obj, jint x, jint y)
+{
+#ifdef ANDROID_INSTRUMENT
+    TimeCounterAuto counter(TimeCounter::WebViewCoreTimeCounter);
+#endif
+    WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj);
+    viewImpl->scrollFocusedTextInput(x, y);
+}
+
 static void SetFocusControllerActive(JNIEnv *env, jobject obj, jboolean active)
 {
 #ifdef ANDROID_INSTRUMENT
@@ -2630,7 +2659,9 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = {
     { "nativeMoveMouseIfLatest", "(IIII)V",
         (void*) MoveMouseIfLatest },
     { "passToJs", "(ILjava/lang/String;IIZZZZ)V",
-        (void*) PassToJs } ,
+        (void*) PassToJs },
+    { "nativeScrollFocusedTextInput", "(II)V",
+        (void*) ScrollFocusedTextInput },
     { "nativeSetFocusControllerActive", "(Z)V",
         (void*) SetFocusControllerActive },
     { "nativeSaveDocumentState", "(I)V",
index 66ef470..be08830 100644 (file)
@@ -266,6 +266,10 @@ namespace android {
             int textGeneration);
         void passToJs(int generation,
             const WebCore::String& , const WebCore::PlatformKeyboardEvent& );
+        /**
+         * Scroll the focused textfield to (x, y) in document space
+         */
+        void scrollFocusedTextInput(int x, int y);
         void setFocusControllerActive(bool active);
 
         void saveDocumentState(WebCore::Frame* frame);