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 "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/omnibox_focus_state.h" | 10 #include "chrome/common/omnibox_focus_state.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 SearchBox::SearchBox(content::RenderView* render_view) | 29 SearchBox::SearchBox(content::RenderView* render_view) |
30 : content::RenderViewObserver(render_view), | 30 : content::RenderViewObserver(render_view), |
31 content::RenderViewObserverTracker<SearchBox>(render_view), | 31 content::RenderViewObserverTracker<SearchBox>(render_view), |
32 verbatim_(false), | 32 verbatim_(false), |
33 query_is_restricted_(false), | 33 query_is_restricted_(false), |
34 selection_start_(0), | 34 selection_start_(0), |
35 selection_end_(0), | 35 selection_end_(0), |
36 start_margin_(0), | 36 start_margin_(0), |
| 37 is_focused_(false), |
37 is_key_capture_enabled_(false), | 38 is_key_capture_enabled_(false), |
38 display_instant_results_(false), | 39 display_instant_results_(false), |
39 omnibox_font_size_(0), | 40 omnibox_font_size_(0), |
40 autocomplete_results_cache_(kMaxInstantAutocompleteResultItemCacheSize), | 41 autocomplete_results_cache_(kMaxInstantAutocompleteResultItemCacheSize), |
41 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize) { | 42 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize) { |
42 } | 43 } |
43 | 44 |
44 SearchBox::~SearchBox() { | 45 SearchBox::~SearchBox() { |
45 } | 46 } |
46 | 47 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 OnDetermineIfPageSupportsInstant) | 166 OnDetermineIfPageSupportsInstant) |
166 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults, | 167 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults, |
167 OnAutocompleteResults) | 168 OnAutocompleteResults) |
168 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed, | 169 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed, |
169 OnUpOrDownKeyPressed) | 170 OnUpOrDownKeyPressed) |
170 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxEscKeyPressed, OnEscKeyPressed) | 171 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxEscKeyPressed, OnEscKeyPressed) |
171 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancelSelection, | 172 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancelSelection, |
172 OnCancelSelection) | 173 OnCancelSelection) |
173 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults, | 174 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults, |
174 OnSetDisplayInstantResults) | 175 OnSetDisplayInstantResults) |
175 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxKeyCaptureChanged, | 176 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFocusChanged, OnFocusChanged) |
176 OnKeyCaptureChange) | |
177 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged, | 177 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged, |
178 OnThemeChanged) | 178 OnThemeChanged) |
179 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFontInformation, | 179 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFontInformation, |
180 OnFontInformationReceived) | 180 OnFontInformationReceived) |
181 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMostVisitedItemsChanged, | 181 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMostVisitedItemsChanged, |
182 OnMostVisitedChanged) | 182 OnMostVisitedChanged) |
183 IPC_MESSAGE_UNHANDLED(handled = false) | 183 IPC_MESSAGE_UNHANDLED(handled = false) |
184 IPC_END_MESSAGE_MAP() | 184 IPC_END_MESSAGE_MAP() |
185 return handled; | 185 return handled; |
186 } | 186 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 SetQuery(query, verbatim); | 317 SetQuery(query, verbatim); |
318 selection_start_ = selection_start; | 318 selection_start_ = selection_start; |
319 selection_end_ = selection_end; | 319 selection_end_ = selection_end; |
320 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 320 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
321 DVLOG(1) << render_view() << " OnKeyPress ESC"; | 321 DVLOG(1) << render_view() << " OnKeyPress ESC"; |
322 extensions_v8::SearchBoxExtension::DispatchEscKeyPress( | 322 extensions_v8::SearchBoxExtension::DispatchEscKeyPress( |
323 render_view()->GetWebView()->mainFrame()); | 323 render_view()->GetWebView()->mainFrame()); |
324 } | 324 } |
325 } | 325 } |
326 | 326 |
327 void SearchBox::OnKeyCaptureChange(bool is_key_capture_enabled) { | 327 void SearchBox::OnFocusChanged(OmniboxFocusState new_focus_state, |
328 if (is_key_capture_enabled != is_key_capture_enabled_ && | 328 OmniboxFocusChangeReason reason) { |
329 render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 329 bool key_capture_enabled = new_focus_state == OMNIBOX_FOCUS_INVISIBLE; |
330 is_key_capture_enabled_ = is_key_capture_enabled; | 330 if (key_capture_enabled != is_key_capture_enabled_) { |
331 DVLOG(1) << render_view() << " OnKeyCaptureChange"; | 331 // Tell the page if the key capture mode changed unless the focus state |
332 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange( | 332 // changed because of TYPING. This is because in that case, the browser |
| 333 // hasn't really stopped capturing key strokes. |
| 334 // |
| 335 // (More practically, if we don't do this check, the page would receive |
| 336 // onkeycapturechange before the corresponding onchange, and the page would |
| 337 // have no way of telling whether the keycapturechange happened because of |
| 338 // some actual user action or just because they started typing.) |
| 339 if (reason != OMNIBOX_FOCUS_CHANGE_TYPING && |
| 340 render_view()->GetWebView() && |
| 341 render_view()->GetWebView()->mainFrame()) { |
| 342 is_key_capture_enabled_ = key_capture_enabled; |
| 343 DVLOG(1) << render_view() << " OnKeyCaptureChange"; |
| 344 extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange( |
| 345 render_view()->GetWebView()->mainFrame()); |
| 346 } |
| 347 } |
| 348 bool is_focused = new_focus_state == OMNIBOX_FOCUS_VISIBLE; |
| 349 if (is_focused != is_focused_) { |
| 350 is_focused_ = is_focused; |
| 351 DVLOG(1) << render_view() << " OnFocusChange"; |
| 352 extensions_v8::SearchBoxExtension::DispatchFocusChange( |
333 render_view()->GetWebView()->mainFrame()); | 353 render_view()->GetWebView()->mainFrame()); |
334 } | 354 } |
335 } | 355 } |
336 | 356 |
337 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { | 357 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { |
338 display_instant_results_ = display_instant_results; | 358 display_instant_results_ = display_instant_results; |
339 } | 359 } |
340 | 360 |
341 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { | 361 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { |
342 theme_info_ = theme_info; | 362 theme_info_ = theme_info; |
(...skipping 20 matching lines...) Expand all Loading... |
363 } | 383 } |
364 | 384 |
365 void SearchBox::Reset() { | 385 void SearchBox::Reset() { |
366 query_.clear(); | 386 query_.clear(); |
367 verbatim_ = false; | 387 verbatim_ = false; |
368 query_is_restricted_ = false; | 388 query_is_restricted_ = false; |
369 selection_start_ = 0; | 389 selection_start_ = 0; |
370 selection_end_ = 0; | 390 selection_end_ = 0; |
371 popup_bounds_ = gfx::Rect(); | 391 popup_bounds_ = gfx::Rect(); |
372 start_margin_ = 0; | 392 start_margin_ = 0; |
| 393 is_focused_ = false; |
373 is_key_capture_enabled_ = false; | 394 is_key_capture_enabled_ = false; |
374 theme_info_ = ThemeBackgroundInfo(); | 395 theme_info_ = ThemeBackgroundInfo(); |
375 // Don't reset display_instant_results_ to prevent clearing it on committed | 396 // Don't reset display_instant_results_ to prevent clearing it on committed |
376 // results pages in extended mode. Otherwise resetting it is a no-op because | 397 // results pages in extended mode. Otherwise resetting it is a no-op because |
377 // a new loader is created when it changes; see crbug.com/164662. | 398 // a new loader is created when it changes; see crbug.com/164662. |
378 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never | 399 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never |
379 // changes. | 400 // changes. |
380 } | 401 } |
381 | 402 |
382 void SearchBox::SetQuery(const string16& query, bool verbatim) { | 403 void SearchBox::SetQuery(const string16& query, bool verbatim) { |
(...skipping 16 matching lines...) Expand all Loading... |
399 std::vector<InstantMostVisitedItemIDPair>* items) const { | 420 std::vector<InstantMostVisitedItemIDPair>* items) const { |
400 return most_visited_items_cache_.GetCurrentItems(items); | 421 return most_visited_items_cache_.GetCurrentItems(items); |
401 } | 422 } |
402 | 423 |
403 bool SearchBox::GetMostVisitedItemWithID( | 424 bool SearchBox::GetMostVisitedItemWithID( |
404 InstantRestrictedID most_visited_item_id, | 425 InstantRestrictedID most_visited_item_id, |
405 InstantMostVisitedItem* item) const { | 426 InstantMostVisitedItem* item) const { |
406 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, | 427 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, |
407 item); | 428 item); |
408 } | 429 } |
OLD | NEW |