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

Unified Diff: chrome/browser/autocomplete/bookmark_provider.cc

Issue 499343004: Omnibox: Fix to Display Bookmarks With Leading Spaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/autocomplete/bookmark_provider_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autocomplete/bookmark_provider.cc
diff --git a/chrome/browser/autocomplete/bookmark_provider.cc b/chrome/browser/autocomplete/bookmark_provider.cc
index 2e7ed4862a1e59a8190f879f4a0d183f8037e6f5..29ccb2a8370bd930ffebb59685e62e819fbdff90 100644
--- a/chrome/browser/autocomplete/bookmark_provider.cc
+++ b/chrome/browser/autocomplete/bookmark_provider.cc
@@ -9,6 +9,7 @@
#include <vector>
#include "base/prefs/pref_service.h"
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
#include "chrome/browser/autocomplete/history_provider.h"
@@ -27,6 +28,30 @@ using bookmarks::BookmarkMatch;
typedef std::vector<BookmarkMatch> BookmarkMatches;
+namespace {
+
+// Remove leading spaces from |title| before displaying, otherwise it looks
Peter Kasting 2014/08/25 19:46:44 Nit: Remove -> Removes; correct -> corrects
Mark P 2014/08/25 19:51:16 Both done.
+// funny. In the process, correct |title_match_positions| so the correct
+// characters are highlighted.
+void CorrectTitleAndMatchPositions(
+ base::string16* title,
+ BookmarkMatch::MatchPositions* title_match_positions) {
+ base::string16 trimmed_title;
Peter Kasting 2014/08/25 19:46:44 Nit: Saves the assignment later: size_t correct
Mark P 2014/08/25 19:51:16 Too much less readable, not worth it to save one s
+ base::TrimWhitespace(*title, base::TRIM_LEADING, &trimmed_title);
+ const size_t correction = title->length() - trimmed_title.length();
+ if (correction == 0)
+ return;
+ (*title) = trimmed_title;
+ for (query_parser::Snippet::MatchPositions::iterator it =
+ title_match_positions->begin();
+ it != title_match_positions->end(); ++it) {
+ (*it) = query_parser::Snippet::MatchPosition(
+ it->first - correction, it->second - correction);
+ }
+}
+
+} // namespace
+
// BookmarkProvider ------------------------------------------------------------
BookmarkProvider::BookmarkProvider(Profile* profile)
@@ -147,6 +172,9 @@ AutocompleteMatch BookmarkProvider::BookmarkMatchToACMatch(
AutocompleteMatch match(this, 0, false,
AutocompleteMatchType::BOOKMARK_TITLE);
base::string16 title(bookmark_match.node->GetTitle());
+ BookmarkMatch::MatchPositions new_title_match_positions =
+ bookmark_match.title_match_positions;
+ CorrectTitleAndMatchPositions(&title, &new_title_match_positions);
const GURL& url(bookmark_match.node->url());
const base::string16& url_utf16 = base::UTF8ToUTF16(url.spec());
size_t inline_autocomplete_offset = URLPrefix::GetInlineAutocompleteOffset(
« no previous file with comments | « no previous file | chrome/browser/autocomplete/bookmark_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698