summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-07-09 16:48:00 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-07-13 13:33:45 +0200
commit56b1f53d9b2927f5ba2a73f85cee59e385bf489d (patch)
tree3113af56066dfb6c4ae8b08cc364b09bfec6b56b
parente4bb4b8bc443fa78c0cd4509cc8ec1251e8296ae (diff)
Update parameters to findText callback
Pick-to: 6.2 Change-Id: I622ff55c1c9b6f9d4818228c75543c3deffa37be Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
-rw-r--r--src/core/api/qwebenginepage.cpp4
-rw-r--r--src/core/api/qwebenginepage.h4
-rw-r--r--src/core/doc/src/qwebenginepage_lgpl.qdoc5
-rw-r--r--src/core/find_text_helper.cpp14
-rw-r--r--src/core/find_text_helper.h10
-rw-r--r--src/webenginewidgets/api/qwebengineview.cpp2
-rw-r--r--src/webenginewidgets/api/qwebengineview.h2
-rw-r--r--src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc5
-rw-r--r--tests/auto/util/util.h5
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp30
10 files changed, 41 insertions, 40 deletions
diff --git a/src/core/api/qwebenginepage.cpp b/src/core/api/qwebenginepage.cpp
index 9943def62..973826efb 100644
--- a/src/core/api/qwebenginepage.cpp
+++ b/src/core/api/qwebenginepage.cpp
@@ -1520,12 +1520,12 @@ void QWebEnginePage::replaceMisspelledWord(const QString &replacement)
d->adapter->replaceMisspelling(replacement);
}
-void QWebEnginePage::findText(const QString &subString, FindFlags options, const std::function<void(bool)> &resultCallback)
+void QWebEnginePage::findText(const QString &subString, FindFlags options, const std::function<void(const QWebEngineFindTextResult &)> &resultCallback)
{
Q_D(QWebEnginePage);
if (!d->adapter->isInitialized()) {
if (resultCallback)
- resultCallback(false);
+ resultCallback(QWebEngineFindTextResult());
return;
}
diff --git a/src/core/api/qwebenginepage.h b/src/core/api/qwebenginepage.h
index 801bcf84d..73b1bfd3a 100644
--- a/src/core/api/qwebenginepage.h
+++ b/src/core/api/qwebenginepage.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -255,7 +255,7 @@ public:
bool event(QEvent*) override;
- void findText(const QString &subString, FindFlags options = {}, const std::function<void(bool)> &resultCallback = std::function<void(bool)>());
+ void findText(const QString &subString, FindFlags options = {}, const std::function<void(const QWebEngineFindTextResult &)> &resultCallback = std::function<void(const QWebEngineFindTextResult &)>());
void setFeaturePermission(const QUrl &securityOrigin, Feature feature, PermissionPolicy policy);
diff --git a/src/core/doc/src/qwebenginepage_lgpl.qdoc b/src/core/doc/src/qwebenginepage_lgpl.qdoc
index bbe1e0110..d250e0356 100644
--- a/src/core/doc/src/qwebenginepage_lgpl.qdoc
+++ b/src/core/doc/src/qwebenginepage_lgpl.qdoc
@@ -472,14 +472,13 @@
*/
/*!
- \fn void QWebEnginePage::findText(const QString &subString, QWebEnginePage::FindFlags options = {}, const std::function<void(bool)> &resultCallback = std::function<void(bool)>)
+ \fn void QWebEnginePage::findText(const QString &subString, QWebEnginePage::FindFlags options = {}, const std::function<void(const QWebEngineFindTextResult &)> &resultCallback = std::function<void(const QWebEngineFindTextResult &)>)
Finds the specified string, \a subString, in the page, using the given \a options.
The findTextFinished() signal is emitted when a string search is completed.
To clear the search highlight, just pass an empty string.
- The \a resultCallback must take a boolean parameter. It will be called with a value of \c true
- if the \a subString was found; otherwise the callback value will be \c false.
+ The \a resultCallback must take a QWebEngineFindTextResult parameter.
\warning We guarantee that the callback (\a resultCallback) is always called, but it might be done
during page destruction. When QWebEnginePage is deleted, the callback is triggered with an invalid
diff --git a/src/core/find_text_helper.cpp b/src/core/find_text_helper.cpp
index b9158aa73..3f0852536 100644
--- a/src/core/find_text_helper.cpp
+++ b/src/core/find_text_helper.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -64,13 +64,13 @@ FindTextHelper::~FindTextHelper()
stopFinding();
}
-void FindTextHelper::startFinding(const QString &findText, bool caseSensitively, bool findBackward, const std::function<void(bool)> &resultCallback)
+void FindTextHelper::startFinding(const QString &findText, bool caseSensitively, bool findBackward, const std::function<void(const QWebEngineFindTextResult &)> &resultCallback)
{
if (findText.isEmpty()) {
stopFinding();
m_viewClient->findTextFinished(QWebEngineFindTextResult());
if (resultCallback)
- resultCallback(false);
+ resultCallback(QWebEngineFindTextResult());
return;
}
@@ -111,7 +111,7 @@ void FindTextHelper::startFinding(const QString &findText, bool caseSensitively,
if (!findNext)
m_webContents->StopFinding(content::STOP_FIND_ACTION_KEEP_SELECTION);
m_viewClient->findTextFinished(QWebEngineFindTextResult());
- invokeResultCallback(m_currentFindRequestId, 0);
+ invokeResultCallback(m_currentFindRequestId, 0, 0);
}
blink::mojom::FindOptionsPtr options = blink::mojom::FindOptions::New();
@@ -149,7 +149,7 @@ void FindTextHelper::handleFindReply(content::WebContents *source, int requestId
Q_ASSERT(m_currentFindRequestId == requestId);
m_lastCompletedFindRequestId = requestId;
m_viewClient->findTextFinished(QWebEngineFindTextResult(numberOfMatches, activeMatch));
- invokeResultCallback(requestId, numberOfMatches);
+ invokeResultCallback(requestId, numberOfMatches, activeMatch);
}
void FindTextHelper::handleLoadCommitted()
@@ -158,7 +158,7 @@ void FindTextHelper::handleLoadCommitted()
m_previousFindText = QString();
}
-void FindTextHelper::invokeResultCallback(int requestId, int numberOfMatches)
+void FindTextHelper::invokeResultCallback(int requestId, int numberOfMatches, int activeMatch)
{
if (m_quickCallbacks.contains(requestId)) {
QJSValue resultCallback = m_quickCallbacks.take(requestId);
@@ -166,7 +166,7 @@ void FindTextHelper::invokeResultCallback(int requestId, int numberOfMatches)
args.append(QJSValue(numberOfMatches));
resultCallback.call(args);
} else if (auto func = m_widgetCallbacks.take(requestId)) {
- func(numberOfMatches > 0);
+ func(QWebEngineFindTextResult(numberOfMatches, activeMatch));
}
}
diff --git a/src/core/find_text_helper.h b/src/core/find_text_helper.h
index 394ea5bb0..cdea3c2f8 100644
--- a/src/core/find_text_helper.h
+++ b/src/core/find_text_helper.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2019 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtWebEngine module of the Qt Toolkit.
@@ -63,6 +63,8 @@ namespace gfx {
class Rect;
}
+QT_FORWARD_DECLARE_CLASS(QWebEngineFindTextResult)
+
namespace QtWebEngineCore {
class WebContentsAdapterClient;
@@ -72,7 +74,7 @@ public:
FindTextHelper(content::WebContents *webContents, WebContentsAdapterClient *viewClient);
~FindTextHelper();
- void startFinding(const QString &findText, bool caseSensitively, bool findBackward, const std::function<void(bool)> &resultCallback);
+ void startFinding(const QString &findText, bool caseSensitively, bool findBackward, const std::function<void(const QWebEngineFindTextResult &)> &resultCallback);
void startFinding(const QString &findText, bool caseSensitively, bool findBackward, const QJSValue &resultCallback);
void startFinding(const QString &findText, bool caseSensitively, bool findBackward);
void stopFinding();
@@ -81,7 +83,7 @@ public:
void handleLoadCommitted();
private:
- void invokeResultCallback(int requestId, int numberOfMatches);
+ void invokeResultCallback(int requestId, int numberOfMatches, int activeMatch);
content::WebContents *m_webContents;
WebContentsAdapterClient *m_viewClient;
@@ -93,7 +95,7 @@ private:
QString m_previousFindText;
QMap<int, QJSValue> m_quickCallbacks;
- QMap<int, std::function<void(bool)>> m_widgetCallbacks;
+ QMap<int, std::function<void(const QWebEngineFindTextResult &)>> m_widgetCallbacks;
};
} // namespace QtWebEngineCore
diff --git a/src/webenginewidgets/api/qwebengineview.cpp b/src/webenginewidgets/api/qwebengineview.cpp
index 85c10dd94..89cc356fe 100644
--- a/src/webenginewidgets/api/qwebengineview.cpp
+++ b/src/webenginewidgets/api/qwebengineview.cpp
@@ -737,7 +737,7 @@ void QWebEngineView::triggerPageAction(QWebEnginePage::WebAction action, bool ch
page()->triggerAction(action, checked);
}
-void QWebEngineView::findText(const QString &subString, QWebEnginePage::FindFlags options, const std::function<void(bool)> &resultCallback)
+void QWebEngineView::findText(const QString &subString, QWebEnginePage::FindFlags options, const std::function<void(const QWebEngineFindTextResult &)> &resultCallback)
{
page()->findText(subString, options, resultCallback);
}
diff --git a/src/webenginewidgets/api/qwebengineview.h b/src/webenginewidgets/api/qwebengineview.h
index 27c29ba3a..fbb230dda 100644
--- a/src/webenginewidgets/api/qwebengineview.h
+++ b/src/webenginewidgets/api/qwebengineview.h
@@ -99,7 +99,7 @@ public:
qreal zoomFactor() const;
void setZoomFactor(qreal factor);
- void findText(const QString &subString, QWebEnginePage::FindFlags options = {}, const std::function<void(bool)> &resultCallback = std::function<void(bool)>());
+ void findText(const QString &subString, QWebEnginePage::FindFlags options = {}, const std::function<void(const QWebEngineFindTextResult &)> &resultCallback = std::function<void(const QWebEngineFindTextResult &)>());
QSize sizeHint() const override;
QWebEngineSettings *settings() const;
diff --git a/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc
index 052ff239f..34aa53278 100644
--- a/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc
+++ b/src/webenginewidgets/doc/src/qwebengineview_lgpl.qdoc
@@ -249,13 +249,12 @@
*/
/*!
- \fn void QWebEngineView::findText(const QString &subString, QWebEnginePage::FindFlags options = {}, const std::function<void(bool)> &resultCallback = std::function<void(bool)>)
+ \fn void QWebEngineView::findText(const QString &subString, QWebEnginePage::FindFlags options = {}, const std::function<void(const QWebEngineFindTextResult &)> &resultCallback = std::function<void(const QWebEngineFindTextResult &)>)
Finds the specified string, \a subString, in the page, using the given \a options.
To clear the selection, just pass an empty string.
- \a resultCallback must take a boolean parameter. It will be called with a value of \c true
- if \a subString was found; otherwise the callback value will be \c false.
+ The \a resultCallback must take a QWebEngineFindTextResult parameter.
\warning We guarantee that the callback (\a resultCallback) is always called, but it might be done
during page destruction. When QWebEnginePage is deleted, the callback is triggered with an invalid
diff --git a/tests/auto/util/util.h b/tests/auto/util/util.h
index cc5f5e8b4..a624a978f 100644
--- a/tests/auto/util/util.h
+++ b/tests/auto/util/util.h
@@ -35,6 +35,7 @@
#include <QEventLoop>
#include <QSignalSpy>
#include <QTimer>
+#include <qwebenginefindtextresult.h>
#include <qwebenginepage.h>
// Disconnect signal on destruction.
@@ -141,9 +142,9 @@ static inline QString toHtmlSync(QWebEnginePage *page)
static inline bool findTextSync(QWebEnginePage *page, const QString &subString)
{
- CallbackSpy<bool> spy;
+ CallbackSpy<QWebEngineFindTextResult> spy;
page->findText(subString, {}, spy.ref());
- return spy.waitForResult();
+ return spy.waitForResult().numberOfMatches() > 0;
}
static inline QVariant evaluateJavaScriptSync(QWebEnginePage *page, const QString &script)
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 0376168a2..db467562a 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -1050,7 +1050,7 @@ void tst_QWebEnginePage::findText()
// Invoking a stopFinding operation will not change or clear the currently selected text,
// if nothing was found beforehand.
{
- CallbackSpy<bool> callbackSpy;
+ CallbackSpy<QWebEngineFindTextResult> callbackSpy;
QSignalSpy signalSpy(m_view->page(), &QWebEnginePage::findTextFinished);
m_view->findText("", {}, callbackSpy.ref());
QVERIFY(callbackSpy.wasCalled());
@@ -1061,10 +1061,10 @@ void tst_QWebEnginePage::findText()
// Invoking a startFinding operation with text that won't be found, will clear the current
// selection.
{
- CallbackSpy<bool> callbackSpy;
+ CallbackSpy<QWebEngineFindTextResult> callbackSpy;
QSignalSpy signalSpy(m_view->page(), &QWebEnginePage::findTextFinished);
m_view->findText("Will not be found", {}, callbackSpy.ref());
- QCOMPARE(callbackSpy.waitForResult(), false);
+ QCOMPARE(callbackSpy.waitForResult().numberOfMatches(), 0);
QTRY_COMPARE(signalSpy.count(), 1);
auto result = signalSpy.takeFirst().value(0).value<QWebEngineFindTextResult>();
QCOMPARE(result.numberOfMatches(), 0);
@@ -1078,10 +1078,10 @@ void tst_QWebEnginePage::findText()
// Invoking a startFinding operation with text that will be found, will clear the current
// selection as well.
{
- CallbackSpy<bool> callbackSpy;
+ CallbackSpy<QWebEngineFindTextResult> callbackSpy;
QSignalSpy signalSpy(m_view->page(), &QWebEnginePage::findTextFinished);
m_view->findText("foo", {}, callbackSpy.ref());
- QVERIFY(callbackSpy.waitForResult());
+ QVERIFY(callbackSpy.waitForResult().numberOfMatches() > 0);
QTRY_COMPARE(signalSpy.count(), 1);
QTRY_VERIFY(m_view->selectedText().isEmpty());
}
@@ -1089,7 +1089,7 @@ void tst_QWebEnginePage::findText()
// Invoking a stopFinding operation after text was found, will set the selected text to the
// found text.
{
- CallbackSpy<bool> callbackSpy;
+ CallbackSpy<QWebEngineFindTextResult> callbackSpy;
QSignalSpy signalSpy(m_view->page(), &QWebEnginePage::findTextFinished);
m_view->findText("", {}, callbackSpy.ref());
QTRY_VERIFY(callbackSpy.wasCalled());
@@ -1149,11 +1149,11 @@ void tst_QWebEnginePage::findTextResult()
void tst_QWebEnginePage::findTextSuccessiveShouldCallAllCallbacks()
{
- CallbackSpy<bool> spy1;
- CallbackSpy<bool> spy2;
- CallbackSpy<bool> spy3;
- CallbackSpy<bool> spy4;
- CallbackSpy<bool> spy5;
+ CallbackSpy<QWebEngineFindTextResult> spy1;
+ CallbackSpy<QWebEngineFindTextResult> spy2;
+ CallbackSpy<QWebEngineFindTextResult> spy3;
+ CallbackSpy<QWebEngineFindTextResult> spy4;
+ CallbackSpy<QWebEngineFindTextResult> spy5;
QSignalSpy loadSpy(m_view, SIGNAL(loadFinished(bool)));
m_view->setHtml(QString("<html><head></head><body><div>abcdefg abcdefg abcdefg abcdefg abcdefg</div></body></html>"));
QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 1, 20000);
@@ -1182,11 +1182,11 @@ void tst_QWebEnginePage::findTextCalledOnMatch()
// CALLBACK
bool callbackCalled = false;
- m_view->page()->findText("foo", {}, [this, &callbackCalled](bool found) {
- QVERIFY(found);
+ m_view->page()->findText("foo", {}, [this, &callbackCalled](QWebEngineFindTextResult result) {
+ QVERIFY(result.numberOfMatches());
- m_view->page()->findText("bar", {}, [&callbackCalled](bool found) {
- QVERIFY(found);
+ m_view->page()->findText("bar", {}, [&callbackCalled](QWebEngineFindTextResult result) {
+ QVERIFY(result.numberOfMatches());
callbackCalled = true;
});
});