diff options
author | John Reck <jreck@google.com> | 2012-04-13 12:42:54 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2012-04-13 13:09:58 -0700 |
commit | 8f05073be1549b39eaf2e0ff3b6fe0f8cae3afcd (patch) | |
tree | 795d2d3de25865ab0a9632c8a858fbcdd62c3ddb /Source/WebKit | |
parent | 6db940d5b0fdc1d28edd7851ed30885e5f7d0dc8 (diff) | |
download | external_webkit-8f05073be1549b39eaf2e0ff3b6fe0f8cae3afcd.zip external_webkit-8f05073be1549b39eaf2e0ff3b6fe0f8cae3afcd.tar.gz external_webkit-8f05073be1549b39eaf2e0ff3b6fe0f8cae3afcd.tar.bz2 |
Set initial focus
Bug: 6108927
Change-Id: I150e75a7d1c0d971db03e407a58ba28acbd6283c
Diffstat (limited to 'Source/WebKit')
-rw-r--r-- | Source/WebKit/android/jni/WebViewCore.cpp | 35 | ||||
-rw-r--r-- | Source/WebKit/android/jni/WebViewCore.h | 1 |
2 files changed, 36 insertions, 0 deletions
diff --git a/Source/WebKit/android/jni/WebViewCore.cpp b/Source/WebKit/android/jni/WebViewCore.cpp index 7da8103..9f66d7e 100644 --- a/Source/WebKit/android/jni/WebViewCore.cpp +++ b/Source/WebKit/android/jni/WebViewCore.cpp @@ -3132,6 +3132,32 @@ void WebViewCore::chromeTakeFocus(FocusDirection direction) env->CallVoidMethod(javaObject.get(), m_javaGlue->m_chromeTakeFocus, direction); } +void WebViewCore::setInitialFocus(const WebCore::PlatformKeyboardEvent& platformEvent) +{ + Frame* frame = focusedFrame(); + Document* document = frame->document(); + if (document) + document->setFocusedNode(0); + FocusDirection direction; + switch (platformEvent.nativeVirtualKeyCode()) { + case AKEYCODE_DPAD_LEFT: + direction = FocusDirectionLeft; + break; + case AKEYCODE_DPAD_RIGHT: + direction = FocusDirectionRight; + break; + case AKEYCODE_DPAD_UP: + direction = FocusDirectionUp; + break; + default: + direction = FocusDirectionDown; + break; + } + RefPtr<KeyboardEvent> webkitEvent = KeyboardEvent::create(platformEvent, 0); + m_mainFrame->page()->focusController()->setInitialFocus(direction, + webkitEvent.get()); +} + #if USE(ACCELERATED_COMPOSITING) GraphicsLayerAndroid* WebViewCore::graphicsRootLayer() const { @@ -4401,6 +4427,14 @@ static jboolean Key(JNIEnv* env, jobject obj, jint nativeClass, jint keyCode, unichar, repeatCount, isDown, isShift, isAlt, isSym)); } +static void SetInitialFocus(JNIEnv* env, jobject obj, jint nativeClass, + jint keyDirection) +{ + WebViewCore* viewImpl = reinterpret_cast<WebViewCore*>(nativeClass); + viewImpl->setInitialFocus(PlatformKeyboardEvent(keyDirection, + 0, 0, false, false, false, false)); +} + static void ContentInvalidateAll(JNIEnv* env, jobject obj, jint nativeClass) { reinterpret_cast<WebViewCore*>(nativeClass)->contentInvalidateAll(); @@ -5073,6 +5107,7 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = { (void*) FindAll }, { "nativeFindNext", "(IZ)I", (void*) FindNext }, + { "nativeSetInitialFocus", "(II)V", (void*) SetInitialFocus }, }; int registerWebViewCore(JNIEnv* env) diff --git a/Source/WebKit/android/jni/WebViewCore.h b/Source/WebKit/android/jni/WebViewCore.h index 82a65cf..eec98b0 100644 --- a/Source/WebKit/android/jni/WebViewCore.h +++ b/Source/WebKit/android/jni/WebViewCore.h @@ -321,6 +321,7 @@ namespace android { bool key(const WebCore::PlatformKeyboardEvent& event); bool chromeCanTakeFocus(WebCore::FocusDirection direction); void chromeTakeFocus(WebCore::FocusDirection direction); + void setInitialFocus(const WebCore::PlatformKeyboardEvent& event); /** * Handle touch event |