From 7cbd4ebf240ea720b70851fd40945291d69add16 Mon Sep 17 00:00:00 2001 From: Michal Klocek <michal.klocek@qt.io> Date: Mon, 19 Dec 2016 18:57:12 +0100 Subject: [PATCH] Add print and pdf feature to new configure system Currently printing and pdf are bounded together. Make compilation optional by adding it as a feature. Fix formatting of embedded_linux.pri Task-number: QTBUG-57731 Task-number: QTBUG-58108 Change-Id: I53a2baea656df0a5b6139365ed06385c9ebc5830 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> --- configure.json | 12 ++++++++ src/core/config/common.pri | 12 ++++++++ src/core/config/desktop_linux.pri | 5 +--- src/core/config/embedded_linux.pri | 5 +--- src/core/config/embedded_qnx.pri | 3 -- src/core/config/mac_osx.pri | 5 +--- src/core/config/windows.pri | 5 +--- src/core/core_generator.pro | 22 ++++++++++++-- src/core/qtwebengine.gypi | 10 ------- src/webengine/api/qquickwebengineview.cpp | 2 +- src/webengine/webengine.pro | 2 +- src/webenginewidgets/api/qwebenginepage.cpp | 30 +++++++++++-------- src/webenginewidgets/api/qwebenginepage.h | 7 ++++- src/webenginewidgets/api/qwebenginepage_p.h | 4 +-- src/webenginewidgets/webenginewidgets.pro | 10 ++++--- .../qquickwebengineview.pro | 5 ++++ .../tst_qquickwebengineview.cpp | 4 +++ .../widgets/qwebenginepage/qwebenginepage.pro | 2 +- tools/qmake/mkspecs/features/configure.prf | 4 +-- 19 files changed, 92 insertions(+), 57 deletions(-) diff --git a/configure.json b/configure.json index 7f5f46f72..531a034e6 100644 --- a/configure.json +++ b/configure.json @@ -1,11 +1,15 @@ { "module": "webengine", + "depends": [ + "printsupport" + ], "testDir": "tools/qmake/config.tests", "commandline": { "options": { "alsa": "boolean", + "printing-and-pdf": "boolean", "proprietary-codecs": "boolean", "pulseaudio": "boolean", "spellchecker": "boolean" @@ -51,6 +55,13 @@ "condition": "libs.pulseaudio", "output": [ "privateFeature" ] }, + "printing-and-pdf": { + "label": "Printing and PDF", + "condition": "module.printsupport && features.printer", + "autoDetect": "!features.cross_compile", + "purpose": "Enables printing and output to PDF", + "output": [ "privateFeature" ] + }, "proprietary-codecs": { "label": "Proprietary Codecs", "autoDetect": false, @@ -78,6 +89,7 @@ { "section": "Qt WebEngine", "entries": [ + "printing-and-pdf", "proprietary-codecs", "spellchecker", "system-gn", diff --git a/src/core/config/common.pri b/src/core/config/common.pri index b5bb23684..b125cff93 100644 --- a/src/core/config/common.pri +++ b/src/core/config/common.pri @@ -13,3 +13,15 @@ sanitize_address: GYP_CONFIG += asan=1 sanitize_thread: GYP_CONFIG += tsan=1 sanitize_memory: GYP_CONFIG += msan=1 sanitize_undefined: GYP_CONFIG += ubsan=1 + +use?(printing) { + GYP_CONFIG += enable_basic_printing=1 enable_print_preview=1 +} else { + GYP_CONFIG += enable_basic_printing=0 enable_print_preview=0 +} + +use?(pdf) { + GYP_CONFIG += enable_pdf=1 +} else { + GYP_CONFIG += enable_pdf=0 +} diff --git a/src/core/config/desktop_linux.pri b/src/core/config/desktop_linux.pri index 23044619b..2a39f7aee 100644 --- a/src/core/config/desktop_linux.pri +++ b/src/core/config/desktop_linux.pri @@ -4,10 +4,7 @@ include(linux.pri) GYP_CONFIG += \ desktop_linux=1 \ - enable_widevine=1 \ - enable_basic_printing=1 \ - enable_print_preview=1 \ - enable_pdf=1 + enable_widevine=1 clang { GYP_CONFIG += werror= diff --git a/src/core/config/embedded_linux.pri b/src/core/config/embedded_linux.pri index 7a909f1e2..e390a158f 100644 --- a/src/core/config/embedded_linux.pri +++ b/src/core/config/embedded_linux.pri @@ -9,16 +9,13 @@ GYP_CONFIG += \ embedded=1 \ enable_autofill_dialog=0 \ enable_automation=0 \ - enable_basic_printing=0 \ enable_captive_portal_detection=0 \ enable_extensions=0 \ enable_google_now=0 \ enable_language_detection=0 \ enable_managed_users=0 \ - enable_pdf=0 \ enable_plugin_installation=0 \ enable_plugins=0 \ - enable_print_preview=0 \ enable_session_service=0 \ enable_task_manager=0 \ enable_themes=0 \ @@ -39,6 +36,6 @@ GYP_CONFIG += \ use_x11=0 \ v8_use_snapshot=false \ want_separate_host_toolset=1 \ - angle_enable_gl=0Â \ + angle_enable_gl=0 WEBENGINE_CONFIG *= reduce_binary_size diff --git a/src/core/config/embedded_qnx.pri b/src/core/config/embedded_qnx.pri index 3effdb816..f24888776 100644 --- a/src/core/config/embedded_qnx.pri +++ b/src/core/config/embedded_qnx.pri @@ -4,9 +4,6 @@ include(common.pri) GYP_CONFIG += \ disable_nacl=1 \ - enable_basic_printing=0 \ - enable_pdf=0 \ - enable_plugins=0 \ enable_webrtc=0 \ use_ash=0 \ use_aura=1 \ diff --git a/src/core/config/mac_osx.pri b/src/core/config/mac_osx.pri index 4111236ed..17f200449 100644 --- a/src/core/config/mac_osx.pri +++ b/src/core/config/mac_osx.pri @@ -25,10 +25,7 @@ GYP_CONFIG += \ mac_deployment_target=\"$${QMAKE_MACOSX_DEPLOYMENT_TARGET}\" \ 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 + enable_widevine=1 # Force touch API is used in 49-based Chromium, which is included starting with 10.10.3 SDK, so we # disable the API usage if the SDK version is lower. diff --git a/src/core/config/windows.pri b/src/core/config/windows.pri index a1c116ff8..51b83ac04 100644 --- a/src/core/config/windows.pri +++ b/src/core/config/windows.pri @@ -6,10 +6,7 @@ GYP_CONFIG += \ disable_nacl=1 \ remoting=0 \ use_ash=0 \ - enable_widevine=1 \ - enable_basic_printing=1 \ - enable_print_preview=1 \ - enable_pdf=1 + enable_widevine=1 # Libvpx build needs additional search path on Windows. GYP_ARGS += "-D qtwe_chromium_obj_dir=\"$$OUT_PWD/$$getConfigDir()/obj/$${getChromiumSrcDir()}\"" diff --git a/src/core/core_generator.pro b/src/core/core_generator.pro index 6071333aa..15e27997a 100644 --- a/src/core/core_generator.pro +++ b/src/core/core_generator.pro @@ -75,7 +75,6 @@ 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 \ @@ -156,7 +155,6 @@ 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 \ @@ -198,6 +196,26 @@ HEADERS = \ web_engine_visited_links_manager.h \ web_event_factory.h + +use?(pdf) { + SOURCES += pdfium_document_wrapper_qt.cpp + HEADERS += pdfium_document_wrapper_qt.h +} + +use?(printing) { + SOURCES += \ + printing_message_filter_qt.cpp \ + print_view_manager_base_qt.cpp \ + print_view_manager_qt.cpp \ + renderer/print_web_view_helper_delegate_qt.cpp + + HEADERS += \ + printing_message_filter_qt.h \ + print_view_manager_base_qt.h \ + print_view_manager_qt.h \ + renderer/print_web_view_helper_delegate_qt.h +} + contains(QT_CONFIG, opengl) { SOURCES += \ yuv_video_node.cpp \ diff --git a/src/core/qtwebengine.gypi b/src/core/qtwebengine.gypi index d0ab01534..5131ce8cc 100644 --- a/src/core/qtwebengine.gypi +++ b/src/core/qtwebengine.gypi @@ -126,16 +126,6 @@ '<(chromium_src_dir)/components/components.gyp:printing_browser', '<(chromium_src_dir)/components/components.gyp:printing_common', '<(chromium_src_dir)/components/components.gyp:printing_renderer', - ], - 'sources': [ - 'printing_message_filter_qt.cpp', - 'print_view_manager_base_qt.cpp', - 'print_view_manager_qt.cpp', - 'printing_message_filter_qt.h', - 'print_view_manager_base_qt.h', - 'print_view_manager_qt.h', - 'renderer/print_web_view_helper_delegate_qt.cpp', - 'renderer/print_web_view_helper_delegate_qt.h', ] }], ['icu_use_data_file_flag==1', { diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index 76d1ca8b5..a19f0be53 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -1326,7 +1326,7 @@ void QQuickWebEngineView::printToPdf(const QString& filePath, PrintedPageSizeId void QQuickWebEngineView::printToPdf(const QJSValue &callback, PrintedPageSizeId pageSizeId, PrintedPageOrientation orientation) { -#if defined (ENABLE_PDF) +#if defined(ENABLE_PDF) Q_D(QQuickWebEngineView); QPageSize layoutSize(static_cast<QPageSize::PageSizeId>(pageSizeId)); QPageLayout::Orientation layoutOrientation = static_cast<QPageLayout::Orientation>(orientation); diff --git a/src/webengine/webengine.pro b/src/webengine/webengine.pro index 2bbf82810..5fa49c77e 100644 --- a/src/webengine/webengine.pro +++ b/src/webengine/webengine.pro @@ -65,7 +65,7 @@ contains(WEBENGINE_CONFIG, use_spellchecker) { DEFINES += ENABLE_SPELLCHECK } -contains(WEBENGINE_CONFIG, enable_pdf) { +use?(pdf) { DEFINES += ENABLE_PDF } diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index ae7b209e4..2af3db414 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -80,9 +80,11 @@ #include <QMenu> #include <QMessageBox> #include <QMimeData> +#if defined(QT_PRINTSUPPORT_LIB) #ifndef QT_NO_PRINTER #include <QPrinter> -#endif +#endif //QT_NO_PRINTER +#endif //QT_PRINTSUPPORT_LIB #include <QStandardPaths> #include <QStyle> #include <QTimer> @@ -96,8 +98,7 @@ using namespace QtWebEngineCore; static const int MaxTooltipLength = 1024; -#ifndef QT_NO_PRINTER -#if defined(ENABLE_PDF) +#if defined(ENABLE_PRINTING) && defined(ENABLE_PDF) static bool printPdfDataOnPrinter(const QByteArray& data, QPrinter& printer) { QRect printerPageRect = printer.pageRect(); @@ -174,8 +175,7 @@ static bool printPdfDataOnPrinter(const QByteArray& data, QPrinter& printer) return true; } -#endif // defined(ENABLE_PDF) -#endif // QT_NO_PRINTER +#endif // defined(ENABLE_PRINTING) && defined(ENABLE_PDF) static QWebEnginePage::WebWindowType toWindowType(WebContentsAdapterClient::WindowOpenDisposition disposition) { @@ -227,7 +227,7 @@ QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile *_profile) , fullscreenMode(false) , webChannel(nullptr) , webChannelWorldId(QWebEngineScript::MainWorld) -#ifndef QT_NO_PRINTER +#if defined(ENABLE_PRINTING) , currentPrinter(nullptr) #endif { @@ -484,7 +484,7 @@ void QWebEnginePagePrivate::didFindText(quint64 requestId, int matchCount) void QWebEnginePagePrivate::didPrintPage(quint64 requestId, const QByteArray &result) { #if defined(ENABLE_PDF) -#ifndef QT_NO_PRINTER +#if defined(ENABLE_PRINTING) // If no currentPrinter is set that means that were printing to PDF only. if (!currentPrinter) { m_callbacks.invoke(requestId, result); @@ -497,7 +497,7 @@ void QWebEnginePagePrivate::didPrintPage(quint64 requestId, const QByteArray &re currentPrinter = nullptr; #else // If print support is disabled, only PDF printing is available. m_callbacks.invoke(requestId, result); -#endif // ifndef QT_NO_PRINTER +#endif // defined(ENABLE_PRINTING) #else // defined(ENABLE_PDF) // we should never enter this branch, but just for safe-keeping... Q_UNUSED(result); @@ -1985,7 +1985,7 @@ void QWebEnginePage::printToPdf(const QString &filePath, const QPageLayout &page { #if defined(ENABLE_PDF) Q_D(const QWebEnginePage); -#ifndef QT_NO_PRINTER +#if defined(ENABLE_PRINTING) if (d->currentPrinter) { #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) qWarning("Cannot print to PDF while at the same time printing on printer %ls", qUtf16Printable(d->currentPrinter->printerName())); @@ -1994,7 +1994,7 @@ void QWebEnginePage::printToPdf(const QString &filePath, const QPageLayout &page #endif return; } -#endif +#endif // ENABLE_PRINTING d->adapter->printToPDF(pageLayout, filePath); #else Q_UNUSED(filePath); @@ -2018,7 +2018,7 @@ void QWebEnginePage::printToPdf(const QWebEngineCallback<const QByteArray&> &res { Q_D(QWebEnginePage); #if defined(ENABLE_PDF) -#ifndef QT_NO_PRINTER +#if defined(ENABLE_PRINTING) if (d->currentPrinter) { #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) qWarning("Cannot print to PDF while at the same time printing on printer %ls", qUtf16Printable(d->currentPrinter->printerName())); @@ -2028,7 +2028,7 @@ void QWebEnginePage::printToPdf(const QWebEngineCallback<const QByteArray&> &res d->m_callbacks.invokeEmpty(resultCallback); return; } -#endif // ifndef QT_NO_PRINTER +#endif // ENABLE_PRINTING quint64 requestId = d->adapter->printToPDFCallbackResult(pageLayout); d->m_callbacks.registerCallback(requestId, resultCallback); #else // if defined(ENABLE_PDF) @@ -2037,6 +2037,7 @@ void QWebEnginePage::printToPdf(const QWebEngineCallback<const QByteArray&> &res #endif // if defined(ENABLE_PDF) } +#if defined(QT_PRINTSUPPORT_LIB) #ifndef QT_NO_PRINTER /*! \fn void QWebEnginePage::print(QPrinter *printer, FunctorOrLambda resultCallback) @@ -2055,6 +2056,7 @@ void QWebEnginePage::print(QPrinter *printer, const QWebEngineCallback<bool> &re { Q_D(QWebEnginePage); #if defined(ENABLE_PDF) +#if defined(ENABLE_PRINTING) if (d->currentPrinter) { #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) qWarning("Cannot print page on printer %ls: Already printing on %ls.", qUtf16Printable(printer->printerName()), qUtf16Printable(d->currentPrinter->printerName())); @@ -2065,6 +2067,7 @@ void QWebEnginePage::print(QPrinter *printer, const QWebEngineCallback<bool> &re return; } d->currentPrinter = printer; +#endif // ENABLE_PRINTING quint64 requestId = d->adapter->printToPDFCallbackResult(printer->pageLayout(), printer->colorMode() == QPrinter::Color); d->m_callbacks.registerCallback(requestId, resultCallback); #else // if defined(ENABLE_PDF) @@ -2072,7 +2075,8 @@ void QWebEnginePage::print(QPrinter *printer, const QWebEngineCallback<bool> &re d->m_callbacks.invokeDirectly(resultCallback, false); #endif // if defined(ENABLE_PDF) } -#endif // QT_NO_PRINTER +#endif // if defined(QT_NO_PRINTER) +#endif // if defined(QT_PRINTSUPPORT_LIB) /*! \since 5.7 diff --git a/src/webenginewidgets/api/qwebenginepage.h b/src/webenginewidgets/api/qwebenginepage.h index 75621304b..bc5799aac 100644 --- a/src/webenginewidgets/api/qwebenginepage.h +++ b/src/webenginewidgets/api/qwebenginepage.h @@ -55,9 +55,12 @@ QT_BEGIN_NAMESPACE class QMenu; +#if defined(QT_PRINTSUPPORT_LIB) #ifndef QT_NO_PRINTER class QPrinter; -#endif +#endif // QT_NO_PRINTER +#endif // QT_PRINTSUPPORT_LIB + class QWebChannel; class QWebEngineContextMenuData; class QWebEngineFullScreenRequest; @@ -283,6 +286,7 @@ public: void printToPdf(const QWebEngineCallback<const QByteArray&> &resultCallback, const QPageLayout &layout = QPageLayout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF())); #endif +#if defined(QT_PRINTSUPPORT_LIB) #ifndef QT_NO_PRINTER #ifdef Q_QDOC void print(QPrinter *printer, FunctorOrLambda resultCallback); @@ -290,6 +294,7 @@ public: void print(QPrinter *printer, const QWebEngineCallback<bool> &resultCallback); #endif // QDOC #endif // QT_NO_PRINTER +#endif // QT_PRINTSUPPORT_LIB const QWebEngineContextMenuData &contextMenuData() const; diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index 99caeac86..c7b805c45 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -179,9 +179,9 @@ public: mutable QtWebEngineCore::CallbackDirectory m_callbacks; mutable QAction *actions[QWebEnginePage::WebActionCount]; -#ifndef QT_NO_PRINTER +#if defined(ENABLE_PRINTING) QPrinter *currentPrinter; -#endif // QT_NO_PRINTER +#endif }; QT_END_NAMESPACE diff --git a/src/webenginewidgets/webenginewidgets.pro b/src/webenginewidgets/webenginewidgets.pro index b60de6e1e..ad79c1ef9 100644 --- a/src/webenginewidgets/webenginewidgets.pro +++ b/src/webenginewidgets/webenginewidgets.pro @@ -52,11 +52,13 @@ contains(WEBENGINE_CONFIG, use_spellchecker) { DEFINES += ENABLE_SPELLCHECK } -contains(WEBENGINE_CONFIG, enable_pdf) { - DEFINES += ENABLE_PDF +use?(printing) { + DEFINES += ENABLE_PRINTING + QT += printsupport } -qtHaveModule(printsupport) { - QT += printsupport +use?(pdf) { + DEFINES += ENABLE_PDF } + load(qt_module) diff --git a/tests/auto/quick/qquickwebengineview/qquickwebengineview.pro b/tests/auto/quick/qquickwebengineview/qquickwebengineview.pro index 36e74a2a8..df9b3e1b7 100644 --- a/tests/auto/quick/qquickwebengineview/qquickwebengineview.pro +++ b/tests/auto/quick/qquickwebengineview/qquickwebengineview.pro @@ -4,3 +4,8 @@ exists($${TARGET}.qrc):RESOURCES += $${TARGET}.qrc QT_PRIVATE += webengine-private gui-private HEADERS += ../shared/util.h + +use?(pdf) { + DEFINES += ENABLE_PDF +} + diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp index 236358e9c..7f808a4e2 100644 --- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp +++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp @@ -499,6 +499,9 @@ void tst_QQuickWebEngineView::setZoomFactor() void tst_QQuickWebEngineView::printToPdf() { +#if !defined(ENABLE_PDF) + QSKIP("ENABLE_PDF"); +#else QTemporaryDir tempDir(QDir::tempPath() + "/tst_qwebengineview-XXXXXX"); QVERIFY(tempDir.isValid()); QQuickWebEngineView *view = webEngineView(); @@ -523,6 +526,7 @@ void tst_QQuickWebEngineView::printToPdf() QList<QVariant> failedArguments = savePdfSpy.takeFirst(); QVERIFY2(failedArguments.at(0).toString() == path, "File path for second saved PDF does not match arguments"); QVERIFY2(failedArguments.at(1).toBool() == false, "Printing to PDF file succeeded though it should fail"); +#endif // !defined(ENABLE_PDF) } void tst_QQuickWebEngineView::stopSettingFocusWhenDisabled() diff --git a/tests/auto/widgets/qwebenginepage/qwebenginepage.pro b/tests/auto/widgets/qwebenginepage/qwebenginepage.pro index df733c473..fef92c311 100644 --- a/tests/auto/widgets/qwebenginepage/qwebenginepage.pro +++ b/tests/auto/widgets/qwebenginepage/qwebenginepage.pro @@ -1,4 +1,4 @@ include(../tests.pri) QT *= core-private gui-private -contains(WEBENGINE_CONFIG, enable_pdf): DEFINES+=QWEBENGINEPAGE_PDFPRINTINGENABLED +contains(WEBENGINE_CONFIG, use_pdf): DEFINES+=QWEBENGINEPAGE_PDFPRINTINGENABLED diff --git a/tools/qmake/mkspecs/features/configure.prf b/tools/qmake/mkspecs/features/configure.prf index bea1c5fdf..3cdcc400b 100644 --- a/tools/qmake/mkspecs/features/configure.prf +++ b/tools/qmake/mkspecs/features/configure.prf @@ -23,6 +23,7 @@ defineTest(runConfigure) { isQtMinimum(5, 8) { include($$QTWEBENGINE_OUT_ROOT/qtwebengine-config.pri) QT_FOR_CONFIG += webengine-private + qtConfig(printing-and-pdf): WEBENGINE_CONFIG += use_printing use_pdf qtConfig(proprietary-codecs): WEBENGINE_CONFIG += use_proprietary_codecs qtConfig(spellchecker): WEBENGINE_CONFIG += use_spellchecker qtConfig(appstore-compliant): WEBENGINE_CONFIG += use_appstore_compliant_code @@ -86,9 +87,6 @@ defineTest(runConfigure) { else: log("System NSS not found, BoringSSL will be used.$${EOL}") } } - !cross_compile { - WEBENGINE_CONFIG += enable_pdf - } isEmpty(skipBuildReason): { cache(CONFIG, add, $$list(webengine_successfully_configured)) -- GitLab