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

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: apply more feedback 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 return AutocompleteMatch::MergeClassifications(original_class, match_class);
298 if ((match_class.size() == 1) &&
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 } 298 }
317 299
318 history::ShortcutsBackend::ShortcutMap::const_iterator 300 history::ShortcutsBackend::ShortcutMap::const_iterator
319 ShortcutsProvider::FindFirstMatch(const string16& keyword, 301 ShortcutsProvider::FindFirstMatch(const string16& keyword,
320 history::ShortcutsBackend* backend) { 302 history::ShortcutsBackend* backend) {
321 DCHECK(backend); 303 DCHECK(backend);
322 history::ShortcutsBackend::ShortcutMap::const_iterator it = 304 history::ShortcutsBackend::ShortcutMap::const_iterator it =
323 backend->shortcuts_map().lower_bound(keyword); 305 backend->shortcuts_map().lower_bound(keyword);
324 // Lower bound not necessarily matches the keyword, check for item pointed by 306 // Lower bound not necessarily matches the keyword, check for item pointed by
325 // the lower bound iterator to at least start with keyword. 307 // 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. 339 // (1.0 / each 5 additional hits), up to a maximum of 5x as long.
358 const double kMaxDecaySpeedDivisor = 5.0; 340 const double kMaxDecaySpeedDivisor = 5.0;
359 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0; 341 const double kNumUsesPerDecaySpeedDivisorIncrement = 5.0;
360 double decay_divisor = std::min(kMaxDecaySpeedDivisor, 342 double decay_divisor = std::min(kMaxDecaySpeedDivisor,
361 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) / 343 (shortcut.number_of_hits + kNumUsesPerDecaySpeedDivisorIncrement - 1) /
362 kNumUsesPerDecaySpeedDivisorIncrement); 344 kNumUsesPerDecaySpeedDivisorIncrement);
363 345
364 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) + 346 return static_cast<int>((base_score / exp(decay_exponent / decay_divisor)) +
365 0.5); 347 0.5);
366 } 348 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_match_unittest.cc ('k') | chrome/browser/autocomplete/shortcuts_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698