diff options
author | Derek Sollenberger <djsollen@google.com> | 2009-06-08 10:50:38 -0400 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2009-06-08 13:14:13 -0400 |
commit | a2c69492fd11733119d4f6ce3540acdfee9bf88c (patch) | |
tree | a842f77c700e8cd7dd49e8371950bea381868a07 | |
parent | 26500d99088472bd711b0e07a68856581af6f02a (diff) | |
download | external_webkit-a2c69492fd11733119d4f6ce3540acdfee9bf88c.zip external_webkit-a2c69492fd11733119d4f6ce3540acdfee9bf88c.tar.gz external_webkit-a2c69492fd11733119d4f6ce3540acdfee9bf88c.tar.bz2 |
Added support for plugins receiving lifecycle events such as gain/lose focus.
-rw-r--r-- | WebCore/plugins/android/PluginViewAndroid.cpp | 75 | ||||
-rw-r--r-- | WebKit/android/jni/WebViewCore.cpp | 6 | ||||
-rw-r--r-- | WebKit/android/plugins/android_npapi.h | 56 |
3 files changed, 79 insertions, 58 deletions
diff --git a/WebCore/plugins/android/PluginViewAndroid.cpp b/WebCore/plugins/android/PluginViewAndroid.cpp index 9a2f7f6..0cb33f8 100644 --- a/WebCore/plugins/android/PluginViewAndroid.cpp +++ b/WebCore/plugins/android/PluginViewAndroid.cpp @@ -149,22 +149,22 @@ void PluginView::platformInit() m_isWindowed = false; // we don't support windowed yet m_window = new PluginWidgetAndroid(this); - + m_npWindow.type = NPWindowTypeDrawable; m_npWindow.window = 0; } - + PluginView::~PluginView() { stop(); - + deleteAllValues(m_requests); - + freeStringArray(m_paramNames, m_paramCount); freeStringArray(m_paramValues, m_paramCount); - + m_parentFrame->script()->cleanupScriptObjectsForPlugin(this); - + // Since we have no legacy plugins to check, we ignore the quirks check // if (m_plugin && !m_plugin->quirks().contains(PluginQuirkDontUnloadPlugin)) if (m_plugin) { @@ -186,38 +186,47 @@ void PluginView::init() ASSERT(m_status == PluginStatusCanNotFindPlugin); return; } - + if (!m_plugin->load()) { m_plugin = 0; m_status = PluginStatusCanNotLoadPlugin; return; } - + if (!start()) { m_status = PluginStatusCanNotLoadPlugin; return; } - + m_status = PluginStatusLoadedSuccessfully; } - + void PluginView::handleMouseEvent(MouseEvent* event) { const AtomicString& type = event->type(); bool isDown = (eventNames().mousedownEvent == type); bool isUp = (eventNames().mouseupEvent == type); - if (!isDown && !isUp) { - return; - } - + bool isOver = (eventNames().mouseoverEvent == type); + bool isOut = (eventNames().mouseoutEvent == type); + ANPEvent evt; - SkANP::InitEvent(&evt, kTouch_ANPEventType); - evt.data.touch.action = isDown ? kDown_ANPTouchAction : kUp_ANPTouchAction; - evt.data.touch.modifiers = 0; // todo - // these are relative to plugin - evt.data.touch.x = event->pageX() - m_npWindow.x; - evt.data.touch.y = event->pageY() - m_npWindow.y; + if (isDown || isUp) { + SkANP::InitEvent(&evt, kTouch_ANPEventType); + evt.data.touch.action = isDown ? kDown_ANPTouchAction : kUp_ANPTouchAction; + evt.data.touch.modifiers = 0; // todo + // these are relative to plugin + evt.data.touch.x = event->pageX() - m_npWindow.x; + evt.data.touch.y = event->pageY() - m_npWindow.y; + } + else if (isOver || isOut) { + SkANP::InitEvent(&evt, kLifecycle_ANPEventType); + evt.data.lifecycle.action = isOver ? kGainFocus_ANPLifecycleAction : kLooseFocus_ANPLifecycleAction; + } + else { + return; + } + if (m_plugin->pluginFuncs()->event(m_instance, &evt)) { event->setDefaultHandled(); } @@ -272,7 +281,7 @@ void PluginView::handleKeyboardEvent(KeyboardEvent* event) evt.data.key.repeatCount = pke->repeatCount(); evt.data.key.modifiers = make_modifiers(pke->shiftKey(), pke->altKey()); evt.data.key.unichar = pke->unichar(); - + if (m_plugin->pluginFuncs()->event(m_instance, &evt)) { event->setDefaultHandled(); } @@ -309,7 +318,7 @@ void PluginView::setNPWindowRect(const IntRect& rect) { if (!m_isStarted) return; - + const int width = rect.width(); const int height = rect.height(); @@ -317,24 +326,24 @@ void PluginView::setNPWindowRect(const IntRect& rect) IntPoint p = parent()->convertToContainingWindow(rect.location()); m_npWindow.x = p.x(); m_npWindow.y = p.y(); - + m_npWindow.width = width; m_npWindow.height = height; - + m_npWindow.clipRect.left = 0; m_npWindow.clipRect.top = 0; m_npWindow.clipRect.right = width; m_npWindow.clipRect.bottom = height; if (m_plugin->pluginFuncs()->setwindow) { -#if USE(JSC) +#if USE(JSC) JSC::JSLock::DropAllLocks dropAllLocks(false); -#endif +#endif setCallingPlugin(true); m_plugin->pluginFuncs()->setwindow(m_instance, &m_npWindow); setCallingPlugin(false); } - + m_window->setWindow(m_npWindow.x, m_npWindow.y, width, height, m_isTransparent); } @@ -446,13 +455,13 @@ NPError PluginView::getValue(NPNVariable variable, void* value) *retValue = !networkStateNotifier().onLine(); return NPERR_NO_ERROR; } - + case kSupportedDrawingModel_ANPGetValue: { uint32_t* bits = reinterpret_cast<uint32_t*>(value); *bits = (1 << kBitmap_ANPDrawingModel); return NPERR_NO_ERROR; } - + default: { NPError error = NPERR_GENERIC_ERROR; (void)anp_getInterface(variable, value, &error); @@ -538,12 +547,12 @@ void PluginView::paint(GraphicsContext* context, const IntRect& rect) paintMissingPluginIcon(context, rect); return; } - + IntRect frame = frameRect(); if (!frame.width() || !frame.height()) { return; } - + m_window->inval(rect, false); m_window->draw(android_gc2canvas(context)); } @@ -559,8 +568,8 @@ void PluginView::updatePluginWidget() } // new as of SVN 38068, Nov 5 2008 -void PluginView::setParentVisible(bool) { - notImplemented(); +void PluginView::setParentVisible(bool) { + notImplemented(); } } // namespace WebCore diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index f50dd1a..1abb90a 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -2412,14 +2412,16 @@ static bool PictureReady(JNIEnv* env, jobject obj) static void Pause(JNIEnv* env, jobject obj) { ANPEvent event; - SkANP::InitEvent(&event, kPause_ANPEventType); + SkANP::InitEvent(&event, kLifecycle_ANPEventType); + event.data.lifecycle.action = kPause_ANPLifecycleAction; GET_NATIVE_VIEW(env, obj)->sendPluginEvent(event); } static void Resume(JNIEnv* env, jobject obj) { ANPEvent event; - SkANP::InitEvent(&event, kResume_ANPEventType); + SkANP::InitEvent(&event, kLifecycle_ANPEventType); + event.data.lifecycle.action = kResume_ANPLifecycleAction; GET_NATIVE_VIEW(env, obj)->sendPluginEvent(event); } diff --git a/WebKit/android/plugins/android_npapi.h b/WebKit/android/plugins/android_npapi.h index a3ffdfb..ba48321 100644 --- a/WebKit/android/plugins/android_npapi.h +++ b/WebKit/android/plugins/android_npapi.h @@ -24,10 +24,10 @@ */ /* Defines the android-specific types and functions as part of npapi - + In particular, defines the window and event types that are passed to NPN_GetValue, NPP_SetWindow and NPP_HandleEvent. - + To minimize what native libraries the plugin links against, some functionality is provided via function-ptrs (e.g. time, sound) */ @@ -91,9 +91,9 @@ typedef uint32_t ANPMatrixFlag; // NPN_GetValue /* queries for a specific ANPInterface. - + Maybe called with NULL for the NPP instance - + NPN_GetValue(inst, interface_enum, ANPInterface*) */ #define kLogInterfaceV0_ANPGetValue ((NPNVariable)1000) @@ -106,9 +106,9 @@ typedef uint32_t ANPMatrixFlag; #define kWindowInterfaceV0_ANPGetValue ((NPNVariable)1007) /* queries for which drawing model is desired (for the draw event) - + Should be called inside NPP_New(...) - + NPN_GetValue(inst, ANPSupportedDrawingModel_EnumValue, uint32_t* bits) */ #define kSupportedDrawingModel_ANPGetValue ((NPNVariable)2000) @@ -117,7 +117,7 @@ typedef uint32_t ANPMatrixFlag; // NPN_GetValue /** Reqeust to set the drawing model. - + NPN_SetValue(inst, ANPRequestDrawingModel_EnumValue, (void*)foo_DrawingModel) */ #define kRequestDrawingModel_ANPSetValue ((NPPVariable)1000) @@ -138,7 +138,7 @@ typedef int32_t ANPDrawingModel; /* Interfaces provide additional functionality to the plugin via function ptrs. Once an interface is retrived, it is valid for the lifetime of the plugin (just like browserfuncs). - + All ANPInterfaces begin with an inSize field, which must be set by the caller (plugin) with the number of bytes allocated for the interface. e.g. SomeInterface si; si.inSize = sizeof(si); browser->getvalue(..., &si); @@ -351,7 +351,7 @@ struct ANPTypefaceInterfaceV0 : ANPInterface { */ ANPTypeface* (*createFromTypeface)(const ANPTypeface* family, ANPTypefaceStyle); - + /** Return the owner count of the typeface. A newly created typeface has an owner count of 1. When the owner count is reaches 0, the typeface is deleted. @@ -366,7 +366,7 @@ struct ANPTypefaceInterfaceV0 : ANPInterface { the typeface is deleted. */ void (*unref)(ANPTypeface*); - + /** Return the style bits for the specified typeface */ ANPTypefaceStyle (*getStyle)(const ANPTypeface*); @@ -376,19 +376,19 @@ struct ANPPaintInterfaceV0 : ANPInterface { /* Return a new paint object, which holds all of the color and style attributes that affect how things (geometry, text, bitmaps) are drawn in a ANPCanvas. - + The paint that is returned is not tied to any particular plugin instance, but it must only be accessed from one thread at a time. */ ANPPaint* (*newPaint)(); void (*deletePaint)(ANPPaint*); - + ANPPaintFlags (*getFlags)(const ANPPaint*); void (*setFlags)(ANPPaint*, ANPPaintFlags); - + ANPColor (*getColor)(const ANPPaint*); void (*setColor)(ANPPaint*, ANPColor); - + ANPPaintStyle (*getStyle)(const ANPPaint*); void (*setStyle)(ANPPaint*, ANPPaintStyle); @@ -400,7 +400,7 @@ struct ANPPaintInterfaceV0 : ANPInterface { void (*setStrokeMiter)(ANPPaint*, float); void (*setStrokeCap)(ANPPaint*, ANPPaintCap); void (*setStrokeJoin)(ANPPaint*, ANPPaintJoin); - + ANPTextEncoding (*getTextEncoding)(const ANPPaint*); ANPPaintAlign (*getTextAlign)(const ANPPaint*); float (*getTextSize)(const ANPPaint*); @@ -428,7 +428,7 @@ struct ANPPaintInterfaceV0 : ANPInterface { */ float (*measureText)(ANPPaint*, const void* text, uint32_t byteLength, ANPRectF* bounds); - + /** Return the number of unichars specifed by the text. If widths is not null, returns the array of advance widths for each unichar. @@ -436,7 +436,7 @@ struct ANPPaintInterfaceV0 : ANPInterface { */ int (*getTextWidths)(ANPPaint*, const void* text, uint32_t byteLength, float widths[], ANPRectF bounds[]); - + /** Return in metrics the spacing values for text, respecting the paint's typeface and pointsize, and return the spacing between lines (descent - ascent + leading). If metrics is NULL, it will be ignored. @@ -452,7 +452,7 @@ struct ANPCanvasInterfaceV0 : ANPInterface { goes out of scope. In the case of creating a canvas to draw into the pixels provided by kDraw_ANPEventType, those pixels are only while handling that event. - + The canvas that is returned is not tied to any particular plugin instance, but it must only be accessed from one thread at a time. */ @@ -505,7 +505,7 @@ struct ANPWindowInterfaceV0 : ANPInterface { describing the subset of the window that will be drawn to (may be null) return true if the bitmap for that window can be accessed, and if so, fill out the specified ANPBitmap to point to the window's pixels. - + When drawing is complete, call unlock(window) */ bool (*lockRect)(void* window, const ANPRectI* inval, ANPBitmap*); @@ -567,11 +567,11 @@ typedef int32_t ANPAudioEvent; /** Called to feed sample data to the track. This will be called in a separate thread. However, you may call trackStop() from the callback (but you cannot delete the track). - + For example, when you have written the last chunk of sample data, you can immediately call trackStop(). This will take effect after the current buffer has been played. - + The "user" parameter is the same value that was passed to newTrack() */ typedef void (*ANPAudioCallbackProc)(ANPAudioEvent event, void* user, @@ -606,8 +606,7 @@ enum ANPEventTypes { kKey_ANPEventType = 1, kTouch_ANPEventType = 2, kDraw_ANPEventType = 3, - kPause_ANPEventType = 4, // no extra data in the event - kResume_ANPEventType = 5 // no extra data in the event + kLifecycle_ANPEventType = 4 }; typedef int32_t ANPEventType; @@ -643,6 +642,14 @@ struct ANPDrawContext { } data; }; +enum ANPLifecycleActions { + kPause_ANPLifecycleAction = 0, + kResume_ANPLifecycleAction = 1, + kGainFocus_ANPLifecycleAction = 2, + kLooseFocus_ANPLifecycleAction = 3, +}; +typedef uint32_t ANPLifecycleAction; + /* This is what is passed to NPP_HandleEvent() */ struct ANPEvent { uint32_t inSize; // size of this struct in bytes @@ -663,6 +670,9 @@ struct ANPEvent { int32_t x; // relative to your "window" (0...width) int32_t y; // relative to your "window" (0...height) } touch; + struct { + ANPLifecycleAction action; + } lifecycle; ANPDrawContext drawContext; int32_t other[8]; } data; |