OLD | NEW |
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 last_results_base_(0), | 19 last_results_base_(0), |
| 20 is_key_capture_enabled_(false), |
20 theme_area_height_(0), | 21 theme_area_height_(0), |
21 display_instant_results_(false) { | 22 display_instant_results_(false) { |
22 } | 23 } |
23 | 24 |
24 SearchBox::~SearchBox() { | 25 SearchBox::~SearchBox() { |
25 } | 26 } |
26 | 27 |
27 void SearchBox::SetSuggestions( | 28 void SearchBox::SetSuggestions( |
28 const std::vector<InstantSuggestion>& suggestions) { | 29 const std::vector<InstantSuggestion>& suggestions) { |
29 if (!suggestions.empty() && | 30 if (!suggestions.empty() && |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, | 108 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, |
108 OnDetermineIfPageSupportsInstant) | 109 OnDetermineIfPageSupportsInstant) |
109 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults, | 110 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults, |
110 OnAutocompleteResults) | 111 OnAutocompleteResults) |
111 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed, | 112 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed, |
112 OnUpOrDownKeyPressed) | 113 OnUpOrDownKeyPressed) |
113 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxModeChanged, | 114 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxModeChanged, |
114 OnModeChanged) | 115 OnModeChanged) |
115 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults, | 116 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults, |
116 OnSetDisplayInstantResults) | 117 OnSetDisplayInstantResults) |
| 118 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxKeyCaptureChanged, |
| 119 OnKeyCaptureChange) |
117 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged, | 120 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged, |
118 OnThemeChanged) | 121 OnThemeChanged) |
119 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeAreaHeightChanged, | 122 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeAreaHeightChanged, |
120 OnThemeAreaHeightChanged) | 123 OnThemeAreaHeightChanged) |
121 IPC_MESSAGE_UNHANDLED(handled = false) | 124 IPC_MESSAGE_UNHANDLED(handled = false) |
122 IPC_END_MESSAGE_MAP() | 125 IPC_END_MESSAGE_MAP() |
123 return handled; | 126 return handled; |
124 } | 127 } |
125 | 128 |
126 void SearchBox::DidClearWindowObject(WebKit::WebFrame* frame) { | 129 void SearchBox::DidClearWindowObject(WebKit::WebFrame* frame) { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 200 } |
198 | 201 |
199 void SearchBox::OnUpOrDownKeyPressed(int count) { | 202 void SearchBox::OnUpOrDownKeyPressed(int count) { |
200 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 203 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
201 DVLOG(1) << render_view() << " OnKeyPress: " << count; | 204 DVLOG(1) << render_view() << " OnKeyPress: " << count; |
202 extensions_v8::SearchBoxExtension::DispatchUpOrDownKeyPress( | 205 extensions_v8::SearchBoxExtension::DispatchUpOrDownKeyPress( |
203 render_view()->GetWebView()->mainFrame(), count); | 206 render_view()->GetWebView()->mainFrame(), count); |
204 } | 207 } |
205 } | 208 } |
206 | 209 |
| 210 void SearchBox::OnKeyCaptureChange(bool is_key_capture_enabled) { |
| 211 if (is_key_capture_enabled != is_key_capture_enabled_ && |
| 212 render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 213 is_key_capture_enabled_ = is_key_capture_enabled; |
| 214 DVLOG(1) << render_view() << " OnKeyCaptureChange"; |
| 215 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange( |
| 216 render_view()->GetWebView()->mainFrame()); |
| 217 } |
| 218 } |
| 219 |
207 void SearchBox::OnModeChanged(const chrome::search::Mode& mode) { | 220 void SearchBox::OnModeChanged(const chrome::search::Mode& mode) { |
208 mode_ = mode; | 221 mode_ = mode; |
209 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 222 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
210 DVLOG(1) << render_view() << " OnModeChanged"; | 223 DVLOG(1) << render_view() << " OnModeChanged"; |
211 extensions_v8::SearchBoxExtension::DispatchContextChange( | 224 extensions_v8::SearchBoxExtension::DispatchContextChange( |
212 render_view()->GetWebView()->mainFrame()); | 225 render_view()->GetWebView()->mainFrame()); |
213 } | 226 } |
214 } | 227 } |
215 | 228 |
216 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { | 229 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { |
(...skipping 17 matching lines...) Expand all Loading... |
234 } | 247 } |
235 | 248 |
236 void SearchBox::Reset() { | 249 void SearchBox::Reset() { |
237 query_.clear(); | 250 query_.clear(); |
238 verbatim_ = false; | 251 verbatim_ = false; |
239 selection_start_ = 0; | 252 selection_start_ = 0; |
240 selection_end_ = 0; | 253 selection_end_ = 0; |
241 results_base_ = 0; | 254 results_base_ = 0; |
242 rect_ = gfx::Rect(); | 255 rect_ = gfx::Rect(); |
243 autocomplete_results_.clear(); | 256 autocomplete_results_.clear(); |
| 257 is_key_capture_enabled_ = false; |
244 mode_ = chrome::search::Mode(); | 258 mode_ = chrome::search::Mode(); |
245 theme_info_ = ThemeBackgroundInfo(); | 259 theme_info_ = ThemeBackgroundInfo(); |
246 theme_area_height_ = 0; | 260 theme_area_height_ = 0; |
247 // Don't reset display_instant_results_ to prevent clearing it on committed | 261 // Don't reset display_instant_results_ to prevent clearing it on committed |
248 // results pages in extended mode. Otherwise resetting it is a no-op because | 262 // results pages in extended mode. Otherwise resetting it is a no-op because |
249 // a new loader is created when it changes; see crbug.com/164662. | 263 // a new loader is created when it changes; see crbug.com/164662. |
250 } | 264 } |
OLD | NEW |