OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/views/search_result_tile_item_view.h" | 5 #include "ui/app_list/views/search_result_tile_item_view.h" |
6 | 6 |
7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
8 #include "ui/app_list/app_list_constants.h" | 8 #include "ui/app_list/app_list_constants.h" |
9 #include "ui/app_list/app_list_features.h" | 9 #include "ui/app_list/app_list_features.h" |
10 #include "ui/app_list/app_list_view_delegate.h" | 10 #include "ui/app_list/app_list_view_delegate.h" |
11 #include "ui/app_list/search_result.h" | 11 #include "ui/app_list/search_result.h" |
| 12 #include "ui/app_list/vector_icons/vector_icons.h" |
12 #include "ui/app_list/views/search_result_container_view.h" | 13 #include "ui/app_list/views/search_result_container_view.h" |
| 14 #include "ui/gfx/paint_vector_icon.h" |
13 #include "ui/views/controls/image_view.h" | 15 #include "ui/views/controls/image_view.h" |
14 #include "ui/views/controls/label.h" | 16 #include "ui/views/controls/label.h" |
15 #include "ui/views/controls/menu/menu_runner.h" | 17 #include "ui/views/controls/menu/menu_runner.h" |
16 | 18 |
17 namespace app_list { | 19 namespace app_list { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 constexpr int kSearchTileWidth = 80; | 23 constexpr int kSearchTileWidth = 80; |
22 constexpr int kSearchTileTopPadding = 4; | 24 constexpr int kSearchTileTopPadding = 4; |
23 constexpr int kSearchTitleSpacing = 6; | 25 constexpr int kSearchTitleSpacing = 6; |
| 26 constexpr int kSearchRatingStarSize = 12; |
| 27 constexpr int kSearchRatingStarHorizontalSpacing = 1; |
| 28 constexpr int kSearchRatingStarVerticalSpacing = 2; |
24 | 29 |
25 constexpr SkColor kSearchTitleColor = | 30 constexpr SkColor kSearchTitleColor = |
26 SkColorSetARGBMacro(0xDF, 0x00, 0x00, 0x00); | 31 SkColorSetARGBMacro(0xDF, 0x00, 0x00, 0x00); |
27 constexpr SkColor kSearchAppRatingColor = | 32 constexpr SkColor kSearchAppRatingColor = |
28 SkColorSetARGBMacro(0x8F, 0x00, 0x00, 0x00); | 33 SkColorSetARGBMacro(0x8F, 0x00, 0x00, 0x00); |
29 constexpr SkColor kSearchAppPriceColor = | 34 constexpr SkColor kSearchAppPriceColor = |
30 SkColorSetARGBMacro(0xFF, 0x0F, 0x9D, 0x58); | 35 SkColorSetARGBMacro(0xFF, 0x0F, 0x9D, 0x58); |
| 36 constexpr SkColor kSearchRatingStarColor = |
| 37 SkColorSetARGBMacro(0x8F, 0x00, 0x00, 0x00); |
31 | 38 |
32 } // namespace | 39 } // namespace |
33 | 40 |
34 SearchResultTileItemView::SearchResultTileItemView( | 41 SearchResultTileItemView::SearchResultTileItemView( |
35 SearchResultContainerView* result_container, | 42 SearchResultContainerView* result_container, |
36 AppListViewDelegate* view_delegate) | 43 AppListViewDelegate* view_delegate) |
37 : result_container_(result_container), | 44 : result_container_(result_container), |
38 view_delegate_(view_delegate), | 45 view_delegate_(view_delegate), |
39 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) { | 46 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) { |
40 // When |item_| is null, the tile is invisible. Calling SetSearchResult with a | 47 // When |item_| is null, the tile is invisible. Calling SetSearchResult with a |
41 // non-null item makes the tile visible. | 48 // non-null item makes the tile visible. |
42 SetVisible(false); | 49 SetVisible(false); |
43 | 50 |
44 if (is_fullscreen_app_list_enabled_) { | 51 if (is_fullscreen_app_list_enabled_) { |
45 const gfx::FontList& base_font = | 52 const gfx::FontList& base_font = |
46 ui::ResourceBundle::GetSharedInstance().GetFontList( | 53 ui::ResourceBundle::GetSharedInstance().GetFontList( |
47 ui::ResourceBundle::BaseFont); | 54 ui::ResourceBundle::BaseFont); |
48 | 55 |
49 rating_ = new views::Label; | 56 rating_ = new views::Label; |
50 rating_->SetEnabledColor(kSearchAppRatingColor); | 57 rating_->SetEnabledColor(kSearchAppRatingColor); |
51 rating_->SetFontList(base_font); | 58 rating_->SetFontList(base_font); |
52 rating_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 59 rating_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
53 rating_->SetVisible(false); | 60 rating_->SetVisible(false); |
54 AddChildView(rating_); | 61 AddChildView(rating_); |
55 | 62 |
| 63 rating_star_ = new views::ImageView; |
| 64 rating_star_->set_can_process_events_within_subtree(false); |
| 65 rating_star_->SetVerticalAlignment(views::ImageView::LEADING); |
| 66 rating_star_->SetImage(gfx::CreateVectorIcon( |
| 67 kIcBadgeRatingIcon, kSearchRatingStarSize, kSearchRatingStarColor)); |
| 68 rating_star_->SetVisible(false); |
| 69 AddChildView(rating_star_); |
| 70 |
56 price_ = new views::Label; | 71 price_ = new views::Label; |
57 price_->SetEnabledColor(kSearchAppPriceColor); | 72 price_->SetEnabledColor(kSearchAppPriceColor); |
58 price_->SetFontList(base_font); | 73 price_->SetFontList(base_font); |
59 price_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 74 price_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
60 price_->SetVisible(false); | 75 price_->SetVisible(false); |
61 AddChildView(price_); | 76 AddChildView(price_); |
62 } | 77 } |
63 | 78 |
64 set_context_menu_controller(this); | 79 set_context_menu_controller(this); |
65 } | 80 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 OnBadgeIconChanged(); | 132 OnBadgeIconChanged(); |
118 } | 133 } |
119 } | 134 } |
120 | 135 |
121 void SearchResultTileItemView::SetRating(float rating) { | 136 void SearchResultTileItemView::SetRating(float rating) { |
122 if (!rating_) | 137 if (!rating_) |
123 return; | 138 return; |
124 | 139 |
125 if (rating < 0) { | 140 if (rating < 0) { |
126 rating_->SetVisible(false); | 141 rating_->SetVisible(false); |
| 142 rating_star_->SetVisible(false); |
127 return; | 143 return; |
128 } | 144 } |
129 | 145 |
130 rating_->SetText(base::FormatDouble(rating, 1)); | 146 rating_->SetText(base::FormatDouble(rating, 1)); |
131 rating_->SetVisible(true); | 147 rating_->SetVisible(true); |
| 148 rating_star_->SetVisible(true); |
132 } | 149 } |
133 | 150 |
134 void SearchResultTileItemView::SetPrice(const base::string16& price) { | 151 void SearchResultTileItemView::SetPrice(const base::string16& price) { |
135 if (!price_) | 152 if (!price_) |
136 return; | 153 return; |
137 | 154 |
138 if (price.empty()) { | 155 if (price.empty()) { |
139 price_->SetVisible(false); | 156 price_->SetVisible(false); |
140 return; | 157 return; |
141 } | 158 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 rect.set_height(title()->GetPreferredSize().height()); | 261 rect.set_height(title()->GetPreferredSize().height()); |
245 title()->SetBoundsRect(rect); | 262 title()->SetBoundsRect(rect); |
246 | 263 |
247 if (rating_) { | 264 if (rating_) { |
248 gfx::Rect rating_rect(rect); | 265 gfx::Rect rating_rect(rect); |
249 rating_rect.Inset(0, title()->GetPreferredSize().height(), 0, 0); | 266 rating_rect.Inset(0, title()->GetPreferredSize().height(), 0, 0); |
250 rating_rect.set_height(rating_->GetPreferredSize().height()); | 267 rating_rect.set_height(rating_->GetPreferredSize().height()); |
251 rating_->SetBoundsRect(rating_rect); | 268 rating_->SetBoundsRect(rating_rect); |
252 } | 269 } |
253 | 270 |
| 271 if (rating_star_) { |
| 272 gfx::Rect rating_star_rect(rect); |
| 273 rating_star_rect.Inset(rating_->GetPreferredSize().width() + |
| 274 kSearchRatingStarHorizontalSpacing, |
| 275 title()->GetPreferredSize().height() + |
| 276 kSearchRatingStarVerticalSpacing, |
| 277 0, 0); |
| 278 rating_star_rect.set_height(rating_star_->GetPreferredSize().height()); |
| 279 rating_star_rect.set_width(rating_star_->GetPreferredSize().width()); |
| 280 rating_star_->SetBoundsRect(rating_star_rect); |
| 281 } |
| 282 |
254 if (price_) { | 283 if (price_) { |
255 gfx::Rect price_rect(rect); | 284 gfx::Rect price_rect(rect); |
256 price_rect.Inset(0, title()->GetPreferredSize().height(), 0, 0); | 285 price_rect.Inset(0, title()->GetPreferredSize().height(), 0, 0); |
257 price_rect.set_height(price_->GetPreferredSize().height()); | 286 price_rect.set_height(price_->GetPreferredSize().height()); |
258 price_->SetBoundsRect(price_rect); | 287 price_->SetBoundsRect(price_rect); |
259 } | 288 } |
260 } else { | 289 } else { |
261 TileItemView::Layout(); | 290 TileItemView::Layout(); |
262 } | 291 } |
263 } | 292 } |
264 | 293 |
265 gfx::Size SearchResultTileItemView::CalculatePreferredSize() const { | 294 gfx::Size SearchResultTileItemView::CalculatePreferredSize() const { |
266 if (is_fullscreen_app_list_enabled_ && item_) { | 295 if (is_fullscreen_app_list_enabled_ && item_) { |
267 if (item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) | 296 if (item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) |
268 return gfx::Size(kGridTileWidth, kGridTileHeight); | 297 return gfx::Size(kGridTileWidth, kGridTileHeight); |
269 if (item_->display_type() == SearchResult::DISPLAY_TILE) | 298 if (item_->display_type() == SearchResult::DISPLAY_TILE) |
270 return gfx::Size(kSearchTileWidth, kSearchTileHeight); | 299 return gfx::Size(kSearchTileWidth, kSearchTileHeight); |
271 } | 300 } |
272 | 301 |
273 return TileItemView::CalculatePreferredSize(); | 302 return TileItemView::CalculatePreferredSize(); |
274 } | 303 } |
275 | 304 |
276 } // namespace app_list | 305 } // namespace app_list |
OLD | NEW |