void WebViewHost::paintPagesWithBoundaries() { ASSERT(!m_isPainting); ASSERT(canvas()); m_isPainting = true; WebSize pageSizeInPixels = webWidget()->size(); WebFrame* webFrame = webView()->mainFrame(); int pageCount = webFrame->printBegin(pageSizeInPixels); int totalHeight = pageCount * (pageSizeInPixels.height + 1) - 1; SkCanvas* testCanvas = skia::TryCreateBitmapCanvas(pageSizeInPixels.width, totalHeight, true); if (testCanvas) { discardBackingStore(); m_canvas = adoptPtr(testCanvas); } else { webFrame->printEnd(); return; } webFrame->printPagesWithBoundaries(canvas(), pageSizeInPixels); webFrame->printEnd(); m_isPainting = false; }
void LayoutTestController::numberOfPages(const CppArgumentList& arguments, CppVariant* result) { result->setNull(); float pageWidthInPixels = 0; float pageHeightInPixels = 0; if (!parsePageSizeParameters(arguments, 0, &pageWidthInPixels, &pageHeightInPixels)) return; WebFrame* frame = m_shell->webView()->mainFrame(); if (!frame) return; WebSize size(pageWidthInPixels, pageHeightInPixels); int numberOfPages = frame->printBegin(size); frame->printEnd(); result->set(numberOfPages); }
TEST_F(WebPluginContainerTest, PrintAllPages) { URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8("test.pdf"), WebString::fromUTF8("application/pdf")); TestPluginWebFrameClient pluginWebFrameClient; // Must outlive webViewHelper. FrameTestHelpers::WebViewHelper webViewHelper; WebView* webView = webViewHelper.initializeAndLoad(m_baseURL + "test.pdf", true, &pluginWebFrameClient); ASSERT(webView); webView->updateAllLifecyclePhases(); runPendingTasks(); WebFrame* frame = webView->mainFrame(); WebPrintParams printParams; printParams.printContentArea.width = 500; printParams.printContentArea.height = 500; frame->printBegin(printParams); SkPictureRecorder recorder; frame->printPagesWithBoundaries(recorder.beginRecording(IntRect()), WebSize()); frame->printEnd(); ASSERT(pluginWebFrameClient.printedAtLeastOnePage()); }