static inline WKPoint getPointAtIndex(WKArrayRef array, size_t index) { WKTouchPointRef pointRef = static_cast<WKTouchPointRef>(WKArrayGetItemAtIndex(array, index)); ASSERT(pointRef); return WKTouchPointGetPosition(pointRef); }
static void paintRepaintRectOverlay(CGContextRef context, WKImageRef image, WKArrayRef repaintRects) { WKSize imageSize = WKImageGetSize(image); CGContextSaveGState(context); // Using a transparency layer is easier than futzing with clipping. CGContextBeginTransparencyLayer(context, 0); // Flip the context. CGContextScaleCTM(context, 1, -1); CGContextTranslateCTM(context, 0, -imageSize.height); CGContextSetRGBFillColor(context, 0, 0, 0, static_cast<CGFloat>(0.66)); CGContextFillRect(context, CGRectMake(0, 0, imageSize.width, imageSize.height)); // Clear the repaint rects. size_t count = WKArrayGetSize(repaintRects); for (size_t i = 0; i < count; ++i) { WKRect rect = WKRectGetValue(static_cast<WKRectRef>(WKArrayGetItemAtIndex(repaintRects, i))); CGRect cgRect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); CGContextClearRect(context, cgRect); } CGContextEndTransparencyLayer(context); CGContextRestoreGState(context); }
void GestureRecognizer::pinchGesture(WKEventType type, WKArrayRef touchPoints) { size_t numberOfTouchPoints = WKArrayGetSize(touchPoints); ASSERT(numberOfTouchPoints >= 2); switch (type) { case kWKEventTypeTouchMove: { m_gestureHandler->handlePinch(createVectorWithWKArray(touchPoints, 2)); break; } case kWKEventTypeTouchEnd: if (numberOfTouchPoints == 2) { m_gestureHandler->handlePinchFinished(); m_recognizerFunction = &GestureRecognizer::panGesture; WKTouchPointRef pointRef; for (size_t i = 0; i < numberOfTouchPoints; ++i) { pointRef = static_cast<WKTouchPointRef>(WKArrayGetItemAtIndex(touchPoints, i)); WKTouchPointState state = WKTouchPointGetState(pointRef); if (state != kWKTouchPointStateTouchReleased && state != kWKTouchPointStateTouchCancelled) break; } ASSERT(pointRef); m_gestureHandler->handlePanStarted(toIntPoint(WKTouchPointGetPosition(pointRef))); } break; case kWKEventTypeTouchStart: break; default: ASSERT_NOT_REACHED(); break; } }
static void paintRepaintRectOverlay(cairo_surface_t* surface, WKArrayRef repaintRects) { cairo_t* context = cairo_create(surface); cairo_push_group(context); // Paint the gray mask over the original image. cairo_set_source_rgba(context, 0, 0, 0, 0.66); cairo_paint(context); // Paint transparent rectangles over the mask to show the repainted regions. cairo_set_source_rgba(context, 0, 0, 0, 0); cairo_set_operator(context, CAIRO_OPERATOR_SOURCE); size_t count = WKArrayGetSize(repaintRects); for (size_t i = 0; i < count; ++i) { WKRect rect = WKRectGetValue(static_cast<WKRectRef>(WKArrayGetItemAtIndex(repaintRects, i))); cairo_rectangle(context, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height); cairo_fill(context); } cairo_pop_group_to_source(context); cairo_paint(context); cairo_destroy(context); }
void QtWebContext::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody) { if (!WKStringIsEqualToUTF8CString(messageName, "MessageFromNavigatorQtObject")) return; ASSERT(messageBody); ASSERT(WKGetTypeID(messageBody) == WKArrayGetTypeID()); WKArrayRef body = static_cast<WKArrayRef>(messageBody); ASSERT(WKArrayGetSize(body) == 2); ASSERT(WKGetTypeID(WKArrayGetItemAtIndex(body, 0)) == WKPageGetTypeID()); ASSERT(WKGetTypeID(WKArrayGetItemAtIndex(body, 1)) == WKStringGetTypeID()); WKPageRef page = static_cast<WKPageRef>(WKArrayGetItemAtIndex(body, 0)); WKStringRef str = static_cast<WKStringRef>(WKArrayGetItemAtIndex(body, 1)); toImpl(page)->didReceiveMessageFromNavigatorQtObject(toImpl(str)->string()); }
static void dumpDescendantFrameScrollPositions(WKBundleFrameRef frame) { WKRetainPtr<WKArrayRef> childFrames(AdoptWK, WKBundleFrameCopyChildFrames(frame)); size_t size = WKArrayGetSize(childFrames.get()); for (size_t i = 0; i < size; ++i) { WKBundleFrameRef subframe = static_cast<WKBundleFrameRef>(WKArrayGetItemAtIndex(childFrames.get(), i)); dumpFrameScrollPosition(subframe, ShouldIncludeFrameName); dumpDescendantFrameScrollPositions(subframe); } }
static void dumpDescendantFramesText(WKBundleFrameRef frame) { WKRetainPtr<WKArrayRef> childFrames(AdoptWK, WKBundleFrameCopyChildFrames(frame)); size_t size = WKArrayGetSize(childFrames.get()); for (size_t i = 0; i < size; ++i) { WKBundleFrameRef subframe = static_cast<WKBundleFrameRef>(WKArrayGetItemAtIndex(childFrames.get(), i)); WKRetainPtr<WKStringRef> subframeName(AdoptWK, WKBundleFrameCopyName(subframe)); InjectedBundle::shared().os() << "\n--------\nFrame: '" << subframeName << "'\n--------\n"; dumpFrameText(subframe); dumpDescendantFramesText(subframe); } }
EwkPopupMenu::EwkPopupMenu(EwkView* view, WKPopupMenuListenerRef popupMenuListener, WKArrayRef items, unsigned selectedIndex) : m_view(view) , m_popupMenuListener(popupMenuListener) , m_popupMenuItems(0) , m_selectedIndex(selectedIndex) { size_t size = WKArrayGetSize(items); for (size_t i = 0; i < size; ++i) { WKPopupItemRef wkItem = static_cast<WKPopupItemRef>(WKArrayGetItemAtIndex(items, i)); m_popupMenuItems = eina_list_append(m_popupMenuItems, std::make_unique<EwkPopupMenuItem>(wkItem).release()); } }
void QtWebPageUIClient::runOpenPanel(WKPageRef, WKFrameRef, WKOpenPanelParametersRef parameters, WKOpenPanelResultListenerRef listener, const void* clientInfo) { WKRetainPtr<WKArrayRef> wkSelectedFileNames = adoptWK(WKOpenPanelParametersCopySelectedFileNames(parameters)); QStringList selectedFileNames; size_t selectedFilesSize = WKArrayGetSize(wkSelectedFileNames.get()); selectedFileNames.reserve(selectedFilesSize); for (size_t i = 0; i < selectedFilesSize; ++i) selectedFileNames += WKStringCopyQString(static_cast<WKStringRef>(WKArrayGetItemAtIndex(wkSelectedFileNames.get(), i))); FileChooserType allowMultipleFiles = WKOpenPanelParametersGetAllowsMultipleFiles(parameters) ? MultipleFilesSelection : SingleFileSelection; toQtWebPageUIClient(clientInfo)->runOpenPanel(listener, selectedFileNames, allowMultipleFiles); }
static inline JSValueRef stringArrayToJS(JSContextRef context, WKArrayRef strings) { const size_t count = WKArrayGetSize(strings); OwnArrayPtr<JSValueRef> jsStringsArray = adoptArrayPtr(new JSValueRef[count]); for (size_t i = 0; i < count; ++i) { WKStringRef stringRef = static_cast<WKStringRef>(WKArrayGetItemAtIndex(strings, i)); JSRetainPtr<JSStringRef> stringJS = toJS(stringRef); jsStringsArray[i] = JSValueMakeString(context, stringJS.get()); } return JSObjectMakeArray(context, count, jsStringsArray.get(), 0); }
static inline JSValueRef stringArrayToJS(JSContextRef context, WKArrayRef strings) { const size_t count = WKArrayGetSize(strings); JSValueRef arrayResult = JSObjectMakeArray(context, 0, 0, 0); JSObjectRef arrayObj = JSValueToObject(context, arrayResult, 0); for (size_t i = 0; i < count; ++i) { WKStringRef stringRef = static_cast<WKStringRef>(WKArrayGetItemAtIndex(strings, i)); JSRetainPtr<JSStringRef> stringJS = toJS(stringRef); JSObjectSetPropertyAtIndex(context, arrayObj, i, JSValueMakeString(context, stringJS.get()), 0); } return arrayResult; }
void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef imageRef, WKArrayRef repaintRects) { QImage image; if (PlatformWebView::windowShapshotEnabled()) { WKPageRef page = TestController::shared().mainWebView()->page(); WKPageForceRepaint(page, this, &forceRepaintDoneCallback); TestController::shared().runUntil(m_gotRepaint, TestController::ShortTimeout); if (m_gotRepaint) image = WKImageCreateQImage(TestController::shared().mainWebView()->windowSnapshotImage().get()); else { m_error = true; m_errorMessage = "Timed out waiting for repaint\n"; m_webProcessIsUnresponsive = true; return; } } else image = WKImageCreateQImage(imageRef); if (repaintRects) { QImage mask(image.size(), image.format()); mask.fill(QColor(0, 0, 0, 0.66 * 255)); QPainter maskPainter(&mask); maskPainter.setCompositionMode(QPainter::CompositionMode_Source); size_t count = WKArrayGetSize(repaintRects); for (size_t i = 0; i < count; ++i) { WKRect wkRect = WKRectGetValue(static_cast<WKRectRef>(WKArrayGetItemAtIndex(repaintRects, i))); QRectF rect(wkRect.origin.x, wkRect.origin.y, wkRect.size.width, wkRect.size.height); maskPainter.fillRect(rect, Qt::transparent); } QPainter painter(&image); painter.drawImage(image.rect(), mask); } QCryptographicHash hash(QCryptographicHash::Md5); for (unsigned row = 0; row < image.height(); ++row) hash.addData(reinterpret_cast<const char*>(image.constScanLine(row)), image.bytesPerLine()); QByteArray actualHash = hash.result().toHex(); ASSERT(actualHash.size() == 32); if (!compareActualHashToExpectedAndDumpResults(actualHash)) { image.setText("checksum", actualHash); dumpImage(image); } }
static void getContextMenuFromProposedMenu(WKPageRef pageRef, WKArrayRef proposedMenuRef, WKArrayRef* newMenuRef, WKHitTestResultRef, WKTypeRef, const void*) { WKMutableArrayRef menuItems = WKMutableArrayCreate(); size_t count = WKArrayGetSize(proposedMenuRef); for (size_t i = 0; i < count; ++i) { WKContextMenuItemRef contextMenuItem = static_cast<WKContextMenuItemRef>(WKArrayGetItemAtIndex(proposedMenuRef, i)); switch (WKContextMenuItemGetTag(contextMenuItem)) { case kWKContextMenuItemTagOpenLinkInNewWindow: case kWKContextMenuItemTagOpenImageInNewWindow: case kWKContextMenuItemTagOpenFrameInNewWindow: case kWKContextMenuItemTagOpenMediaInNewWindow: case kWKContextMenuItemTagDownloadLinkToDisk: case kWKContextMenuItemTagDownloadImageToDisk: break; default: WKArrayAppendItem(menuItems, contextMenuItem); break; } } *newMenuRef = menuItems; }
{ 1, nullptr }, // didCreatePage [](WKBundleRef, WKBundlePageRef page, const void*) { WKBundlePageSetPageLoaderClient(page, &s_pageLoaderClient.base); }, nullptr, // willDestroyPage nullptr, // didInitializePageGroup nullptr, // didReceiveMessage // didReceiveMessageToPage [](WKBundleRef, WKBundlePageRef, WKStringRef messageName, WKTypeRef messageBodyObj, const void*) { if (WKStringIsEqualToUTF8CString(messageName, "Hello")) { fprintf(stderr, "[WPEInjectedBundle] Hello!\n"); WKArrayRef messageBody = static_cast<WKArrayRef>(messageBodyObj); for (size_t i = 0, size = WKArrayGetSize(messageBody); i < size; ++i) { WKStringRef itemString = static_cast<WKStringRef>(WKArrayGetItemAtIndex(messageBody, i)); std::string item = toSTDString(itemString); fprintf(stderr, "\tarray item: %s\n", item.data()); } } }, }; extern "C" void WKBundleInitialize(WKBundleRef bundle, WKTypeRef) { fprintf(stderr, "[WPEInjectedBundle] Initialized.\n"); WKBundleSetClient(bundle, &s_bundleClient.base); }