OLD | NEW |
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_result.h" | 5 #include "components/omnibox/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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 const AutocompleteMatch& AutocompleteResult::match_at(size_t index) const { | 287 const AutocompleteMatch& AutocompleteResult::match_at(size_t index) const { |
288 DCHECK_LT(index, matches_.size()); | 288 DCHECK_LT(index, matches_.size()); |
289 return matches_[index]; | 289 return matches_[index]; |
290 } | 290 } |
291 | 291 |
292 AutocompleteMatch* AutocompleteResult::match_at(size_t index) { | 292 AutocompleteMatch* AutocompleteResult::match_at(size_t index) { |
293 DCHECK_LT(index, matches_.size()); | 293 DCHECK_LT(index, matches_.size()); |
294 return &matches_[index]; | 294 return &matches_[index]; |
295 } | 295 } |
296 | 296 |
297 bool AutocompleteResult::ShouldHideTopMatch() const { | |
298 return chrome::ShouldHideTopVerbatimMatch() && | |
299 TopMatchIsStandaloneVerbatimMatch(); | |
300 } | |
301 | |
302 bool AutocompleteResult::TopMatchIsStandaloneVerbatimMatch() const { | |
303 if (empty() || !match_at(0).IsVerbatimType()) | |
304 return false; | |
305 | |
306 // Skip any copied matches, under the assumption that they'll be expired and | |
307 // disappear. We don't want this disappearance to cause the visibility of the | |
308 // top match to change. | |
309 for (const_iterator i(begin() + 1); i != end(); ++i) { | |
310 if (!i->from_previous) | |
311 return !i->IsVerbatimType(); | |
312 } | |
313 return true; | |
314 } | |
315 | |
316 void AutocompleteResult::Reset() { | 297 void AutocompleteResult::Reset() { |
317 matches_.clear(); | 298 matches_.clear(); |
318 default_match_ = end(); | 299 default_match_ = end(); |
319 } | 300 } |
320 | 301 |
321 void AutocompleteResult::Swap(AutocompleteResult* other) { | 302 void AutocompleteResult::Swap(AutocompleteResult* other) { |
322 const size_t default_match_offset = default_match_ - begin(); | 303 const size_t default_match_offset = default_match_ - begin(); |
323 const size_t other_default_match_offset = | 304 const size_t other_default_match_offset = |
324 other->default_match_ - other->begin(); | 305 other->default_match_ - other->begin(); |
325 matches_.swap(other->matches_); | 306 matches_.swap(other->matches_); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 i != old_matches.rend() && delta > 0; ++i) { | 423 i != old_matches.rend() && delta > 0; ++i) { |
443 if (!HasMatchByDestination(*i, new_matches)) { | 424 if (!HasMatchByDestination(*i, new_matches)) { |
444 AutocompleteMatch match = *i; | 425 AutocompleteMatch match = *i; |
445 match.relevance = std::min(max_relevance, match.relevance); | 426 match.relevance = std::min(max_relevance, match.relevance); |
446 match.from_previous = true; | 427 match.from_previous = true; |
447 matches_.push_back(match); | 428 matches_.push_back(match); |
448 delta--; | 429 delta--; |
449 } | 430 } |
450 } | 431 } |
451 } | 432 } |
OLD | NEW |