Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/autocomplete_result.h" | 5 #include "chrome/browser/autocomplete/autocomplete_result.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 DCHECK_LT(index, matches_.size()); | 251 DCHECK_LT(index, matches_.size()); |
| 252 return matches_[index]; | 252 return matches_[index]; |
| 253 } | 253 } |
| 254 | 254 |
| 255 AutocompleteMatch* AutocompleteResult::match_at(size_t index) { | 255 AutocompleteMatch* AutocompleteResult::match_at(size_t index) { |
| 256 DCHECK_LT(index, matches_.size()); | 256 DCHECK_LT(index, matches_.size()); |
| 257 return &matches_[index]; | 257 return &matches_[index]; |
| 258 } | 258 } |
| 259 | 259 |
| 260 bool AutocompleteResult::ShouldHideTopMatch() const { | 260 bool AutocompleteResult::ShouldHideTopMatch() const { |
| 261 // Gate on our field trial flag. | 261 // Gate on our field trial flag. |
|
Peter Kasting
2013/12/17 23:47:34
Nit: Remove this comment.
kmadhusu
2013/12/18 23:26:08
Done.
| |
| 262 if (!chrome::ShouldHideTopVerbatimMatch()) | 262 return chrome::ShouldHideTopVerbatimMatch() && |
| 263 return false; | 263 TopMatchIsVerbatimAndHasNoConsecutiveVerbatimMatches(); |
| 264 } | |
| 264 | 265 |
| 265 // If we don't have a verbatim first match, show everything. | 266 bool AutocompleteResult::TopMatchIsVerbatimAndHasNoConsecutiveVerbatimMatches() |
|
Peter Kasting
2013/12/17 23:47:34
Nit: Name this TopMatchIsStandaloneVerbatimMatch()
kmadhusu
2013/12/18 23:26:08
Done.
| |
| 267 const { | |
| 266 if (empty() || !match_at(0).IsVerbatimType()) | 268 if (empty() || !match_at(0).IsVerbatimType()) |
| 267 return false; | 269 return false; |
| 268 | 270 return !(size() > 1) || !match_at(1).IsVerbatimType(); |
|
Peter Kasting
2013/12/17 23:47:34
Nit: Simpler:
return !empty() && match_at(0).Is
kmadhusu
2013/12/18 23:26:08
Done.
| |
| 269 // If the verbatim first match is followed by another verbatim match, don't | |
| 270 // hide anything, lest we cause user confusion. | |
| 271 if ((size() > 1) && match_at(1).IsVerbatimType()) | |
| 272 return false; | |
| 273 | |
| 274 // Otherwise, it's safe to hide the verbatim first match. | |
| 275 return true; | |
| 276 } | 271 } |
| 277 | 272 |
| 278 void AutocompleteResult::Reset() { | 273 void AutocompleteResult::Reset() { |
| 279 matches_.clear(); | 274 matches_.clear(); |
| 280 default_match_ = end(); | 275 default_match_ = end(); |
| 281 } | 276 } |
| 282 | 277 |
| 283 void AutocompleteResult::Swap(AutocompleteResult* other) { | 278 void AutocompleteResult::Swap(AutocompleteResult* other) { |
| 284 const size_t default_match_offset = default_match_ - begin(); | 279 const size_t default_match_offset = default_match_ - begin(); |
| 285 const size_t other_default_match_offset = | 280 const size_t other_default_match_offset = |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 i != old_matches.rend() && delta > 0; ++i) { | 371 i != old_matches.rend() && delta > 0; ++i) { |
| 377 if (!HasMatchByDestination(*i, new_matches)) { | 372 if (!HasMatchByDestination(*i, new_matches)) { |
| 378 AutocompleteMatch match = *i; | 373 AutocompleteMatch match = *i; |
| 379 match.relevance = std::min(max_relevance, match.relevance); | 374 match.relevance = std::min(max_relevance, match.relevance); |
| 380 match.from_previous = true; | 375 match.from_previous = true; |
| 381 AddMatch(page_classification, match); | 376 AddMatch(page_classification, match); |
| 382 delta--; | 377 delta--; |
| 383 } | 378 } |
| 384 } | 379 } |
| 385 } | 380 } |
| OLD | NEW |