summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2014-02-10 18:04:33 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-13 14:28:04 +0100
commit324706a5fe9fbfd5aeaef54387dd4b08159a92a0 (patch)
tree5a99ceb64b794890fd339d0e67ea6fee5ed79abf /src/core
parent9cf0007b6ff49305550754babaeb67eb85c8d5ef (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/core')
-rw-r--r--src/core/web_contents_adapter.cpp25
-rw-r--r--src/core/web_contents_adapter.h2
-rw-r--r--src/core/web_contents_adapter_client.h1
-rw-r--r--src/core/web_contents_delegate_qt.cpp9
-rw-r--r--src/core/web_contents_delegate_qt.h1
5 files changed, 38 insertions, 0 deletions
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 <QDir>
#include <QGuiApplication>
@@ -173,6 +174,7 @@ public:
scoped_ptr<QtRenderViewObserverHost> 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);
diff --git a/src/core/web_contents_adapter.h b/src/core/web_contents_adapter.h
index 56e39ba32..4cef56103 100644
--- a/src/core/web_contents_adapter.h
+++ b/src/core/web_contents_adapter.h
@@ -89,6 +89,8 @@ public:
quint64 runJavaScriptCallbackResult(const QString &javaScript, const QString &xPath);
quint64 fetchDocumentMarkup();
quint64 fetchDocumentInnerText();
+ quint64 findText(const QString &subString, bool caseSensitively, bool findBackward);
+ void stopFinding();
void wasShown();
void wasHidden();
diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h
index 778446a12..f56e31a71 100644
--- a/src/core/web_contents_adapter_client.h
+++ b/src/core/web_contents_adapter_client.h
@@ -136,6 +136,7 @@ public:
virtual void didRunJavaScript(quint64 requestId, const QVariant& result) = 0;
virtual void didFetchDocumentMarkup(quint64 requestId, const QString& result) = 0;
virtual void didFetchDocumentInnerText(quint64 requestId, const QString& result) = 0;
+ virtual void didFindText(quint64 requestId, int matchCount) = 0;
virtual void passOnFocus(bool reverse) = 0;
virtual void javaScriptConsoleMessage(int level, const QString& message, int lineNumber, const QString& sourceID) = 0;
};
diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp
index 16ec54afd..c0b050de6 100644
--- a/src/core/web_contents_delegate_qt.cpp
+++ b/src/core/web_contents_delegate_qt.cpp
@@ -166,3 +166,12 @@ bool WebContentsDelegateQt::AddMessageToConsole(content::WebContents *source, in
m_viewClient->javaScriptConsoleMessage(static_cast<int>(level), toQt(message), static_cast<int>(line_no), toQt(source_id));
return false;
}
+
+void WebContentsDelegateQt::FindReply(content::WebContents *source, int request_id, int number_of_matches, const gfx::Rect& selection_rect, int active_match_ordinal, bool final_update)
+{
+ Q_UNUSED(source)
+ Q_UNUSED(selection_rect)
+ Q_UNUSED(active_match_ordinal)
+ if (final_update)
+ m_viewClient->didFindText(request_id, number_of_matches);
+}
diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h
index 460bb9ec2..4c8701945 100644
--- a/src/core/web_contents_delegate_qt.h
+++ b/src/core/web_contents_delegate_qt.h
@@ -77,6 +77,7 @@ public:
virtual bool IsFullscreenForTabOrPending(const content::WebContents* web_contents) const Q_DECL_OVERRIDE;
virtual void RunFileChooser(content::WebContents *, const content::FileChooserParams &params) Q_DECL_OVERRIDE;
virtual bool AddMessageToConsole(content::WebContents* source, int32 level, const string16& message, int32 line_no, const string16& source_id) Q_DECL_OVERRIDE;
+ virtual void FindReply(content::WebContents *source, int request_id, int number_of_matches, const gfx::Rect& selection_rect, int active_match_ordinal, bool final_update) Q_DECL_OVERRIDE;
private:
WebContentsAdapterClient *m_viewClient;