summaryrefslogtreecommitdiffstats
path: root/src/webengine
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@theqtcompany.com>2016-05-11 13:43:45 +0200
committerMichal Klocek <michal.klocek@theqtcompany.com>2016-07-02 04:33:41 +0000
commit42504596248a10eb31a5b719e0676b71f55871e4 (patch)
treee7f1008595bb417e2b92bcfbb5bf4c0eb71196bf /src/webengine
parent1e204d3b74fbe275fb4d9fe45bbb011742f828f9 (diff)
Add back spellchecking support
This reverts commit: * d364c05de52f9ab39034e56cac4e0a7981dc541d * e507f140b70f464fb970d2f94357ac588dcc4f03 Moreover it fixes shut down of keyed services, updates versioning of and fixes spellcheck unit test context menu request, which otherwise fails on windows. Change-Id: I9bfc589544cb969abd6d2d7af69531b4c5c907b7 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/webengine')
-rw-r--r--src/webengine/api/qquickwebenginecontextmenudata.cpp34
-rw-r--r--src/webengine/api/qquickwebenginecontextmenudata_p.h7
-rw-r--r--src/webengine/api/qquickwebengineprofile.cpp79
-rw-r--r--src/webengine/api/qquickwebengineprofile.h9
-rw-r--r--src/webengine/api/qquickwebengineview.cpp17
-rw-r--r--src/webengine/api/qquickwebengineview_p.h4
-rw-r--r--src/webengine/plugin/experimental/plugin.cpp5
-rw-r--r--src/webengine/plugin/plugin.cpp2
8 files changed, 153 insertions, 4 deletions
diff --git a/src/webengine/api/qquickwebenginecontextmenudata.cpp b/src/webengine/api/qquickwebenginecontextmenudata.cpp
index 684903ec0..16cb4ff69 100644
--- a/src/webengine/api/qquickwebenginecontextmenudata.cpp
+++ b/src/webengine/api/qquickwebenginecontextmenudata.cpp
@@ -170,6 +170,34 @@ bool QQuickWebEngineContextMenuData::isContentEditable() const
return d ? d->isEditable : false;
}
+/*!
+ \qmlproperty QString WebEngineContextMenuData::misspelledWord
+
+ If the context is a word considered misspelled by the spell-checker, returns the misspelled word.
+
+ \since QtWebEngine 1.4
+*/
+QString QQuickWebEngineContextMenuData::misspelledWord() const
+{
+ if (d)
+ return d->misspelledWord;
+ return QString();
+}
+
+/*!
+ \qmlproperty QStringList WebEngineContextMenuData::spellCheckerSuggestions
+
+ If the context is a word considered misspelled by the spell-checker, returns a list of suggested replacements.
+
+ \since QtWebEngine 1.4
+*/
+QStringList QQuickWebEngineContextMenuData::spellCheckerSuggestions() const
+{
+ if (d)
+ return d->spellCheckerSuggestions;
+ return QStringList();
+}
+
void QQuickWebEngineContextMenuData::update(const QtWebEngineCore::WebEngineContextMenuData &update)
{
const QQuickWebEngineContextMenuData old(d);
@@ -198,6 +226,12 @@ void QQuickWebEngineContextMenuData::update(const QtWebEngineCore::WebEngineCont
if (isContentEditable() != old.isContentEditable())
Q_EMIT isContentEditableChanged();
+
+ if (misspelledWord() != old.misspelledWord())
+ Q_EMIT misspelledWordChanged();
+
+ if (spellCheckerSuggestions() != old.spellCheckerSuggestions())
+ Q_EMIT spellCheckerSuggestionsChanged();
}
QQuickWebEngineContextMenuData::QQuickWebEngineContextMenuData(const QQuickWebEngineContextMenuDataPrivate *p, QObject *parent)
diff --git a/src/webengine/api/qquickwebenginecontextmenudata_p.h b/src/webengine/api/qquickwebenginecontextmenudata_p.h
index aa081cbe6..7175838db 100644
--- a/src/webengine/api/qquickwebenginecontextmenudata_p.h
+++ b/src/webengine/api/qquickwebenginecontextmenudata_p.h
@@ -92,6 +92,8 @@ public:
Q_PROPERTY(QUrl mediaUrl READ mediaUrl NOTIFY mediaUrlChanged)
Q_PROPERTY(MediaType mediaType READ mediaType NOTIFY mediaTypeChanged)
Q_PROPERTY(bool isContentEditable READ isContentEditable NOTIFY isContentEditableChanged)
+ Q_PROPERTY(QString misspelledWord READ misspelledWord NOTIFY misspelledWordChanged FINAL REVISION 1)
+ Q_PROPERTY(QStringList spellCheckerSuggestions READ spellCheckerSuggestions NOTIFY spellCheckerSuggestionsChanged FINAL REVISION 1)
bool isValid() const;
@@ -103,6 +105,9 @@ public:
MediaType mediaType() const;
bool isContentEditable() const;
+ QString misspelledWord() const;
+ QStringList spellCheckerSuggestions() const;
+
Q_SIGNALS:
void isValidChanged();
void positionChanged();
@@ -112,6 +117,8 @@ Q_SIGNALS:
void mediaUrlChanged();
void mediaTypeChanged();
void isContentEditableChanged();
+ Q_REVISION(1) void misspelledWordChanged();
+ Q_REVISION(1) void spellCheckerSuggestionsChanged();
private:
void update(const QtWebEngineCore::WebEngineContextMenuData &update);
diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp
index b39fb02fd..e4141c575 100644
--- a/src/webengine/api/qquickwebengineprofile.cpp
+++ b/src/webengine/api/qquickwebengineprofile.cpp
@@ -614,6 +614,85 @@ QQuickWebEngineProfile *QQuickWebEngineProfile::defaultProfile()
}
/*!
+ \property QQuickWebEngineProfile::spellCheckLanguage
+ \brief the language used by the spell checker.
+
+ \since QtWebEngine 1.4
+*/
+
+/*!
+ \qmlproperty QString WebEngineProfile::spellCheckLanguage
+
+ This property holds the language used by the spell checker.
+ The language should match the name of the \c .bdic dictionary.
+ For example, the \a language \c en-US will load the \c en-US.bdic
+ dictionary file.
+
+ The web engine checks for the \c qtwebengine_dictionaries subdirectory
+ first in the local directory and if it is not found in the Qt
+ installation directory:
+
+ \list
+ \li QCoreApplication::applicationDirPath()/qtwebengine_dictionaries
+ \li [QLibraryInfo::DataPath]/qtwebengine_dictionaries
+ \endlist
+
+ For more information about how to compile \c .bdic dictionaries, see the
+ \l{WebEngine Widgets Spellchecker Example}{Spellchecker Example}.
+
+ \since QtWebEngine 1.4
+*/
+void QQuickWebEngineProfile::setSpellCheckLanguage(const QString &language)
+{
+ Q_D(QQuickWebEngineProfile);
+ if (language != d->browserContext()->spellCheckLanguage()) {
+ d->browserContext()->setSpellCheckLanguage(language);
+ emit spellCheckLanguageChanged();
+ }
+}
+
+/*!
+ \since 5.8
+
+ Returns the language used by the spell checker.
+*/
+QString QQuickWebEngineProfile::spellCheckLanguage() const
+{
+ const Q_D(QQuickWebEngineProfile);
+ return d->browserContext()->spellCheckLanguage();
+}
+
+/*!
+ \property QQuickWebEngineProfile::spellCheckEnabled
+ \brief whether the web engine spell checker is enabled.
+
+ \since QtWebEngine 1.4
+*/
+
+/*!
+ \qmlproperty QString WebEngineProfile::spellCheckEnabled
+
+ This property holds whether the web engine spell checker is enabled.
+
+ \since QtWebEngine 1.4
+*/
+void QQuickWebEngineProfile::setSpellCheckEnabled(bool enable)
+{
+ Q_D(QQuickWebEngineProfile);
+ if (enable != isSpellCheckEnabled()) {
+ d->browserContext()->setSpellCheckEnabled(enable);
+ emit spellCheckEnabledChanged();
+ }
+}
+
+bool QQuickWebEngineProfile::isSpellCheckEnabled() const
+{
+ const Q_D(QQuickWebEngineProfile);
+ return d->browserContext()->isSpellCheckEnabled();
+}
+
+/*!
+
Returns the cookie store for this profile.
*/
QWebEngineCookieStore *QQuickWebEngineProfile::cookieStore() const
diff --git a/src/webengine/api/qquickwebengineprofile.h b/src/webengine/api/qquickwebengineprofile.h
index dc5aa7df8..2b0dbf9d4 100644
--- a/src/webengine/api/qquickwebengineprofile.h
+++ b/src/webengine/api/qquickwebengineprofile.h
@@ -71,6 +71,8 @@ class Q_WEBENGINE_EXPORT QQuickWebEngineProfile : public QObject {
Q_PROPERTY(QString httpAcceptLanguage READ httpAcceptLanguage WRITE setHttpAcceptLanguage NOTIFY httpAcceptLanguageChanged FINAL REVISION 1)
Q_PROPERTY(PersistentCookiesPolicy persistentCookiesPolicy READ persistentCookiesPolicy WRITE setPersistentCookiesPolicy NOTIFY persistentCookiesPolicyChanged FINAL)
Q_PROPERTY(int httpCacheMaximumSize READ httpCacheMaximumSize WRITE setHttpCacheMaximumSize NOTIFY httpCacheMaximumSizeChanged FINAL)
+ Q_PROPERTY(QString spellCheckLanguage READ spellCheckLanguage WRITE setSpellCheckLanguage NOTIFY spellCheckLanguageChanged FINAL REVISION 3)
+ Q_PROPERTY(bool spellCheckEnabled READ isSpellCheckEnabled WRITE setSpellCheckEnabled NOTIFY spellCheckEnabledChanged FINAL REVISION 3)
public:
QQuickWebEngineProfile(QObject *parent = Q_NULLPTR);
@@ -129,6 +131,11 @@ public:
Q_REVISION(2) Q_INVOKABLE void clearHttpCache();
+ Q_REVISION(3) void setSpellCheckLanguage(const QString &language);
+ Q_REVISION(3) QString spellCheckLanguage() const;
+ Q_REVISION(3) void setSpellCheckEnabled(bool enabled);
+ Q_REVISION(3) bool isSpellCheckEnabled() const;
+
static QQuickWebEngineProfile *defaultProfile();
Q_SIGNALS:
@@ -141,6 +148,8 @@ Q_SIGNALS:
void persistentCookiesPolicyChanged();
void httpCacheMaximumSizeChanged();
Q_REVISION(1) void httpAcceptLanguageChanged();
+ Q_REVISION(3) void spellCheckLanguageChanged();
+ Q_REVISION(3) void spellCheckEnabledChanged();
void downloadRequested(QQuickWebEngineDownloadItem *download);
void downloadFinished(QQuickWebEngineDownloadItem *download);
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index ac25cd4d2..b660b06be 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -212,7 +212,16 @@ bool QQuickWebEngineViewPrivate::contextMenuRequested(const WebEngineContextMenu
// Populate our menu
MenuItemHandler *item = 0;
-
+ if (contextMenuData.isContentEditable() && !contextMenuData.spellCheckerSuggestions().isEmpty()) {
+ const QPointer<QQuickWebEngineView> qRef(q);
+ for (int i=0; i < contextMenuData.spellCheckerSuggestions().count() && i < 4; i++) {
+ item = new MenuItemHandler(menu);
+ QString replacement = contextMenuData.spellCheckerSuggestions().at(i);
+ QObject::connect(item, &MenuItemHandler::triggered, [qRef, replacement] { qRef->replaceMisspelledWord(replacement); });
+ ui()->addMenuItem(item, replacement);
+ }
+ ui()->addMenuSeparator(menu);
+ }
if (!data.linkText.isEmpty() && data.linkUrl.isValid()) {
item = new MenuItemHandler(menu);
QObject::connect(item, &MenuItemHandler::triggered, [q] { q->triggerWebAction(QQuickWebEngineView::OpenLinkInThisWindow); });
@@ -1258,6 +1267,12 @@ void QQuickWebEngineView::printToPdf(const QJSValue &callback, PrintedPageSizeId
d->m_callbacks.insert(requestId, callback);
}
+void QQuickWebEngineView::replaceMisspelledWord(const QString &replacement)
+{
+ Q_D(QQuickWebEngineView);
+ d->adapter->replaceMisspelling(replacement);
+}
+
bool QQuickWebEngineView::isFullScreen() const
{
Q_D(const QQuickWebEngineView);
diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h
index b9555d2d9..367497da5 100644
--- a/src/webengine/api/qquickwebengineview_p.h
+++ b/src/webengine/api/qquickwebengineview_p.h
@@ -94,7 +94,7 @@ private:
const bool m_toggleOn;
};
-#define LATEST_WEBENGINEVIEW_REVISION 3
+#define LATEST_WEBENGINEVIEW_REVISION 4
class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineView : public QQuickItem {
Q_OBJECT
@@ -472,6 +472,8 @@ public Q_SLOTS:
Q_REVISION(2) void triggerWebAction(WebAction action);
Q_REVISION(3) void printToPdf(const QString &filePath, PrintedPageSizeId pageSizeId = PrintedPageSizeId::A4, PrintedPageOrientation orientation = PrintedPageOrientation::Portrait);
Q_REVISION(3) void printToPdf(const QJSValue &callback, PrintedPageSizeId pageSizeId = PrintedPageSizeId::A4, PrintedPageOrientation orientation = PrintedPageOrientation::Portrait);
+ Q_REVISION(4) void replaceMisspelledWord(const QString &replacement);
+
private Q_SLOTS:
void lazyInitialize();
diff --git a/src/webengine/plugin/experimental/plugin.cpp b/src/webengine/plugin/experimental/plugin.cpp
index c45bcee43..d4f68d142 100644
--- a/src/webengine/plugin/experimental/plugin.cpp
+++ b/src/webengine/plugin/experimental/plugin.cpp
@@ -72,9 +72,10 @@ public:
tr("Cannot create a separate instance of WebEngineViewport"));
qmlRegisterUncreatableType<const QQuickWebEngineContextMenuData>(uri, 1, 0, "WebEngineContextMenuData",
tr("Cannot create a separate instance of WebEngineContextMenuData"));
-
+ qmlRegisterUncreatableType<const QQuickWebEngineContextMenuData, 1>(uri, 1, 1, "WebEngineContextMenuData",
+ tr("Cannot create a separate instance of WebEngineContextMenuData"));
// Use the latest revision of QQuickWebEngineView when importing QtWebEngine.experimental 1.0
- qmlRegisterRevision<QQuickWebEngineView, LATEST_WEBENGINEVIEW_REVISION>(uri, 1, 0);
+ qmlRegisterRevision<QQuickWebEngineView, LATEST_WEBENGINEVIEW_REVISION>(uri, 1, 1);
}
};
diff --git a/src/webengine/plugin/plugin.cpp b/src/webengine/plugin/plugin.cpp
index 6fae500f3..2f7d2c2c4 100644
--- a/src/webengine/plugin/plugin.cpp
+++ b/src/webengine/plugin/plugin.cpp
@@ -81,9 +81,11 @@ public:
qmlRegisterType<QQuickWebEngineView, 1>(uri, 1, 1, "WebEngineView");
qmlRegisterType<QQuickWebEngineView, 2>(uri, 1, 2, "WebEngineView");
qmlRegisterType<QQuickWebEngineView, 3>(uri, 1, 3, "WebEngineView");
+ qmlRegisterType<QQuickWebEngineView, 4>(uri, 1, 4, "WebEngineView");
qmlRegisterType<QQuickWebEngineProfile>(uri, 1, 1, "WebEngineProfile");
qmlRegisterType<QQuickWebEngineProfile, 1>(uri, 1, 2, "WebEngineProfile");
qmlRegisterType<QQuickWebEngineProfile, 2>(uri, 1, 3, "WebEngineProfile");
+ qmlRegisterType<QQuickWebEngineProfile, 3>(uri, 1, 4, "WebEngineProfile");
qmlRegisterType<QQuickWebEngineScript>(uri, 1, 1, "WebEngineScript");
qmlRegisterUncreatableType<QQuickWebEngineCertificateError>(uri, 1, 1, "WebEngineCertificateError", tr("Cannot create separate instance of WebEngineCertificateError"));
qmlRegisterUncreatableType<QQuickWebEngineDownloadItem>(uri, 1, 1, "WebEngineDownloadItem",