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 |