Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(374)

Unified Diff: components/html_viewer/html_frame.cc

Issue 1371773003: mandoline: Add find in page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to ToT to fix patch failure. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/html_viewer/html_frame.cc
diff --git a/components/html_viewer/html_frame.cc b/components/html_viewer/html_frame.cc
index 19be8ee782549531875b450ed3897fb9ef242c04..236ac0b667d0148d86157ef392f4a82f830f3a47 100644
--- a/components/html_viewer/html_frame.cc
+++ b/components/html_viewer/html_frame.cc
@@ -50,6 +50,7 @@
#include "third_party/WebKit/public/web/WebConsoleMessage.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
+#include "third_party/WebKit/public/web/WebFindOptions.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "third_party/WebKit/public/web/WebKit.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
@@ -251,6 +252,14 @@ blink::WebView* HTMLFrame::web_view() {
: nullptr;
}
+blink::WebView* HTMLFrame::web_view() const {
+ blink::WebWidget* web_widget =
+ html_widget_ ? html_widget_->GetWidget() : nullptr;
+ return web_widget && web_widget->isWebView()
+ ? static_cast<blink::WebView*>(web_widget)
+ : nullptr;
+}
+
blink::WebWidget* HTMLFrame::GetWebWidget() {
return html_widget_ ? html_widget_->GetWidget() : nullptr;
}
@@ -503,6 +512,17 @@ void HTMLFrame::didReceiveTitle(blink::WebLocalFrame* frame,
server_->TitleChanged(formatted);
}
+void HTMLFrame::reportFindInFrameMatchCount(
+ int identifier, int count, bool finalUpdate) {
+ server_->OnReportFindInFrameMatchCount(identifier, count, finalUpdate);
+}
+
+void HTMLFrame::reportFindInPageSelection(int identifier,
+ int activeMatchOrdinal,
+ const blink::WebRect& selection) {
+ server_->OnReportFindInPageSelection(identifier, activeMatchOrdinal);
+}
+
void HTMLFrame::Bind(
web_view::mojom::FramePtr frame,
mojo::InterfaceRequest<web_view::mojom::FrameClient> frame_client_request) {
@@ -662,6 +682,19 @@ void HTMLFrame::SwapDelegate(HTMLFrameDelegate* delegate) {
delegate->OnSwap(this, old_delegate);
}
+blink::WebElement HTMLFrame::GetFocusedElement() const {
+ if (!web_view())
+ return blink::WebElement();
+ blink::WebFrame* focused_frame = web_view()->focusedFrame();
+ if (focused_frame) {
sky 2015/10/02 16:03:40 Should you only look at focused_frame if it's the
+ blink::WebDocument doc = focused_frame->document();
+ if (!doc.isNull())
+ return doc.focusedElement();
+ }
+
+ return blink::WebElement();
+}
+
HTMLFrame* HTMLFrame::FindFrameWithWebFrame(blink::WebFrame* web_frame) {
if (web_frame_ == web_frame)
return this;
@@ -857,6 +890,54 @@ void HTMLFrame::OnDispatchFrameLoadEvent(uint32_t frame_id) {
frame->web_frame_->toWebRemoteFrame()->DispatchLoadEventForFrameOwner();
}
+void HTMLFrame::Find(int32 request_id, const mojo::String& search_text,
+ const FindCallback& callback) {
+ // TODO(erg): We need to synchronize whether we're a singleton frame here
+ // with the parent; we can't trust our state.
+ bool wrap_within_frame = false;
+
+ blink::WebFindOptions options;
+ blink::WebRect selection_rect;
+ bool result = web_frame_->find(request_id,
+ search_text.To<blink::WebString>(),
+ options,
+ wrap_within_frame,
+ &selection_rect);
+ if (!result) {
+ // don't leave text selected as you move to the next frame.
+ web_frame_->executeCommand(blink::WebString::fromUTF8("Unselect"),
+ GetFocusedElement());
+ }
+
+ callback.Run(request_id, search_text, result);
+}
+
+void HTMLFrame::StopFinding(bool clear_selection) {
+ // TODO(erg): |clear_selection| isn't correct; this should be a state enum
+ // that lets us STOP_FIND_ACTION_ACTIVATE_SELECTION, too.
+ if (clear_selection) {
+ web_frame_->executeCommand(blink::WebString::fromUTF8("Unselect"),
+ GetFocusedElement());
+ }
+
+ web_frame_->stopFinding(clear_selection);
+}
+
+void HTMLFrame::ScopeStringMatches(int32_t request_id,
+ const mojo::String& search_text,
+ bool reset) {
+ blink::WebFindOptions options;
+ web_frame_->scopeStringMatches(request_id,
+ search_text.To<blink::WebString>(),
+ options,
+ reset);
+}
+
+void HTMLFrame::CancelPendingScopingEffort() {
+ web_frame_->resetMatchCount();
+ web_frame_->cancelPendingScopingEffort();
+}
+
void HTMLFrame::frameDetached(blink::WebRemoteFrameClient::DetachType type) {
if (type == blink::WebRemoteFrameClient::DetachType::Swap) {
web_frame_->close();

Powered by Google App Engine
This is Rietveld 408576698