OSDN Git Service

scroll text field with touch
authorCary Clark <cary@android.com>
Mon, 28 Sep 2009 16:57:26 +0000 (12:57 -0400)
committerCary Clark <cary@android.com>
Tue, 29 Sep 2009 19:42:07 +0000 (15:42 -0400)
Pass the percentage of the current scroll from the UI
thread to webkit. The max scroll in X is computed as
renderer->scrollWidth() - renderer->clientWidth().

Companion fix is in framework/base

Fixes http://b/issue?id=2133049

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

index 359da03..d41b3a8 100644 (file)
@@ -1649,7 +1649,7 @@ void WebViewCore::passToJs(int generation, const WebCore::String& current,
     updateTextfield(focus, false, test);
 }
 
-void WebViewCore::scrollFocusedTextInput(int x, int y)
+void WebViewCore::scrollFocusedTextInput(float xPercent, int y)
 {
     WebCore::Node* focus = currentFocus();
     if (!focus) {
@@ -1665,6 +1665,10 @@ void WebViewCore::scrollFocusedTextInput(int x, int y)
     }
     WebCore::RenderTextControl* renderText =
         static_cast<WebCore::RenderTextControl*>(renderer);
+    int x = (int) (xPercent * (renderText->scrollWidth() -
+        renderText->clientWidth()));
+    DBG_NAV_LOGD("x=%d y=%d xPercent=%g scrollW=%d clientW=%d", x, y,
+        xPercent, renderText->scrollWidth(), renderText->clientWidth());
     renderText->setScrollLeft(x);
     renderText->setScrollTop(y);
 }
@@ -2398,13 +2402,14 @@ 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)
+static void ScrollFocusedTextInput(JNIEnv *env, jobject obj, jfloat xPercent,
+    jint y)
 {
 #ifdef ANDROID_INSTRUMENT
     TimeCounterAuto counter(TimeCounter::WebViewCoreTimeCounter);
 #endif
     WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj);
-    viewImpl->scrollFocusedTextInput(x, y);
+    viewImpl->scrollFocusedTextInput(xPercent, y);
 }
 
 static void SetFocusControllerActive(JNIEnv *env, jobject obj, jboolean active)
@@ -2825,7 +2830,7 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = {
         (void*) MoveMouseIfLatest },
     { "passToJs", "(ILjava/lang/String;IIZZZZ)V",
         (void*) PassToJs },
-    { "nativeScrollFocusedTextInput", "(II)V",
+    { "nativeScrollFocusedTextInput", "(FI)V",
         (void*) ScrollFocusedTextInput },
     { "nativeSetFocusControllerActive", "(Z)V",
         (void*) SetFocusControllerActive },
index 1a86482..ff5e175 100644 (file)
@@ -319,7 +319,7 @@ namespace android {
         /**
          * Scroll the focused textfield to (x, y) in document space
          */
-        void scrollFocusedTextInput(int x, int y);
+        void scrollFocusedTextInput(float x, int y);
         void setFocusControllerActive(bool active);
 
         void saveDocumentState(WebCore::Frame* frame);