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

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

Issue 11359198: Implement the Instant extended API startMargin, endMargin, and rtl properties and the onmarginchang… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "chrome/renderer/searchbox/searchbox.h" 5 #include "chrome/renderer/searchbox/searchbox.h"
6 6
7 #include "chrome/common/render_messages.h" 7 #include "chrome/common/render_messages.h"
8 #include "chrome/renderer/searchbox/searchbox_extension.h" 8 #include "chrome/renderer/searchbox/searchbox_extension.h"
9 #include "content/public/renderer/render_view.h" 9 #include "content/public/renderer/render_view.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
11 11
12 SearchBox::SearchBox(content::RenderView* render_view) 12 SearchBox::SearchBox(content::RenderView* render_view)
13 : content::RenderViewObserver(render_view), 13 : content::RenderViewObserver(render_view),
14 content::RenderViewObserverTracker<SearchBox>(render_view), 14 content::RenderViewObserverTracker<SearchBox>(render_view),
15 verbatim_(false), 15 verbatim_(false),
16 selection_start_(0), 16 selection_start_(0),
17 selection_end_(0), 17 selection_end_(0),
18 results_base_(0), 18 results_base_(0),
19 start_margin_(0),
20 end_margin_(0),
19 last_results_base_(0), 21 last_results_base_(0),
20 theme_area_height_(0), 22 theme_area_height_(0),
21 display_instant_results_(false) { 23 display_instant_results_(false) {
22 } 24 }
23 25
24 SearchBox::~SearchBox() { 26 SearchBox::~SearchBox() {
25 } 27 }
26 28
27 void SearchBox::SetSuggestions( 29 void SearchBox::SetSuggestions(
28 const std::vector<InstantSuggestion>& suggestions) { 30 const std::vector<InstantSuggestion>& suggestions) {
(...skipping 19 matching lines...) Expand all
48 void SearchBox::StartCapturingKeyStrokes() { 50 void SearchBox::StartCapturingKeyStrokes() {
49 render_view()->Send(new ChromeViewHostMsg_StartCapturingKeyStrokes( 51 render_view()->Send(new ChromeViewHostMsg_StartCapturingKeyStrokes(
50 render_view()->GetRoutingID(), render_view()->GetPageId())); 52 render_view()->GetRoutingID(), render_view()->GetPageId()));
51 } 53 }
52 54
53 void SearchBox::StopCapturingKeyStrokes() { 55 void SearchBox::StopCapturingKeyStrokes() {
54 render_view()->Send(new ChromeViewHostMsg_StopCapturingKeyStrokes( 56 render_view()->Send(new ChromeViewHostMsg_StopCapturingKeyStrokes(
55 render_view()->GetRoutingID(), render_view()->GetPageId())); 57 render_view()->GetRoutingID(), render_view()->GetPageId()));
56 } 58 }
57 59
58 gfx::Rect SearchBox::GetRect() { 60 int SearchBox::GetStartMargin() const {
59 // Need to adjust for scale. 61 return static_cast<int>(start_margin_ / GetZoom());
60 if (rect_.IsEmpty()) 62 }
61 return rect_; 63
62 WebKit::WebView* web_view = render_view()->GetWebView(); 64 int SearchBox::GetEndMargin() const {
63 if (!web_view) 65 return static_cast<int>(end_margin_ / GetZoom());
64 return rect_; 66 }
65 double zoom = WebKit::WebView::zoomLevelToZoomFactor(web_view->zoomLevel()); 67
66 if (zoom == 0) 68 gfx::Rect SearchBox::GetPopupBounds() const {
67 return rect_; 69 double zoom = GetZoom();
68 return gfx::Rect(static_cast<int>(static_cast<float>(rect_.x()) / zoom), 70 return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom),
69 static_cast<int>(static_cast<float>(rect_.y()) / zoom), 71 static_cast<int>(popup_bounds_.y() / zoom),
70 static_cast<int>(static_cast<float>(rect_.width()) / zoom), 72 static_cast<int>(popup_bounds_.width() / zoom),
71 static_cast<int>(static_cast<float>(rect_.height()) / zoom)); 73 static_cast<int>(popup_bounds_.height() / zoom));
72 } 74 }
73 75
74 const std::vector<InstantAutocompleteResult>& 76 const std::vector<InstantAutocompleteResult>&
75 SearchBox::GetAutocompleteResults() { 77 SearchBox::GetAutocompleteResults() {
76 // Remember the last requested autocomplete_results to account for race 78 // Remember the last requested autocomplete_results to account for race
77 // conditions between autocomplete providers returning new data and the user 79 // conditions between autocomplete providers returning new data and the user
78 // clicking on a suggestion. 80 // clicking on a suggestion.
79 last_autocomplete_results_ = autocomplete_results_; 81 last_autocomplete_results_ = autocomplete_results_;
80 last_results_base_ = results_base_; 82 last_results_base_ = results_base_;
81 return autocomplete_results_; 83 return autocomplete_results_;
(...skipping 14 matching lines...) Expand all
96 int SearchBox::GetThemeAreaHeight() { 98 int SearchBox::GetThemeAreaHeight() {
97 return theme_area_height_; 99 return theme_area_height_;
98 } 100 }
99 101
100 bool SearchBox::OnMessageReceived(const IPC::Message& message) { 102 bool SearchBox::OnMessageReceived(const IPC::Message& message) {
101 bool handled = true; 103 bool handled = true;
102 IPC_BEGIN_MESSAGE_MAP(SearchBox, message) 104 IPC_BEGIN_MESSAGE_MAP(SearchBox, message)
103 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange) 105 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange)
104 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit) 106 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit)
105 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel) 107 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel)
106 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxResize, OnResize) 108 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxPopupResize, OnPopupResize)
109 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMarginChange, OnMarginChange)
107 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, 110 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant,
108 OnDetermineIfPageSupportsInstant) 111 OnDetermineIfPageSupportsInstant)
109 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults, 112 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults,
110 OnAutocompleteResults) 113 OnAutocompleteResults)
111 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed, 114 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed,
112 OnUpOrDownKeyPressed) 115 OnUpOrDownKeyPressed)
113 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxModeChanged, 116 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxModeChanged,
114 OnModeChanged) 117 OnModeChanged)
115 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults, 118 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults,
116 OnSetDisplayInstantResults) 119 OnSetDisplayInstantResults)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 verbatim_ = true; 158 verbatim_ = true;
156 selection_start_ = selection_end_ = query_.size(); 159 selection_start_ = selection_end_ = query_.size();
157 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 160 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
158 DVLOG(1) << render_view() << " OnCancel"; 161 DVLOG(1) << render_view() << " OnCancel";
159 extensions_v8::SearchBoxExtension::DispatchCancel( 162 extensions_v8::SearchBoxExtension::DispatchCancel(
160 render_view()->GetWebView()->mainFrame()); 163 render_view()->GetWebView()->mainFrame());
161 } 164 }
162 Reset(); 165 Reset();
163 } 166 }
164 167
165 void SearchBox::OnResize(const gfx::Rect& bounds) { 168 void SearchBox::OnPopupResize(const gfx::Rect& bounds) {
166 rect_ = bounds; 169 popup_bounds_ = bounds;
167 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 170 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
168 DVLOG(1) << render_view() << " OnResize"; 171 DVLOG(1) << render_view() << " OnPopupResize";
169 extensions_v8::SearchBoxExtension::DispatchResize( 172 extensions_v8::SearchBoxExtension::DispatchResize(
170 render_view()->GetWebView()->mainFrame()); 173 render_view()->GetWebView()->mainFrame());
171 } 174 }
172 } 175 }
173 176
177 void SearchBox::OnMarginChange(int start, int end) {
178 start_margin_ = start;
179 end_margin_ = end;
180 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
181 extensions_v8::SearchBoxExtension::DispatchMarginChange(
182 render_view()->GetWebView()->mainFrame());
183 }
184 }
185
174 void SearchBox::OnDetermineIfPageSupportsInstant() { 186 void SearchBox::OnDetermineIfPageSupportsInstant() {
175 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 187 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
176 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant( 188 bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant(
177 render_view()->GetWebView()->mainFrame()); 189 render_view()->GetWebView()->mainFrame());
178 DVLOG(1) << render_view() << " PageSupportsInstant: " << result; 190 DVLOG(1) << render_view() << " PageSupportsInstant: " << result;
179 render_view()->Send(new ChromeViewHostMsg_InstantSupportDetermined( 191 render_view()->Send(new ChromeViewHostMsg_InstantSupportDetermined(
180 render_view()->GetRoutingID(), render_view()->GetPageId(), result)); 192 render_view()->GetRoutingID(), render_view()->GetPageId(), result));
181 } 193 }
182 } 194 }
183 195
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 234 }
223 235
224 void SearchBox::OnThemeAreaHeightChanged(int height) { 236 void SearchBox::OnThemeAreaHeightChanged(int height) {
225 theme_area_height_ = height; 237 theme_area_height_ = height;
226 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 238 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
227 extensions_v8::SearchBoxExtension::DispatchThemeAreaHeightChange( 239 extensions_v8::SearchBoxExtension::DispatchThemeAreaHeightChange(
228 render_view()->GetWebView()->mainFrame()); 240 render_view()->GetWebView()->mainFrame());
229 } 241 }
230 } 242 }
231 243
244 double SearchBox::GetZoom() const {
245 WebKit::WebView* web_view = render_view()->GetWebView();
246 if (web_view) {
247 double zoom = WebKit::WebView::zoomLevelToZoomFactor(web_view->zoomLevel());
248 if (zoom != 0)
249 return zoom;
250 }
251 return 1.0;
252 }
253
232 void SearchBox::Reset() { 254 void SearchBox::Reset() {
233 query_.clear(); 255 query_.clear();
234 verbatim_ = false; 256 verbatim_ = false;
235 selection_start_ = 0; 257 selection_start_ = 0;
236 selection_end_ = 0; 258 selection_end_ = 0;
237 results_base_ = 0; 259 results_base_ = 0;
238 rect_ = gfx::Rect(); 260 popup_bounds_ = gfx::Rect();
261 start_margin_ = 0;
262 end_margin_ = 0;
239 autocomplete_results_.clear(); 263 autocomplete_results_.clear();
240 mode_ = chrome::search::Mode(); 264 mode_ = chrome::search::Mode();
241 theme_info_ = ThemeBackgroundInfo(); 265 theme_info_ = ThemeBackgroundInfo();
242 theme_area_height_ = 0; 266 theme_area_height_ = 0;
243 // Don't reset display_instant_results_ to prevent clearing it on committed 267 // Don't reset display_instant_results_ to prevent clearing it on committed
244 // results pages in extended mode. Otherwise resetting it is a no-op because 268 // results pages in extended mode. Otherwise resetting it is a no-op because
245 // a new loader is created when it changes; see crbug.com/164662. 269 // a new loader is created when it changes; see crbug.com/164662.
246 } 270 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698