From 22526e698d410058e24987164a4e6a01bd4d80b0 Mon Sep 17 00:00:00 2001 From: Cary Clark Date: Mon, 28 Sep 2009 12:57:26 -0400 Subject: [PATCH] scroll text field with touch 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 | 13 +++++++++---- WebKit/android/jni/WebViewCore.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index 359da03d6..d41b3a826 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -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(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 }, diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h index 1a8648242..ff5e175df 100644 --- a/WebKit/android/jni/WebViewCore.h +++ b/WebKit/android/jni/WebViewCore.h @@ -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); -- 2.11.0