OLD | NEW |
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 "ui/app_list/search_result.h" | 5 #include "ui/app_list/search_result.h" |
6 | 6 |
| 7 #include <map> |
| 8 |
7 #include "ui/app_list/app_list_constants.h" | 9 #include "ui/app_list/app_list_constants.h" |
| 10 #include "ui/app_list/search/tokenized_string.h" |
| 11 #include "ui/app_list/search/tokenized_string_match.h" |
8 #include "ui/app_list/search_result_observer.h" | 12 #include "ui/app_list/search_result_observer.h" |
9 | 13 |
10 namespace app_list { | 14 namespace app_list { |
11 | 15 |
12 SearchResult::Action::Action(const gfx::ImageSkia& base_image, | 16 SearchResult::Action::Action(const gfx::ImageSkia& base_image, |
13 const gfx::ImageSkia& hover_image, | 17 const gfx::ImageSkia& hover_image, |
14 const gfx::ImageSkia& pressed_image, | 18 const gfx::ImageSkia& pressed_image, |
15 const base::string16& tooltip_text) | 19 const base::string16& tooltip_text) |
16 : base_image(base_image), | 20 : base_image(base_image), |
17 hover_image(hover_image), | 21 hover_image(hover_image), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 96 } |
93 | 97 |
94 void SearchResult::AddObserver(SearchResultObserver* observer) { | 98 void SearchResult::AddObserver(SearchResultObserver* observer) { |
95 observers_.AddObserver(observer); | 99 observers_.AddObserver(observer); |
96 } | 100 } |
97 | 101 |
98 void SearchResult::RemoveObserver(SearchResultObserver* observer) { | 102 void SearchResult::RemoveObserver(SearchResultObserver* observer) { |
99 observers_.RemoveObserver(observer); | 103 observers_.RemoveObserver(observer); |
100 } | 104 } |
101 | 105 |
| 106 void SearchResult::UpdateFromMatch(const TokenizedString& title, |
| 107 const TokenizedStringMatch& match) { |
| 108 const TokenizedStringMatch::Hits& hits = match.hits(); |
| 109 |
| 110 Tags tags; |
| 111 tags.reserve(hits.size()); |
| 112 for (size_t i = 0; i < hits.size(); ++i) |
| 113 tags.push_back(Tag(Tag::MATCH, hits[i].start(), hits[i].end())); |
| 114 |
| 115 set_title(title.text()); |
| 116 set_title_tags(tags); |
| 117 set_relevance(match.relevance()); |
| 118 } |
| 119 |
102 void SearchResult::Open(int event_flags) { | 120 void SearchResult::Open(int event_flags) { |
103 } | 121 } |
104 | 122 |
105 void SearchResult::InvokeAction(int action_index, int event_flags) { | 123 void SearchResult::InvokeAction(int action_index, int event_flags) { |
106 } | 124 } |
107 | 125 |
108 ui::MenuModel* SearchResult::GetContextMenuModel() { | 126 ui::MenuModel* SearchResult::GetContextMenuModel() { |
109 return NULL; | 127 return NULL; |
110 } | 128 } |
111 | 129 |
| 130 // static |
| 131 std::string SearchResult::TagsDebugString(const std::string& text, |
| 132 const Tags& tags) { |
| 133 std::string result = text; |
| 134 |
| 135 // Build a table of delimiters to insert. |
| 136 std::map<size_t, std::string> inserts; |
| 137 for (const auto& tag : tags) { |
| 138 if (tag.styles & Tag::URL) |
| 139 inserts[tag.range.start()].push_back('{'); |
| 140 if (tag.styles & Tag::MATCH) |
| 141 inserts[tag.range.start()].push_back('['); |
| 142 if (tag.styles & Tag::DIM) { |
| 143 inserts[tag.range.start()].push_back('<'); |
| 144 inserts[tag.range.end()].push_back('>'); |
| 145 } |
| 146 if (tag.styles & Tag::MATCH) |
| 147 inserts[tag.range.end()].push_back(']'); |
| 148 if (tag.styles & Tag::URL) |
| 149 inserts[tag.range.end()].push_back('}'); |
| 150 } |
| 151 |
| 152 // Insert the delimiters (in reverse order, to preserve indices). |
| 153 for (auto it = inserts.rbegin(); it != inserts.rend(); ++it) |
| 154 result.insert(it->first, it->second); |
| 155 |
| 156 return result; |
| 157 } |
| 158 |
112 } // namespace app_list | 159 } // namespace app_list |
OLD | NEW |