Chromium Code Reviews| 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..4aa588937231dc7f1550c155be484f18fbf23f4d 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" |
| @@ -503,6 +504,18 @@ 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 +675,26 @@ void HTMLFrame::SwapDelegate(HTMLFrameDelegate* delegate) { |
| delegate->OnSwap(this, old_delegate); |
| } |
| +blink::WebElement HTMLFrame::GetFocusedElement() { |
| + if (!web_view()) |
| + return blink::WebElement(); |
| + |
| + HTMLFrame* frame = this; |
| + while (frame) { |
| + if (frame->web_view()) { |
| + if (frame->web_view()->focusedFrame() == web_frame_) { |
| + blink::WebDocument doc = web_frame_->document(); |
| + if (!doc.isNull()) |
| + return doc.focusedElement(); |
| + } |
| + return blink::WebElement(); |
| + } |
| + frame = frame->parent(); |
| + } |
| + |
| + return blink::WebElement(); |
| +} |
| + |
| HTMLFrame* HTMLFrame::FindFrameWithWebFrame(blink::WebFrame* web_frame) { |
| if (web_frame_ == web_frame) |
| return this; |
| @@ -857,6 +890,50 @@ void HTMLFrame::OnDispatchFrameLoadEvent(uint32_t frame_id) { |
| frame->web_frame_->toWebRemoteFrame()->DispatchLoadEventForFrameOwner(); |
| } |
| +void HTMLFrame::Find(int32 request_id, |
| + const mojo::String& search_text, |
|
sky
2015/10/05 15:55:08
What should happen if search_text is empty? Either
Elliot Glaysher
2015/10/05 20:43:50
When search text is empty (this happens all the ti
|
| + 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(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"), |
|
sky
2015/10/05 15:55:08
What happens if Find() was invoked, something was
Elliot Glaysher
2015/10/05 20:43:50
Added check to ensure focused element is part of w
|
| + 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(); |