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::OnChange(const string16& query, | 129 void SearchBox::OnChange(const string16& query, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 196 } |
194 | 197 |
195 void SearchBox::OnUpOrDownKeyPressed(int count) { | 198 void SearchBox::OnUpOrDownKeyPressed(int count) { |
196 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 199 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
197 DVLOG(1) << render_view() << " OnKeyPress: " << count; | 200 DVLOG(1) << render_view() << " OnKeyPress: " << count; |
198 extensions_v8::SearchBoxExtension::DispatchUpOrDownKeyPress( | 201 extensions_v8::SearchBoxExtension::DispatchUpOrDownKeyPress( |
199 render_view()->GetWebView()->mainFrame(), count); | 202 render_view()->GetWebView()->mainFrame(), count); |
200 } | 203 } |
201 } | 204 } |
202 | 205 |
| 206 void SearchBox::OnKeyCaptureChange(bool is_key_capture_enabled) { |
| 207 if (is_key_capture_enabled != is_key_capture_enabled_ && |
| 208 render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
| 209 is_key_capture_enabled_ = is_key_capture_enabled; |
| 210 DVLOG(1) << render_view() << " OnKeyCaptureChange"; |
| 211 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange( |
| 212 render_view()->GetWebView()->mainFrame()); |
| 213 } |
| 214 } |
| 215 |
203 void SearchBox::OnModeChanged(const chrome::search::Mode& mode) { | 216 void SearchBox::OnModeChanged(const chrome::search::Mode& mode) { |
204 mode_ = mode; | 217 mode_ = mode; |
205 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 218 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
206 DVLOG(1) << render_view() << " OnModeChanged"; | 219 DVLOG(1) << render_view() << " OnModeChanged"; |
207 extensions_v8::SearchBoxExtension::DispatchContextChange( | 220 extensions_v8::SearchBoxExtension::DispatchContextChange( |
208 render_view()->GetWebView()->mainFrame()); | 221 render_view()->GetWebView()->mainFrame()); |
209 } | 222 } |
210 } | 223 } |
211 | 224 |
212 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { | 225 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { |
(...skipping 17 matching lines...) Expand all Loading... |
230 } | 243 } |
231 | 244 |
232 void SearchBox::Reset() { | 245 void SearchBox::Reset() { |
233 query_.clear(); | 246 query_.clear(); |
234 verbatim_ = false; | 247 verbatim_ = false; |
235 selection_start_ = 0; | 248 selection_start_ = 0; |
236 selection_end_ = 0; | 249 selection_end_ = 0; |
237 results_base_ = 0; | 250 results_base_ = 0; |
238 rect_ = gfx::Rect(); | 251 rect_ = gfx::Rect(); |
239 autocomplete_results_.clear(); | 252 autocomplete_results_.clear(); |
| 253 is_key_capture_enabled_ = false; |
240 mode_ = chrome::search::Mode(); | 254 mode_ = chrome::search::Mode(); |
241 theme_info_ = ThemeBackgroundInfo(); | 255 theme_info_ = ThemeBackgroundInfo(); |
242 theme_area_height_ = 0; | 256 theme_area_height_ = 0; |
243 display_instant_results_ = false; | 257 display_instant_results_ = false; |
244 } | 258 } |
OLD | NEW |