From 3cec2ccb0ffdd41a41ab55d4c1ba88d4866e71d1 Mon Sep 17 00:00:00 2001 From: Szabolcs David Date: Mon, 22 Jan 2018 15:49:16 +0100 Subject: Use correct margins when printing with QPrinter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Margins were applied two times: PrintViewManagerQt included them when rendering to a temporary PDF, then QPrinter applied them when printing. This patch changes the parameters of PDF generation to not contain the area of margins. This way the user-provided QPrinter can handle it without any kind of customization. Task-number: QTBUG-65715 Change-Id: Ie32785857e5195aa21c6e2ccb7ebd1e6f6ecd954 Reviewed-by: Michael BrĂ¼ning --- src/webenginewidgets/api/qwebenginepage.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/webenginewidgets') diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 438e3ea24..3f585cf78 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -106,8 +106,8 @@ static bool printPdfDataOnPrinter(const QByteArray& data, QPrinter& printer) return false; } - QRect printerPageRect = printer.pageRect(); - PdfiumDocumentWrapperQt pdfiumWrapper(data.constData(), data.size(), printerPageRect.size()); + QSize pageSize = printer.pageRect().size(); + PdfiumDocumentWrapperQt pdfiumWrapper(data.constData(), data.size(), pageSize); int toPage = printer.toPage(); int fromPage = printer.fromPage(); @@ -155,7 +155,8 @@ static bool printPdfDataOnPrinter(const QByteArray& data, QPrinter& printer) if (currentImage.isNull()) return false; - painter.drawImage(printerPageRect, currentImage, currentImage.rect()); + // Painting operations are automatically clipped to the bounds of the drawable part of the page. + painter.drawImage(QRect(0, 0, pageSize.width(), pageSize.height()), currentImage, currentImage.rect()); if (printedPages < pageCopies - 1) printer.newPage(); } -- cgit v1.2.3 From 7644564d754bbee640a091950b77e23586c2d283 Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Tue, 16 Jan 2018 18:44:01 +0100 Subject: Fix crashes of url load qml tests Currently we can get QuickWebEngineViewPrivate::loadFinished while still being in RenderFrameHostImpl::OnDidStopLoading, unfortunately if user connects onLoadingChanged signal with new url load request this will end up in DiscardUnusedFrame and delete on RenderFrameHostImpl which is still on the bottom of the stack. Use QTimer::singleShot to return to the event loop before emitting load handling signals. Post all load handling calls with singleShot to avoid out of order load "signals" delivery in some cases. Emitting signals should be done from WebContentsAdapterClient to make sure the destruction of WebConentAdapterClient prevents emitting signals on already deleted adapter. Task-numbmer: QTBUG-65813 Change-Id: I93263876fb14bd959ba951463c8aeb5155f04a4f Reviewed-by: Allan Sandfeld Jensen --- src/webenginewidgets/api/qwebenginepage.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/webenginewidgets') diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 3f585cf78..ac8e9c667 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -328,7 +328,7 @@ void QWebEnginePagePrivate::loadStarted(const QUrl &provisionalUrl, bool isError return; isLoading = true; - Q_EMIT q->loadStarted(); + QTimer::singleShot(0, q, &QWebEnginePage::loadStarted); updateNavigationActions(); } @@ -346,7 +346,9 @@ void QWebEnginePagePrivate::loadFinished(bool success, const QUrl &url, bool isE if (isErrorPage) { Q_ASSERT(settings->testAttribute(QWebEngineSettings::ErrorPageEnabled)); - Q_EMIT q->loadFinished(false); + QTimer::singleShot(0, q, [q](){ + emit q->loadFinished(false); + }); return; } @@ -356,7 +358,9 @@ void QWebEnginePagePrivate::loadFinished(bool success, const QUrl &url, bool isE // Delay notifying failure until the error-page is done loading. // Error-pages are not loaded on failures due to abort. if (success || errorCode == -3 /* ERR_ABORTED*/ || !settings->testAttribute(QWebEngineSettings::ErrorPageEnabled)) { - Q_EMIT q->loadFinished(success); + QTimer::singleShot(0, q, [q, success](){ + emit q->loadFinished(success); + }); } updateNavigationActions(); } -- cgit v1.2.3