Adding support for recording the visible rect and auto-scrolling.
diff --git a/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp b/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp
index 7f15d0d..45b5cbb 100644
--- a/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp
+++ b/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp
@@ -37,6 +37,7 @@
extern ANPPaintInterfaceV0 gPaintI;
extern ANPPathInterfaceV0 gPathI;
extern ANPTypefaceInterfaceV0 gTypefaceI;
+extern ANPWindowInterfaceV0 gWindowI;
static void inval(NPP instance) {
browser->invalidaterect(instance, NULL);
@@ -101,7 +102,7 @@
gTypefaceI.unref(tf);
//register for key and touch events
- ANPEventFlags flags = kKey_ANPEventFlag | kTouch_ANPEventFlag;
+ ANPEventFlags flags = kKey_ANPEventFlag | kTouch_ANPEventFlag | kVisibleRect_ANPEventFlag;
NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags);
if (err != NPERR_NO_ERROR) {
gLogI.log(inst, kError_ANPLogType, "Error selecting input events.");
@@ -186,6 +187,39 @@
}
}
+void BallAnimation::centerPluginOnScreen() {
+ NPP instance = this->inst();
+ PluginObject *obj = (PluginObject*) instance->pdata;
+ NPWindow *window = obj->window;
+
+ //find global (x,y) coordinates for center of the plugin
+ int pluginCenterX = window->x + (window->width / 2);
+ int pluginCenterY = window->y + (window->height / 2);
+
+ gLogI.log(instance, kDebug_ANPLogType, "---- %p Plugin Center: %d,%d : %d,%d",
+ instance, pluginCenterX, pluginCenterY, window->x, window->y);
+
+ //find global (x,y) coordinates for center of the visible screen
+ int screenCenterX = m_scrollX + (m_screenW / 2);
+ int screenCenterY = m_scrollY + (m_screenH / 2);
+
+ gLogI.log(instance, kDebug_ANPLogType, "---- %p Screen Center: %d,%d : %d,%d",
+ instance, screenCenterX, screenCenterY, m_scrollX, m_scrollY);
+
+ //compute the delta of the two coordinates
+ int deltaX = pluginCenterX - screenCenterX;
+ int deltaY = pluginCenterY - screenCenterY;
+
+ gLogI.log(instance, kDebug_ANPLogType, "---- %p Centering: %d,%d : %d,%d",
+ instance, deltaX, deltaY, m_scrollX + deltaX, m_scrollY + deltaY);
+
+ //move the visible screen
+ //webviewCore...
+ // (m_scrollX + deltaX, m_scrollY + deltaY)
+ gWindowI.scrollTo(instance, m_scrollX + deltaX, m_scrollY + deltaY);
+
+}
+
int16 BallAnimation::handleEvent(const ANPEvent* evt) {
NPP instance = this->inst();
@@ -206,7 +240,18 @@
browser->invalidaterect(instance, NULL);
}
return 1;
+ case kTouch_ANPEventType:
+ if (kDown_ANPTouchAction == evt->data.touch.action) {
+ centerPluginOnScreen();
+ }
+ return 1;
+ case kVisibleRect_ANPEventType:
+ m_scrollX = evt->data.visibleRect.x;
+ m_scrollY = evt->data.visibleRect.y;
+ m_screenW = evt->data.visibleRect.width;
+ m_screenH = evt->data.visibleRect.height;
+ return 1;
default:
break;
}
diff --git a/samples/BrowserPlugin/jni/animation/AnimationPlugin.h b/samples/BrowserPlugin/jni/animation/AnimationPlugin.h
index 1771d79..fa60a8a 100644
--- a/samples/BrowserPlugin/jni/animation/AnimationPlugin.h
+++ b/samples/BrowserPlugin/jni/animation/AnimationPlugin.h
@@ -47,6 +47,12 @@
ANPPaint* m_paint;
static const float SCALE = 0.1;
+
+ void centerPluginOnScreen();
+ int m_scrollX;
+ int m_scrollY;
+ int m_screenH;
+ int m_screenW;
};
uint32_t getMSecs();
diff --git a/samples/BrowserPlugin/jni/main.cpp b/samples/BrowserPlugin/jni/main.cpp
index e2fb6d6..0b77741 100644
--- a/samples/BrowserPlugin/jni/main.cpp
+++ b/samples/BrowserPlugin/jni/main.cpp
@@ -67,8 +67,10 @@
ANPPaintInterfaceV0 gPaintI;
ANPPathInterfaceV0 gPathI;
ANPTypefaceInterfaceV0 gTypefaceI;
+ANPWindowInterfaceV0 gWindowI;
#define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0]))
+#define DEBUG_PLUGIN_EVENTS 0
NPError NP_Initialize(NPNetscapeFuncs* browserFuncs, NPPluginFuncs* pluginFuncs, void *java_env, void *application_context)
{
@@ -110,6 +112,7 @@
{ kPathInterfaceV0_ANPGetValue, sizeof(gPathI), &gPathI },
{ kTypefaceInterfaceV0_ANPGetValue, sizeof(gPaintI), &gTypefaceI },
{ kAudioTrackInterfaceV0_ANPGetValue, sizeof(gSoundI), &gSoundI },
+ { kWindowInterfaceV0_ANPGetValue, sizeof(gWindowI), &gWindowI },
};
for (size_t i = 0; i < ARRAY_COUNT(gPairs); i++) {
gPairs[i].i->inSize = gPairs[i].size;
@@ -299,6 +302,7 @@
PluginObject *obj = reinterpret_cast<PluginObject*>(instance->pdata);
const ANPEvent* evt = reinterpret_cast<const ANPEvent*>(event);
+#if DEBUG_PLUGIN_EVENTS
switch (evt->eventType) {
case kDraw_ANPEventType:
@@ -352,11 +356,20 @@
}
}
}
- return 1;
+ break;
+
+ case kVisibleRect_ANPEventType:
+ gLogI.log(instance, kDebug_ANPLogType, "---- %p VisibleRect [%d %d %d %d]",
+ instance, evt->data.visibleRect.x, evt->data.visibleRect.y,
+ evt->data.visibleRect.width, evt->data.visibleRect.height);
+ break;
default:
+ gLogI.log(instance, kError_ANPLogType, "---- %p Unknown Event [%d]",
+ instance, evt->eventType);
break;
}
+#endif
if(!obj->activePlugin) {
gLogI.log(instance, kError_ANPLogType, "the active plugin is null.");