From 324706a5fe9fbfd5aeaef54387dd4b08159a92a0 Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Mon, 10 Feb 2014 18:04:33 +0100 Subject: 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 --- src/core/web_contents_adapter.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/core/web_contents_adapter.cpp') diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 82d6ed26f..be68e6ef4 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -59,6 +59,7 @@ #include "content/public/common/renderer_preferences.h" #include "content/public/common/url_constants.h" #include "ui/shell_dialogs/selected_file_info.h" +#include "third_party/WebKit/public/web/WebFindOptions.h" #include #include @@ -173,6 +174,7 @@ public: scoped_ptr renderViewObserverHost; WebContentsAdapterClient *adapterClient; quint64 lastRequestId; + QString lastSearchedString; }; WebContentsAdapterPrivate::WebContentsAdapterPrivate(WebContentsAdapterClient::RenderingMode renderingMode) @@ -429,6 +431,29 @@ quint64 WebContentsAdapter::fetchDocumentInnerText() return d->lastRequestId; } +quint64 WebContentsAdapter::findText(const QString &subString, bool caseSensitively, bool findBackward) +{ + Q_D(WebContentsAdapter); + WebKit::WebFindOptions options; + options.forward = !findBackward; + options.matchCase = caseSensitively; + options.findNext = subString == d->lastSearchedString; + d->lastSearchedString = subString; + + // Find already allows a request ID as input, but only as an int. + // Use the same counter but mod it to MAX_INT, this keeps the same likeliness of request ID clashing. + int shrunkRequestId = ++d->lastRequestId & 0x7fffffff; + d->webContents->GetRenderViewHost()->Find(shrunkRequestId, toString16(subString), options); + return shrunkRequestId; +} + +void WebContentsAdapter::stopFinding() +{ + Q_D(WebContentsAdapter); + d->lastSearchedString = QString(); + d->webContents->GetRenderViewHost()->StopFinding(content::STOP_FIND_ACTION_CLEAR_SELECTION); +} + void WebContentsAdapter::wasShown() { Q_D(WebContentsAdapter); -- cgit v1.2.3