From bf16ddc110ef3fde2cfa1ae43ab31d993377981d Mon Sep 17 00:00:00 2001 From: Leon Scroggins Date: Tue, 8 Dec 2009 16:59:46 -0500 Subject: [PATCH] Pass a message to move the focus when user hits "Next". Directly move the focus rather than passing a click. Fixes http://b/issue?id=2292683 Requires a change to frameworks/base --- WebKit/android/jni/WebViewCore.cpp | 33 ++++++++++++++++++++++++++++++++- WebKit/android/jni/WebViewCore.h | 1 + WebKit/android/nav/WebView.cpp | 22 ++++++++++++++++++---- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index 113908624..135d1b28a 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -1453,7 +1453,26 @@ void WebViewCore::moveMouseIfLatest(int moveGeneration, moveMouse(frame, x, y); } -// Update mouse position and may change focused node. +void WebViewCore::moveFocus(WebCore::Frame* frame, WebCore::Node* node) +{ + DBG_NAV_LOGD("frame=%p node=%p", frame, node); + if (!node || !CacheBuilder::validNode(m_mainFrame, frame, node) + || !node->isElementNode()) + return; + // Code borrowed from FocusController::advanceFocus + WebCore::FocusController* focusController + = m_mainFrame->page()->focusController(); + WebCore::Document* oldDoc + = focusController->focusedOrMainFrame()->document(); + if (oldDoc->focusedNode() == node) + return; + if (node->document() != oldDoc) + oldDoc->setFocusedNode(0); + focusController->setFocusedFrame(frame); + static_cast(node)->focus(false); +} + +// Update mouse position void WebViewCore::moveMouse(WebCore::Frame* frame, int x, int y) { DBG_NAV_LOGD("frame=%p x=%d y=%d scrollOffset=(%d,%d)", frame, @@ -2863,6 +2882,16 @@ static jstring RetrieveAnchorText(JNIEnv *env, jobject obj, jint frame, } +static void MoveFocus(JNIEnv *env, jobject obj, jint framePtr, jint nodePtr) +{ +#ifdef ANDROID_INSTRUMENT + TimeCounterAuto counter(TimeCounter::WebViewCoreTimeCounter); +#endif + WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj); + LOG_ASSERT(viewImpl, "viewImpl not set in %s", __FUNCTION__); + viewImpl->moveFocus((WebCore::Frame*) framePtr, (WebCore::Node*) nodePtr); +} + static void MoveMouse(JNIEnv *env, jobject obj, jint frame, jint x, jint y) { @@ -3171,6 +3200,8 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = { (void*) DeleteSelection } , { "nativeReplaceTextfieldText", "(IILjava/lang/String;III)V", (void*) ReplaceTextfieldText } , + { "nativeMoveFocus", "(II)V", + (void*) MoveFocus }, { "nativeMoveMouse", "(III)V", (void*) MoveMouse }, { "nativeMoveMouseIfLatest", "(IIII)V", diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h index e3c9b5136..09f02a532 100644 --- a/WebKit/android/jni/WebViewCore.h +++ b/WebKit/android/jni/WebViewCore.h @@ -250,6 +250,7 @@ namespace android { // Create a set of pictures to represent the drawn DOM, driven by // the invalidated region and the time required to draw (used to draw) void recordPictureSet(PictureSet* master); + void moveFocus(WebCore::Frame* frame, WebCore::Node* node); void moveMouse(WebCore::Frame* frame, int x, int y); void moveMouseIfLatest(int moveGeneration, WebCore::Frame* frame, int x, int y); diff --git a/WebKit/android/nav/WebView.cpp b/WebKit/android/nav/WebView.cpp index 938d93cf6..3232a748a 100644 --- a/WebKit/android/nav/WebView.cpp +++ b/WebKit/android/nav/WebView.cpp @@ -100,6 +100,7 @@ struct JavaGlue { jmethodID m_clearTextEntry; jmethodID m_overrideLoading; jmethodID m_scrollBy; + jmethodID m_sendMoveFocus; jmethodID m_sendMoveMouse; jmethodID m_sendMoveMouseIfLatest; jmethodID m_sendMotionUp; @@ -129,6 +130,7 @@ WebView(JNIEnv* env, jobject javaWebView, int viewImpl) m_javaGlue.m_scrollBy = GetJMethod(env, clazz, "setContentScrollBy", "(IIZ)Z"); m_javaGlue.m_clearTextEntry = GetJMethod(env, clazz, "clearTextEntry", "()V"); m_javaGlue.m_overrideLoading = GetJMethod(env, clazz, "overrideLoading", "(Ljava/lang/String;)V"); + m_javaGlue.m_sendMoveFocus = GetJMethod(env, clazz, "sendMoveFocus", "(II)V"); m_javaGlue.m_sendMoveMouse = GetJMethod(env, clazz, "sendMoveMouse", "(IIII)V"); m_javaGlue.m_sendMoveMouseIfLatest = GetJMethod(env, clazz, "sendMoveMouseIfLatest", "(Z)V"); m_javaGlue.m_sendMotionUp = GetJMethod(env, clazz, "sendMotionUp", "(IIIII)V"); @@ -1098,6 +1100,20 @@ void getSelectionCaret(SkPath* path) path->rLineTo(-dist, -dist); } +void sendMoveFocus(WebCore::Frame* framePtr, WebCore::Node* nodePtr) +{ + DBG_NAV_LOGD("framePtr=%p nodePtr=%p x=%d y=%d", framePtr, nodePtr, x, y); + JNIEnv* env = JSC::Bindings::getJNIEnv(); + AutoJObject obj = m_javaGlue.object(env); + // if it is called during or after DESTROY is handled, the real object of + // WebView can be gone. Check before using it. + if (!obj.get()) + return; + env->CallVoidMethod(obj.get(), m_javaGlue.m_sendMoveFocus, (jint) framePtr, + (jint) nodePtr); + checkException(env); +} + void sendMoveMouse(WebCore::Frame* framePtr, WebCore::Node* nodePtr, int x, int y) { DBG_NAV_LOGD("framePtr=%p nodePtr=%p x=%d y=%d", framePtr, nodePtr, x, y); @@ -1954,10 +1970,8 @@ static void nativeMoveCursorToNextTextInput(JNIEnv *env, jobject obj) view->updateCursorBounds(root, frame, next); root->setCursor(const_cast(frame), const_cast(next)); - WebCore::IntPoint pos; - root->getSimulatedMousePosition(&pos); - view->sendMoveMouse(static_cast(frame->framePointer()), - static_cast(next->nodePointer()), pos.x(), pos.y()); + view->sendMoveFocus(static_cast(frame->framePointer()), + static_cast(next->nodePointer())); view->scrollRectOnScreen(bounds.x(), bounds.y(), bounds.right(), bounds.bottom()); view->getWebViewCore()->m_moveGeneration++; -- 2.11.0