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> | 7 #include <map> |
8 | 8 |
| 9 #include "base/i18n/message_formatter.h" |
| 10 #include "base/i18n/number_formatting.h" |
9 #include "ui/app_list/app_list_constants.h" | 11 #include "ui/app_list/app_list_constants.h" |
10 #include "ui/app_list/search/tokenized_string.h" | 12 #include "ui/app_list/search/tokenized_string.h" |
11 #include "ui/app_list/search/tokenized_string_match.h" | 13 #include "ui/app_list/search/tokenized_string_match.h" |
12 #include "ui/app_list/search_result_observer.h" | 14 #include "ui/app_list/search_result_observer.h" |
| 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/strings/grit/ui_strings.h" |
13 | 17 |
14 namespace app_list { | 18 namespace app_list { |
15 | 19 |
16 SearchResult::Action::Action(const gfx::ImageSkia& base_image, | 20 SearchResult::Action::Action(const gfx::ImageSkia& base_image, |
17 const gfx::ImageSkia& hover_image, | 21 const gfx::ImageSkia& hover_image, |
18 const gfx::ImageSkia& pressed_image, | 22 const gfx::ImageSkia& pressed_image, |
19 const base::string16& tooltip_text) | 23 const base::string16& tooltip_text) |
20 : base_image(base_image), | 24 : base_image(base_image), |
21 hover_image(hover_image), | 25 hover_image(hover_image), |
22 pressed_image(pressed_image), | 26 pressed_image(pressed_image), |
(...skipping 19 matching lines...) Expand all Loading... |
42 for (auto& observer : observers_) | 46 for (auto& observer : observers_) |
43 observer.OnIconChanged(); | 47 observer.OnIconChanged(); |
44 } | 48 } |
45 | 49 |
46 void SearchResult::SetBadgeIcon(const gfx::ImageSkia& badge_icon) { | 50 void SearchResult::SetBadgeIcon(const gfx::ImageSkia& badge_icon) { |
47 badge_icon_ = badge_icon; | 51 badge_icon_ = badge_icon; |
48 for (auto& observer : observers_) | 52 for (auto& observer : observers_) |
49 observer.OnBadgeIconChanged(); | 53 observer.OnBadgeIconChanged(); |
50 } | 54 } |
51 | 55 |
| 56 const base::string16& SearchResult::GetPriceString() const { |
| 57 return price_string_; |
| 58 } |
| 59 |
| 60 void SearchResult::SetPrice(double price) { |
| 61 price_ = price; |
| 62 price_string_ = base::i18n::MessageFormatter::FormatWithNumberedArgs( |
| 63 l10n_util::GetStringUTF16(IDS_APP_LIST_PRICE), |
| 64 base::FormatDouble(price, 2)); |
| 65 |
| 66 for (auto& observer : observers_) |
| 67 observer.OnPriceChanged(); |
| 68 } |
| 69 |
| 70 const base::string16& SearchResult::GetRatingString() const { |
| 71 return rating_string_; |
| 72 } |
| 73 |
| 74 void SearchResult::SetRating(double rating) { |
| 75 rating_ = rating; |
| 76 rating_string_ = base::i18n::MessageFormatter::FormatWithNumberedArgs( |
| 77 l10n_util::GetStringUTF16(IDS_APP_LIST_RATING), |
| 78 base::FormatDouble(rating, 1)); |
| 79 |
| 80 for (auto& observer : observers_) |
| 81 observer.OnRatingChanged(); |
| 82 } |
| 83 |
52 void SearchResult::SetIsMouseInView(bool mouse_is_inside) { | 84 void SearchResult::SetIsMouseInView(bool mouse_is_inside) { |
53 mouse_is_in_view_ = mouse_is_inside; | 85 mouse_is_in_view_ = mouse_is_inside; |
54 for (auto& observer : observers_) | 86 for (auto& observer : observers_) |
55 observer.OnViewHoverStateChanged(); | 87 observer.OnViewHoverStateChanged(); |
56 } | 88 } |
57 | 89 |
58 void SearchResult::SetActions(const Actions& sets) { | 90 void SearchResult::SetActions(const Actions& sets) { |
59 actions_ = sets; | 91 actions_ = sets; |
60 for (auto& observer : observers_) | 92 for (auto& observer : observers_) |
61 observer.OnActionsChanged(); | 93 observer.OnActionsChanged(); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 } | 186 } |
155 | 187 |
156 // Insert the delimiters (in reverse order, to preserve indices). | 188 // Insert the delimiters (in reverse order, to preserve indices). |
157 for (auto it = inserts.rbegin(); it != inserts.rend(); ++it) | 189 for (auto it = inserts.rbegin(); it != inserts.rend(); ++it) |
158 result.insert(it->first, it->second); | 190 result.insert(it->first, it->second); |
159 | 191 |
160 return result; | 192 return result; |
161 } | 193 } |
162 | 194 |
163 } // namespace app_list | 195 } // namespace app_list |
OLD | NEW |