From 1f7eee5350a1e078daa31e06b09a911f3fc6cb37 Mon Sep 17 00:00:00 2001 From: Derek Sollenberger Date: Wed, 5 Jan 2011 09:40:04 -0500 Subject: [PATCH] Plugin API to report the onscreen visibility of the plugin. bug: 3324143 Change-Id: I4ad5837b4d79ee63bf53ce974a634d357130930e --- WebCore/plugins/android/PluginViewAndroid.cpp | 2 ++ WebKit/android/plugins/ANPWindowInterface.cpp | 14 ++++++++++++++ WebKit/android/plugins/PluginWidgetAndroid.cpp | 18 ++++++++++++++++++ WebKit/android/plugins/PluginWidgetAndroid.h | 6 ++++++ WebKit/android/plugins/android_npapi.h | 9 +++++++++ 5 files changed, 49 insertions(+) diff --git a/WebCore/plugins/android/PluginViewAndroid.cpp b/WebCore/plugins/android/PluginViewAndroid.cpp index 68fa3d7b8..912068e21 100644 --- a/WebCore/plugins/android/PluginViewAndroid.cpp +++ b/WebCore/plugins/android/PluginViewAndroid.cpp @@ -104,6 +104,7 @@ extern void ANPPathInterfaceV0_Init(ANPInterface* value); extern void ANPSurfaceInterfaceV0_Init(ANPInterface* value); extern void ANPTypefaceInterfaceV0_Init(ANPInterface* value); extern void ANPWindowInterfaceV0_Init(ANPInterface* value); +extern void ANPWindowInterfaceV1_Init(ANPInterface* value); extern void ANPSystemInterfaceV0_Init(ANPInterface* value); extern void ANPOpenGLInterfaceV0_Init(ANPInterface* value); @@ -129,6 +130,7 @@ static const VarProcPair gVarProcs[] = { { VARPROCLINE(SurfaceInterfaceV0) }, { VARPROCLINE(TypefaceInterfaceV0) }, { VARPROCLINE(WindowInterfaceV0) }, + { VARPROCLINE(WindowInterfaceV1) }, { VARPROCLINE(SystemInterfaceV0) }, { VARPROCLINE(OpenGLInterfaceV0) }, }; diff --git a/WebKit/android/plugins/ANPWindowInterface.cpp b/WebKit/android/plugins/ANPWindowInterface.cpp index f086b449a..a74616c24 100644 --- a/WebKit/android/plugins/ANPWindowInterface.cpp +++ b/WebKit/android/plugins/ANPWindowInterface.cpp @@ -73,6 +73,12 @@ static void anp_requestCenterFitZoom(NPP instance) { pluginWidget->requestCenterFitZoom(); } +static ANPRectI anp_visibleRect(NPP instance) { + PluginView* pluginView = pluginViewForInstance(instance); + PluginWidgetAndroid* pluginWidget = pluginView->platformPluginWidget(); + return pluginWidget->visibleRect(); +} + /////////////////////////////////////////////////////////////////////////////// #define ASSIGN(obj, name) (obj)->name = anp_##name @@ -87,3 +93,11 @@ void ANPWindowInterfaceV0_Init(ANPInterface* value) { ASSIGN(i, exitFullScreen); ASSIGN(i, requestCenterFitZoom); } + +void ANPWindowInterfaceV1_Init(ANPInterface* value) { + // initialize the functions from the previous interface + ANPWindowInterfaceV0_Init(value); + // add any new functions or override existing functions + ANPWindowInterfaceV1* i = reinterpret_cast(value); + ASSIGN(i, visibleRect); +} diff --git a/WebKit/android/plugins/PluginWidgetAndroid.cpp b/WebKit/android/plugins/PluginWidgetAndroid.cpp index 925f823a8..de3d94438 100644 --- a/WebKit/android/plugins/PluginWidgetAndroid.cpp +++ b/WebKit/android/plugins/PluginWidgetAndroid.cpp @@ -415,6 +415,24 @@ void PluginWidgetAndroid::setVisibleScreen(const ANPRectI& visibleDocRect, float } } +ANPRectI PluginWidgetAndroid::visibleRect() { + + SkIRect visibleRect; + visibleRect.setEmpty(); + + // compute the interesection of the visible screen and the plugin + bool visible = visibleRect.intersect(m_visibleDocRect, m_pluginBounds); + if (visible) { + // convert from absolute coordinates to the plugin's relative coordinates + visibleRect.offset(-m_pluginBounds.fLeft, -m_pluginBounds.fTop); + } + + // convert from SkRect to ANPRect + ANPRectI result; + memcpy(&result, &visibleRect, sizeof(ANPRectI)); + return result; +} + void PluginWidgetAndroid::setVisibleRects(const ANPRectI rects[], int32_t count) { #if DEBUG_VISIBLE_RECTS PLUGIN_LOG("%s count=%d", __FUNCTION__, count); diff --git a/WebKit/android/plugins/PluginWidgetAndroid.h b/WebKit/android/plugins/PluginWidgetAndroid.h index 974fbf097..36b7acdac 100644 --- a/WebKit/android/plugins/PluginWidgetAndroid.h +++ b/WebKit/android/plugins/PluginWidgetAndroid.h @@ -117,6 +117,12 @@ struct PluginWidgetAndroid { */ void setVisibleScreen(const ANPRectI& visibleScreenRect, float zoom); + /** Returns a rectangle representing the visible area of the plugin on + screen. The coordinates are relative to the size of the plugin in the + document and will not be negative or exceed the plugin's size. + */ + ANPRectI visibleRect(); + /** Registers a set of rectangles that the plugin would like to keep on screen. The rectangles are listed in order of priority with the highest priority rectangle in location rects[0]. The browser will attempt to keep diff --git a/WebKit/android/plugins/android_npapi.h b/WebKit/android/plugins/android_npapi.h index a99666e5f..2431985c9 100644 --- a/WebKit/android/plugins/android_npapi.h +++ b/WebKit/android/plugins/android_npapi.h @@ -122,6 +122,7 @@ typedef uint32_t ANPMatrixFlag; #define kAudioTrackInterfaceV1_ANPGetValue ((NPNVariable)1012) #define kOpenGLInterfaceV0_ANPGetValue ((NPNVariable)1013) +#define kWindowInterfaceV1_ANPGetValue ((NPNVariable)1014) /** queries for the drawing models supported on this device. @@ -682,6 +683,14 @@ struct ANPWindowInterfaceV0 : ANPInterface { void (*requestCenterFitZoom)(NPP instance); }; +struct ANPWindowInterfaceV1 : ANPWindowInterfaceV0 { + /** Returns a rectangle representing the visible area of the plugin on + screen. The coordinates are relative to the size of the plugin in the + document and therefore will never be negative or exceed the plugin's size. + */ + ANPRectI (*visibleRect)(NPP instance); +}; + /////////////////////////////////////////////////////////////////////////////// enum ANPSampleFormats { -- 2.11.0