summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets
diff options
context:
space:
mode:
authorJüri Valdmann <juri.valdmann@qt.io>2019-07-02 12:43:52 +0200
committerJüri Valdmann <juri.valdmann@qt.io>2019-07-02 12:43:52 +0200
commit57119f16668cf79dec0dbdfbc9a2183f9e5c44fa (patch)
treea9f6c7ec75d91eb8408d02dd2c16eec4a39e0541 /src/webenginewidgets
parentfb430b4e104dd6313a776980b4798f1333193149 (diff)
parentbd864f6418ed164c19a700fc4b6ebab3be431c62 (diff)
Merge remote-tracking branch 'origin/5.13' into dev
Diffstat (limited to 'src/webenginewidgets')
-rw-r--r--src/webenginewidgets/api/qwebenginepage.cpp22
-rw-r--r--src/webenginewidgets/api/qwebenginepage_p.h1
-rw-r--r--src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc8
-rw-r--r--src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc9
-rw-r--r--src/webenginewidgets/printer_worker.cpp40
5 files changed, 66 insertions, 14 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp
index 893200826..4658a4739 100644
--- a/src/webenginewidgets/api/qwebenginepage.cpp
+++ b/src/webenginewidgets/api/qwebenginepage.cpp
@@ -592,6 +592,16 @@ void QWebEnginePagePrivate::updateAction(QWebEnginePage::WebAction action) const
case QWebEnginePage::ViewSource:
enabled = adapter->canViewSource();
break;
+ case QWebEnginePage::Cut:
+ case QWebEnginePage::Copy:
+ case QWebEnginePage::Paste:
+ case QWebEnginePage::Undo:
+ case QWebEnginePage::Redo:
+ case QWebEnginePage::SelectAll:
+ case QWebEnginePage::PasteAndMatchStyle:
+ case QWebEnginePage::Unselect:
+ enabled = adapter->hasFocusedFrame();
+ break;
default:
break;
}
@@ -610,6 +620,18 @@ void QWebEnginePagePrivate::updateNavigationActions()
updateAction(QWebEnginePage::ViewSource);
}
+void QWebEnginePagePrivate::updateEditActions()
+{
+ updateAction(QWebEnginePage::Cut);
+ updateAction(QWebEnginePage::Copy);
+ updateAction(QWebEnginePage::Paste);
+ updateAction(QWebEnginePage::Undo);
+ updateAction(QWebEnginePage::Redo);
+ updateAction(QWebEnginePage::SelectAll);
+ updateAction(QWebEnginePage::PasteAndMatchStyle);
+ updateAction(QWebEnginePage::Unselect);
+}
+
#ifndef QT_NO_ACTION
void QWebEnginePagePrivate::_q_webActionTriggered(bool checked)
{
diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h
index 059da8e4c..acf95a265 100644
--- a/src/webenginewidgets/api/qwebenginepage_p.h
+++ b/src/webenginewidgets/api/qwebenginepage_p.h
@@ -149,6 +149,7 @@ public:
void updateScrollPosition(const QPointF &position) override;
void updateContentsSize(const QSizeF &size) override;
void updateNavigationActions() override;
+ void updateEditActions() override;
void startDragging(const content::DropData &dropData, Qt::DropActions allowedActions,
const QPixmap &pixmap, const QPoint &offset) override;
bool supportsDragging() const override;
diff --git a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
index e33f9f37f..99bbc5162 100644
--- a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
+++ b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc
@@ -112,8 +112,7 @@
Actions only have an effect when they are applicable.
The availability of actions can be be determined by checking
- \l{QAction::}{isEnabled()} on the action returned by action(). Context-dependent
- actions are always enabled.
+ \l{QAction::}{isEnabled()} on the action returned by action().
\value NoWebAction No action is triggered.
\value Back Navigate back in the history of navigated links.
@@ -126,7 +125,10 @@
\value Paste Paste content from the clipboard.
\value Undo Undo the last editing action.
\value Redo Redo the last editing action.
- \value SelectAll Select all content.
+ \value SelectAll Select all content. This action is only enabled when the page's content is focused.
+ The focus can be forced by the JavaScript \c{window.focus()} call, or the
+ \l{QWebEngineSettings::FocusOnNavigationEnabled} {FocusOnNavigationEnabled} setting
+ should be enabled to get automatic focus.
\value PasteAndMatchStyle Paste content from the clipboard with current style.
\value OpenLinkInThisWindow Open the current link in the current window. (Added in Qt 5.6)
diff --git a/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc
index fce1e8d8f..1b7812dff 100644
--- a/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc
+++ b/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2015 The Qt Company Ltd.
+ Copyright (C) 2019 The Qt Company Ltd.
Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
Copyright (C) 2008 Holger Hans Peter Freyther
Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in>
@@ -125,7 +125,11 @@
Sets the content of the web view to the specified \a html content.
External objects, such as stylesheets or images referenced in the HTML
- document, are located relative to \a baseUrl.
+ document, are located relative to \a baseUrl. For external objects to
+ be loaded, \c baseUrl cannot be empty. For example, if \a html
+ is retrieved from \c http://www.example.com/documents/overview.html, which
+ is the base URL, then an image referenced with the relative URL, \c diagram.png,
+ should be at \c{http://www.example.com/documents/diagram.png}.
The HTML document is loaded immediately, whereas external objects are loaded asynchronously.
@@ -156,6 +160,7 @@
is empty, it is assumed that the content is \c{text/plain,charset=US-ASCII}.
External objects referenced in the content are located relative to \a baseUrl.
+ For external objects to be loaded, \c baseUrl cannot be empty.
The data is loaded immediately; external objects are loaded asynchronously.
diff --git a/src/webenginewidgets/printer_worker.cpp b/src/webenginewidgets/printer_worker.cpp
index 3a670ad49..94a862cda 100644
--- a/src/webenginewidgets/printer_worker.cpp
+++ b/src/webenginewidgets/printer_worker.cpp
@@ -65,8 +65,7 @@ void PrinterWorker::print()
return;
}
- QSize pageSize = m_printer->pageRect().size();
- PdfiumDocumentWrapperQt pdfiumWrapper(m_data->constData(), m_data->size(), pageSize);
+ PdfiumDocumentWrapperQt pdfiumWrapper(m_data->constData(), m_data->size());
int toPage = m_printer->toPage();
int fromPage = m_printer->fromPage();
@@ -95,6 +94,10 @@ void PrinterWorker::print()
documentCopies = 1;
}
+ bool isLandscape = pdfiumWrapper.pageIsLandscape(0);
+ QPageLayout::Orientation prevOrientation = m_printer->pageLayout().orientation();
+ m_printer->setPageOrientation(isLandscape ? QPageLayout::Landscape : QPageLayout::Portrait);
+
QPainter painter;
if (!painter.begin(m_printer)) {
qWarning("Failure to print on printer %ls: Could not open printer for painting.",
@@ -104,8 +107,21 @@ void PrinterWorker::print()
}
for (int printedDocuments = 0; printedDocuments < documentCopies; printedDocuments++) {
+ if (printedDocuments > 0)
+ m_printer->newPage();
+
int currentPageIndex = fromPage;
- while (true) {
+
+ for (int i = 0; true; i++) {
+ prevOrientation = m_printer->pageLayout().orientation();
+ isLandscape = pdfiumWrapper.pageIsLandscape(currentPageIndex - 1);
+ m_printer->setPageOrientation(isLandscape ? QPageLayout::Landscape : QPageLayout::Portrait);
+
+ QSize pageSize = m_printer->pageRect().size();
+
+ if (i > 0)
+ m_printer->newPage();
+
for (int printedPages = 0; printedPages < pageCopies; printedPages++) {
if (m_printer->printerState() == QPrinter::Aborted
|| m_printer->printerState() == QPrinter::Error) {
@@ -113,16 +129,24 @@ void PrinterWorker::print()
return;
}
+ if (printedPages > 0)
+ m_printer->newPage();
+
QImage currentImage = pdfiumWrapper.pageAsQImage(currentPageIndex - 1);
if (currentImage.isNull()) {
Q_EMIT resultReady(false);
return;
}
+ QRect targetRect = currentImage.rect();
+ // Scale down currentImage by both width and height to fit into the drawable area of the page.
+ float scaleFactor = (float)pageSize.width() / (float)targetRect.width();
+ targetRect = QRect(0, 0, targetRect.width() * scaleFactor, targetRect.height() * scaleFactor);
+ scaleFactor = (float)pageSize.height() / (float)targetRect.height();
+ targetRect = QRect(0, 0, targetRect.width() * scaleFactor, targetRect.height() * scaleFactor);
+
// 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)
- m_printer->newPage();
+ painter.drawImage(targetRect, currentImage, currentImage.rect());
}
if (currentPageIndex == toPage)
@@ -133,10 +157,8 @@ void PrinterWorker::print()
else
currentPageIndex--;
- m_printer->newPage();
+ m_printer->setPageOrientation(prevOrientation);
}
- if (printedDocuments < documentCopies - 1)
- m_printer->newPage();
}
painter.end();