diff options
author | Liang Qi <liang.qi@qt.io> | 2016-08-04 07:29:26 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-08-05 11:35:18 +0200 |
commit | 179463fd2b17343dae291ab6f7617311bcfbdb75 (patch) | |
tree | e32e298ca5d6e2b6e206dab7d42538a6ce68eba1 /src/webenginewidgets/api/qwebenginepage.cpp | |
parent | c8851dd1a77e730bc6a3c17b7c75b1a4c6b41f53 (diff) | |
parent | 336e706cbc839dd7b7c1d461b6b015600b5f009e (diff) |
Merge remote-tracking branch 'origin/5.7' into dev
Also blacklist tst_QWebEnginePage::comboBoxPopupPositionAfterChildMove()
and comboBoxPopupPositionAfterMove().
Conflicts:
.qmake.conf
src/3rdparty
src/core/render_widget_host_view_qt.cpp
src/core/resources/resources.gyp
src/webengine/doc/src/qtwebengine-platform-notes.qdoc
src/webenginewidgets/render_widget_host_view_qt_delegate_widget.cpp
src/webenginewidgets/render_widget_host_view_qt_delegate_widget.h
tests/auto/widgets/qwebenginepage/BLACKLIST
tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
tools/qmake/mkspecs/features/functions.prf
Task-number: QTBUG-55158
Change-Id: I1d73ac9b3ca5293ad3c7e3a56f4c395da930e6f4
Diffstat (limited to 'src/webenginewidgets/api/qwebenginepage.cpp')
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 76 |
1 files changed, 61 insertions, 15 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index be5a39e83..c180699f3 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -84,6 +84,8 @@ #include <QTimer> #include <QUrl> +#include <private/qguiapplication_p.h> + QT_BEGIN_NAMESPACE using namespace QtWebEngineCore; @@ -106,14 +108,35 @@ static QWebEnginePage::WebWindowType toWindowType(WebContentsAdapterClient::Wind } } +QWebEnginePage::WebAction editorActionForKeyEvent(QKeyEvent* event) +{ + static struct { + QKeySequence::StandardKey standardKey; + QWebEnginePage::WebAction action; + } editorActions[] = { + { QKeySequence::Cut, QWebEnginePage::Cut }, + { QKeySequence::Copy, QWebEnginePage::Copy }, + { QKeySequence::Paste, QWebEnginePage::Paste }, + { QKeySequence::Undo, QWebEnginePage::Undo }, + { QKeySequence::Redo, QWebEnginePage::Redo }, + { QKeySequence::SelectAll, QWebEnginePage::SelectAll }, + { QKeySequence::UnknownKey, QWebEnginePage::NoWebAction } + }; + for (int i = 0; editorActions[i].standardKey != QKeySequence::UnknownKey; ++i) + if (event == editorActions[i].standardKey) + return editorActions[i].action; + + return QWebEnginePage::NoWebAction; +} + QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile *_profile) - : adapter(new WebContentsAdapter) + : adapter(QSharedPointer<WebContentsAdapter>::create()) , history(new QWebEngineHistory(new QWebEngineHistoryPrivate(this))) , profile(_profile ? _profile : QWebEngineProfile::defaultProfile()) , settings(new QWebEngineSettings(profile->settings())) , view(0) , isLoading(false) - , scriptCollection(new QWebEngineScriptCollectionPrivate(browserContextAdapter()->userResourceController(), adapter.data())) + , scriptCollection(new QWebEngineScriptCollectionPrivate(browserContextAdapter()->userResourceController(), adapter)) , m_isBeingAdopted(false) , m_backgroundColor(Qt::white) , fullscreenMode(false) @@ -247,11 +270,24 @@ void QWebEnginePagePrivate::focusContainer() void QWebEnginePagePrivate::unhandledKeyEvent(QKeyEvent *event) { +#ifdef Q_OS_OSX + Q_Q(QWebEnginePage); + if (event->type() == QEvent::KeyPress) { + QWebEnginePage::WebAction action = editorActionForKeyEvent(event); + if (action != QWebEnginePage::NoWebAction) { + // Try triggering a registered short-cut + if (QGuiApplicationPrivate::instance()->shortcutMap.tryShortcut(event)) + return; + q->triggerAction(action); + return; + } + } +#endif if (view && view->parentWidget()) QGuiApplication::sendEvent(view->parentWidget(), event); } -void QWebEnginePagePrivate::adoptNewWindow(WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect &initialGeometry) +void QWebEnginePagePrivate::adoptNewWindow(QSharedPointer<WebContentsAdapter> newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect &initialGeometry) { Q_Q(QWebEnginePage); Q_UNUSED(userGesture); @@ -260,6 +296,20 @@ void QWebEnginePagePrivate::adoptNewWindow(WebContentsAdapter *newWebContents, W if (!newPage) return; + if (newPage->d_func() == this) { + // If createWindow returns /this/ we must delay the adoption. + Q_ASSERT(q == newPage); + QTimer::singleShot(0, q, [this, newPage, newWebContents, initialGeometry] () { + adoptNewWindowImpl(newPage, newWebContents, initialGeometry); + }); + } else { + adoptNewWindowImpl(newPage, newWebContents, initialGeometry); + } +} + +void QWebEnginePagePrivate::adoptNewWindowImpl(QWebEnginePage *newPage, + const QSharedPointer<WebContentsAdapter> &newWebContents, const QRect &initialGeometry) +{ // Mark the new page as being in the process of being adopted, so that a second mouse move event // sent by newWebContents->initialize() gets filtered in RenderWidgetHostViewQt::forwardEvent. // The first mouse move event is being sent by q->createWindow(). This is necessary because @@ -272,12 +322,11 @@ void QWebEnginePagePrivate::adoptNewWindow(WebContentsAdapter *newWebContents, W newPage->d_func()->m_isBeingAdopted = true; // Overwrite the new page's WebContents with ours. - if (newPage->d_func() != this) { - newPage->d_func()->adapter = newWebContents; - newWebContents->initialize(newPage->d_func()); - if (!initialGeometry.isEmpty()) - emit newPage->geometryChangeRequested(initialGeometry); - } + newPage->d_func()->adapter = newWebContents; + newWebContents->initialize(newPage->d_func()); + newPage->d_func()->scriptCollection.d->rebindToContents(newWebContents); + if (!initialGeometry.isEmpty()) + emit newPage->geometryChangeRequested(initialGeometry); // Page has finished the adoption process. newPage->d_func()->m_isBeingAdopted = false; @@ -458,16 +507,13 @@ void QWebEnginePagePrivate::_q_webActionTriggered(bool checked) void QWebEnginePagePrivate::recreateFromSerializedHistory(QDataStream &input) { - QExplicitlySharedDataPointer<WebContentsAdapter> newWebContents = WebContentsAdapter::createFromSerializedNavigationHistory(input, this); + QSharedPointer<WebContentsAdapter> newWebContents = WebContentsAdapter::createFromSerializedNavigationHistory(input, this); if (newWebContents) { - // Keep the old adapter referenced so the user-scripts are not - // unregistered immediately. - QExplicitlySharedDataPointer<WebContentsAdapter> oldWebContents = adapter; - adapter = newWebContents.data(); + adapter = std::move(newWebContents); adapter->initialize(this); if (webChannel) adapter->setWebChannel(webChannel, webChannelWorldId); - scriptCollection.d->rebindToContents(adapter.data()); + scriptCollection.d->rebindToContents(adapter); } } |