diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-02-10 18:04:33 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-13 14:28:04 +0100 |
commit | 324706a5fe9fbfd5aeaef54387dd4b08159a92a0 (patch) | |
tree | 5a99ceb64b794890fd339d0e67ea6fee5ed79abf /src/webenginewidgets/api/qwebenginepage.cpp | |
parent | 9cf0007b6ff49305550754babaeb67eb85c8d5ef (diff) |
Implement QWebEnginePage::findText
A few changes to the API:
- Return the success result asynchronously.
- FindWrapsAroundDocument and HighlightAllOccurrences are enabled by
defaults and cannot be disabled.
- Found text isn't updating the selection on the page like QtWebKit
did, but triggers a separate state not available. A find count and
current index could be exposed, but isn't in this case to keep the
API delta lower.
This also adds the possibility to pass bool results through the
CallbackDirectory and add a new tst_QWebEnginePage::findTextResult
test since the old test relied on the selection to be updated when
the searched text is found.
Change-Id: I8189b5aea8d832df183c6c1ae03e3f08198a9c45
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/webenginewidgets/api/qwebenginepage.cpp')
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 760a8eff7..ca1c203dd 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -57,6 +57,9 @@ CallbackDirectory::~CallbackDirectory() case CallbackSharedDataPointer::String: (*sharedPtr.stringCallback)(QString()); break; + case CallbackSharedDataPointer::Bool: + (*sharedPtr.boolCallback)(false); + break; default: Q_UNREACHABLE(); } @@ -73,6 +76,11 @@ void CallbackDirectory::registerCallback(quint64 requestId, const QExplicitlySha m_callbackMap.insert(requestId, CallbackSharedDataPointer(callback.data())); } +void CallbackDirectory::registerCallback(quint64 requestId, const QExplicitlySharedDataPointer<BoolCallback> &callback) +{ + m_callbackMap.insert(requestId, CallbackSharedDataPointer(callback.data())); +} + void CallbackDirectory::invoke(quint64 requestId, const QVariant &result) { CallbackSharedDataPointer sharedPtr = m_callbackMap.take(requestId); @@ -91,6 +99,15 @@ void CallbackDirectory::invoke(quint64 requestId, const QString &result) } } +void CallbackDirectory::invoke(quint64 requestId, bool result) +{ + CallbackSharedDataPointer sharedPtr = m_callbackMap.take(requestId); + if (sharedPtr) { + Q_ASSERT(sharedPtr.type == CallbackSharedDataPointer::Bool); + (*sharedPtr.boolCallback)(result); + } +} + void CallbackDirectory::CallbackSharedDataPointer::doRef() { switch (type) { @@ -102,6 +119,9 @@ void CallbackDirectory::CallbackSharedDataPointer::doRef() case String: stringCallback->ref.ref(); break; + case Bool: + boolCallback->ref.ref(); + break; } } @@ -118,6 +138,10 @@ void CallbackDirectory::CallbackSharedDataPointer::doDeref() if (!stringCallback->ref.deref()) delete stringCallback; break; + case Bool: + if (!boolCallback->ref.deref()) + delete boolCallback; + break; } } @@ -251,6 +275,11 @@ void QWebEnginePagePrivate::didFetchDocumentInnerText(quint64 requestId, const Q m_callbacks.invoke(requestId, result); } +void QWebEnginePagePrivate::didFindText(quint64 requestId, int matchCount) +{ + m_callbacks.invoke(requestId, matchCount > 0); +} + void QWebEnginePagePrivate::updateAction(QWebEnginePage::WebAction action) const { #ifdef QT_NO_ACTION @@ -414,6 +443,20 @@ void QWebEnginePage::triggerAction(WebAction action, bool) } } +void QWebEnginePage::findText(const QString &subString, FindFlags options, const QWebEngineCallback<bool> &resultCallback) +{ + Q_D(QWebEnginePage); + if (subString.isEmpty()) { + d->adapter->stopFinding(); + if (resultCallback.d) + (*resultCallback.d)(false); + } else { + quint64 requestId = d->adapter->findText(subString, options & FindCaseSensitively, options & FindBackward); + if (resultCallback.d) + d->m_callbacks.registerCallback(requestId, resultCallback.d); + } +} + void QWebEnginePage::setViewportSize(const QSize &size) const { Q_UNUSED(size) |