diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2009-01-09 17:51:23 -0800 |
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2009-01-09 17:51:23 -0800 |
| commit | e933faefa1e899dbd5bf371f499cc682aff46c83 (patch) | |
| tree | 8fb31ff5c9a41aec9912d0253be7ef0445e2f58a /WebKit/android/jni | |
| parent | 1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 (diff) | |
| download | external_webkit-e933faefa1e899dbd5bf371f499cc682aff46c83.zip external_webkit-e933faefa1e899dbd5bf371f499cc682aff46c83.tar.gz external_webkit-e933faefa1e899dbd5bf371f499cc682aff46c83.tar.bz2 | |
auto import from //branches/cupcake/...@125939
Diffstat (limited to 'WebKit/android/jni')
| -rw-r--r-- | WebKit/android/jni/WebCoreFrameBridge.cpp | 7 | ||||
| -rw-r--r-- | WebKit/android/jni/WebViewCore.cpp | 135 | ||||
| -rw-r--r-- | WebKit/android/jni/WebViewCore.h | 17 |
3 files changed, 65 insertions, 94 deletions
diff --git a/WebKit/android/jni/WebCoreFrameBridge.cpp b/WebKit/android/jni/WebCoreFrameBridge.cpp index 9f55134..a173305 100644 --- a/WebKit/android/jni/WebCoreFrameBridge.cpp +++ b/WebKit/android/jni/WebCoreFrameBridge.cpp @@ -70,6 +70,7 @@ #include "WebIconDatabase.h" #include "WebFrameView.h" #include "WebViewCore.h" +#include "wds/DebugServer.h" #include <runtime_root.h> #include <runtime_object.h> @@ -736,6 +737,9 @@ static void CreateFrame(JNIEnv* env, jobject obj, jobject javaview, jobject jAss // Create a Frame and the page holds its reference WebCore::Frame* frame = WebCore::Frame::create(page, NULL, loaderC).get(); loaderC->setFrame(frame); +#if ENABLE(WDS) + WDS::server()->addFrame(frame); +#endif // Create a WebViewCore to access the Java WebViewCore associated with this page WebViewCore* webViewCore = new WebViewCore(env, javaview, frame); @@ -793,6 +797,9 @@ static void DestroyFrame(JNIEnv* env, jobject obj) view->deref(); SET_NATIVE_FRAME(env, obj, 0); +#if ENABLE(WDS) + WDS::server()->removeFrame(pFrame); +#endif } static void LoadUrl(JNIEnv *env, jobject obj, jstring url) diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index 363f2be..42a0043 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -1156,10 +1156,22 @@ bool WebViewCore::finalKitFocus(WebCore::Frame* frame, WebCore::Node* node, } if (!node->isTextNode()) static_cast<WebCore::Element*>(node)->focus(false); - //setFocus on things that WebCore doesn't recognize as supporting focus - //for instance, if there is an onclick element that does not support focus + if (node->document()->focusedNode() != node) { + // This happens when Element::focus() fails as we may try to set the + // focus to a node which WebCore doesn't recognize as a focusable node. + // So we need to do some extra work, as it does in Element::focus(), + // besides calling Document::setFocusedNode. + if (oldFocusNode) { + // copied from clearSelectionIfNeeded in FocusController.cpp + WebCore::SelectionController* s = oldDoc->frame()->selection(); + if (!s->isNone()) + s->clear(); + } + //setFocus on things that WebCore doesn't recognize as supporting focus + //for instance, if there is an onclick element that does not support focus + node->document()->setFocusedNode(node); + } DBG_NAV_LOGD("setFocusedNode node=%p", node); - node->document()->setFocusedNode(node); m_lastFocused = node; m_lastFocusedBounds = node->getRect(); return true; @@ -1527,7 +1539,7 @@ public: WebCore::HTMLOptionElement* option; for (int i = 0; i < count; i++) { option = static_cast<WebCore::HTMLOptionElement*>( - m_select->item(array[m_select->listToOptionIndex(i)])); + m_select->item(m_select->listToOptionIndex(array[i]))); option->setSelected(true); } m_viewImpl->contentInvalidate(m_select->getRect()); @@ -1609,78 +1621,40 @@ void WebViewCore::listBoxRequest(WebCoreReply* reply, const uint16_t** labels, s m_popupReply = reply; } -bool WebViewCore::keyUp(KeyCode keyCode, int keyVal) +bool WebViewCore::key(int keyCode, UChar32 unichar, int repeatCount, bool isShift, bool isAlt, bool isDown) { - DBG_NAV_LOGD("keyCode=%d", keyCode); - bool keyHandled = false; + DBG_NAV_LOGD("key: keyCode=%d", keyCode); + + WebCore::EventHandler* eventHandler = m_mainFrame->eventHandler(); WebCore::Node* focusNode = m_mainFrame->getCacheBuilder().currentFocus(); if (focusNode) { - WebCore::Frame* focusFrame = focusNode->document()->frame(); - switch (keyCode) { - case kKeyCodeNewline: - case kKeyCodeDpadCenter: { - focusFrame->loader()->resetMultipleFormSubmissionProtection(); - WebFrame* webFrame = WebFrame::getWebFrame(m_mainFrame); - webFrame->setUserInitiatedClick(true); - if ((focusNode->hasTagName(WebCore::HTMLNames::inputTag) && - ((WebCore::HTMLInputElement*)focusNode)->isTextField()) || - focusNode->hasTagName(WebCore::HTMLNames::textareaTag)) { - // Create the key down event. - WebCore::PlatformKeyboardEvent keydown(keyCode, keyVal, - WebCore::PlatformKeyboardEvent::KeyDown, 0, - NO_MODIFIER_KEYS); - // Create the key up event. - WebCore::PlatformKeyboardEvent keyup(keyCode, keyVal, - WebCore::PlatformKeyboardEvent::KeyUp, 0, - NO_MODIFIER_KEYS); - // Send both events. - keyHandled = focusFrame->eventHandler()->keyEvent(keydown); - keyHandled |= focusFrame->eventHandler()->keyEvent(keyup); - } else { - keyHandled = handleMouseClick(focusFrame, focusNode); - } - webFrame->setUserInitiatedClick(false); - break; - } - default: - keyHandled = false; - } + eventHandler = focusNode->document()->frame()->eventHandler(); } - m_blockFocusChange = false; - return keyHandled; + + int mods = 0; // PlatformKeyboardEvent::ModifierKey + if (isShift) { + mods |= WebCore::PlatformKeyboardEvent::ShiftKey; + } + if (isAlt) { + mods |= WebCore::PlatformKeyboardEvent::AltKey; + } + WebCore::PlatformKeyboardEvent evt(keyCode, unichar, + isDown ? WebCore::PlatformKeyboardEvent::KeyDown : WebCore::PlatformKeyboardEvent::KeyUp, + repeatCount, static_cast<WebCore::PlatformKeyboardEvent::ModifierKey> (mods)); + return eventHandler->keyEvent(evt); } -bool WebViewCore::sendKeyToFocusNode(int keyCode, UChar32 unichar, - int repeatCount, bool isShift, bool isAlt, KeyAction action) { +bool WebViewCore::click() { + bool keyHandled = false; WebCore::Node* focusNode = m_mainFrame->getCacheBuilder().currentFocus(); if (focusNode) { - WebCore::Frame* focusFrame = focusNode->document()->frame(); - WebCore::PlatformKeyboardEvent::Type type; - switch (action) { - case DownKeyAction: - type = WebCore::PlatformKeyboardEvent::KeyDown; - break; - case UpKeyAction: - type = WebCore::PlatformKeyboardEvent::KeyUp; - break; - default: - SkDebugf("---- unexpected KeyAction %d\n", action); - return false; - } - - int mods = 0; // PlatformKeyboardEvent::ModifierKey - if (isShift) { - mods |= WebCore::PlatformKeyboardEvent::ShiftKey; - } - if (isAlt) { - mods |= WebCore::PlatformKeyboardEvent::AltKey; - } - - WebCore::PlatformKeyboardEvent evt(keyCode, unichar, type, repeatCount, - static_cast<WebCore::PlatformKeyboardEvent::ModifierKey>(mods)); - return focusFrame->eventHandler()->keyEvent(evt); + WebFrame::getWebFrame(m_mainFrame)->setUserInitiatedClick(true); + keyHandled = handleMouseClick(focusNode->document()->frame(), focusNode); + WebFrame::getWebFrame(m_mainFrame)->setUserInitiatedClick(false); } - return false; + // match in setFinalFocus() + m_blockFocusChange = false; + return keyHandled; } bool WebViewCore::handleTouchEvent(int action, int x, int y) @@ -2008,29 +1982,27 @@ static void SetGlobalBounds(JNIEnv *env, jobject obj, jint x, jint y, jint h, viewImpl->setGlobalBounds(x, y, h, v); } -static jboolean KeyUp(JNIEnv *env, jobject obj, jint key, jint val) +static jboolean Key(JNIEnv *env, jobject obj, jint keyCode, jint unichar, + jint repeatCount, jboolean isShift, jboolean isAlt, jboolean isDown) { #ifdef ANDROID_INSTRUMENT TimeCounterWV counter; #endif -// LOGV("webviewcore::nativeKeyUp(%u)\n", (unsigned)key); WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj); - LOG_ASSERT(viewImpl, "viewImpl not set in nativeKeyUp"); - return viewImpl->keyUp((KeyCode)key, val); + LOG_ASSERT(viewImpl, "viewImpl not set in Key"); + + return viewImpl->key(keyCode, unichar, repeatCount, isShift, isAlt, isDown); } -static bool SendKeyToFocusNode(JNIEnv *env, jobject jwebviewcore, - jint keyCode, jint unichar, jint repeatCount, - jboolean isShift, jboolean isAlt, jint action) +static jboolean Click(JNIEnv *env, jobject obj) { #ifdef ANDROID_INSTRUMENT TimeCounterWV counter; #endif + WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj); + LOG_ASSERT(viewImpl, "viewImpl not set in Click"); - WebViewCore* viewImpl = GET_NATIVE_VIEW(env, jwebviewcore); - LOG_ASSERT(viewImpl, "viewImpl not set in SendKeyToFocusNode"); - return viewImpl->sendKeyToFocusNode((KeyCode)keyCode, unichar, repeatCount, - isShift, isAlt, static_cast<WebViewCore::KeyAction>(action)); + return viewImpl->click(); } static void DeleteSelection(JNIEnv *env, jobject obj, @@ -2390,9 +2362,10 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = { (void*) CopyContentToPicture }, { "nativeDrawContent", "(Landroid/graphics/Canvas;I)Z", (void*) DrawContent } , - { "nativeKeyUp", "(II)Z", - (void*) KeyUp }, - { "nativeSendKeyToFocusNode", "(IIIZZI)Z", (void*) SendKeyToFocusNode }, + { "nativeKey", "(IIIZZZ)Z", + (void*) Key }, + { "nativeClick", "()Z", + (void*) Click }, { "nativeSendListBoxChoices", "([ZI)V", (void*) SendListBoxChoices }, { "nativeSendListBoxChoice", "(I)V", diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h index 8a073c2..a6c44f8 100644 --- a/WebKit/android/jni/WebViewCore.h +++ b/WebKit/android/jni/WebViewCore.h @@ -189,24 +189,15 @@ namespace android { void setSizeScreenWidthAndScale(int width, int height, int screenWidth, int scale); /** - * Handle keyDown events from Java. - * @param keyCode The key pressed. + * Handle key events from Java. * @return Whether keyCode was handled by this class. */ - bool keyUp(KeyCode keyCode, int keyValue); + bool key(int keyCode, UChar32 unichar, int repeatCount, bool isShift, bool isAlt, bool isDown); - // These need to be lock-step with the KEY_ACTION values in - // WebViewCore.java - enum KeyAction { - DownKeyAction = 0, - UpKeyAction = 1 - }; /** - * Send the key event to the focus node (if there is one). Return true - * if there is a node, and it claims to have handled the event. + * Handle (mouse) click event from Java */ - bool sendKeyToFocusNode(int code, UChar32 unichar, int repeatCount, - bool isShift, bool isAlt, KeyAction); + bool click(); /** * Handle touch event |
