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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 selection_start_(0), | 68 selection_start_(0), |
69 selection_end_(0), | 69 selection_end_(0), |
70 start_margin_(0), | 70 start_margin_(0), |
71 is_focused_(false), | 71 is_focused_(false), |
72 is_key_capture_enabled_(false), | 72 is_key_capture_enabled_(false), |
73 is_input_in_progress_(false), | 73 is_input_in_progress_(false), |
74 display_instant_results_(false), | 74 display_instant_results_(false), |
75 omnibox_font_size_(0), | 75 omnibox_font_size_(0), |
76 autocomplete_results_cache_(kMaxInstantAutocompleteResultItemCacheSize), | 76 autocomplete_results_cache_(kMaxInstantAutocompleteResultItemCacheSize), |
77 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize) { | 77 most_visited_items_cache_(kMaxInstantMostVisitedItemCacheSize) { |
| 78 theme_info_.Initialize(); |
78 } | 79 } |
79 | 80 |
80 SearchBox::~SearchBox() { | 81 SearchBox::~SearchBox() { |
81 } | 82 } |
82 | 83 |
83 void SearchBox::SetSuggestions( | 84 void SearchBox::SetSuggestions( |
84 const std::vector<InstantSuggestion>& suggestions) { | 85 const std::vector<InstantSuggestion>& suggestions) { |
85 if (!suggestions.empty() && | 86 if (!suggestions.empty() && |
86 suggestions[0].behavior == INSTANT_COMPLETE_REPLACE) { | 87 suggestions[0].behavior == INSTANT_COMPLETE_REPLACE) { |
87 SetQuery(suggestions[0].text, true); | 88 SetQuery(suggestions[0].text, true); |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 } | 442 } |
442 } | 443 } |
443 } | 444 } |
444 } | 445 } |
445 | 446 |
446 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { | 447 void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) { |
447 display_instant_results_ = display_instant_results; | 448 display_instant_results_ = display_instant_results; |
448 } | 449 } |
449 | 450 |
450 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { | 451 void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) { |
| 452 DCHECK(theme_info. IsValid()); |
| 453 |
451 theme_info_ = theme_info; | 454 theme_info_ = theme_info; |
452 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 455 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
453 extensions_v8::SearchBoxExtension::DispatchThemeChange( | 456 extensions_v8::SearchBoxExtension::DispatchThemeChange( |
454 render_view()->GetWebView()->mainFrame()); | 457 render_view()->GetWebView()->mainFrame()); |
455 } | 458 } |
456 } | 459 } |
457 | 460 |
458 void SearchBox::OnFontInformationReceived(const string16& omnibox_font, | 461 void SearchBox::OnFontInformationReceived(const string16& omnibox_font, |
459 size_t omnibox_font_size) { | 462 size_t omnibox_font_size) { |
460 omnibox_font_ = omnibox_font; | 463 omnibox_font_ = omnibox_font; |
(...skipping 13 matching lines...) Expand all Loading... |
474 void SearchBox::Reset() { | 477 void SearchBox::Reset() { |
475 query_.clear(); | 478 query_.clear(); |
476 verbatim_ = false; | 479 verbatim_ = false; |
477 query_is_restricted_ = false; | 480 query_is_restricted_ = false; |
478 selection_start_ = 0; | 481 selection_start_ = 0; |
479 selection_end_ = 0; | 482 selection_end_ = 0; |
480 popup_bounds_ = gfx::Rect(); | 483 popup_bounds_ = gfx::Rect(); |
481 start_margin_ = 0; | 484 start_margin_ = 0; |
482 is_focused_ = false; | 485 is_focused_ = false; |
483 is_key_capture_enabled_ = false; | 486 is_key_capture_enabled_ = false; |
| 487 |
484 theme_info_ = ThemeBackgroundInfo(); | 488 theme_info_ = ThemeBackgroundInfo(); |
| 489 theme_info_.Initialize(); |
| 490 |
485 // Don't reset display_instant_results_ to prevent clearing it on committed | 491 // Don't reset display_instant_results_ to prevent clearing it on committed |
486 // results pages in extended mode. Otherwise resetting it is a no-op because | 492 // results pages in extended mode. Otherwise resetting it is a no-op because |
487 // a new loader is created when it changes; see crbug.com/164662. | 493 // a new loader is created when it changes; see crbug.com/164662. |
488 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never | 494 // Also don't reset omnibox_font_ or omnibox_font_size_ since it never |
489 // changes. | 495 // changes. |
490 } | 496 } |
491 | 497 |
492 void SearchBox::SetQuery(const string16& query, bool verbatim) { | 498 void SearchBox::SetQuery(const string16& query, bool verbatim) { |
493 query_ = query; | 499 query_ = query; |
494 verbatim_ = verbatim; | 500 verbatim_ = verbatim; |
(...skipping 25 matching lines...) Expand all Loading... |
520 InstantMostVisitedItem item; | 526 InstantMostVisitedItem item; |
521 return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL(); | 527 return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL(); |
522 } | 528 } |
523 | 529 |
524 void SearchBox::OnToggleVoiceSearch() { | 530 void SearchBox::OnToggleVoiceSearch() { |
525 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { | 531 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { |
526 extensions_v8::SearchBoxExtension::DispatchToggleVoiceSearch( | 532 extensions_v8::SearchBoxExtension::DispatchToggleVoiceSearch( |
527 render_view()->GetWebView()->mainFrame()); | 533 render_view()->GetWebView()->mainFrame()); |
528 } | 534 } |
529 } | 535 } |
OLD | NEW |