Chromium Code Reviews| 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "chrome/browser/autocomplete/autocomplete_match.h" | 6 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 7 #include "grit/theme_resources.h" | 7 #include "grit/theme_resources.h" |
| 8 | 8 |
| 9 // AutocompleteMatch ---------------------------------------------------------- | 9 // AutocompleteMatch ---------------------------------------------------------- |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 "url-what-you-typed", | 44 "url-what-you-typed", |
| 45 "history-url", | 45 "history-url", |
| 46 "history-title", | 46 "history-title", |
| 47 "history-body", | 47 "history-body", |
| 48 "history-keyword", | 48 "history-keyword", |
| 49 "navsuggest", | 49 "navsuggest", |
| 50 "search-what-you-typed", | 50 "search-what-you-typed", |
| 51 "search-history", | 51 "search-history", |
| 52 "search-suggest", | 52 "search-suggest", |
| 53 "search-other-engine", | 53 "search-other-engine", |
| 54 "open-history-page", | |
| 55 }; | 54 }; |
| 56 DCHECK(arraysize(strings) == NUM_TYPES); | 55 DCHECK(arraysize(strings) == NUM_TYPES); |
| 57 return strings[type]; | 56 return strings[type]; |
| 58 } | 57 } |
| 59 | 58 |
| 60 // static | 59 // static |
| 61 int AutocompleteMatch::TypeToIcon(Type type) { | 60 int AutocompleteMatch::TypeToIcon(Type type) { |
| 62 int icons[NUM_TYPES] = { | 61 int icons[NUM_TYPES] = { |
| 63 IDR_OMNIBOX_HTTP, | 62 IDR_OMNIBOX_HTTP, |
| 64 IDR_OMNIBOX_HTTP, | 63 IDR_OMNIBOX_HTTP, |
| 65 IDR_OMNIBOX_HISTORY, | 64 IDR_OMNIBOX_HISTORY, |
| 66 IDR_OMNIBOX_HISTORY, | 65 IDR_OMNIBOX_HISTORY, |
| 67 IDR_OMNIBOX_HISTORY, | 66 IDR_OMNIBOX_HISTORY, |
| 68 IDR_OMNIBOX_HTTP, | 67 IDR_OMNIBOX_HTTP, |
| 69 IDR_OMNIBOX_SEARCH, | 68 IDR_OMNIBOX_SEARCH, |
| 70 IDR_OMNIBOX_SEARCH, | 69 IDR_OMNIBOX_SEARCH, |
| 71 IDR_OMNIBOX_SEARCH, | 70 IDR_OMNIBOX_SEARCH, |
| 72 IDR_OMNIBOX_SEARCH, | 71 IDR_OMNIBOX_SEARCH, |
| 73 IDR_OMNIBOX_MORE, | |
| 74 }; | 72 }; |
| 75 DCHECK(arraysize(icons) == NUM_TYPES); | 73 DCHECK(arraysize(icons) == NUM_TYPES); |
| 76 return icons[type]; | 74 return icons[type]; |
| 77 } | 75 } |
| 78 | 76 |
| 79 // static | 77 // static |
| 80 bool AutocompleteMatch::MoreRelevant(const AutocompleteMatch& elem1, | 78 bool AutocompleteMatch::MoreRelevant(const AutocompleteMatch& elem1, |
| 81 const AutocompleteMatch& elem2) { | 79 const AutocompleteMatch& elem2) { |
| 82 // For equal-relevance matches, we sort alphabetically, so that providers | 80 // For equal-relevance matches, we sort alphabetically, so that providers |
| 83 // who return multiple elements at the same priority get a "stable" sort | 81 // who return multiple elements at the same priority get a "stable" sort |
| 84 // across multiple updates. | 82 // across multiple updates. |
| 85 if (elem1.relevance == elem2.relevance) | 83 if (elem1.relevance == elem2.relevance) |
| 86 return elem1.contents > elem2.contents; | 84 return elem1.contents > elem2.contents; |
| 87 | 85 |
| 88 // A negative relevance indicates the real relevance can be determined by | 86 // A negative relevance indicates the real relevance can be determined by |
|
Peter Kasting
2011/01/19 20:02:36
Nit: The negative stuff can all go away?
| |
| 89 // negating the value. If both relevances are negative, negate the result | 87 // negating the value. If both relevances are negative, negate the result |
| 90 // so that we end up with positive relevances, then negative relevances with | 88 // so that we end up with positive relevances, then negative relevances with |
| 91 // the negative relevances sorted by absolute values. | 89 // the negative relevances sorted by absolute values. |
| 92 const bool result = elem1.relevance > elem2.relevance; | 90 const bool result = elem1.relevance > elem2.relevance; |
| 93 return (elem1.relevance < 0 && elem2.relevance < 0) ? !result : result; | 91 return (elem1.relevance < 0 && elem2.relevance < 0) ? !result : result; |
| 94 } | 92 } |
| 95 | 93 |
| 96 // static | 94 // static |
| 97 bool AutocompleteMatch::DestinationSortFunc(const AutocompleteMatch& elem1, | 95 bool AutocompleteMatch::DestinationSortFunc(const AutocompleteMatch& elem1, |
| 98 const AutocompleteMatch& elem2) { | 96 const AutocompleteMatch& elem2) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 // The classifications should always be sorted. | 177 // The classifications should always be sorted. |
| 180 size_t last_offset = classifications[0].offset; | 178 size_t last_offset = classifications[0].offset; |
| 181 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1); | 179 for (ACMatchClassifications::const_iterator i(classifications.begin() + 1); |
| 182 i != classifications.end(); ++i) { | 180 i != classifications.end(); ++i) { |
| 183 DCHECK(i->offset > last_offset) << "Classification unsorted"; | 181 DCHECK(i->offset > last_offset) << "Classification unsorted"; |
| 184 DCHECK(i->offset < text.length()) << "Classification out of bounds"; | 182 DCHECK(i->offset < text.length()) << "Classification out of bounds"; |
| 185 last_offset = i->offset; | 183 last_offset = i->offset; |
| 186 } | 184 } |
| 187 } | 185 } |
| 188 #endif | 186 #endif |
| OLD | NEW |