diff options
| author | Derek Sollenberger <djsollen@google.com> | 2009-07-02 10:02:25 -0400 |
|---|---|---|
| committer | Derek Sollenberger <djsollen@google.com> | 2009-07-02 13:40:02 -0400 |
| commit | 3a9f8eaff978cf1a11c725266c852f8d43755539 (patch) | |
| tree | 20a1686b040124f3ef6b16e24b62855375226fc2 /WebKit | |
| parent | fb02adff73f691c0eeaaa6fddb2b2349f30233a6 (diff) | |
| download | external_webkit-3a9f8eaff978cf1a11c725266c852f8d43755539.zip external_webkit-3a9f8eaff978cf1a11c725266c852f8d43755539.tar.gz external_webkit-3a9f8eaff978cf1a11c725266c852f8d43755539.tar.bz2 | |
added gain/loose focus support for plugins. (focus = eligible to receive user events)
Diffstat (limited to 'WebKit')
| -rw-r--r-- | WebKit/android/jni/WebViewCore.cpp | 46 | ||||
| -rw-r--r-- | WebKit/android/jni/WebViewCore.h | 8 | ||||
| -rw-r--r-- | WebKit/android/nav/WebView.cpp | 35 |
3 files changed, 80 insertions, 9 deletions
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index 142f0de..57d324c 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -69,6 +69,7 @@ #include "PlatformKeyboardEvent.h" #include "PlatformString.h" #include "PluginWidgetAndroid.h" +#include "PluginView.h" #include "Position.h" #include "ProgressTracker.h" #include "RenderBox.h" @@ -1185,13 +1186,14 @@ void WebViewCore::sendPluginEvent(const ANPEvent& evt) } } -static bool nodeIsPlugin(Node* node) { +static PluginView* nodeIsPlugin(Node* node) { RenderObject* renderer = node->renderer(); if (renderer && renderer->isWidget()) { Widget* widget = static_cast<RenderWidget*>(renderer)->widget(); - return widget && widget->isPluginView(); + if (widget && widget->isPluginView()) + return static_cast<PluginView*>(widget); } - return false; + return 0; } Node* WebViewCore::cursorNodeIsPlugin() { @@ -1208,6 +1210,32 @@ Node* WebViewCore::cursorNodeIsPlugin() { } +void WebViewCore::updatePluginState(Frame* frame, Node* node, PluginState state) { + + // check that the node and frame pointers are (still) valid + if (!frame || !node || !CacheBuilder::validNode(m_mainFrame, frame, node)) + return; + + // check that the node is a plugin view + PluginView* pluginView = nodeIsPlugin(node); + if (!pluginView) + return; + + // create the event + ANPEvent event; + SkANP::InitEvent(&event, kLifecycle_ANPEventType); + + if (state == kLoseFocus_PluginState) + event.data.lifecycle.action = kLooseFocus_ANPLifecycleAction; + else if (state == kGainFocus_PluginState) + event.data.lifecycle.action = kGainFocus_ANPLifecycleAction; + else + return; + + // send the event + pluginView->platformPluginWidget()->sendEvent(event); +} + /////////////////////////////////////////////////////////////////////////////// void WebViewCore::moveMouseIfLatest(int moveGeneration, WebCore::Frame* frame, int x, int y) @@ -2454,6 +2482,17 @@ static bool PictureReady(JNIEnv* env, jobject obj) return GET_NATIVE_VIEW(env, obj)->pictureReady(); } +static void UpdatePluginState(JNIEnv* env, jobject obj, jint framePtr, jint nodePtr, jint state) +{ +#ifdef ANDROID_INSTRUMENT + TimeCounterAuto counter(TimeCounter::WebViewCoreTimeCounter); +#endif + WebViewCore* viewImpl = GET_NATIVE_VIEW(env, obj); + LOG_ASSERT(viewImpl, "viewImpl not set in nativeUpdatePluginState"); + viewImpl->updatePluginState((WebCore::Frame*) framePtr, (WebCore::Node*) nodePtr, + (PluginState) state); +} + static void Pause(JNIEnv* env, jobject obj) { ANPEvent event; @@ -2562,6 +2601,7 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = { { "nativeResume", "()V", (void*) Resume }, { "nativeFreeMemory", "()V", (void*) FreeMemory }, { "nativeSetJsFlags", "(Ljava/lang/String;)V", (void*) SetJsFlags }, + { "nativeUpdatePluginState", "(III)V", (void*) UpdatePluginState }, }; int register_webviewcore(JNIEnv* env) diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h index f076bf1..fe1caa2 100644 --- a/WebKit/android/jni/WebViewCore.h +++ b/WebKit/android/jni/WebViewCore.h @@ -60,6 +60,11 @@ class SkIRect; namespace android { + enum PluginState { + kGainFocus_PluginState = 0, + kLoseFocus_PluginState = 1, + }; + class CachedRoot; class ListBoxReply; @@ -298,6 +303,9 @@ namespace android { // return the cursorNode if it is a plugin Node* cursorNodeIsPlugin(); + // notify the plugin of an update in state + void updatePluginState(Frame* frame, Node* node, PluginState state); + // Notify the Java side whether it needs to pass down the touch events void needTouchEvents(bool); diff --git a/WebKit/android/nav/WebView.cpp b/WebKit/android/nav/WebView.cpp index 74acdf7..56570a6 100644 --- a/WebKit/android/nav/WebView.cpp +++ b/WebKit/android/nav/WebView.cpp @@ -98,6 +98,7 @@ struct JavaGlue { jobject m_obj; jmethodID m_clearTextEntry; jmethodID m_overrideLoading; + jmethodID m_sendPluginState; jmethodID m_scrollBy; jmethodID m_sendMoveMouse; jmethodID m_sendMoveMouseIfLatest; @@ -127,6 +128,7 @@ WebView(JNIEnv* env, jobject javaWebView, int viewImpl) m_javaGlue.m_scrollBy = GetJMethod(env, clazz, "setContentScrollBy", "(IIZ)V"); m_javaGlue.m_clearTextEntry = GetJMethod(env, clazz, "clearTextEntry", "()V"); m_javaGlue.m_overrideLoading = GetJMethod(env, clazz, "overrideLoading", "(Ljava/lang/String;)V"); + m_javaGlue.m_sendPluginState = GetJMethod(env, clazz, "sendPluginState", "(I)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", "(IIIIII)V"); @@ -161,7 +163,10 @@ WebView(JNIEnv* env, jobject javaWebView, int viewImpl) m_matches = 0; m_hasCurrentLocation = false; m_isFindPaintSetUp = false; - m_pluginReceivesEvents = false; + m_pluginReceivesEvents = false; // initialization is the only time this + // variable should be set directly, all + // other changes should be made through + // setPluginReceivesEvents(bool) } ~WebView() @@ -407,7 +412,8 @@ void drawMatches(SkCanvas* canvas) void resetCursorRing() { - m_followedLink = m_pluginReceivesEvents = false; + m_followedLink = false; + setPluginReceivesEvents(false); m_viewImpl->m_hasCursorBounds = false; } @@ -471,7 +477,8 @@ void drawCursorRing(SkCanvas* canvas) DBG_NAV_LOGD("canvas->quickReject cursorNode=%d (nodePointer=%p)" " bounds=(%d,%d,w=%d,h=%d)", node->index(), node->nodePointer(), bounds.x(), bounds.y(), bounds.width(), bounds.height()); - m_followedLink = m_pluginReceivesEvents = false; + m_followedLink = false; + setPluginReceivesEvents(false); return; } CursorRing::Flavor flavor = CursorRing::NORMAL_FLAVOR; @@ -728,7 +735,7 @@ void updateCursorBounds(const CachedRoot* root, const CachedFrame* cachedFrame, /* returns true if the key had no effect (neither scrolled nor changed cursor) */ bool moveCursor(int keyCode, int count, bool ignoreScroll) { - m_pluginReceivesEvents = false; + setPluginReceivesEvents(false); CachedRoot* root = getFrameCache(AllowNewer); if (!root) { DBG_NAV_LOG("!root"); @@ -902,7 +909,7 @@ void setNavBounds(const WebCore::IntRect& rect) bool motionUp(int x, int y, int slop) { bool pageScrolled = false; - m_followedLink = m_pluginReceivesEvents = false; + m_followedLink = false; const CachedFrame* frame; WebCore::IntRect rect = WebCore::IntRect(x - slop, y - slop, slop * 2, slop * 2); int rx, ry; @@ -924,6 +931,7 @@ bool motionUp(int x, int y, int slop) 0, x, y, slop); viewInvalidate(); clearTextEntry(); + setPluginReceivesEvents(false); return pageScrolled; } DBG_NAV_LOGD("CachedNode:%p (%d) x=%d y=%d rx=%d ry=%d", result, @@ -968,13 +976,28 @@ void setFindIsUp(bool up) m_hasCurrentLocation = false; } +void setPluginReceivesEvents(bool value) +{ + if (value == m_pluginReceivesEvents) + return; + + //send message to plugin in webkit + JNIEnv* env = JSC::Bindings::getJNIEnv(); + env->CallVoidMethod(m_javaGlue.object(env).get(), + m_javaGlue.m_sendPluginState, + value ? kGainFocus_PluginState : kLoseFocus_PluginState); + checkException(env); + + m_pluginReceivesEvents = value; +} + void updatePluginReceivesEvents() { CachedRoot* root = getFrameCache(DontAllowNewer); if (!root) return; const CachedNode* cursor = root->currentCursor(); - m_pluginReceivesEvents = cursor && cursor->isPlugin(); + setPluginReceivesEvents(cursor && cursor->isPlugin()); DBG_NAV_LOGD("m_pluginReceivesEvents=%s cursor=%p", m_pluginReceivesEvents ? "true" : "false", cursor); } |
