static PyObject* NIXView_setViewNeedsDisplayCallback(PyObject* self, PyObject* pyArg)
{
    if (!PyCallable_Check(pyArg))
        return 0;

    NIXViewObject* cppSelf = reinterpret_cast<NIXViewObject*>(self);
    cppSelf->viewNeedsDisplayCallback = pyArg;
    NIXViewSetViewClient(cppSelf->cptr, &cppSelf->viewClient);

    Py_RETURN_NONE;
}
Exemple #2
0
int main(int argc, char* argv[])
{
    const char* url = argc == 2 ? argv[1] : "http://www.google.com";

    //ProfilerStart("/home/pi/Sample.prof");

    bcm_host_init();

    memset(&g_state, 0, sizeof(struct state));
    ogl_init(&g_state);

    GMainLoop* mainLoop = g_main_loop_new(0, false);
    WKContextRef context = WKContextCreateWithInjectedBundlePath(WKStringCreateWithUTF8CString(SAMPLE_INJECTEDBUNDLE_DIR "libSampleInjectedBundle.so"));
    NIXView webView = NIXViewCreate(context, NULL);
    WKPageRef page = NIXViewGetPage(webView);

    NIXViewClient viewClient;
    memset(&viewClient, 0, sizeof(NIXViewClient));
    viewClient.version = kNIXViewClientCurrentVersion;
    viewClient.viewNeedsDisplay = viewNeedsDisplay;
    NIXViewSetViewClient(webView, &viewClient);

    NIXViewInitialize(webView);

    WKPageLoaderClient loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));
    loaderClient.version = kWKPageLoaderClientCurrentVersion;
    loaderClient.didReceiveTitleForFrame = didReceiveTitleForFrame;
    WKPageSetPageLoaderClient(page, &loaderClient);

    NIXViewSetSize(webView, WKSizeMake(g_state.screen_width, g_state.screen_height));
    WKPageLoadURL(page, WKURLCreateWithUTF8CString(url));

    //ProfilerFlush();
    //ProfilerStop();

    g_main_loop_run(mainLoop);

    NIXViewRelease(webView);
    WKRelease(context);
    g_main_loop_unref(mainLoop);

    ogl_exit(&g_state);

    return 0;
}
Exemple #3
0
MiniBrowser::MiniBrowser(GMainLoop* mainLoop, Mode mode, int width, int height, int viewportHorizontalDisplacement, int viewportVerticalDisplacement)
    : m_context(AdoptWK, WKContextCreate())
    , m_pageGroup(AdoptWK, (WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("MiniBrowser"))))
    , m_window(new LinuxWindow(this, width, height))
    , m_view(0)
    , m_mainLoop(mainLoop)
    , m_lastClickTime(0)
    , m_lastClickX(0)
    , m_lastClickY(0)
    , m_lastClickButton(kWKEventMouseButtonNoButton)
    , m_clickCount(0)
    , m_touchMocker(0)
    , m_mode(mode)
    , m_displayUpdateScheduled(false)
    , m_gestureRecognizer(GestureRecognizer(this))
    , m_postponeTextInputUpdates(true)
    , m_shouldFocusEditableArea(false)
    , m_shouldRestoreViewportWhenLosingFocus(false)
    , m_pageHandlesTouchEvents(false)
    , m_viewportMinScale(0.25)
    , m_viewportMaxScale(5)
    , m_viewportUserScalable(true)
    , m_viewportInitScale(1)
{
    g_main_loop_ref(m_mainLoop);

    WKPreferencesRef preferences = WKPageGroupGetPreferences(m_pageGroup.get());
    WKPreferencesSetAcceleratedCompositingEnabled(preferences, true);
    WKPreferencesSetFrameFlatteningEnabled(preferences, true);
    WKPreferencesSetDeveloperExtrasEnabled(preferences, true);

    m_view = NIXViewCreate(m_context.get(), m_pageGroup.get());

    NIXViewClient viewClient;
    memset(&viewClient, 0, sizeof(NIXViewClient));
    viewClient.version = kNIXViewClientCurrentVersion;
    viewClient.clientInfo = this;
    viewClient.viewNeedsDisplay = MiniBrowser::viewNeedsDisplay;
    viewClient.webProcessCrashed = MiniBrowser::webProcessCrashed;
    viewClient.webProcessRelaunched = MiniBrowser::webProcessRelaunched;
    viewClient.doneWithTouchEvent = MiniBrowser::doneWithTouchEvent;
    viewClient.doneWithGestureEvent = MiniBrowser::doneWithGestureEvent;
    viewClient.pageDidRequestScroll = MiniBrowser::pageDidRequestScroll;
    viewClient.didChangeContentsSize = MiniBrowser::didChangeContentsSize;
    viewClient.didChangeViewportAttributes = MiniBrowser::didChangeViewportAttributes;
    viewClient.didFindZoomableArea = MiniBrowser::didFindZoomableArea;
    viewClient.updateTextInputState = MiniBrowser::updateTextInputState;
    NIXViewSetViewClient(m_view, &viewClient);

    NIXViewInitialize(m_view);

    WKPageLoaderClient loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));
    loaderClient.version = kWKPageLoaderClientCurrentVersion;
    loaderClient.clientInfo = this;
    loaderClient.didStartProgress = MiniBrowser::didStartProgress;
    WKPageSetPageLoaderClient(pageRef(), &loaderClient);

    if (m_mode == MobileMode)
        WKPageSetUseFixedLayout(pageRef(), true);

    WKSize size = m_window->size();
    m_viewRect = WKRectMake(viewportHorizontalDisplacement, viewportVerticalDisplacement, size.width - viewportHorizontalDisplacement, size.height - viewportVerticalDisplacement);
    NIXViewSetSize(m_view, m_viewRect.size);

    if (viewportHorizontalDisplacement || viewportVerticalDisplacement) {
        NIXMatrix transform = NIXMatrixMakeTranslation(viewportHorizontalDisplacement, viewportVerticalDisplacement);
        NIXViewSetUserViewportTransformation(m_view, &transform);
    }

    NIXViewSetFocused(m_view, true);
    NIXViewSetVisible(m_view, true);
    NIXViewSetActive(m_view, true);
}