adding support for tracking the visible rectangles.
diff --git a/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp b/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp
index 9b26451..e18e29a 100644
--- a/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp
+++ b/samples/BrowserPlugin/jni/animation/AnimationPlugin.cpp
@@ -75,8 +75,6 @@
m_x = m_y = 0;
m_dx = 7 * SCALE;
m_dy = 5 * SCALE;
- m_scrollX = m_scrollY = m_screenW = m_screenH = 0;
- m_zoom = 1;
memset(&m_oval, 0, sizeof(m_oval));
@@ -90,7 +88,7 @@
gTypefaceI.unref(tf);
//register for key and touch events
- ANPEventFlags flags = kKey_ANPEventFlag | kTouch_ANPEventFlag | kVisibleRect_ANPEventFlag;
+ ANPEventFlags flags = kKey_ANPEventFlag | kTouch_ANPEventFlag;
NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags);
if (err != NPERR_NO_ERROR) {
gLogI.log(inst, kError_ANPLogType, "Error selecting input events.");
@@ -193,37 +191,20 @@
}
}
-void BallAnimation::centerPluginOnScreen() {
+void BallAnimation::showEntirePluginOnScreen() {
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);
+ ANPRectI visibleRects[1];
- gLogI.log(instance, kDebug_ANPLogType, "---- %p Plugin Center: %d,%d : %d,%d",
- instance, pluginCenterX, pluginCenterY, window->x, window->y);
+ visibleRects[0].left = 0;
+ visibleRects[0].top = 0;
+ visibleRects[0].right = window->width;
+ visibleRects[0].bottom = window->height;
- //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);
-
+ gWindowI.setVisibleRects(instance, visibleRects, 1);
+ gWindowI.clearVisibleRects(instance);
}
int16 BallAnimation::handleEvent(const ANPEvent* evt) {
@@ -248,18 +229,9 @@
return 1;
case kTouch_ANPEventType:
if (kDown_ANPTouchAction == evt->data.touch.action) {
- centerPluginOnScreen();
+ showEntirePluginOnScreen();
}
return 1;
-
- case kVisibleRect_ANPEventType:
- m_scrollX = evt->data.visibleRect.rect.left;
- m_scrollY = evt->data.visibleRect.rect.top;
- m_screenW = evt->data.visibleRect.rect.right - m_scrollX;
- m_screenH = evt->data.visibleRect.rect.bottom - m_scrollY;
- m_zoom = evt->data.visibleRect.zoomScale;
- gLogI.log(instance, kDebug_ANPLogType, "zoom event %g", m_zoom);
- return 1;
default:
break;
}
diff --git a/samples/BrowserPlugin/jni/animation/AnimationPlugin.h b/samples/BrowserPlugin/jni/animation/AnimationPlugin.h
index 464f906..de453c0 100644
--- a/samples/BrowserPlugin/jni/animation/AnimationPlugin.h
+++ b/samples/BrowserPlugin/jni/animation/AnimationPlugin.h
@@ -37,7 +37,7 @@
private:
void draw(ANPCanvas*);
void drawPlugin(const ANPBitmap& bitmap, const ANPRectI& clip);
- void centerPluginOnScreen();
+ void showEntirePluginOnScreen();
float m_x;
float m_y;
@@ -50,12 +50,6 @@
ANPPaint* m_paint;
static const float SCALE = 0.1;
-
- int m_scrollX;
- int m_scrollY;
- int m_screenH;
- int m_screenW;
- float m_zoom;
};
uint32_t getMSecs();
diff --git a/samples/BrowserPlugin/jni/form/FormPlugin.cpp b/samples/BrowserPlugin/jni/form/FormPlugin.cpp
index fbb4c6b..589550a 100644
--- a/samples/BrowserPlugin/jni/form/FormPlugin.cpp
+++ b/samples/BrowserPlugin/jni/form/FormPlugin.cpp
@@ -97,7 +97,7 @@
gTypefaceI.unref(tf);
//register for key and visibleRect events
- ANPEventFlags flags = kKey_ANPEventFlag | kVisibleRect_ANPEventFlag;
+ ANPEventFlags flags = kKey_ANPEventFlag;
NPError err = browser->setvalue(inst, kAcceptEvents_ANPSetValue, &flags);
if (err != NPERR_NO_ERROR) {
gLogI.log(inst, kError_ANPLogType, "Error selecting input events.");
@@ -275,22 +275,6 @@
}
return 1;
- case kVisibleRect_ANPEventType: {
-
- int oldScreenW = m_visibleRect.right - m_visibleRect.left;
- int oldScreenH = m_visibleRect.bottom - m_visibleRect.top;
-
- m_visibleRect = evt->data.visibleRect.rect;
-
- int newScreenW = m_visibleRect.right - m_visibleRect.left;
- int newScreenH = m_visibleRect.bottom - m_visibleRect.top;
-
- if (m_activeInput && (oldScreenW != newScreenW || oldScreenH != newScreenH))
- scrollIntoView(m_activeInput);
-
- return 1;
- }
-
default:
break;
}
@@ -300,13 +284,17 @@
void FormPlugin::switchActiveInput(TextInput* newInput) {
NPP instance = this->inst();
- if (m_activeInput)
+ if (m_activeInput) {
inval(instance, m_activeInput->rect, true); // inval the old
+ gWindowI.clearVisibleRects(instance);
+ }
m_activeInput = newInput; // set the new active input
- if (m_activeInput)
+ if (m_activeInput) {
inval(instance, m_activeInput->rect, true); // inval the new
+ scrollIntoView(m_activeInput);
+ }
}
bool FormPlugin::handleNavigation(ANPKeyCode keyCode) {
@@ -316,12 +304,10 @@
if (!m_activeInput) {
switchActiveInput(&m_usernameInput);
- scrollIntoView(m_activeInput);
}
else if (m_activeInput == &m_usernameInput) {
if (keyCode == kDpadDown_ANPKeyCode) {
switchActiveInput(&m_passwordInput);
- scrollIntoView(m_activeInput);
}
else if (keyCode == kDpadCenter_ANPKeyCode)
gWindowI.showKeyboard(instance, false);
@@ -331,7 +317,6 @@
else if (m_activeInput == &m_passwordInput) {
if (keyCode == kDpadUp_ANPKeyCode) {
switchActiveInput(&m_usernameInput);
- scrollIntoView(m_activeInput);
}
else if (keyCode == kDpadCenter_ANPKeyCode)
gWindowI.showKeyboard(instance, false);
@@ -373,44 +358,13 @@
NPWindow *window = obj->window;
// find the textInput's global rect coordinates
- ANPRectI inputRect;
- inputRect.left = window->x + input->rect.left;
- inputRect.top = window->y + input->rect.top;
- inputRect.right = inputRect.left + (input->rect.right - input->rect.left);
- inputRect.bottom = inputRect.top + (input->rect.bottom - input->rect.top);
+ ANPRectI visibleRects[1];
+ visibleRects[0].left = input->rect.left;
+ visibleRects[0].top = input->rect.top;
+ visibleRects[0].right = input->rect.right;
+ visibleRects[0].bottom = input->rect.bottom;
- // if the rect is contained within visible window then do nothing
- if (inputRect.left > m_visibleRect.left
- && inputRect.right < m_visibleRect.right
- && inputRect.top > m_visibleRect.top
- && inputRect.bottom < m_visibleRect.bottom) {
- return;
- }
-
- // find the global (x,y) coordinates for center of the textInput
- int inputCenterX = inputRect.left + ((inputRect.right - inputRect.left)/2);
- int inputCenterY = inputRect.top + ((inputRect.bottom - inputRect.top)/2);
-
- gLogI.log(instance, kDebug_ANPLogType, "---- %p Input Center: %d,%d : %d,%d",
- instance, inputCenterX, inputCenterY, window->x, window->y);
-
- //find global (x,y) coordinates for center of the visible screen
- int screenCenterX = m_visibleRect.left + ((m_visibleRect.right - m_visibleRect.left)/2);
- int screenCenterY = m_visibleRect.top + ((m_visibleRect.bottom - m_visibleRect.top)/2);
-
- gLogI.log(instance, kDebug_ANPLogType, "---- %p Screen Center: %d,%d : %d,%d",
- instance, screenCenterX, screenCenterY, m_visibleRect.left, m_visibleRect.top);
-
- //compute the delta of the two coordinates
- int deltaX = inputCenterX - screenCenterX;
- int deltaY = inputCenterY - screenCenterY;
-
- gLogI.log(instance, kDebug_ANPLogType, "---- %p Centering: %d,%d : %d,%d",
- instance, deltaX, deltaY, m_visibleRect.left + deltaX, m_visibleRect.top + deltaY);
-
- //move the visible screen
- gWindowI.scrollTo(instance, m_visibleRect.left + deltaX, m_visibleRect.top + deltaY);
-
+ gWindowI.setVisibleRects(instance, visibleRects, 1);
}
TextInput* FormPlugin::validTap(int x, int y) {