void PluginWidgetAndroid::setVisibleScreen(const ANPRectI& visibleDocRect, float zoom) {
#if DEBUG_VISIBLE_RECTS
    PLUGIN_LOG("%s (%d,%d,%d,%d)[%f]", __FUNCTION__, visibleDocRect.left,
            visibleDocRect.top, visibleDocRect.right,
            visibleDocRect.bottom, zoom);
#endif
    int oldScreenW = m_visibleDocRect.width();
    int oldScreenH = m_visibleDocRect.height();

    const bool zoomChanged = m_cachedZoomLevel != zoom;

    // make local copies of the parameters
    m_cachedZoomLevel = zoom;
    m_visibleDocRect.set(visibleDocRect.left,
                         visibleDocRect.top,
                         visibleDocRect.right,
                         visibleDocRect.bottom);

    int newScreenW = m_visibleDocRect.width();
    int newScreenH = m_visibleDocRect.height();

    // if the screen dimensions have changed by more than 5 pixels in either
    // direction then recompute the plugin's visible rectangle
    if (abs(oldScreenW - newScreenW) > 5 || abs(oldScreenH - newScreenH) > 5) {
        PLUGIN_LOG("%s VisibleDoc old=[%d,%d] new=[%d,%d] ", __FUNCTION__,
                   oldScreenW, oldScreenH, newScreenW, newScreenH);
        computeVisiblePluginRect();
    }

    sendSizeAndVisibilityEvents(zoomChanged);
}
void PluginWidgetAndroid::setVisibleRects(const ANPRectI rects[], int32_t count) {
#if DEBUG_VISIBLE_RECTS
    PLUGIN_LOG("%s count=%d", __FUNCTION__, count);
#endif
    // ensure the count does not exceed our allocated space
    if (count > MAX_REQUESTED_RECTS)
        count = MAX_REQUESTED_RECTS;

    // store the values in member variables
    m_requestedVisibleRectCount = count;
    memcpy(m_requestedVisibleRects, rects, count * sizeof(rects[0]));

#if DEBUG_VISIBLE_RECTS // FIXME: this fixes bad data from the plugin
    // take it out once plugin supplies better data
    for (int index = 0; index < count; index++) {
        PLUGIN_LOG("%s [%d](%d,%d,%d,%d)", __FUNCTION__, index,
            m_requestedVisibleRects[index].left,
            m_requestedVisibleRects[index].top,
            m_requestedVisibleRects[index].right,
            m_requestedVisibleRects[index].bottom);
        if (m_requestedVisibleRects[index].left ==
                m_requestedVisibleRects[index].right) {
            m_requestedVisibleRects[index].right += 1;
        }
        if (m_requestedVisibleRects[index].top ==
                m_requestedVisibleRects[index].bottom) {
            m_requestedVisibleRects[index].bottom += 1;
        }
    }
#endif
    computeVisiblePluginRect();
}
void PluginWidgetAndroid::setVisibleScreen(const ANPRectI& visibleDocRect, float zoom) {
#if DEBUG_VISIBLE_RECTS
    PLUGIN_LOG("%s (%d,%d,%d,%d)[%f]", __FUNCTION__, visibleDocRect.left,
            visibleDocRect.top, visibleDocRect.right,
            visibleDocRect.bottom, zoom);
#endif
    // TODO update the bitmap size based on the zoom? (for kBitmap_ANPDrawingModel)

    int oldScreenW = m_visibleDocRect.width();
    int oldScreenH = m_visibleDocRect.height();

    // make local copies of the parameters
    m_zoomLevel = zoom;
    m_visibleDocRect.set(visibleDocRect.left,
                         visibleDocRect.top,
                         visibleDocRect.right,
                         visibleDocRect.bottom);

    int newScreenW = m_visibleDocRect.width();
    int newScreenH = m_visibleDocRect.height();

    // if the screen dimensions have changed by more than 5 pixels in either
    // direction then recompute the plugin's visible rectangle
    if (abs(oldScreenW - newScreenW) > 5 || abs(oldScreenH - newScreenH) > 5) {
        PLUGIN_LOG("%s VisibleDoc old=[%d,%d] new=[%d,%d] ", __FUNCTION__,
                   oldScreenW, oldScreenH, newScreenW, newScreenH);
        computeVisiblePluginRect();
    }

    bool visible = SkIRect::Intersects(m_visibleDocRect, m_pluginBounds);
    if(m_visible != visible) {

#if DEBUG_VISIBLE_RECTS
        PLUGIN_LOG("%p changeVisiblity[%d] pluginBounds(%d,%d,%d,%d)",
                   m_pluginView->instance(), visible,
                   m_pluginBounds.fLeft, m_pluginBounds.fTop,
                   m_pluginBounds.fRight, m_pluginBounds.fBottom);
#endif

        // change the visibility
        m_visible = visible;
        // send the event
        ANPEvent event;
        SkANP::InitEvent(&event, kLifecycle_ANPEventType);
        event.data.lifecycle.action = visible ? kOnScreen_ANPLifecycleAction
                                              : kOffScreen_ANPLifecycleAction;
        sendEvent(event);
    }
}