| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser/autocomplete/autocomplete.h" | 5 #include "chrome/browser/autocomplete/autocomplete.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 classification->push_back(ACMatchClassification(match_location, | 506 classification->push_back(ACMatchClassification(match_location, |
| 507 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM)); | 507 (style | ACMatchClassification::MATCH) & ~ACMatchClassification::DIM)); |
| 508 | 508 |
| 509 // Mark post-match portion of string (if any). | 509 // Mark post-match portion of string (if any). |
| 510 const size_t after_match(match_location + match_length); | 510 const size_t after_match(match_location + match_length); |
| 511 if (after_match < overall_length) { | 511 if (after_match < overall_length) { |
| 512 classification->push_back(ACMatchClassification(after_match, style)); | 512 classification->push_back(ACMatchClassification(after_match, style)); |
| 513 } | 513 } |
| 514 } | 514 } |
| 515 | 515 |
| 516 bool AutocompleteMatch::IsSearchType() const { |
| 517 switch (type) { |
| 518 case URL_WHAT_YOU_TYPED: |
| 519 case HISTORY_URL: |
| 520 case HISTORY_TITLE: |
| 521 case HISTORY_BODY: |
| 522 case HISTORY_KEYWORD: |
| 523 case NAVSUGGEST: |
| 524 return false; |
| 525 |
| 526 case SEARCH_WHAT_YOU_TYPED: |
| 527 case SEARCH_HISTORY: |
| 528 case SEARCH_SUGGEST: |
| 529 return true; |
| 530 |
| 531 case SEARCH_OTHER_ENGINE: |
| 532 case OPEN_HISTORY_PAGE: |
| 533 return false; |
| 534 |
| 535 default: |
| 536 NOTREACHED(); |
| 537 return false; |
| 538 } |
| 539 } |
| 540 |
| 516 #ifndef NDEBUG | 541 #ifndef NDEBUG |
| 517 void AutocompleteMatch::Validate() const { | 542 void AutocompleteMatch::Validate() const { |
| 518 ValidateClassifications(contents, contents_class); | 543 ValidateClassifications(contents, contents_class); |
| 519 ValidateClassifications(description, description_class); | 544 ValidateClassifications(description, description_class); |
| 520 } | 545 } |
| 521 | 546 |
| 522 void AutocompleteMatch::ValidateClassifications( | 547 void AutocompleteMatch::ValidateClassifications( |
| 523 const std::wstring& text, | 548 const std::wstring& text, |
| 524 const ACMatchClassifications& classifications) const { | 549 const ACMatchClassifications& classifications) const { |
| 525 if (text.empty()) { | 550 if (text.empty()) { |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 if (matches.empty()) | 969 if (matches.empty()) |
| 945 return; | 970 return; |
| 946 if (matches.size() == 1) { | 971 if (matches.size() == 1) { |
| 947 // Only one match not shown, add it. The relevance may be negative, | 972 // Only one match not shown, add it. The relevance may be negative, |
| 948 // which means we need to negate it to get the true relevance. | 973 // which means we need to negate it to get the true relevance. |
| 949 AutocompleteMatch& match = matches.front(); | 974 AutocompleteMatch& match = matches.front(); |
| 950 if (match.relevance < 0) | 975 if (match.relevance < 0) |
| 951 match.relevance = -match.relevance; | 976 match.relevance = -match.relevance; |
| 952 latest_result_.AddMatch(match); | 977 latest_result_.AddMatch(match); |
| 953 return; | 978 return; |
| 954 } // else, fall through and add item. | 979 } // else, fall through and add item. |
| 955 } | 980 } |
| 956 | 981 |
| 957 AutocompleteMatch match(NULL, 0, false, AutocompleteMatch::OPEN_HISTORY_PAGE); | 982 AutocompleteMatch match(NULL, 0, false, AutocompleteMatch::OPEN_HISTORY_PAGE); |
| 958 match.fill_into_edit = input_.text(); | 983 match.fill_into_edit = input_.text(); |
| 959 | 984 |
| 960 // Mark up the text such that the user input text is bold. | 985 // Mark up the text such that the user input text is bold. |
| 961 size_t keyword_offset = std::wstring::npos; // Offset into match.contents. | 986 size_t keyword_offset = std::wstring::npos; // Offset into match.contents. |
| 962 if (history_contents_provider_->db_match_count() == | 987 if (history_contents_provider_->db_match_count() == |
| 963 history_contents_provider_->kMaxMatchCount) { | 988 history_contents_provider_->kMaxMatchCount) { |
| 964 // History contents searcher has maxed out. | 989 // History contents searcher has maxed out. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 void AutocompleteController::CheckIfDone() { | 1032 void AutocompleteController::CheckIfDone() { |
| 1008 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); | 1033 for (ACProviders::const_iterator i(providers_.begin()); i != providers_.end(); |
| 1009 ++i) { | 1034 ++i) { |
| 1010 if (!(*i)->done()) { | 1035 if (!(*i)->done()) { |
| 1011 done_ = false; | 1036 done_ = false; |
| 1012 return; | 1037 return; |
| 1013 } | 1038 } |
| 1014 } | 1039 } |
| 1015 done_ = true; | 1040 done_ = true; |
| 1016 } | 1041 } |
| OLD | NEW |