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

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

Issue 19197005: Omnibox: Change |inline_autocomplete_offset| to |inline_autocompletion| (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix issue with using a reference in a place we shouldn't Created 7 years, 5 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 319
320 // When the user forced a query, we need to make sure all the fill_into_edit 320 // When the user forced a query, we need to make sure all the fill_into_edit
321 // values preserve that property. Otherwise, if the user starts editing a 321 // values preserve that property. Otherwise, if the user starts editing a
322 // suggestion, non-Search results will suddenly appear. 322 // suggestion, non-Search results will suddenly appear.
323 if (input.type() == AutocompleteInput::FORCED_QUERY) 323 if (input.type() == AutocompleteInput::FORCED_QUERY)
324 match.fill_into_edit.assign(ASCIIToUTF16("?")); 324 match.fill_into_edit.assign(ASCIIToUTF16("?"));
325 if (is_keyword) 325 if (is_keyword)
326 match.fill_into_edit.append(match.keyword + char16(' ')); 326 match.fill_into_edit.append(match.keyword + char16(' '));
327 if (!input.prevent_inline_autocomplete() && 327 if (!input.prevent_inline_autocomplete() &&
328 StartsWith(query_string, input_text, false)) { 328 StartsWith(query_string, input_text, false)) {
329 match.inline_autocomplete_offset = 329 match.inline_autocompletion = query_string.substr(input_text.length());
330 match.fill_into_edit.length() + input_text.length();
331 } 330 }
332 match.fill_into_edit.append(query_string); 331 match.fill_into_edit.append(query_string);
333 332
334 const TemplateURLRef& search_url = template_url->url_ref(); 333 const TemplateURLRef& search_url = template_url->url_ref();
335 DCHECK(search_url.SupportsReplacement()); 334 DCHECK(search_url.SupportsReplacement());
336 match.search_terms_args.reset( 335 match.search_terms_args.reset(
337 new TemplateURLRef::SearchTermsArgs(query_string)); 336 new TemplateURLRef::SearchTermsArgs(query_string));
338 match.search_terms_args->original_query = input_text; 337 match.search_terms_args->original_query = input_text;
339 match.search_terms_args->accepted_suggestion = accepted_suggestion; 338 match.search_terms_args->accepted_suggestion = accepted_suggestion;
340 match.search_terms_args->omnibox_start_margin = omnibox_start_margin; 339 match.search_terms_args->omnibox_start_margin = omnibox_start_margin;
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 matches_.front().type == AutocompleteMatchType::SEARCH_OTHER_ENGINE); 1071 matches_.front().type == AutocompleteMatchType::SEARCH_OTHER_ENGINE);
1073 } 1072 }
1074 1073
1075 bool SearchProvider::IsTopMatchNotInlinable() const { 1074 bool SearchProvider::IsTopMatchNotInlinable() const {
1076 // Note: this test assumes the SEARCH_OTHER_ENGINE match corresponds to 1075 // Note: this test assumes the SEARCH_OTHER_ENGINE match corresponds to
1077 // the verbatim search query on the keyword engine. SearchProvider should 1076 // the verbatim search query on the keyword engine. SearchProvider should
1078 // not create any other match of type SEARCH_OTHER_ENGINE. 1077 // not create any other match of type SEARCH_OTHER_ENGINE.
1079 return 1078 return
1080 matches_.front().type != AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED && 1079 matches_.front().type != AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED &&
1081 matches_.front().type != AutocompleteMatchType::SEARCH_OTHER_ENGINE && 1080 matches_.front().type != AutocompleteMatchType::SEARCH_OTHER_ENGINE &&
1082 matches_.front().inline_autocomplete_offset == string16::npos && 1081 matches_.front().inline_autocompletion.empty() &&
1083 matches_.front().fill_into_edit != input_.text(); 1082 matches_.front().fill_into_edit != input_.text();
1084 } 1083 }
1085 1084
1086 void SearchProvider::UpdateMatches() { 1085 void SearchProvider::UpdateMatches() {
1087 ConvertResultsToAutocompleteMatches(); 1086 ConvertResultsToAutocompleteMatches();
1088 1087
1089 // Check constraints that may be violated by suggested relevances. 1088 // Check constraints that may be violated by suggested relevances.
1090 if (!matches_.empty() && 1089 if (!matches_.empty() &&
1091 (default_results_.HasServerProvidedScores() || 1090 (default_results_.HasServerProvidedScores() ||
1092 keyword_results_.HasServerProvidedScores())) { 1091 keyword_results_.HasServerProvidedScores())) {
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 1441
1443 const std::string languages( 1442 const std::string languages(
1444 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); 1443 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
1445 const net::FormatUrlTypes format_types = 1444 const net::FormatUrlTypes format_types =
1446 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP); 1445 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP);
1447 match.fill_into_edit += 1446 match.fill_into_edit +=
1448 AutocompleteInput::FormattedStringWithEquivalentMeaning(navigation.url(), 1447 AutocompleteInput::FormattedStringWithEquivalentMeaning(navigation.url(),
1449 net::FormatUrl(navigation.url(), languages, format_types, 1448 net::FormatUrl(navigation.url(), languages, format_types,
1450 net::UnescapeRule::SPACES, NULL, NULL, 1449 net::UnescapeRule::SPACES, NULL, NULL,
1451 &inline_autocomplete_offset)); 1450 &inline_autocomplete_offset));
1452 if (!input_.prevent_inline_autocomplete()) 1451 if (!input_.prevent_inline_autocomplete() &&
1453 match.inline_autocomplete_offset = inline_autocomplete_offset; 1452 (inline_autocomplete_offset != string16::npos)) {
1454 DCHECK((match.inline_autocomplete_offset == string16::npos) || 1453 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length());
1455 (match.inline_autocomplete_offset <= match.fill_into_edit.length())); 1454 match.inline_autocompletion =
1455 match.fill_into_edit.substr(inline_autocomplete_offset);
1456 }
1456 1457
1457 match.contents = net::FormatUrl(navigation.url(), languages, 1458 match.contents = net::FormatUrl(navigation.url(), languages,
1458 format_types, net::UnescapeRule::SPACES, NULL, NULL, &match_start); 1459 format_types, net::UnescapeRule::SPACES, NULL, NULL, &match_start);
1459 // If the first match in the untrimmed string was inside a scheme that we 1460 // If the first match in the untrimmed string was inside a scheme that we
1460 // trimmed, look for a subsequent match. 1461 // trimmed, look for a subsequent match.
1461 if (match_start == string16::npos) 1462 if (match_start == string16::npos)
1462 match_start = match.contents.find(input); 1463 match_start = match.contents.find(input);
1463 // Safe if |match_start| is npos; also safe if the input is longer than the 1464 // Safe if |match_start| is npos; also safe if the input is longer than the
1464 // remaining contents after |match_start|. 1465 // remaining contents after |match_start|.
1465 AutocompleteMatch::ClassifyLocationInString(match_start, input.length(), 1466 AutocompleteMatch::ClassifyLocationInString(match_start, input.length(),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 it->set_relevance(max_query_relevance); 1517 it->set_relevance(max_query_relevance);
1517 it->set_relevance_from_server(relevance_from_server); 1518 it->set_relevance_from_server(relevance_from_server);
1518 } 1519 }
1519 } 1520 }
1520 1521
1521 void SearchProvider::UpdateDone() { 1522 void SearchProvider::UpdateDone() {
1522 // We're done when the timer isn't running, there are no suggest queries 1523 // We're done when the timer isn't running, there are no suggest queries
1523 // pending, and we're not waiting on Instant. 1524 // pending, and we're not waiting on Instant.
1524 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); 1525 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0);
1525 } 1526 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698