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

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

Issue 12039053: Fix cursor position for default provider searches in keyword mode. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Added unit tests. Created 7 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 // And extract the replacement string. 130 // And extract the replacement string.
131 string16 remaining_input; 131 string16 remaining_input;
132 SplitKeywordFromInput(trimmed_input, trim_leading_whitespace, 132 SplitKeywordFromInput(trimmed_input, trim_leading_whitespace,
133 &remaining_input); 133 &remaining_input);
134 return remaining_input; 134 return remaining_input;
135 } 135 }
136 136
137 // static 137 // static
138 const TemplateURL* KeywordProvider::GetSubstitutingTemplateURLForInput( 138 const TemplateURL* KeywordProvider::GetSubstitutingTemplateURLForInput(
139 Profile* profile, 139 TemplateURLService* model,
140 const AutocompleteInput& input, 140 AutocompleteInput* input) {
141 string16* remaining_input) { 141 if (!input->allow_exact_keyword_match())
142 if (!input.allow_exact_keyword_match())
143 return NULL; 142 return NULL;
144 143
145 string16 keyword; 144 string16 keyword, remaining_input;
146 if (!ExtractKeywordFromInput(input, &keyword, remaining_input)) 145 if (!ExtractKeywordFromInput(*input, &keyword, &remaining_input))
147 return NULL; 146 return NULL;
148 147
149 // Make sure the model is loaded. This is cheap and quickly bails out if
150 // the model is already loaded.
151 TemplateURLService* model = TemplateURLServiceFactory::GetForProfile(profile);
152 DCHECK(model); 148 DCHECK(model);
153 model->Load(); 149 const TemplateURL* template_url = model->GetTemplateURLForKeyword(keyword);
150 if (template_url && template_url->SupportsReplacement()) {
151 // TODO(bartn): For now, none of the keyword providers support cursor
152 // position, so let's not bother with adjusting it to reflect the stripped
153 // keyword part from the input.
Mark P 2013/01/24 04:07:21 Some people do their searches using google as a ke
Bart N. 2013/01/24 18:32:04 You are right. I forgot about this case (BTW, any
Mark P 2013/01/24 19:32:15 I assume cursor position mucking happens at a simi
154 input->UpdateText(remaining_input, string16::npos, input->parts());
155 return template_url;
156 }
154 157
155 const TemplateURL* template_url = model->GetTemplateURLForKeyword(keyword); 158 return NULL;
156 return (template_url && template_url->SupportsReplacement()) ?
157 template_url : NULL;
158 } 159 }
159 160
160 string16 KeywordProvider::GetKeywordForText( 161 string16 KeywordProvider::GetKeywordForText(
161 const string16& text) const { 162 const string16& text) const {
162 const string16 keyword(TemplateURLService::CleanUserInputKeyword(text)); 163 const string16 keyword(TemplateURLService::CleanUserInputKeyword(text));
163 164
164 if (keyword.empty()) 165 if (keyword.empty())
165 return keyword; 166 return keyword;
166 167
167 TemplateURLService* url_service = GetTemplateURLService(); 168 TemplateURLService* url_service = GetTemplateURLService();
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 } 587 }
587 588
588 void KeywordProvider::MaybeEndExtensionKeywordMode() { 589 void KeywordProvider::MaybeEndExtensionKeywordMode() {
589 if (!current_keyword_extension_id_.empty()) { 590 if (!current_keyword_extension_id_.empty()) {
590 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( 591 extensions::ExtensionOmniboxEventRouter::OnInputCancelled(
591 profile_, current_keyword_extension_id_); 592 profile_, current_keyword_extension_id_);
592 593
593 current_keyword_extension_id_.clear(); 594 current_keyword_extension_id_.clear();
594 } 595 }
595 } 596 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698