summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorMichael BrĂ¼ning <michael.bruning@qt.io>2016-09-21 18:02:51 +0200
committerMichael BrĂ¼ning <michael.bruning@qt.io>2016-11-25 11:44:07 +0000
commit41eddfaa4af8aba3820c8401993600e83633f9bc (patch)
tree3b437be48265f3f217352d2bf186fc1bff88687a /src/core
parent5ca2d76b78df1839b92b04d7d6e7710f5d402c98 (diff)
Move the QPrinter and QtWidgets related code out of the PDFium wrapper
This moves the actual printing using QPrinter to the WebEngineWidgets part of the API. The printsupport module depends on the widgets module and therefore QtWebEngineCore also had a dependency to widgets. This is removed by this change. Change-Id: If6e5745709a59de18f2123b930cbe6e64390c867 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/config/common.pri2
-rw-r--r--src/core/config/desktop_linux.pri2
-rw-r--r--src/core/config/mac_osx.pri2
-rw-r--r--src/core/config/windows.pri2
-rw-r--r--src/core/core_common.pri1
-rw-r--r--src/core/core_gyp_generator.pro7
-rw-r--r--src/core/pdfium_document_wrapper_qt.cpp (renamed from src/core/pdfium_printing_wrapper_qt.cpp)127
-rw-r--r--src/core/pdfium_document_wrapper_qt.h (renamed from src/core/pdfium_printing_wrapper_qt.h)29
-rw-r--r--src/core/web_contents_adapter.cpp40
-rw-r--r--src/core/web_contents_adapter.h9
-rw-r--r--src/core/web_contents_adapter_client.h3
11 files changed, 62 insertions, 162 deletions
diff --git a/src/core/config/common.pri b/src/core/config/common.pri
index 7a9656fca..b5bb23684 100644
--- a/src/core/config/common.pri
+++ b/src/core/config/common.pri
@@ -2,8 +2,6 @@
# Trigger Qt-specific build conditions.
GYP_CONFIG += use_qt=1
-# Enable printing. We enable preview because we use preview logic even if we don't support preview.
-GYP_CONFIG += enable_basic_printing=1 enable_print_preview=1
# We do not want to ship more external binary blobs, so let v8 embed its startup data.
GYP_CONFIG += v8_use_external_startup_data=0
# WebSpeech requires Google API keys and adds dependencies on speex and flac.
diff --git a/src/core/config/desktop_linux.pri b/src/core/config/desktop_linux.pri
index e28d7eb7c..23044619b 100644
--- a/src/core/config/desktop_linux.pri
+++ b/src/core/config/desktop_linux.pri
@@ -5,6 +5,8 @@ include(linux.pri)
GYP_CONFIG += \
desktop_linux=1 \
enable_widevine=1 \
+ enable_basic_printing=1 \
+ enable_print_preview=1 \
enable_pdf=1
clang {
diff --git a/src/core/config/mac_osx.pri b/src/core/config/mac_osx.pri
index be037cbde..4111236ed 100644
--- a/src/core/config/mac_osx.pri
+++ b/src/core/config/mac_osx.pri
@@ -26,6 +26,8 @@ GYP_CONFIG += \
make_clang_dir=\"$${QMAKE_CLANG_DIR}\" \
clang_use_chrome_plugins=0 \
enable_widevine=1 \
+ enable_basic_printing=1 \
+ enable_print_preview=1 \
enable_pdf=1
# Force touch API is used in 49-based Chromium, which is included starting with 10.10.3 SDK, so we
diff --git a/src/core/config/windows.pri b/src/core/config/windows.pri
index 5b9551b5a..7f87e885d 100644
--- a/src/core/config/windows.pri
+++ b/src/core/config/windows.pri
@@ -7,6 +7,8 @@ GYP_CONFIG += \
remoting=0 \
use_ash=0 \
enable_widevine=1 \
+ enable_basic_printing=1 \
+ enable_print_preview=1 \
enable_pdf=1
# Libvpx build needs additional search path on Windows.
diff --git a/src/core/core_common.pri b/src/core/core_common.pri
index 721e8c71a..9c29aea71 100644
--- a/src/core/core_common.pri
+++ b/src/core/core_common.pri
@@ -10,4 +10,3 @@ CHROMIUM_SRC_DIR = $$QTWEBENGINE_ROOT/$$getChromiumSrcDir()
INCLUDEPATH += $$CHROMIUM_SRC_DIR
qtHaveModule(positioning):QT += positioning
-qtHaveModule(printsupport):QT += printsupport
diff --git a/src/core/core_gyp_generator.pro b/src/core/core_gyp_generator.pro
index 81dea855a..a09683ba6 100644
--- a/src/core/core_gyp_generator.pro
+++ b/src/core/core_gyp_generator.pro
@@ -75,6 +75,7 @@ SOURCES = \
native_web_keyboard_event_qt.cpp \
network_delegate_qt.cpp \
ozone_platform_eglfs.cpp \
+ pdfium_document_wrapper_qt.cpp \
permission_manager_qt.cpp \
process_main.cpp \
proxy_config_service_qt.cpp \
@@ -155,6 +156,7 @@ HEADERS = \
media_capture_devices_dispatcher.h \
network_delegate_qt.h \
ozone_platform_eglfs.h \
+ pdfium_document_wrapper_qt.h \
permission_manager_qt.h \
process_main.h \
proxy_config_service_qt.h \
@@ -211,8 +213,3 @@ qtHaveModule(positioning) {
HEADERS += location_provider_qt.h
DEFINES += QT_USE_POSITIONING=1
}
-
-qtHaveModule(printsupport) {
- SOURCES += pdfium_printing_wrapper_qt.cpp
- HEADERS += pdfium_printing_wrapper_qt.h
-}
diff --git a/src/core/pdfium_printing_wrapper_qt.cpp b/src/core/pdfium_document_wrapper_qt.cpp
index fceb381af..7c43c77db 100644
--- a/src/core/pdfium_printing_wrapper_qt.cpp
+++ b/src/core/pdfium_document_wrapper_qt.cpp
@@ -36,23 +36,22 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-
-#include "pdfium_printing_wrapper_qt.h"
+#if defined (ENABLE_PDF)
+#include "pdfium_document_wrapper_qt.h"
#include <QtCore/qhash.h>
#include <QtGui/qimage.h>
#include <QtGui/qpainter.h>
-#include <QtPrintSupport/qprinter.h>
#include "third_party/pdfium/public/fpdf_doc.h"
#include "third_party/pdfium/public/fpdfview.h"
namespace QtWebEngineCore {
-int PdfiumPrintingWrapperQt::m_libraryUsers = 0;
+int PdfiumDocumentWrapperQt::m_libraryUsers = 0;
-class PDFiumPageWrapper {
+class QWEBENGINE_EXPORT PdfiumPageWrapperQt {
public:
- PDFiumPageWrapper(void *data, int pageIndex, int targetWidth, int targetHeight)
+ PdfiumPageWrapperQt(void *data, int pageIndex, int targetWidth, int targetHeight)
: m_pageData(FPDF_LoadPage(data, pageIndex))
, m_width(FPDF_GetPageWidth(m_pageData))
, m_height(FPDF_GetPageHeight(m_pageData))
@@ -61,7 +60,7 @@ public:
{
}
- PDFiumPageWrapper()
+ PdfiumPageWrapperQt()
: m_pageData(nullptr)
, m_width(-1)
, m_height(-1)
@@ -70,7 +69,7 @@ public:
{
}
- virtual ~PDFiumPageWrapper()
+ virtual ~PdfiumPageWrapperQt()
{
FPDF_ClosePage(m_pageData);
}
@@ -125,111 +124,49 @@ private:
};
-PdfiumPrintingWrapperQt::PdfiumPrintingWrapperQt(const void *pdfData, size_t size, const char *password)
+PdfiumDocumentWrapperQt::PdfiumDocumentWrapperQt(const void *pdfData, size_t size, const QSize& imageSize, const char *password)
+ : m_imageSize(imageSize * 2.0)
{
- Q_ASSERT(pdfData);
- Q_ASSERT(size);
- if (m_libraryUsers++ == 0)
- FPDF_InitLibrary();
+ Q_ASSERT(pdfData);
+ Q_ASSERT(size);
+ if (m_libraryUsers++ == 0)
+ FPDF_InitLibrary();
- m_documentHandle = FPDF_LoadMemDocument(pdfData, static_cast<int>(size), password);
- m_pageCount = FPDF_GetPageCount(m_documentHandle);
+ m_documentHandle = FPDF_LoadMemDocument(pdfData, static_cast<int>(size), password);
+ m_pageCount = FPDF_GetPageCount(m_documentHandle);
}
-bool PdfiumPrintingWrapperQt::printOnPrinter(QPrinter &printer)
+QImage PdfiumDocumentWrapperQt::pageAsQImage(size_t index)
{
if (!m_documentHandle || !m_pageCount) {
-#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
- qWarning("Failure to print on printer %ls: invalid document.\n", qUtf16Printable(printer.printerName()));
-#endif
- return false;
- }
-
- int toPage = printer.toPage();
- int fromPage = printer.fromPage();
- bool ascendingOrder = true;
-
- if (fromPage == 0 && toPage == 0) {
- fromPage = 1;
- toPage = m_pageCount;
+ qWarning("Failure to generate QImage from invalid or empty PDF document.");
+ return QImage();
}
- fromPage = qMax(1, fromPage);
- toPage = qMin(m_pageCount, toPage);
- if (printer.pageOrder() == QPrinter::LastPageFirst) {
- qSwap(fromPage, toPage);
- ascendingOrder = false;
+ if (static_cast<int>(index) >= m_pageCount) {
+ qWarning("Failure to generate QImage from PDF data: index out of bounds.");
+ return QImage();
}
- int documentCopies = printer.copyCount();
- int pageCopies = 1;
- if (printer.collateCopies()) {
- pageCopies = documentCopies;
- documentCopies = 1;
+ PdfiumPageWrapperQt *pageWrapper = nullptr;
+ if (!m_cachedPages.contains(index)) {
+ pageWrapper = new PdfiumPageWrapperQt(m_documentHandle, index,
+ m_imageSize.width(), m_imageSize.height());
+ m_cachedPages.insert(index, pageWrapper);
+ } else {
+ pageWrapper = m_cachedPages.value(index);
}
- QRect printerPageRect = printer.pageRect();
- int doubledPrinterWidth = 2 * printerPageRect.width();
- int doubledPrinterHeight = 2 * printerPageRect.height();
-
- QPainter painter;
- if (!painter.begin(&printer)) {
-#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
- qWarning("Failure to print on printer %ls: Could not open printer for painting.\n", qUtf16Printable(printer.printerName()));
-#endif
- return false;
- }
-
- QHash<int, PDFiumPageWrapper*> cachedPages;
- for (int printedDocuments = 0; printedDocuments < documentCopies; printedDocuments++) {
- int currentPageIndex = fromPage;
- while (true) {
- for (int printedPages = 0; printedPages < pageCopies; printedPages++) {
- if (printer.printerState() == QPrinter::Aborted
- || printer.printerState() == QPrinter::Error)
- return false;
-
- PDFiumPageWrapper *currentPageWrapper;
- if (!cachedPages.contains(currentPageIndex - 1)) {
- currentPageWrapper
- = new PDFiumPageWrapper(m_documentHandle, currentPageIndex - 1
- , doubledPrinterWidth, doubledPrinterHeight);
- cachedPages.insert(currentPageIndex - 1, currentPageWrapper);
- } else {
- currentPageWrapper = cachedPages.value(currentPageIndex - 1);
- }
-
- QImage currentImage = currentPageWrapper->image();
- painter.drawImage(printerPageRect, currentImage, currentImage.rect());
- if (printedPages < pageCopies - 1)
- printer.newPage();
- }
-
- if (currentPageIndex == toPage)
- break;
-
- if (ascendingOrder)
- currentPageIndex++;
- else
- currentPageIndex--;
-
- printer.newPage();
- }
- if (printedDocuments < documentCopies - 1)
- printer.newPage();
- }
- painter.end();
-
- qDeleteAll(cachedPages);
-
- return true;
+ return pageWrapper->image();
}
-PdfiumPrintingWrapperQt::~PdfiumPrintingWrapperQt()
+PdfiumDocumentWrapperQt::~PdfiumDocumentWrapperQt()
{
+ qDeleteAll(m_cachedPages);
FPDF_CloseDocument(m_documentHandle);
if (--m_libraryUsers == 0)
FPDF_DestroyLibrary();
}
}
+#endif // defined (ENABLE_PDF)
diff --git a/src/core/pdfium_printing_wrapper_qt.h b/src/core/pdfium_document_wrapper_qt.h
index 3aaf2b461..42ac94a28 100644
--- a/src/core/pdfium_printing_wrapper_qt.h
+++ b/src/core/pdfium_document_wrapper_qt.h
@@ -37,30 +37,35 @@
**
****************************************************************************/
-#ifndef PDFIUM_PRINTING_WRAPPER_QT_H
-#define PDFIUM_PRINTING_WRAPPER_QT_H
+#ifndef PDFIUM_DOCUMENT_WRAPPER_QT_H
+#define PDFIUM_DOCUMENT_WRAPPER_QT_H
-#include <QtCore/qglobal.h>
+#if defined(ENABLE_PDF)
+#include "qtwebenginecoreglobal.h"
-QT_BEGIN_NAMESPACE
-class QPrinter;
-QT_END_NAMESPACE
+#include <QtCore/qglobal.h>
+#include <QtCore/qhash.h>
+#include <QtGui/qimage.h>
namespace QtWebEngineCore {
+class PdfiumPageWrapperQt;
-class PdfiumPrintingWrapperQt
+class QWEBENGINE_EXPORT PdfiumDocumentWrapperQt
{
public:
- PdfiumPrintingWrapperQt(const void *pdfData, size_t size, const char *password = nullptr);
- virtual ~PdfiumPrintingWrapperQt();
- bool printOnPrinter(QPrinter &printer);
+ PdfiumDocumentWrapperQt(const void *pdfData, size_t size, const QSize &imageSize, const char *password = nullptr);
+ virtual ~PdfiumDocumentWrapperQt();
+ QImage pageAsQImage(size_t index);
int pageCount() const { return m_pageCount; }
private:
static int m_libraryUsers;
- void *m_documentHandle;
int m_pageCount;
+ void *m_documentHandle;
+ QSize m_imageSize;
+ QHash<int, PdfiumPageWrapperQt*> m_cachedPages;
};
} // namespace QtWebEngineCore
-#endif // PDFIUM_PRINTING_WRAPPER_QT_H
+#endif // defined (ENABLE_PDF)
+#endif // PDFIUM_DOCUMENT_WRAPPER_QT_H
diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp
index fadbd6d2e..cafaad93d 100644
--- a/src/core/web_contents_adapter.cpp
+++ b/src/core/web_contents_adapter.cpp
@@ -50,7 +50,7 @@
#include "browser_context_qt.h"
#include "download_manager_delegate_qt.h"
#include "media_capture_devices_dispatcher.h"
-#include "pdfium_printing_wrapper_qt.h"
+#include "pdfium_document_wrapper_qt.h"
#include "print_view_manager_qt.h"
#include "qwebenginecallback_p.h"
#include "renderer_host/web_channel_ipc_transport_host.h"
@@ -92,9 +92,6 @@
#include <QtGui/qaccessible.h>
#include <QtGui/qdrag.h>
#include <QtGui/qpixmap.h>
-#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER)
-#include <QtPrintSupport/qprinter.h>
-#endif // QT_NO_PRINTER
#include <QtWebChannel/QWebChannel>
namespace QtWebEngineCore {
@@ -188,21 +185,9 @@ static void callbackOnEvaluateJS(WebContentsAdapterClient *adapterClient, quint6
static void callbackOnPrintingFinished(WebContentsAdapterClient *adapterClient, int requestId, const std::vector<char>& result)
{
- if (requestId) {
+ if (requestId)
adapterClient->didPrintPage(requestId, QByteArray(result.data(), result.size()));
- }
-}
-
-#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER)
-static void callbackOnPrintingOnPrinterFinished(WebContentsAdapterClient *adapterClient, int requestId, QPrinter *printer, const std::vector<char> &result)
-{
- if (requestId) {
- PdfiumPrintingWrapperQt printWrapper(result.data(), result.size());
- bool printerResult = printWrapper.printOnPrinter(*printer);
- adapterClient->didPrintPageOnPrinter(requestId, printerResult);
- }
}
-#endif // QT_NO_PRINTER
static content::WebContents *createBlankWebContents(WebContentsAdapterClient *adapterClient, content::BrowserContext *browserContext)
{
@@ -978,14 +963,14 @@ void WebContentsAdapter::printToPDF(const QPageLayout &pageLayout, const QString
#endif // if defined(ENABLE_BASIC_PRINTING)
}
-quint64 WebContentsAdapter::printToPDFCallbackResult(const QPageLayout &pageLayout)
+quint64 WebContentsAdapter::printToPDFCallbackResult(const QPageLayout &pageLayout, const bool colorMode)
{
#if defined(ENABLE_BASIC_PRINTING)
Q_D(WebContentsAdapter);
PrintViewManagerQt::PrintToPDFCallback callback = base::Bind(&callbackOnPrintingFinished
, d->adapterClient
, d->nextRequestId);
- PrintViewManagerQt::FromWebContents(webContents())->PrintToPDFWithCallback(pageLayout, true
+ PrintViewManagerQt::FromWebContents(webContents())->PrintToPDFWithCallback(pageLayout, colorMode
, callback);
return d->nextRequestId++;
#else
@@ -993,23 +978,6 @@ quint64 WebContentsAdapter::printToPDFCallbackResult(const QPageLayout &pageLayo
#endif // if defined(ENABLE_BASIC_PRINTING)
}
-#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER)
-quint64 WebContentsAdapter::printOnPrinterCallbackResult(QPrinter *printer)
-{
-#if defined(ENABLE_BASIC_PRINTING)
- Q_D(WebContentsAdapter);
- PrintViewManagerQt::PrintToPDFCallback callback
- = base::Bind(&callbackOnPrintingOnPrinterFinished, d->adapterClient
- , d->nextRequestId, printer);
- PrintViewManagerQt::FromWebContents(webContents())->PrintToPDFWithCallback(
- printer->pageLayout(), printer->colorMode() == QPrinter::Color, callback);
- return d->nextRequestId++;
-#else
- return 0;
-#endif // if defined(ENABLE_BASIC_PRINTING)
-}
-#endif // QT_NO_PRINTER
-
QPointF WebContentsAdapter::lastScrollOffset() const
{
Q_D(const WebContentsAdapter);
diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h
index 7a109770e..3befe6d27 100644
--- a/src/core/web_contents_adapter.h
+++ b/src/core/web_contents_adapter.h
@@ -58,9 +58,6 @@ class QAccessibleInterface;
class QDragEnterEvent;
class QDragMoveEvent;
class QPageLayout;
-#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER)
-class QPrinter;
-#endif // QT_NO_PRINTER
class QString;
class QWebChannel;
QT_END_NAMESPACE
@@ -175,11 +172,7 @@ public:
void leaveDrag();
void initUpdateDragCursorMessagePollingTimer();
void printToPDF(const QPageLayout&, const QString&);
- quint64 printToPDFCallbackResult(const QPageLayout &);
-
-#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER)
- quint64 printOnPrinterCallbackResult(QPrinter *printer);
-#endif
+ quint64 printToPDFCallbackResult(const QPageLayout &, const bool colorMode = true);
// meant to be used within WebEngineCore only
content::WebContents *webContents() const;
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index 85a379409..4e15df753 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -347,9 +347,6 @@ public:
virtual void didFetchDocumentInnerText(quint64 requestId, const QString& result) = 0;
virtual void didFindText(quint64 requestId, int matchCount) = 0;
virtual void didPrintPage(quint64 requestId, const QByteArray &result) = 0;
-#if !defined(QT_NO_WIDGETS) && !defined(QT_NO_PRINTER)
- virtual void didPrintPageOnPrinter(quint64 requestId, bool result) = 0;
-#endif
virtual void passOnFocus(bool reverse) = 0;
// returns the last QObject (QWidget/QQuickItem) based object in the accessibility
// hierarchy before going into the BrowserAccessibility tree