Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(629)

Side by Side Diff: chrome/browser/autocomplete/keyword_provider.cc

Issue 6731036: Enabled pressing TAB to cycle through the Omnibox results. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/keyword_provider.h" 5 #include "chrome/browser/autocomplete/keyword_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 // don't bother. 172 // don't bother.
173 // 173 //
174 // TODO(pkasting): http://b/893701 We should remember the user's use of a 174 // TODO(pkasting): http://b/893701 We should remember the user's use of a
175 // search query both from the autocomplete popup and from web pages 175 // search query both from the autocomplete popup and from web pages
176 // themselves. 176 // themselves.
177 std::vector<string16> keyword_matches; 177 std::vector<string16> keyword_matches;
178 model->FindMatchingKeywords(keyword, 178 model->FindMatchingKeywords(keyword,
179 !remaining_input.empty(), 179 !remaining_input.empty(),
180 &keyword_matches); 180 &keyword_matches);
181 181
182 // Prune any extension keywords that are disallowed in incognito mode (if
183 // we're incognito), or disabled.
184 for (std::vector<string16>::iterator i(keyword_matches.begin()); 182 for (std::vector<string16>::iterator i(keyword_matches.begin());
185 i != keyword_matches.end(); ) { 183 i != keyword_matches.end(); ) {
186 const TemplateURL* template_url(model->GetTemplateURLForKeyword(*i)); 184 const TemplateURL* template_url(model->GetTemplateURLForKeyword(*i));
185
186 // Prune any extension keywords that are disallowed in incognito mode (if
187 // we're incognito), or disabled.
187 if (profile_ && 188 if (profile_ &&
188 input.matches_requested() == AutocompleteInput::ALL_MATCHES && 189 input.matches_requested() == AutocompleteInput::ALL_MATCHES &&
189 template_url->IsExtensionKeyword()) { 190 template_url->IsExtensionKeyword()) {
190 ExtensionService* service = profile_->GetExtensionService(); 191 ExtensionService* service = profile_->GetExtensionService();
191 const Extension* extension = service->GetExtensionById( 192 const Extension* extension = service->GetExtensionById(
192 template_url->GetExtensionId(), false); 193 template_url->GetExtensionId(), false);
193 bool enabled = 194 bool enabled =
194 extension && (!profile_->IsOffTheRecord() || 195 extension && (!profile_->IsOffTheRecord() ||
195 service->IsIncognitoEnabled(extension->id())); 196 service->IsIncognitoEnabled(extension->id()));
196 if (!enabled) { 197 if (!enabled) {
197 i = keyword_matches.erase(i); 198 i = keyword_matches.erase(i);
198 continue; 199 continue;
199 } 200 }
200 } 201 }
202
203 // Prune any substituting keywords if there is no substitution.
204 if (TemplateURL::SupportsReplacement(template_url) &&
205 !input.allow_exact_keyword_match()) {
206 i = keyword_matches.erase(i);
207 continue;
208 }
209
201 ++i; 210 ++i;
202 } 211 }
203 if (keyword_matches.empty()) 212 if (keyword_matches.empty())
204 return; 213 return;
205 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality()); 214 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality());
206 215
207 // Limit to one exact or three inexact matches, and mark them up for display 216 // Limit to one exact or three inexact matches, and mark them up for display
208 // in the autocomplete popup. 217 // in the autocomplete popup.
209 // Any exact match is going to be the highest quality match, and thus at the 218 // Any exact match is going to be the highest quality match, and thus at the
210 // front of our vector. 219 // front of our vector.
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 // to the user's input. Because right now inexact keyword matches can't score 427 // to the user's input. Because right now inexact keyword matches can't score
419 // more highly than a "what you typed" match from one of the other providers, 428 // more highly than a "what you typed" match from one of the other providers,
420 // we just don't bother to do this, and leave inline autocompletion off. 429 // we just don't bother to do this, and leave inline autocompletion off.
421 result.inline_autocomplete_offset = string16::npos; 430 result.inline_autocomplete_offset = string16::npos;
422 431
423 // Create destination URL and popup entry content by substituting user input 432 // Create destination URL and popup entry content by substituting user input
424 // into keyword templates. 433 // into keyword templates.
425 FillInURLAndContents(remaining_input, element, &result); 434 FillInURLAndContents(remaining_input, element, &result);
426 435
427 if (supports_replacement) 436 if (supports_replacement)
428 result.template_url = element; 437 result.keyword_url = element;
Peter Kasting 2011/04/13 21:06:59 Seems like this should be set regardless of |suppo
429 result.transition = PageTransition::KEYWORD; 438 result.transition = PageTransition::KEYWORD;
439 result.keyword_state = AutocompleteMatch::KEYWORD;
440 result.keyword.assign(keyword);
Peter Kasting 2011/04/13 21:06:59 Nit: Just use =
430 441
431 // Create popup entry description based on the keyword name. 442 // Create popup entry description based on the keyword name.
432 if (!element->IsExtensionKeyword()) { 443 if (!element->IsExtensionKeyword()) {
433 result.description.assign(l10n_util::GetStringFUTF16( 444 result.description.assign(l10n_util::GetStringFUTF16(
434 IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION, keyword)); 445 IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION, keyword));
435 string16 keyword_desc( 446 string16 keyword_desc(
436 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION)); 447 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_KEYWORD_DESCRIPTION));
437 AutocompleteMatch::ClassifyLocationInString( 448 AutocompleteMatch::ClassifyLocationInString(
438 keyword_desc.find(ASCIIToUTF16("%s")), 449 keyword_desc.find(ASCIIToUTF16("%s")),
439 prefix_length, 450 prefix_length,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 } 544 }
534 545
535 void KeywordProvider::MaybeEndExtensionKeywordMode() { 546 void KeywordProvider::MaybeEndExtensionKeywordMode() {
536 if (!current_keyword_extension_id_.empty()) { 547 if (!current_keyword_extension_id_.empty()) {
537 ExtensionOmniboxEventRouter::OnInputCancelled( 548 ExtensionOmniboxEventRouter::OnInputCancelled(
538 profile_, current_keyword_extension_id_); 549 profile_, current_keyword_extension_id_);
539 550
540 current_keyword_extension_id_.clear(); 551 current_keyword_extension_id_.clear();
541 } 552 }
542 } 553 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698