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

Side by Side Diff: chrome/renderer/searchbox.cc

Issue 10825304: Creating a new directory chrome/renderer/searchbox and moving appropriate code to it. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removing sky from OWNERS. Created 8 years, 4 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
« no previous file with comments | « chrome/renderer/searchbox.h ('k') | chrome/renderer/searchbox/OWNERS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/renderer/searchbox.h"
6
7 #include "chrome/common/render_messages.h"
8 #include "chrome/renderer/searchbox_extension.h"
9 #include "content/public/renderer/render_view.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
11
12 SearchBox::SearchBox(content::RenderView* render_view)
13 : content::RenderViewObserver(render_view),
14 content::RenderViewObserverTracker<SearchBox>(render_view),
15 verbatim_(false),
16 selection_start_(0),
17 selection_end_(0) {
18 }
19
20 SearchBox::~SearchBox() {
21 }
22
23 void SearchBox::SetSuggestions(const std::vector<string16>& suggestions,
24 InstantCompleteBehavior behavior) {
25 // Explicitly allow empty vector to be sent to the browser.
26 render_view()->Send(new ChromeViewHostMsg_SetSuggestions(
27 render_view()->GetRoutingID(), render_view()->GetPageId(), suggestions,
28 behavior));
29 }
30
31 gfx::Rect SearchBox::GetRect() {
32 // Need to adjust for scale.
33 if (rect_.IsEmpty())
34 return rect_;
35 WebKit::WebView* web_view = render_view()->GetWebView();
36 if (!web_view)
37 return rect_;
38 double zoom = WebKit::WebView::zoomLevelToZoomFactor(web_view->zoomLevel());
39 if (zoom == 0)
40 return rect_;
41 return gfx::Rect(static_cast<int>(static_cast<float>(rect_.x()) / zoom),
42 static_cast<int>(static_cast<float>(rect_.y()) / zoom),
43 static_cast<int>(static_cast<float>(rect_.width()) / zoom),
44 static_cast<int>(static_cast<float>(rect_.height()) / zoom));
45 }
46
47 bool SearchBox::OnMessageReceived(const IPC::Message& message) {
48 bool handled = true;
49 IPC_BEGIN_MESSAGE_MAP(SearchBox, message)
50 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange)
51 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit)
52 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel)
53 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize)
54 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant,
55 OnDetermineIfPageSupportsInstant)
56 IPC_MESSAGE_UNHANDLED(handled = false)
57 IPC_END_MESSAGE_MAP()
58 return handled;
59 }
60
61 void SearchBox::OnChange(const string16& value,
62 bool verbatim,
63 size_t selection_start,
64 size_t selection_end) {
65 value_ = value;
66 verbatim_ = verbatim;
67 selection_start_ = selection_start;
68 selection_end_ = selection_end;
69 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
70 extensions_v8::SearchBoxExtension::DispatchChange(
71 render_view()->GetWebView()->mainFrame());
72 }
73 }
74
75 void SearchBox::OnSubmit(const string16& value) {
76 value_ = value;
77 verbatim_ = true;
78 selection_start_ = selection_end_ = value_.size();
79 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
80 extensions_v8::SearchBoxExtension::DispatchSubmit(
81 render_view()->GetWebView()->mainFrame());
82 }
83 Reset();
84 }
85
86 void SearchBox::OnCancel(const string16& value) {
87 value_ = value;
88 verbatim_ = true;
89 selection_start_ = selection_end_ = value_.size();
90 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
91 extensions_v8::SearchBoxExtension::DispatchCancel(
92 render_view()->GetWebView()->mainFrame());
93 }
94 Reset();
95 }
96
97 void SearchBox::OnResize(const gfx::Rect& bounds) {
98 rect_ = bounds;
99 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
100 extensions_v8::SearchBoxExtension::DispatchResize(
101 render_view()->GetWebView()->mainFrame());
102 }
103 }
104
105 void SearchBox::OnDetermineIfPageSupportsInstant() {
106 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
107 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant(
108 render_view()->GetWebView()->mainFrame());
109 render_view()->Send(new ChromeViewHostMsg_InstantSupportDetermined(
110 render_view()->GetRoutingID(), render_view()->GetPageId(), result));
111 }
112 }
113
114 void SearchBox::Reset() {
115 value_.clear();
116 verbatim_ = false;
117 selection_start_ = selection_end_ = 0;
118 rect_ = gfx::Rect();
119 }
OLDNEW
« no previous file with comments | « chrome/renderer/searchbox.h ('k') | chrome/renderer/searchbox/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698