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

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

Issue 10911188: autocomplete: Add AutocompleteMatch::MergeClassifications() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: if one of the vectors is non-empty, return it Created 8 years, 3 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/shortcuts_provider.h" 5 #include "chrome/browser/autocomplete/shortcuts_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 match_class.push_back( 287 match_class.push_back(
288 ACMatchClassification(word_end, ACMatchClassification::NONE)); 288 ACMatchClassification(word_end, ACMatchClassification::NONE));
289 } 289 }
290 last_position = word_end; 290 last_position = word_end;
291 break; 291 break;
292 } 292 }
293 } 293 }
294 last_position = std::max(last_position, next_character); 294 last_position = std::max(last_position, next_character);
295 } 295 }
296 296
297 // Merge match-marking data with original classifications. 297 // Merge match-marking data with original classifications.
Peter Kasting 2012/09/10 23:34:35 Nit: Comment no longer needed
Daniel Erat 2012/09/10 23:46:05 Done.
298 if ((match_class.size() == 1) && 298 return AutocompleteMatch::MergeClassifications(original_class, match_class);
299 (match_class.back().style == ACMatchClassification::NONE))
300 return original_class;
301 ACMatchClassifications output;
302 for (ACMatchClassifications::const_iterator i = original_class.begin(),
303 j = match_class.begin(); i != original_class.end();) {
304 AutocompleteMatch::AddLastClassificationIfNecessary(&output,
305 std::max(i->offset, j->offset), i->style | j->style);
306 const size_t next_i_offset = (i + 1) == original_class.end() ?
307 static_cast<size_t>(-1) : (i + 1)->offset;
308 const size_t next_j_offset = (j + 1) == match_class.end() ?
309 static_cast<size_t>(-1) : (j + 1)->offset;
310 if (next_i_offset >= next_j_offset)
311 ++j;
312 if (next_j_offset >= next_i_offset)
313 ++i;
314 }
315 return output;
316 } 299 }
317 300
318 history::ShortcutsBackend::ShortcutMap::const_iterator 301 history::ShortcutsBackend::ShortcutMap::const_iterator
319 ShortcutsProvider::FindFirstMatch(const string16& keyword, 302 ShortcutsProvider::FindFirstMatch(const string16& keyword,
320 history::ShortcutsBackend* backend) { 303 history::ShortcutsBackend* backend) {
321 DCHECK(backend); 304 DCHECK(backend);
322 history::ShortcutsBackend::ShortcutMap::const_iterator it = 305 history::ShortcutsBackend::ShortcutMap::const_iterator it =
323 backend->shortcuts_map().lower_bound(keyword); 306 backend->shortcuts_map().lower_bound(keyword);
324 // Lower bound not necessarily matches the keyword, check for item pointed by 307 // Lower bound not necessarily matches the keyword, check for item pointed by
325 // the lower bound iterator to at least start with keyword. 308 // the lower bound iterator to at least start with keyword.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 // (1.0 / each 5 additional hits), up to a maximum of 5x as long. 340 // (1.0 / each 5 additional hits), up to a maximum of 5x as long.
358 const double kMaxDecaySpeedDivisor = 5.0; 341 const double kMaxDecaySpeedDivisor = 5.0;
359 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; 342 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0;
360 double decay_divisor = std::min(kMaxDecaySpeedDivisor, 343 double decay_divisor = std::min(kMaxDecaySpeedDivisor,
361 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / 344 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) /
362 kNumUsesPerDecaySpeedDivisorIncrement); 345 kNumUsesPerDecaySpeedDivisorIncrement);
363 346
364 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + 347 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) +
365 0.5); 348 0.5);
366 } 349 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698