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

Side by Side 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, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/html_viewer/html_frame.h" 5 #include "components/html_viewer/html_frame.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "mojo/common/common_type_converters.h" 43 #include "mojo/common/common_type_converters.h"
44 #include "mojo/converters/geometry/geometry_type_converters.h" 44 #include "mojo/converters/geometry/geometry_type_converters.h"
45 #include "skia/ext/refptr.h" 45 #include "skia/ext/refptr.h"
46 #include "third_party/WebKit/public/platform/Platform.h" 46 #include "third_party/WebKit/public/platform/Platform.h"
47 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" 47 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h"
48 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 48 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
49 #include "third_party/WebKit/public/platform/WebSize.h" 49 #include "third_party/WebKit/public/platform/WebSize.h"
50 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 50 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
51 #include "third_party/WebKit/public/web/WebDocument.h" 51 #include "third_party/WebKit/public/web/WebDocument.h"
52 #include "third_party/WebKit/public/web/WebElement.h" 52 #include "third_party/WebKit/public/web/WebElement.h"
53 #include "third_party/WebKit/public/web/WebFindOptions.h"
53 #include "third_party/WebKit/public/web/WebInputEvent.h" 54 #include "third_party/WebKit/public/web/WebInputEvent.h"
54 #include "third_party/WebKit/public/web/WebKit.h" 55 #include "third_party/WebKit/public/web/WebKit.h"
55 #include "third_party/WebKit/public/web/WebLocalFrame.h" 56 #include "third_party/WebKit/public/web/WebLocalFrame.h"
56 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" 57 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
57 #include "third_party/WebKit/public/web/WebRemoteFrame.h" 58 #include "third_party/WebKit/public/web/WebRemoteFrame.h"
58 #include "third_party/WebKit/public/web/WebRemoteFrameClient.h" 59 #include "third_party/WebKit/public/web/WebRemoteFrameClient.h"
59 #include "third_party/WebKit/public/web/WebScriptSource.h" 60 #include "third_party/WebKit/public/web/WebScriptSource.h"
60 #include "third_party/WebKit/public/web/WebView.h" 61 #include "third_party/WebKit/public/web/WebView.h"
61 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" 62 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h"
62 #include "third_party/skia/include/core/SkCanvas.h" 63 #include "third_party/skia/include/core/SkCanvas.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 } 245 }
245 246
246 blink::WebView* HTMLFrame::web_view() { 247 blink::WebView* HTMLFrame::web_view() {
247 blink::WebWidget* web_widget = 248 blink::WebWidget* web_widget =
248 html_widget_ ? html_widget_->GetWidget() : nullptr; 249 html_widget_ ? html_widget_->GetWidget() : nullptr;
249 return web_widget && web_widget->isWebView() 250 return web_widget && web_widget->isWebView()
250 ? static_cast<blink::WebView*>(web_widget) 251 ? static_cast<blink::WebView*>(web_widget)
251 : nullptr; 252 : nullptr;
252 } 253 }
253 254
255 blink::WebView* HTMLFrame::web_view() const {
256 blink::WebWidget* web_widget =
257 html_widget_ ? html_widget_->GetWidget() : nullptr;
258 return web_widget && web_widget->isWebView()
259 ? static_cast<blink::WebView*>(web_widget)
260 : nullptr;
261 }
262
254 blink::WebWidget* HTMLFrame::GetWebWidget() { 263 blink::WebWidget* HTMLFrame::GetWebWidget() {
255 return html_widget_ ? html_widget_->GetWidget() : nullptr; 264 return html_widget_ ? html_widget_->GetWidget() : nullptr;
256 } 265 }
257 266
258 bool HTMLFrame::IsLocal() const { 267 bool HTMLFrame::IsLocal() const {
259 return web_frame_->isWebLocalFrame(); 268 return web_frame_->isWebLocalFrame();
260 } 269 }
261 270
262 bool HTMLFrame::HasLocalDescendant() const { 271 bool HTMLFrame::HasLocalDescendant() const {
263 if (IsLocal()) 272 if (IsLocal())
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 blink::WebTextDirection direction) { 505 blink::WebTextDirection direction) {
497 // TODO(beng): handle |direction|. 506 // TODO(beng): handle |direction|.
498 mojo::String formatted; 507 mojo::String formatted;
499 if (!title.isNull()) { 508 if (!title.isNull()) {
500 formatted = 509 formatted =
501 mojo::String::From(base::string16(title).substr(0, kMaxTitleChars)); 510 mojo::String::From(base::string16(title).substr(0, kMaxTitleChars));
502 } 511 }
503 server_->TitleChanged(formatted); 512 server_->TitleChanged(formatted);
504 } 513 }
505 514
515 void HTMLFrame::reportFindInFrameMatchCount(
516 int identifier, int count, bool finalUpdate) {
517 server_->OnReportFindInFrameMatchCount(identifier, count, finalUpdate);
518 }
519
520 void HTMLFrame::reportFindInPageSelection(int identifier,
521 int activeMatchOrdinal,
522 const blink::WebRect& selection) {
523 server_->OnReportFindInPageSelection(identifier, activeMatchOrdinal);
524 }
525
506 void HTMLFrame::Bind( 526 void HTMLFrame::Bind(
507 web_view::mojom::FramePtr frame, 527 web_view::mojom::FramePtr frame,
508 mojo::InterfaceRequest<web_view::mojom::FrameClient> frame_client_request) { 528 mojo::InterfaceRequest<web_view::mojom::FrameClient> frame_client_request) {
509 DCHECK(IsLocal()); 529 DCHECK(IsLocal());
510 server_ = frame.Pass(); 530 server_ = frame.Pass();
511 server_.set_connection_error_handler( 531 server_.set_connection_error_handler(
512 base::Bind(&HTMLFrame::Close, base::Unretained(this))); 532 base::Bind(&HTMLFrame::Close, base::Unretained(this)));
513 frame_client_binding_.reset(new mojo::Binding<web_view::mojom::FrameClient>( 533 frame_client_binding_.reset(new mojo::Binding<web_view::mojom::FrameClient>(
514 this, frame_client_request.Pass())); 534 this, frame_client_request.Pass()));
515 } 535 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 web_layer_.reset(); 675 web_layer_.reset();
656 } 676 }
657 677
658 void HTMLFrame::SwapDelegate(HTMLFrameDelegate* delegate) { 678 void HTMLFrame::SwapDelegate(HTMLFrameDelegate* delegate) {
659 DCHECK(IsLocal()); 679 DCHECK(IsLocal());
660 HTMLFrameDelegate* old_delegate = delegate_; 680 HTMLFrameDelegate* old_delegate = delegate_;
661 delegate_ = delegate; 681 delegate_ = delegate;
662 delegate->OnSwap(this, old_delegate); 682 delegate->OnSwap(this, old_delegate);
663 } 683 }
664 684
685 blink::WebElement HTMLFrame::GetFocusedElement() const {
686 if (!web_view())
687 return blink::WebElement();
688 blink::WebFrame* focused_frame = web_view()->focusedFrame();
689 if (focused_frame) {
sky 2015/10/02 16:03:40 Should you only look at focused_frame if it's the
690 blink::WebDocument doc = focused_frame->document();
691 if (!doc.isNull())
692 return doc.focusedElement();
693 }
694
695 return blink::WebElement();
696 }
697
665 HTMLFrame* HTMLFrame::FindFrameWithWebFrame(blink::WebFrame* web_frame) { 698 HTMLFrame* HTMLFrame::FindFrameWithWebFrame(blink::WebFrame* web_frame) {
666 if (web_frame_ == web_frame) 699 if (web_frame_ == web_frame)
667 return this; 700 return this;
668 for (HTMLFrame* child_frame : children_) { 701 for (HTMLFrame* child_frame : children_) {
669 HTMLFrame* result = child_frame->FindFrameWithWebFrame(web_frame); 702 HTMLFrame* result = child_frame->FindFrameWithWebFrame(web_frame);
670 if (result) 703 if (result)
671 return result; 704 return result;
672 } 705 }
673 return nullptr; 706 return nullptr;
674 } 707 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 frame->web_frame_->toWebRemoteFrame()->didStopLoading(); 883 frame->web_frame_->toWebRemoteFrame()->didStopLoading();
851 } 884 }
852 } 885 }
853 886
854 void HTMLFrame::OnDispatchFrameLoadEvent(uint32_t frame_id) { 887 void HTMLFrame::OnDispatchFrameLoadEvent(uint32_t frame_id) {
855 HTMLFrame* frame = frame_tree_manager_->root_->FindFrame(frame_id); 888 HTMLFrame* frame = frame_tree_manager_->root_->FindFrame(frame_id);
856 if (frame && !frame->IsLocal()) 889 if (frame && !frame->IsLocal())
857 frame->web_frame_->toWebRemoteFrame()->DispatchLoadEventForFrameOwner(); 890 frame->web_frame_->toWebRemoteFrame()->DispatchLoadEventForFrameOwner();
858 } 891 }
859 892
893 void HTMLFrame::Find(int32 request_id, const mojo::String& search_text,
894 const FindCallback& callback) {
895 // TODO(erg): We need to synchronize whether we're a singleton frame here
896 // with the parent; we can't trust our state.
897 bool wrap_within_frame = false;
898
899 blink::WebFindOptions options;
900 blink::WebRect selection_rect;
901 bool result = web_frame_->find(request_id,
902 search_text.To<blink::WebString>(),
903 options,
904 wrap_within_frame,
905 &selection_rect);
906 if (!result) {
907 // don't leave text selected as you move to the next frame.
908 web_frame_->executeCommand(blink::WebString::fromUTF8("Unselect"),
909 GetFocusedElement());
910 }
911
912 callback.Run(request_id, search_text, result);
913 }
914
915 void HTMLFrame::StopFinding(bool clear_selection) {
916 // TODO(erg): |clear_selection| isn't correct; this should be a state enum
917 // that lets us STOP_FIND_ACTION_ACTIVATE_SELECTION, too.
918 if (clear_selection) {
919 web_frame_->executeCommand(blink::WebString::fromUTF8("Unselect"),
920 GetFocusedElement());
921 }
922
923 web_frame_->stopFinding(clear_selection);
924 }
925
926 void HTMLFrame::ScopeStringMatches(int32_t request_id,
927 const mojo::String& search_text,
928 bool reset) {
929 blink::WebFindOptions options;
930 web_frame_->scopeStringMatches(request_id,
931 search_text.To<blink::WebString>(),
932 options,
933 reset);
934 }
935
936 void HTMLFrame::CancelPendingScopingEffort() {
937 web_frame_->resetMatchCount();
938 web_frame_->cancelPendingScopingEffort();
939 }
940
860 void HTMLFrame::frameDetached(blink::WebRemoteFrameClient::DetachType type) { 941 void HTMLFrame::frameDetached(blink::WebRemoteFrameClient::DetachType type) {
861 if (type == blink::WebRemoteFrameClient::DetachType::Swap) { 942 if (type == blink::WebRemoteFrameClient::DetachType::Swap) {
862 web_frame_->close(); 943 web_frame_->close();
863 return; 944 return;
864 } 945 }
865 946
866 DCHECK(type == blink::WebRemoteFrameClient::DetachType::Remove); 947 DCHECK(type == blink::WebRemoteFrameClient::DetachType::Remove);
867 FrameDetachedImpl(web_frame_); 948 FrameDetachedImpl(web_frame_);
868 } 949 }
869 950
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 if (!surface_layer_) 1011 if (!surface_layer_)
931 return; 1012 return;
932 1013
933 surface_layer_->SetSurfaceId( 1014 surface_layer_->SetSurfaceId(
934 cc::SurfaceId(owned_view_->view()->id()), 1015 cc::SurfaceId(owned_view_->view()->id()),
935 global_state()->device_pixel_ratio(), 1016 global_state()->device_pixel_ratio(),
936 owned_view_->view()->bounds().To<gfx::Rect>().size()); 1017 owned_view_->view()->bounds().To<gfx::Rect>().size());
937 } 1018 }
938 1019
939 } // namespace mojo 1020 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698