WebPageProxy* WebInspectorProxy::platformCreateInspectorPage()
{
    ASSERT(m_inspectedPage);

#ifdef HAVE_ECORE_X
    const char* engine = "opengl_x11";
    m_inspectorWindow = ecore_evas_new(engine, 0, 0, initialWindowWidth, initialWindowHeight, 0);

    // Gracefully fall back to software if evas_gl engine is not available.
    if (!m_inspectorWindow)
#endif
    m_inspectorWindow = ecore_evas_new(0, 0, 0, initialWindowWidth, initialWindowHeight, 0);
    if (!m_inspectorWindow)
        return 0;

    WKContextRef wkContext = toAPI(&inspectorProcessPool());
    WKRetainPtr<WKStringRef> wkGroupIdentifier = adoptWK(WKStringCreateWithUTF8CString(inspectorPageGroupIdentifier().utf8().data()));
    WKPageGroupRef wkPageGroup = WKPageGroupCreateWithIdentifier(wkGroupIdentifier.get());

    WKRetainPtr<WKPageConfigurationRef> wkPageConfiguration = adoptWK(WKPageConfigurationCreate());
    WKPageConfigurationSetContext(wkPageConfiguration.get(), wkContext);
    WKPageConfigurationSetPageGroup(wkPageConfiguration.get(), wkPageGroup);

    m_inspectorView = EWKViewCreate(wkContext, wkPageConfiguration.get(), ecore_evas_get(m_inspectorWindow), /* smart */ 0);
    WKViewRef wkView = EWKViewGetWKView(m_inspectorView);

    WKRetainPtr<WKStringRef> wkTheme = adoptWK(WKStringCreateWithUTF8CString(DEFAULT_THEME_DIR "/default.edj"));
    WKViewSetThemePath(wkView, wkTheme.get());

    WKPreferencesRef wkPreferences = WKPageGroupGetPreferences(wkPageGroup);
    WKPreferencesSetFileAccessFromFileURLsAllowed(wkPreferences, true);
    WKPreferencesSetJavaScriptRuntimeFlags(wkPreferences, 0);

    return toImpl(WKViewGetPage(wkView));
}
Ejemplo n.º 2
0
View::View(GLContext& glContext)
    : m_glContext(glContext)
{
    m_context = WKContextCreate();
    m_pageConfiguration = WKPageConfigurationCreate();
    {
        auto pageGroupIdentifier = adoptWK(WKStringCreateWithUTF8CString("WPEPageGroup"));
        auto pageGroup = adoptWK(WKPageGroupCreateWithIdentifier(pageGroupIdentifier.get()));
        WKPageConfigurationSetContext(m_pageConfiguration, m_context);
        WKPageConfigurationSetPageGroup(m_pageConfiguration, pageGroup.get());
    }

    m_exportable = wpe_mesa_view_backend_exportable_create(&s_exportableClient, this);

    auto* backend = wpe_mesa_view_backend_exportable_get_view_backend(m_exportable);
    m_view = WKViewCreateWithViewBackend(backend, m_pageConfiguration);

    WKPageSetPageNavigationClient(WKViewGetPage(m_view), &s_pageNavigationClient.base);

    m_updateSource = g_timeout_source_new(m_frameRate / 1000);
    g_source_set_callback(m_updateSource,
        [](gpointer data) -> gboolean {
            auto& view = *static_cast<View*>(data);
            view.performUpdate();
            return TRUE;
        }, this, nullptr);
    g_source_attach(m_updateSource, g_main_context_default());
}
TEST(WebKit2, DISABLED_WKViewUserViewportToContents)
{
    // This test creates a WKView and uses the WKViewUserViewportToContents
    // function to convert viewport coordinates to contents (page) coordinates.
    // It scrolls and scales around the contents and check if the coordinates
    // conversion math is right.

    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    WKRetainPtr<WKPageConfigurationRef> configuration(AdoptWK, WKPageConfigurationCreate());
    WKPageConfigurationSetContext(configuration.get(), context.get());

    WKRetainPtr<WKViewRef> webView(AdoptWK, WKViewCreate(configuration.get()));

    WKViewSetIsActive(webView.get(), true);
    WKPageSetUseFixedLayout(WKViewGetPage(webView.get()), false);

    WKPoint out;

    // At scale 1.0 the viewport and contents coordinates should match.

    WKViewSetContentScaleFactor(webView.get(), 1.0);
    WKViewSetContentPosition(webView.get(), WKPointMake(0, 0));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 0);
    EXPECT_EQ(out.y, 0);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 10);
    EXPECT_EQ(out.y, 10);

    WKViewSetContentPosition(webView.get(), WKPointMake(20, 20));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 20);
    EXPECT_EQ(out.y, 20);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 30);
    EXPECT_EQ(out.y, 30);

    // At scale 2.0 the viewport distance values will be half
    // the ones seem in the contents.

    WKViewSetContentScaleFactor(webView.get(), 2.0);
    WKViewSetContentPosition(webView.get(), WKPointMake(0, 0));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 0);
    EXPECT_EQ(out.y, 0);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 5);
    EXPECT_EQ(out.y, 5);

    WKViewSetContentPosition(webView.get(), WKPointMake(20, 20));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 20);
    EXPECT_EQ(out.y, 20);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 25);
    EXPECT_EQ(out.y, 25);

    // At scale 0.5 the viewport distance values will be twice
    // the ones seem in the contents.

    WKViewSetContentScaleFactor(webView.get(), 0.5);
    WKViewSetContentPosition(webView.get(), WKPointMake(0, 0));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 0);
    EXPECT_EQ(out.y, 0);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 20);
    EXPECT_EQ(out.y, 20);

    WKViewSetContentPosition(webView.get(), WKPointMake(20, 20));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 20);
    EXPECT_EQ(out.y, 20);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 40);
    EXPECT_EQ(out.y, 40);

    // Let's add translation to the viewport.

    const int delta = 10;
    WKViewSetUserViewportTranslation(webView.get(), delta, delta);

    WKViewSetContentPosition(webView.get(), WKPointMake(0, 0));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 0 - delta / 0.5);
    EXPECT_EQ(out.y, 0 - delta / 0.5);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 20 - delta / 0.5);
    EXPECT_EQ(out.y, 20 - delta / 0.5);

    WKViewSetContentPosition(webView.get(), WKPointMake(20, 20));

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(0, 0));
    EXPECT_EQ(out.x, 20 - delta / 0.5);
    EXPECT_EQ(out.y, 20 - delta / 0.5);

    out = WKViewUserViewportToContents(webView.get(), WKPointMake(10, 10));
    EXPECT_EQ(out.x, 40 - delta / 0.5);
    EXPECT_EQ(out.y, 40 - delta / 0.5);
}