void BrowserView::create(RECT webViewRect, BrowserWindow* parentWindow) { assert(!m_webView); bool isShiftKeyDown = ::GetKeyState(VK_SHIFT) & HIGH_BIT_MASK_SHORT; WKContextRef context; if (isShiftKeyDown) context = WKContextGetSharedThreadContext(); else context = WKContextGetSharedProcessContext(); WKPageNamespaceRef pageNamespace = WKPageNamespaceCreate(context); m_webView = WKViewCreate(webViewRect, pageNamespace, parentWindow->window()); WKPageUIClient uiClient = { 0, /* version */ parentWindow, /* clientInfo */ createNewPage, showPage, closePage, runJavaScriptAlert, runJavaScriptConfirm, runJavaScriptPrompt, setStatusText, contentsSizeChanged }; WKPageSetPageUIClient(WKViewGetPage(m_webView), &uiClient); }
static WKPageRef createNewPage(WKPageRef page, const void* clientInfo) { BrowserWindow* browserWindow = BrowserWindow::create(); browserWindow->createWindow(0, 0, 800, 600); return WKViewGetPage(browserWindow->view().webView()); }
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()); }
gpointer Shell::launchWPE(gpointer data) { Shell::m_instance = static_cast<Shell*>(data); GMainContext* threadContext = g_main_context_new(); GMainLoop* threadLoop = g_main_loop_new(threadContext, FALSE); g_main_context_push_thread_default(threadContext); auto pageGroupIdentifier = adoptWK(WKStringCreateWithUTF8CString("WPEPageGroup")); auto pageGroup = adoptWK(WKPageGroupCreateWithIdentifier(pageGroupIdentifier.get())); auto context = adoptWK(WKContextCreate()); Shell::instance().m_view = adoptWK(WKViewCreate(context.get(), pageGroup.get())); auto view = Shell::instance().m_view.get(); WKViewResize(view, Shell::instance().m_environment.outputSize()); WKViewMakeWPEInputTarget(view); const char* url = g_getenv("WPE_SHELL_URL"); if (!url) url = "http://www.webkit.org/blog-files/3d-transforms/poster-circle.html"; auto shellURL = adoptWK(WKURLCreateWithUTF8CString(url)); WKPageLoadURL(WKViewGetPage(view), shellURL.get()); g_main_loop_run(threadLoop); return nullptr; }
WebPageProxy* WebInspectorProxy::platformCreateInspectorPage() { ASSERT(m_page); #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(page()->process()->context()); WKPageGroupRef wkPageGroup = toAPI(inspectorPageGroup()); m_inspectorView = EWKViewCreate(wkContext, wkPageGroup, ecore_evas_get(m_inspectorWindow), /* smart */ 0); WKViewRef wkView = EWKViewGetWKView(m_inspectorView); WKRetainPtr<WKStringRef> wkTheme = adoptWK(WKStringCreateWithUTF8CString(TEST_THEME_DIR "/default.edj")); WKViewSetThemePath(wkView, wkTheme.get()); WKPreferencesRef wkPreferences = WKPageGroupGetPreferences(wkPageGroup); WKPreferencesSetFileAccessFromFileURLsAllowed(wkPreferences, true); return toImpl(WKViewGetPage(wkView)); }
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)); }
static WKPageRef createNewPage(WKPageRef page, WKURLRequestRef request, WKDictionaryRef features, WKEventModifiers modifiers, WKEventMouseButton mouseButton, const void* clientInfo) { BrowserWindow* browserWindow = BrowserWindow::create(); browserWindow->createWindow(0, 0, 800, 600); return WKViewGetPage(browserWindow->view().webView()); }
void BrowserView::create(RECT webViewRect, BrowserWindow* parentWindow) { assert(!m_webView); static WKContextRef context = WKContextCreate(); m_webView = WKViewCreate(webViewRect, context, 0, parentWindow->window()); WKPageUIClient uiClient = { kWKPageUIClientCurrentVersion, parentWindow, /* clientInfo */ 0, /* createNewPage_deprecatedForUseWithV0 */ showPage, closePage, 0, /* takeFocus */ 0, /* focus */ 0, /* unfocus */ runJavaScriptAlert, runJavaScriptConfirm, runJavaScriptPrompt, setStatusText, 0, /* mouseDidMoveOverElement_deprecatedForUseWithV0 */ 0, /* missingPluginButtonClicked */ 0, /* didNotHandleKeyEvent */ 0, /* didNotHandleWheelEvent */ 0, /* toolbarsAreVisible */ 0, /* setToolbarsAreVisible */ 0, /* menuBarIsVisible */ 0, /* setMenuBarIsVisible */ 0, /* statusBarIsVisible */ 0, /* setStatusBarIsVisible */ 0, /* isResizable */ 0, /* setIsResizable */ 0, /* getWindowFrame */ 0, /* setWindowFrame */ 0, /* runBeforeUnloadConfirmPanel */ 0, /* didDraw */ 0, /* pageDidScroll */ 0, /* exceededDatabaseQuota */ 0, /* runOpenPanel */ 0, /* decidePolicyForGeolocationPermissionRequest */ 0, /* headerHeight */ 0, /* footerHeight */ 0, /* drawHeader */ 0, /* drawFooter */ 0, /* printFrame */ 0, /* runModal */ 0, /* didCompleteRubberBandForMainFrame */ 0, /* saveDataToFileInDownloadsFolder */ 0, /* shouldInterruptJavaScript */ createNewPage, mouseDidMoveOverElement, }; WKPageSetPageUIClient(WKViewGetPage(m_webView), &uiClient); WKViewSetIsInWindow(m_webView, true); }
void BrowserView::goToURL(const std::wstring& urlString) { CFStringRef string = CFStringCreateWithCharacters(0, (const UniChar*)urlString.data(), urlString.size()); CFURLRef cfURL = CFURLCreateWithString(0, string, 0); CFRelease(string); WKURLRef url = WKURLCreateWithCFURL(cfURL); CFRelease(cfURL); WKPageRef page = WKViewGetPage(m_webView); WKPageLoadURL(page, url); WKRelease(url); }
TEST(WebKit2, WebWorker) { // This test cover the binding between functions of JavaScript Workers and // functions defined at a previously loaded bundle. It verifies the two // types of Workers, dedicated and shared. WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("WebWorkerTest")); PlatformWebView view(context.get()); WKPageLoaderClientV3 pageLoaderClient; memset(&pageLoaderClient, 0, sizeof(pageLoaderClient)); pageLoaderClient.base.version = 3; pageLoaderClient.didReceiveTitleForFrame = didReceiveTitleForFrame; WKPageSetPageLoaderClient(WKViewGetPage(view.platformView()), &pageLoaderClient.base); WKContextInjectedBundleClientV1 injectedBundleClient; memset(&injectedBundleClient, 0, sizeof(injectedBundleClient)); injectedBundleClient.base.version = 1; injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle; WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient.base); WKPageGroupRef pageGroup = WKPageGetPageGroup(WKViewGetPage(view.platformView())); WKPreferencesRef preferences = WKPageGroupGetPreferences(pageGroup); WKPreferencesSetFileAccessFromFileURLsAllowed(preferences, true); WKRetainPtr<WKURLRef> url = adoptWK(Util::createURLForResource("../WebKit2/WebWorkerTest", "html")); WKPageLoadURL(WKViewGetPage(view.platformView()), url.get()); Util::run(&initialized); Util::run(&terminated); Util::run(&changedTitle); url = adoptWK(Util::createURLForResource("../WebKit2/WebWorkerSharedTest", "html")); WKPageLoadURL(WKViewGetPage(view.platformView()), url.get()); Util::run(&initializedShared); Util::run(&terminatedShared); Util::run(&changedTitleShared); }
TEST(WebKitNix, WebViewTranslatedScaled) { // This test opens a webpage that contains a white background, no viewport // metatag and a red rectangle (20x20)px at (0,0) position. The viewport is // then translated to (10,10) position. After that it's applied a scale=2.0 // At this point we will have a red rectangle of (40x40)px at (10,10). const WKSize size = WKSizeMake(100, 100); ToolsNix::GLOffscreenBuffer offscreenBuffer(size.width, size.height); ASSERT_TRUE(offscreenBuffer.makeCurrent()); WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate()); WKRetainPtr<WKViewRef> view(AdoptWK, WKViewCreate(context.get(), 0)); Util::ForceRepaintClient forceRepaintClient(view.get()); forceRepaintClient.setClearColor(0, 0, 1, 1); const int delta = 10; WKViewSetUserViewportTranslation(view.get(), delta, delta); WKViewInitialize(view.get()); WKPageSetUseFixedLayout(WKViewGetPage(view.get()), true); WKViewSetSize(view.get(), size); glViewport(0, 0, size.width, size.height); forceRepaintClient.clear(); Util::PageLoader loader(view.get()); loader.waitForLoadURLAndRepaint("../nix/red-square"); for (double scale = 1.0; scale < 3.0; scale++) { WKViewSetContentScaleFactor(view.get(), scale); loader.forceRepaint(); ToolsNix::RGBAPixel outsideTheContent = offscreenBuffer.readPixelAtPoint(delta - 1, delta - 1); EXPECT_EQ(ToolsNix::RGBAPixel::blue(), outsideTheContent); ToolsNix::RGBAPixel squareTopLeft = offscreenBuffer.readPixelAtPoint(delta, delta); EXPECT_EQ(ToolsNix::RGBAPixel::red(), squareTopLeft); const int scaledSize = scale * 20; ToolsNix::RGBAPixel squareBottomRight = offscreenBuffer.readPixelAtPoint(delta + scaledSize - 1, delta + scaledSize - 1); EXPECT_EQ(ToolsNix::RGBAPixel::red(), squareBottomRight); ToolsNix::RGBAPixel outsideSquare = offscreenBuffer.readPixelAtPoint(delta + scaledSize, delta + scaledSize); EXPECT_EQ(ToolsNix::RGBAPixel::white(), outsideSquare); } }
void BrowserView::create(RECT webViewRect, BrowserWindow* parentWindow) { assert(!m_webView); bool isShiftKeyDown = ::GetKeyState(VK_SHIFT) & HIGH_BIT_MASK_SHORT; WKContextRef context; if (isShiftKeyDown) context = WKContextGetSharedThreadContext(); else context = WKContextGetSharedProcessContext(); m_webView = WKViewCreate(webViewRect, context, 0, parentWindow->window()); WKPageUIClient uiClient = { 0, /* version */ parentWindow, /* clientInfo */ createNewPage, showPage, closePage, runJavaScriptAlert, runJavaScriptConfirm, runJavaScriptPrompt, setStatusText, mouseDidMoveOverElement, 0, /* didNotHandleKeyEvent */ 0, /* toolbarsAreVisible */ 0, /* setToolbarsAreVisible */ 0, /* menuBarIsVisible */ 0, /* setMenuBarIsVisible */ 0, /* statusBarIsVisible */ 0, /* setStatusBarIsVisible */ 0, /* isResizable */ 0, /* setIsResizable */ 0, /* getWindowFrame */ 0, /* setWindowFrame */ 0, /* runBeforeUnloadConfirmPanel */ 0, /* didDraw */ 0, /* pageDidScroll */ 0, /* exceededDatabaseQuota */ 0 /* runOpenPanel */ }; WKPageSetPageUIClient(WKViewGetPage(m_webView), &uiClient); }
PlatformWebView::PlatformWebView(WKContextRef context, WKPageGroupRef pageGroup, WKPageRef /* relatedPage */, WKDictionaryRef options) : m_options(options) { WKRetainPtr<WKStringRef> useFixedLayoutKey(AdoptWK, WKStringCreateWithUTF8CString("UseFixedLayout")); m_usingFixedLayout = options ? WKBooleanGetValue(static_cast<WKBooleanRef>(WKDictionaryGetItemForKey(options, useFixedLayoutKey.get()))) : false; m_window = initEcoreEvas(); m_view = EWKViewCreate(context, pageGroup, ecore_evas_get(m_window), /* smart */ 0); WKPageSetUseFixedLayout(WKViewGetPage(EWKViewGetWKView(m_view)), m_usingFixedLayout); if (m_usingFixedLayout) resizeTo(800, 600); ewk_view_theme_set(m_view, TEST_THEME_DIR "/default.edj"); m_windowIsKey = false; evas_object_show(m_view); }
PlatformWebView::PlatformWebView(WKPageConfigurationRef configuration, const TestOptions& options) : m_options(options) { WKRetainPtr<WKStringRef> useFixedLayoutKey(AdoptWK, WKStringCreateWithUTF8CString("UseFixedLayout")); m_usingFixedLayout = options.useFixedLayout; m_window = initEcoreEvas(); WKContextRef context = WKPageConfigurationGetContext(configuration); m_view = EWKViewCreate(context, configuration, ecore_evas_get(m_window), /* smart */ 0); WKPageSetUseFixedLayout(WKViewGetPage(EWKViewGetWKView(m_view)), m_usingFixedLayout); if (m_usingFixedLayout) resizeTo(800, 600); ewk_view_theme_set(m_view, DEFAULT_THEME_DIR "/default.edj"); m_windowIsKey = false; evas_object_show(m_view); }
void Tab::init() { m_view = WKViewCreate(m_context, m_browser->contentPageGroup()); WKViewInitialize(m_view); WKViewSetIsFocused(m_view, true); WKViewSetIsVisible(m_view, true); m_page = WKViewGetPage(m_view); WKStringRef appName = WKStringCreateWithUTF8CString("Drowser"); WKPageSetApplicationNameForUserAgent(m_page, appName); WKRelease(appName); WKViewClient client; std::memset(&client, 0, sizeof(WKViewClient)); client.version = kWKViewClientCurrentVersion; client.clientInfo = this; client.viewNeedsDisplay = &Tab::onViewNeedsDisplayCallback; WKViewSetViewClient(m_view, &client); WKPageLoaderClient loaderClient; memset(&loaderClient, 0, sizeof(WKPageLoaderClient)); loaderClient.version = kWKPageLoaderClientCurrentVersion; loaderClient.clientInfo = this; loaderClient.didStartProgress = &Tab::onStartProgressCallback; loaderClient.didChangeProgress = &Tab::onChangeProgressCallback; loaderClient.didFinishProgress = &Tab::onFinishProgressCallback; loaderClient.didCommitLoadForFrame = &Tab::onCommitLoadForFrame; loaderClient.didReceiveTitleForFrame = &Tab::onReceiveTitleForFrame; loaderClient.didFailProvisionalLoadWithErrorForFrame = &Tab::onFailProvisionalLoadWithErrorForFrameCallback; WKPageSetPageLoaderClient(m_page, &loaderClient); WKPageUIClient uiClient; memset(&uiClient, 0, sizeof(WKPageUIClient)); uiClient.version = kWKPageUIClientCurrentVersion; uiClient.clientInfo = this; uiClient.createNewPage = &Tab::createNewPageCallback; uiClient.mouseDidMoveOverElement = &Tab::onMouseDidMoveOverElement; WKPageSetPageUIClient(m_page, &uiClient); }
WKPageRef PlatformWebView::page() { return WKViewGetPage(EWKViewGetWKView(m_view)); }
TEST(WebKit2, 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<WKViewRef> webView(AdoptWK, WKViewCreate(context.get(), 0)); WKViewInitialize(webView.get()); 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); }
WKPageRef PlatformWebView::page() const { return WKViewGetPage(m_view); }
void View::load(const char* url) { auto shellURL = adoptWK(WKURLCreateWithUTF8CString(url)); WKPageLoadURL(WKViewGetPage(m_view), shellURL.get()); }
TEST(WebKitNix, SuspendResumeAPI) { // This test uses a page that changes its title - showing current time. // As the suspend method is called the page's changes are paused. The // animation continues as we call the resume method. During this process // there are checkpoints to ensure that changes are pausing/resuming. const WKSize size = WKSizeMake(150, 100); ToolsNix::GLOffscreenBuffer offscreenBuffer(size.width, size.height); ASSERT_TRUE(offscreenBuffer.makeCurrent()); WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate()); WKRetainPtr<WKViewRef> view(AdoptWK, WKViewCreate(context.get(), 0)); Util::ForceRepaintClient forceRepaintClient(view.get()); forceRepaintClient.setClearColor(0, 0, 1, 1); WKViewInitialize(view.get()); WKViewSetSize(view.get(), size); glViewport(0, 0, size.width, size.height); forceRepaintClient.clear(); Util::PageLoader loader(view.get()); loader.waitForLoadURLAndRepaint("../nix/SuspendResume"); size_t bufferSize = WKStringGetMaximumUTF8CStringSize(WKPageCopyTitle(WKViewGetPage(view.get()))); char firstSampleBeforeSuspend[bufferSize]; char secondSampleBeforeSuspend[bufferSize]; char firstSampleAfterSuspend[bufferSize]; char secondSampleAfterSuspend[bufferSize]; char firstSampleAfterResume[bufferSize]; WKStringGetUTF8CString(WKPageCopyTitle(WKViewGetPage(view.get())), firstSampleBeforeSuspend, bufferSize); // After collecting the first sample a repaint is needed to get viewport updated accordingly. // This proccess is repeated for each collected sample. Util::sleep(0.1); loader.forceRepaint(); WKStringGetUTF8CString(WKPageCopyTitle(WKViewGetPage(view.get())), secondSampleBeforeSuspend, bufferSize); // The timer is ticking - two different samples. EXPECT_STRNE(firstSampleBeforeSuspend, secondSampleBeforeSuspend); // Force an update before suspending otherwise we can get same sample value after suspending // and the test becomes flacky. Util::sleep(0.1); loader.forceRepaint(); WKViewSuspendActiveDOMObjectsAndAnimations(view.get()); Util::sleep(0.1); loader.forceRepaint(); WKStringGetUTF8CString(WKPageCopyTitle(WKViewGetPage(view.get())), firstSampleAfterSuspend, bufferSize); // The timer is paused - still two different samples. EXPECT_STRNE(secondSampleBeforeSuspend, firstSampleAfterSuspend); Util::sleep(0.1); loader.forceRepaint(); WKStringGetUTF8CString(WKPageCopyTitle(WKViewGetPage(view.get())), secondSampleAfterSuspend, bufferSize); // The timer is paused - two samples collected while paused so they are equal. EXPECT_STREQ(firstSampleAfterSuspend, secondSampleAfterSuspend); WKViewResumeActiveDOMObjectsAndAnimations(view.get()); Util::sleep(0.1); loader.forceRepaint(); WKStringGetUTF8CString(WKPageCopyTitle(WKViewGetPage(view.get())), firstSampleAfterResume, bufferSize); // The timer is ticking again - two different samples. EXPECT_STRNE(secondSampleAfterSuspend, firstSampleAfterResume); }
TEST(WebKitNix, WebViewUpdateTextInputState) { memset(&stateReceived, 0, sizeof(stateReceived)); WKRetainPtr<WKContextRef> context = adoptWK(WKContextCreate()); WKRetainPtr<WKViewRef> view(AdoptWK, WKViewCreate(context.get(), 0)); NIXViewClient nixViewClient; memset(&nixViewClient, 0, sizeof(NIXViewClient)); nixViewClient.version = kNIXViewClientCurrentVersion; nixViewClient.updateTextInputState = updateTextInputState; NIXViewSetNixViewClient(view.get(), &nixViewClient); WKViewInitialize(view.get()); WKPageLoaderClient pageLoaderClient; memset(&pageLoaderClient, 0, sizeof(WKPageLoaderClient)); pageLoaderClient.version = kWKPageLoaderClientCurrentVersion; pageLoaderClient.didFinishLoadForFrame = didFinishLoadForFrame; WKPageSetPageLoaderClient(WKViewGetPage(view.get()), &pageLoaderClient); const WKSize size = WKSizeMake(100, 100); WKViewSetSize(view.get(), size); NIXMouseEvent nixEvent; memset(&nixEvent, 0, sizeof(NIXMouseEvent)); nixEvent.type = kNIXInputEventTypeMouseDown; nixEvent.button = kWKEventMouseButtonLeftButton; nixEvent.x = 55; nixEvent.y = 55; nixEvent.globalX = 55; nixEvent.globalY = 55; nixEvent.clickCount = 1; nixEvent.modifiers = static_cast<NIXInputEventModifiers>(0);; nixEvent.timestamp = 0; // Simple test on content editable. WKRetainPtr<WKURLRef> editableContentUrl = adoptWK(Util::createURLForResource("../nix/single-tap-on-editable-content", "html")); WKPageLoadURL(WKViewGetPage(view.get()), editableContentUrl.get()); Util::run(&didFinishLoad); NIXViewSendMouseEvent(view.get(), &nixEvent); nixEvent.type = kNIXInputEventTypeMouseUp; NIXViewSendMouseEvent(view.get(), &nixEvent); Util::run(&didUpdateTextInputState); ASSERT_TRUE(didFinishLoad); ASSERT_TRUE(didUpdateTextInputState); ASSERT_TRUE(stateReceived.isContentEditable); ASSERT_TRUE(WKStringIsEqualToUTF8CString(stateReceived.surroundingText, "foobar")); WKRelease(stateReceived.surroundingText); ASSERT_TRUE(WKStringIsEmpty(stateReceived.submitLabel)); WKRelease(stateReceived.submitLabel); ASSERT_FALSE(stateReceived.inputMethodHints & NIXImhSensitiveData); ASSERT_TRUE(!WKRectIsEqual(stateReceived.cursorRect, invalidRectState)); ASSERT_TRUE(!WKRectIsEqual(stateReceived.editorRect, invalidRectState)); ASSERT_TRUE(!WKRectIsEqual(stateReceived.cursorRect, stateReceived.editorRect)); // Test on a form field. didFinishLoad = false; memset(&stateReceived, 0, sizeof(stateReceived)); editableContentUrl = adoptWK(Util::createURLForResource("../nix/single-tap-on-form-field", "html")); WKPageLoadURL(WKViewGetPage(view.get()), editableContentUrl.get()); Util::run(&didFinishLoad); nixEvent.type = kNIXInputEventTypeMouseDown; NIXViewSendMouseEvent(view.get(), &nixEvent); nixEvent.type = kNIXInputEventTypeMouseUp; NIXViewSendMouseEvent(view.get(), &nixEvent); didUpdateTextInputState = false; Util::run(&didUpdateTextInputState); WKRelease(stateReceived.surroundingText); ASSERT_TRUE(didFinishLoad); ASSERT_TRUE(didUpdateTextInputState); ASSERT_TRUE(WKStringIsEqualToUTF8CString(stateReceived.submitLabel, "submitLabelValue")); WKRelease(stateReceived.submitLabel); ASSERT_TRUE(stateReceived.inputMethodHints & NIXImhSensitiveData); }