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

Unified Diff: ui/app_list/search_result.cc

Issue 1110883003: App Launcher: Webstore results are now highlighted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@applist-webstore-result-match
Patch Set: Update tests to test for highlighting. Created 5 years, 7 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 | « ui/app_list/search_result.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/app_list/search_result.cc
diff --git a/ui/app_list/search_result.cc b/ui/app_list/search_result.cc
index 87bea21334f15fe203c441f86ec9f532dc00fa1a..8f9c0b976035713ab0743a258f7323fbb1c0ef60 100644
--- a/ui/app_list/search_result.cc
+++ b/ui/app_list/search_result.cc
@@ -4,7 +4,11 @@
#include "ui/app_list/search_result.h"
+#include <map>
+
#include "ui/app_list/app_list_constants.h"
+#include "ui/app_list/search/tokenized_string.h"
+#include "ui/app_list/search/tokenized_string_match.h"
#include "ui/app_list/search_result_observer.h"
namespace app_list {
@@ -99,6 +103,20 @@ void SearchResult::RemoveObserver(SearchResultObserver* observer) {
observers_.RemoveObserver(observer);
}
+void SearchResult::UpdateFromMatch(const TokenizedString& title,
+ const TokenizedStringMatch& match) {
+ const TokenizedStringMatch::Hits& hits = match.hits();
+
+ Tags tags;
+ tags.reserve(hits.size());
+ for (size_t i = 0; i < hits.size(); ++i)
+ tags.push_back(Tag(Tag::MATCH, hits[i].start(), hits[i].end()));
+
+ set_title(title.text());
+ set_title_tags(tags);
+ set_relevance(match.relevance());
+}
+
void SearchResult::Open(int event_flags) {
}
@@ -109,4 +127,33 @@ ui::MenuModel* SearchResult::GetContextMenuModel() {
return NULL;
}
+// static
+std::string SearchResult::TagsDebugString(const std::string& text,
+ const Tags& tags) {
+ std::string result = text;
+
+ // Build a table of delimiters to insert.
+ std::map<size_t, std::string> inserts;
+ for (const auto& tag : tags) {
+ if (tag.styles & Tag::URL)
+ inserts[tag.range.start()].push_back('{');
+ if (tag.styles & Tag::MATCH)
+ inserts[tag.range.start()].push_back('[');
+ if (tag.styles & Tag::DIM) {
+ inserts[tag.range.start()].push_back('<');
+ inserts[tag.range.end()].push_back('>');
+ }
+ if (tag.styles & Tag::MATCH)
+ inserts[tag.range.end()].push_back(']');
+ if (tag.styles & Tag::URL)
+ inserts[tag.range.end()].push_back('}');
+ }
+
+ // Insert the delimiters (in reverse order, to preserve indices).
+ for (auto it = inserts.rbegin(); it != inserts.rend(); ++it)
+ result.insert(it->first, it->second);
+
+ return result;
+}
+
} // namespace app_list
« no previous file with comments | « ui/app_list/search_result.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698