adding support for tracking the visible rectangles.
This commit is contained in:
@@ -75,8 +75,6 @@ BallAnimation::BallAnimation(NPP inst) : SubPlugin(inst) {
|
||||
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 @@ BallAnimation::BallAnimation(NPP inst) : SubPlugin(inst) {
|
||||
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::draw(ANPCanvas* canvas) {
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
//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);
|
||||
visibleRects[0].left = 0;
|
||||
visibleRects[0].top = 0;
|
||||
visibleRects[0].right = window->width;
|
||||
visibleRects[0].bottom = window->height;
|
||||
|
||||
gWindowI.setVisibleRects(instance, visibleRects, 1);
|
||||
gWindowI.clearVisibleRects(instance);
|
||||
}
|
||||
|
||||
int16 BallAnimation::handleEvent(const ANPEvent* evt) {
|
||||
@@ -248,18 +229,9 @@ int16 BallAnimation::handleEvent(const ANPEvent* evt) {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
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 @@ private:
|
||||
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();
|
||||
|
||||
@@ -97,7 +97,7 @@ FormPlugin::FormPlugin(NPP inst) : SubPlugin(inst) {
|
||||
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 @@ int16 FormPlugin::handleEvent(const ANPEvent* evt) {
|
||||
}
|
||||
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 @@ int16 FormPlugin::handleEvent(const ANPEvent* evt) {
|
||||
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 @@ bool FormPlugin::handleNavigation(ANPKeyCode keyCode) {
|
||||
|
||||
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 @@ bool FormPlugin::handleNavigation(ANPKeyCode keyCode) {
|
||||
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 @@ void FormPlugin::scrollIntoView(TextInput* input) {
|
||||
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);
|
||||
|
||||
// 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);
|
||||
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;
|
||||
|
||||
gWindowI.setVisibleRects(instance, visibleRects, 1);
|
||||
}
|
||||
|
||||
TextInput* FormPlugin::validTap(int x, int y) {
|
||||
|
||||
Reference in New Issue
Block a user