OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/builtin_provider.h" | 5 #include "chrome/browser/autocomplete/builtin_provider.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_about_handler.h" | 9 #include "chrome/browser/browser_about_handler.h" |
10 #include "chrome/browser/net/url_fixer_upper.h" | 10 #include "chrome/browser/net/url_fixer_upper.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 void BuiltinProvider::Start(const AutocompleteInput& input, | 57 void BuiltinProvider::Start(const AutocompleteInput& input, |
58 bool minimal_changes) { | 58 bool minimal_changes) { |
59 matches_.clear(); | 59 matches_.clear(); |
60 if ((input.type() == AutocompleteInput::INVALID) || | 60 if ((input.type() == AutocompleteInput::INVALID) || |
61 (input.type() == AutocompleteInput::FORCED_QUERY) || | 61 (input.type() == AutocompleteInput::FORCED_QUERY) || |
62 (input.type() == AutocompleteInput::QUERY) || | 62 (input.type() == AutocompleteInput::QUERY) || |
63 (input.matches_requested() == AutocompleteInput::BEST_MATCH)) | 63 (input.matches_requested() == AutocompleteInput::BEST_MATCH)) |
64 return; | 64 return; |
65 | 65 |
66 static const string16 kAbout = ASCIIToUTF16(chrome::kAboutScheme) + | 66 const string16 kAbout = ASCIIToUTF16(chrome::kAboutScheme) + |
67 ASCIIToUTF16(chrome::kStandardSchemeSeparator); | 67 ASCIIToUTF16(chrome::kStandardSchemeSeparator); |
68 static const string16 kChrome = ASCIIToUTF16(chrome::kChromeUIScheme) + | 68 const string16 kChrome = ASCIIToUTF16(chrome::kChromeUIScheme) + |
69 ASCIIToUTF16(chrome::kStandardSchemeSeparator); | 69 ASCIIToUTF16(chrome::kStandardSchemeSeparator); |
70 | 70 |
71 static const int kUrl = ACMatchClassification::URL; | 71 const int kUrl = ACMatchClassification::URL; |
72 static const int kMatch = kUrl | ACMatchClassification::MATCH; | 72 const int kMatch = kUrl | ACMatchClassification::MATCH; |
73 | 73 |
74 string16 text = input.text(); | 74 string16 text = input.text(); |
75 bool starting_chrome = StartsWith(kChrome, text, false); | 75 bool starting_chrome = StartsWith(kChrome, text, false); |
76 if (starting_chrome || StartsWith(kAbout, text, false)) { | 76 if (starting_chrome || StartsWith(kAbout, text, false)) { |
77 ACMatchClassifications styles; | 77 ACMatchClassifications styles; |
78 // Highlight the input portion matching "chrome://"; or if the user has | 78 // Highlight the input portion matching "chrome://"; or if the user has |
79 // input "about:" (with optional slashes), highlight the whole "chrome://". | 79 // input "about:" (with optional slashes), highlight the whole "chrome://". |
80 static const size_t kAboutSchemeLength = strlen(chrome::kAboutScheme); | 80 const size_t kAboutSchemeLength = strlen(chrome::kAboutScheme); |
81 bool highlight = starting_chrome || text.length() > kAboutSchemeLength; | 81 bool highlight = starting_chrome || text.length() > kAboutSchemeLength; |
82 styles.push_back(ACMatchClassification(0, highlight ? kMatch : kUrl)); | 82 styles.push_back(ACMatchClassification(0, highlight ? kMatch : kUrl)); |
83 size_t offset = starting_chrome ? text.length() : kChrome.length(); | 83 size_t offset = starting_chrome ? text.length() : kChrome.length(); |
84 if (highlight) | 84 if (highlight) |
85 styles.push_back(ACMatchClassification(offset, kUrl)); | 85 styles.push_back(ACMatchClassification(offset, kUrl)); |
86 // Include some common builtin chrome URLs as the user types the scheme. | 86 // Include some common builtin chrome URLs as the user types the scheme. |
87 AddMatch(ASCIIToUTF16(chrome::kChromeUIChromeURLsURL), styles); | 87 AddMatch(ASCIIToUTF16(chrome::kChromeUIChromeURLsURL), styles); |
88 AddMatch(ASCIIToUTF16(chrome::kChromeUISettingsURL), styles); | 88 AddMatch(ASCIIToUTF16(chrome::kChromeUISettingsURL), styles); |
89 AddMatch(ASCIIToUTF16(chrome::kChromeUIVersionURL), styles); | 89 AddMatch(ASCIIToUTF16(chrome::kChromeUIVersionURL), styles); |
90 } else { | 90 } else { |
(...skipping 26 matching lines...) Expand all Loading... |
117 void BuiltinProvider::AddMatch(const string16& match_string, | 117 void BuiltinProvider::AddMatch(const string16& match_string, |
118 const ACMatchClassifications& styles) { | 118 const ACMatchClassifications& styles) { |
119 AutocompleteMatch match(this, kRelevance, false, | 119 AutocompleteMatch match(this, kRelevance, false, |
120 AutocompleteMatch::NAVSUGGEST); | 120 AutocompleteMatch::NAVSUGGEST); |
121 match.fill_into_edit = match_string; | 121 match.fill_into_edit = match_string; |
122 match.destination_url = GURL(match_string); | 122 match.destination_url = GURL(match_string); |
123 match.contents = match_string; | 123 match.contents = match_string; |
124 match.contents_class = styles; | 124 match.contents_class = styles; |
125 matches_.push_back(match); | 125 matches_.push_back(match); |
126 } | 126 } |
OLD | NEW |