OSDN Git Service

Plugin API to report the onscreen visibility of the plugin.
authorDerek Sollenberger <djsollen@google.com>
Wed, 5 Jan 2011 14:40:04 +0000 (09:40 -0500)
committerDerek Sollenberger <djsollen@google.com>
Wed, 5 Jan 2011 15:46:27 +0000 (10:46 -0500)
bug: 3324143
Change-Id: I4ad5837b4d79ee63bf53ce974a634d357130930e

WebCore/plugins/android/PluginViewAndroid.cpp
WebKit/android/plugins/ANPWindowInterface.cpp
WebKit/android/plugins/PluginWidgetAndroid.cpp
WebKit/android/plugins/PluginWidgetAndroid.h
WebKit/android/plugins/android_npapi.h

index 68fa3d7..912068e 100644 (file)
@@ -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)        },
 };
index f086b44..a74616c 100644 (file)
@@ -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<ANPWindowInterfaceV1*>(value);
+    ASSIGN(i, visibleRect);
+}
index 925f823..de3d944 100644 (file)
@@ -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);
index 974fbf0..36b7acd 100644 (file)
@@ -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
index a99666e..2431985 100644 (file)
@@ -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 {