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

Side by Side Diff: components/omnibox/autocomplete_match.cc

Issue 1206673002: Omnibox: Bug Fixes for Reverse Title (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: HasMatch -> HasMatchStyle Created 5 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
« no previous file with comments | « components/omnibox/autocomplete_match.h ('k') | components/omnibox/autocomplete_result.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/omnibox/autocomplete_match.h" 5 #include "components/omnibox/autocomplete_match.h"
6 6
7 #include "base/command_line.h"
8 #include "base/i18n/time_formatting.h" 7 #include "base/i18n/time_formatting.h"
9 #include "base/logging.h" 8 #include "base/logging.h"
10 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
11 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
13 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 14 #include "base/time/time.h"
16 #include "components/omnibox/autocomplete_provider.h" 15 #include "components/omnibox/autocomplete_provider.h"
17 #include "components/omnibox/omnibox_switches.h"
18 #include "components/omnibox/suggestion_answer.h" 16 #include "components/omnibox/suggestion_answer.h"
19 #include "components/search_engines/template_url.h" 17 #include "components/search_engines/template_url.h"
20 #include "components/search_engines/template_url_service.h" 18 #include "components/search_engines/template_url_service.h"
21 #include "grit/components_scaled_resources.h" 19 #include "grit/components_scaled_resources.h"
22 20
23 namespace { 21 namespace {
24 22
25 bool IsTrivialClassification(const ACMatchClassifications& classifications) { 23 bool IsTrivialClassification(const ACMatchClassifications& classifications) {
26 return classifications.empty() || 24 return classifications.empty() ||
27 ((classifications.size() == 1) && 25 ((classifications.size() == 1) &&
(...skipping 11 matching lines...) Expand all
39 0x2029, // Paragraph separator 37 0x2029, // Paragraph separator
40 0 38 0
41 }; 39 };
42 40
43 AutocompleteMatch::AutocompleteMatch() 41 AutocompleteMatch::AutocompleteMatch()
44 : provider(NULL), 42 : provider(NULL),
45 relevance(0), 43 relevance(0),
46 typed_count(-1), 44 typed_count(-1),
47 deletable(false), 45 deletable(false),
48 allowed_to_be_default_match(false), 46 allowed_to_be_default_match(false),
47 swap_contents_and_description(false),
49 transition(ui::PAGE_TRANSITION_GENERATED), 48 transition(ui::PAGE_TRANSITION_GENERATED),
50 type(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED), 49 type(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED),
51 from_previous(false) { 50 from_previous(false) {
52 } 51 }
53 52
54 AutocompleteMatch::AutocompleteMatch(AutocompleteProvider* provider, 53 AutocompleteMatch::AutocompleteMatch(AutocompleteProvider* provider,
55 int relevance, 54 int relevance,
56 bool deletable, 55 bool deletable,
57 Type type) 56 Type type)
58 : provider(provider), 57 : provider(provider),
59 relevance(relevance), 58 relevance(relevance),
60 typed_count(-1), 59 typed_count(-1),
61 deletable(deletable), 60 deletable(deletable),
62 allowed_to_be_default_match(false), 61 allowed_to_be_default_match(false),
62 swap_contents_and_description(false),
63 transition(ui::PAGE_TRANSITION_TYPED), 63 transition(ui::PAGE_TRANSITION_TYPED),
64 type(type), 64 type(type),
65 from_previous(false) { 65 from_previous(false) {
66 } 66 }
67 67
68 AutocompleteMatch::AutocompleteMatch(const AutocompleteMatch& match) 68 AutocompleteMatch::AutocompleteMatch(const AutocompleteMatch& match)
69 : provider(match.provider), 69 : provider(match.provider),
70 relevance(match.relevance), 70 relevance(match.relevance),
71 typed_count(match.typed_count), 71 typed_count(match.typed_count),
72 deletable(match.deletable), 72 deletable(match.deletable),
73 fill_into_edit(match.fill_into_edit), 73 fill_into_edit(match.fill_into_edit),
74 inline_autocompletion(match.inline_autocompletion), 74 inline_autocompletion(match.inline_autocompletion),
75 allowed_to_be_default_match(match.allowed_to_be_default_match), 75 allowed_to_be_default_match(match.allowed_to_be_default_match),
76 destination_url(match.destination_url), 76 destination_url(match.destination_url),
77 stripped_destination_url(match.stripped_destination_url), 77 stripped_destination_url(match.stripped_destination_url),
78 contents(match.contents), 78 contents(match.contents),
79 contents_class(match.contents_class), 79 contents_class(match.contents_class),
80 description(match.description), 80 description(match.description),
81 description_class(match.description_class), 81 description_class(match.description_class),
82 swap_contents_and_description(match.swap_contents_and_description),
82 answer_contents(match.answer_contents), 83 answer_contents(match.answer_contents),
83 answer_type(match.answer_type), 84 answer_type(match.answer_type),
84 answer(SuggestionAnswer::copy(match.answer.get())), 85 answer(SuggestionAnswer::copy(match.answer.get())),
85 transition(match.transition), 86 transition(match.transition),
86 type(match.type), 87 type(match.type),
87 associated_keyword(match.associated_keyword.get() ? 88 associated_keyword(match.associated_keyword.get() ?
88 new AutocompleteMatch(*match.associated_keyword) : NULL), 89 new AutocompleteMatch(*match.associated_keyword) : NULL),
89 keyword(match.keyword), 90 keyword(match.keyword),
90 from_previous(match.from_previous), 91 from_previous(match.from_previous),
91 search_terms_args(match.search_terms_args.get() ? 92 search_terms_args(match.search_terms_args.get() ?
(...skipping 17 matching lines...) Expand all
109 deletable = match.deletable; 110 deletable = match.deletable;
110 fill_into_edit = match.fill_into_edit; 111 fill_into_edit = match.fill_into_edit;
111 inline_autocompletion = match.inline_autocompletion; 112 inline_autocompletion = match.inline_autocompletion;
112 allowed_to_be_default_match = match.allowed_to_be_default_match; 113 allowed_to_be_default_match = match.allowed_to_be_default_match;
113 destination_url = match.destination_url; 114 destination_url = match.destination_url;
114 stripped_destination_url = match.stripped_destination_url; 115 stripped_destination_url = match.stripped_destination_url;
115 contents = match.contents; 116 contents = match.contents;
116 contents_class = match.contents_class; 117 contents_class = match.contents_class;
117 description = match.description; 118 description = match.description;
118 description_class = match.description_class; 119 description_class = match.description_class;
120 swap_contents_and_description = match.swap_contents_and_description;
119 answer_contents = match.answer_contents; 121 answer_contents = match.answer_contents;
120 answer_type = match.answer_type; 122 answer_type = match.answer_type;
121 answer = SuggestionAnswer::copy(match.answer.get()); 123 answer = SuggestionAnswer::copy(match.answer.get());
122 transition = match.transition; 124 transition = match.transition;
123 type = match.type; 125 type = match.type;
124 associated_keyword.reset(match.associated_keyword.get() ? 126 associated_keyword.reset(match.associated_keyword.get() ?
125 new AutocompleteMatch(*match.associated_keyword) : NULL); 127 new AutocompleteMatch(*match.associated_keyword) : NULL);
126 keyword = match.keyword; 128 keyword = match.keyword;
127 from_previous = match.from_previous; 129 from_previous = match.from_previous;
128 search_terms_args.reset(match.search_terms_args.get() ? 130 search_terms_args.reset(match.search_terms_args.get() ?
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 int style) { 324 int style) {
323 DCHECK(classifications); 325 DCHECK(classifications);
324 if (classifications->empty() || classifications->back().style != style) { 326 if (classifications->empty() || classifications->back().style != style) {
325 DCHECK(classifications->empty() || 327 DCHECK(classifications->empty() ||
326 (offset > classifications->back().offset)); 328 (offset > classifications->back().offset));
327 classifications->push_back(ACMatchClassification(offset, style)); 329 classifications->push_back(ACMatchClassification(offset, style));
328 } 330 }
329 } 331 }
330 332
331 // static 333 // static
334 bool AutocompleteMatch::HasMatchStyle(
335 const ACMatchClassifications& classifications) {
336 for (const auto& it : classifications) {
337 if (it.style & AutocompleteMatch::ACMatchClassification::MATCH)
338 return true;
339 }
340 return false;
341 }
342
343 // static
332 base::string16 AutocompleteMatch::SanitizeString(const base::string16& text) { 344 base::string16 AutocompleteMatch::SanitizeString(const base::string16& text) {
333 // NOTE: This logic is mirrored by |sanitizeString()| in 345 // NOTE: This logic is mirrored by |sanitizeString()| in
334 // omnibox_custom_bindings.js. 346 // omnibox_custom_bindings.js.
335 base::string16 result; 347 base::string16 result;
336 base::TrimWhitespace(text, base::TRIM_LEADING, &result); 348 base::TrimWhitespace(text, base::TRIM_LEADING, &result);
337 base::RemoveChars(result, kInvalidChars, &result); 349 base::RemoveChars(result, kInvalidChars, &result);
338 return result; 350 return result;
339 } 351 }
340 352
341 // static 353 // static
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 return true; 533 return true;
522 534
523 for (ACMatches::const_iterator it(duplicate_matches.begin()); 535 for (ACMatches::const_iterator it(duplicate_matches.begin());
524 it != duplicate_matches.end(); ++it) { 536 it != duplicate_matches.end(); ++it) {
525 if (it->deletable) 537 if (it->deletable)
526 return true; 538 return true;
527 } 539 }
528 return false; 540 return false;
529 } 541 }
530 542
531 void AutocompleteMatch::PossiblySwapContentsAndDescriptionForURLSuggestion( 543 void AutocompleteMatch::PossiblySwapContentsAndDescriptionForDisplay() {
532 const AutocompleteInput& input) { 544 if (swap_contents_and_description) {
533 if (!IsSearchType(type) && !description.empty() &&
534 base::CommandLine::ForCurrentProcess()->
535 HasSwitch(switches::kEmphasizeTitlesInOmniboxDropdown) &&
536 ((input.type() == metrics::OmniboxInputType::QUERY) ||
537 (input.type() == metrics::OmniboxInputType::FORCED_QUERY))) {
538 std::swap(contents, description); 545 std::swap(contents, description);
539 std::swap(contents_class, description_class); 546 std::swap(contents_class, description_class);
540 } 547 }
541 } 548 }
542 549
543 #ifndef NDEBUG 550 #ifndef NDEBUG
544 void AutocompleteMatch::Validate() const { 551 void AutocompleteMatch::Validate() const {
545 ValidateClassifications(contents, contents_class); 552 ValidateClassifications(contents, contents_class);
546 ValidateClassifications(description, description_class); 553 ValidateClassifications(description, description_class);
547 } 554 }
(...skipping 23 matching lines...) Expand all
571 << " is unsorted in relation to last offset of " << last_offset 578 << " is unsorted in relation to last offset of " << last_offset
572 << ". Provider: " << provider_name << "."; 579 << ". Provider: " << provider_name << ".";
573 DCHECK_LT(i->offset, text.length()) 580 DCHECK_LT(i->offset, text.length())
574 << " Classification of [" << i->offset << "," << text.length() 581 << " Classification of [" << i->offset << "," << text.length()
575 << "] is out of bounds for \"" << text << "\". Provider: " 582 << "] is out of bounds for \"" << text << "\". Provider: "
576 << provider_name << "."; 583 << provider_name << ".";
577 last_offset = i->offset; 584 last_offset = i->offset;
578 } 585 }
579 } 586 }
580 #endif 587 #endif
OLDNEW
« no previous file with comments | « components/omnibox/autocomplete_match.h ('k') | components/omnibox/autocomplete_result.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698