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.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 kSearchTileHeight = 92; | 24 constexpr int kSearchTileHeight = 92; |
23 constexpr int kSearchTileTopPadding = 4; | 25 constexpr int kSearchTileTopPadding = 4; |
24 constexpr int kSearchTitleSpacing = 6; | 26 constexpr int kSearchTitleSpacing = 6; |
27 constexpr int kSearchRatingStarSize = 12; | |
28 constexpr int kSearchRatingStarHorizontalSpacing = 1; | |
29 constexpr int kSearchRatingStarVerticalSpacing = 2; | |
25 | 30 |
26 constexpr SkColor kSearchTitleColor = | 31 constexpr SkColor kSearchTitleColor = |
27 SkColorSetARGBMacro(0xDF, 0x00, 0x00, 0x00); | 32 SkColorSetARGBMacro(0xDF, 0x00, 0x00, 0x00); |
28 constexpr SkColor kSearchAppRatingColor = | 33 constexpr SkColor kSearchAppRatingColor = |
29 SkColorSetARGBMacro(0x8F, 0x00, 0x00, 0x00); | 34 SkColorSetARGBMacro(0x8F, 0x00, 0x00, 0x00); |
30 constexpr SkColor kSearchAppPriceColor = | 35 constexpr SkColor kSearchAppPriceColor = |
31 SkColorSetARGBMacro(0xFF, 0x0F, 0x9D, 0x58); | 36 SkColorSetARGBMacro(0xFF, 0x0F, 0x9D, 0x58); |
37 constexpr SkColor kSearchRatingStarColor = | |
38 SkColorSetARGBMacro(0x8F, 0x00, 0x00, 0x00); | |
32 | 39 |
33 } // namespace | 40 } // namespace |
34 | 41 |
35 SearchResultTileItemView::SearchResultTileItemView( | 42 SearchResultTileItemView::SearchResultTileItemView( |
36 SearchResultContainerView* result_container, | 43 SearchResultContainerView* result_container, |
37 AppListViewDelegate* view_delegate) | 44 AppListViewDelegate* view_delegate) |
38 : result_container_(result_container), | 45 : result_container_(result_container), |
39 view_delegate_(view_delegate), | 46 view_delegate_(view_delegate), |
40 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) { | 47 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) { |
41 // When |item_| is null, the tile is invisible. Calling SetSearchResult with a | 48 // When |item_| is null, the tile is invisible. Calling SetSearchResult with a |
42 // non-null item makes the tile visible. | 49 // non-null item makes the tile visible. |
43 SetVisible(false); | 50 SetVisible(false); |
44 | 51 |
45 if (is_fullscreen_app_list_enabled_) { | 52 if (is_fullscreen_app_list_enabled_) { |
46 const gfx::FontList& base_font = | 53 const gfx::FontList& base_font = |
47 ui::ResourceBundle::GetSharedInstance().GetFontList( | 54 ui::ResourceBundle::GetSharedInstance().GetFontList( |
48 ui::ResourceBundle::BaseFont); | 55 ui::ResourceBundle::BaseFont); |
49 | 56 |
50 rating_ = new views::Label; | 57 rating_ = new views::Label; |
51 rating_->SetEnabledColor(kSearchAppRatingColor); | 58 rating_->SetEnabledColor(kSearchAppRatingColor); |
52 rating_->SetFontList(base_font); | 59 rating_->SetFontList(base_font); |
53 rating_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 60 rating_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
54 rating_->SetVisible(false); | 61 rating_->SetVisible(false); |
55 AddChildView(rating_); | 62 AddChildView(rating_); |
56 | 63 |
64 rating_star_ = new views::ImageView; | |
65 rating_star_->set_can_process_events_within_subtree(false); | |
66 rating_star_->SetVerticalAlignment(views::ImageView::LEADING); | |
67 rating_star_->SetImage(gfx::CreateVectorIcon( | |
68 kIcBadgeRatingIcon, kSearchRatingStarSize, kSearchRatingStarColor)); | |
69 rating_star_->SetVisible(false); | |
70 AddChildView(rating_star_); | |
71 | |
57 price_ = new views::Label; | 72 price_ = new views::Label; |
58 price_->SetEnabledColor(kSearchAppPriceColor); | 73 price_->SetEnabledColor(kSearchAppPriceColor); |
59 price_->SetFontList(base_font); | 74 price_->SetFontList(base_font); |
60 price_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 75 price_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
61 price_->SetVisible(false); | 76 price_->SetVisible(false); |
62 AddChildView(price_); | 77 AddChildView(price_); |
63 } | 78 } |
64 | 79 |
65 set_context_menu_controller(this); | 80 set_context_menu_controller(this); |
66 } | 81 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 OnIconChanged(); | 128 OnIconChanged(); |
114 } | 129 } |
115 } | 130 } |
116 | 131 |
117 void SearchResultTileItemView::SetRating(float rating) { | 132 void SearchResultTileItemView::SetRating(float rating) { |
118 if (!rating_) | 133 if (!rating_) |
119 return; | 134 return; |
120 | 135 |
121 if (rating < 0) { | 136 if (rating < 0) { |
122 rating_->SetVisible(false); | 137 rating_->SetVisible(false); |
138 rating_star_->SetVisible(false); | |
123 return; | 139 return; |
124 } | 140 } |
125 | 141 |
126 rating_->SetText(base::FormatDouble(rating, 1)); | 142 rating_->SetText(base::FormatDouble(rating, 1)); |
127 rating_->SetVisible(true); | 143 rating_->SetVisible(true); |
144 rating_star_->SetVisible(true); | |
128 } | 145 } |
129 | 146 |
130 void SearchResultTileItemView::SetPrice(const base::string16& price) { | 147 void SearchResultTileItemView::SetPrice(const base::string16& price) { |
131 if (!price_) | 148 if (!price_) |
132 return; | 149 return; |
133 | 150 |
134 if (price.empty()) { | 151 if (price.empty()) { |
135 price_->SetVisible(false); | 152 price_->SetVisible(false); |
136 return; | 153 return; |
137 } | 154 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 rect.set_height(title()->GetPreferredSize().height()); | 255 rect.set_height(title()->GetPreferredSize().height()); |
239 title()->SetBoundsRect(rect); | 256 title()->SetBoundsRect(rect); |
240 | 257 |
241 if (rating_) { | 258 if (rating_) { |
242 gfx::Rect rating_rect(rect); | 259 gfx::Rect rating_rect(rect); |
243 rating_rect.Inset(0, title()->GetPreferredSize().height(), 0, 0); | 260 rating_rect.Inset(0, title()->GetPreferredSize().height(), 0, 0); |
244 rating_rect.set_height(rating_->GetPreferredSize().height()); | 261 rating_rect.set_height(rating_->GetPreferredSize().height()); |
245 rating_->SetBoundsRect(rating_rect); | 262 rating_->SetBoundsRect(rating_rect); |
246 } | 263 } |
247 | 264 |
265 if (rating_star_) { | |
266 gfx::Rect rating_star_rect(rect); | |
267 rating_star_rect.Inset(rating_->GetPreferredSize().width() + | |
268 kSearchRatingStarHorizontalSpacing, | |
269 title()->GetPreferredSize().height() + | |
270 kSearchRatingStarVerticalSpacing, | |
271 0, 0); | |
272 rating_star_rect.set_height(rating_star_->GetPreferredSize().height()); | |
273 rating_star_rect.set_width(rating_star_->GetPreferredSize().width()); | |
274 rating_star_->SetBoundsRect(rating_star_rect); | |
xiyuan
2017/06/27 14:46:02
Please run with a rtl lang (e.g. --lang=ar or --la
weidongg
2017/06/27 17:06:06
The star is in the left side of number for both ar
| |
275 } | |
276 | |
248 if (price_) { | 277 if (price_) { |
249 gfx::Rect price_rect(rect); | 278 gfx::Rect price_rect(rect); |
250 price_rect.Inset(0, title()->GetPreferredSize().height(), 0, 0); | 279 price_rect.Inset(0, title()->GetPreferredSize().height(), 0, 0); |
251 price_rect.set_height(price_->GetPreferredSize().height()); | 280 price_rect.set_height(price_->GetPreferredSize().height()); |
252 price_->SetBoundsRect(price_rect); | 281 price_->SetBoundsRect(price_rect); |
253 } | 282 } |
254 } else { | 283 } else { |
255 TileItemView::Layout(); | 284 TileItemView::Layout(); |
256 } | 285 } |
257 } | 286 } |
258 | 287 |
259 gfx::Size SearchResultTileItemView::CalculatePreferredSize() const { | 288 gfx::Size SearchResultTileItemView::CalculatePreferredSize() const { |
260 if (is_fullscreen_app_list_enabled_ && item_) { | 289 if (is_fullscreen_app_list_enabled_ && item_) { |
261 if (item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) | 290 if (item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) |
262 return gfx::Size(kGridTileWidth, kGridTileHeight); | 291 return gfx::Size(kGridTileWidth, kGridTileHeight); |
263 if (item_->display_type() == SearchResult::DISPLAY_TILE) | 292 if (item_->display_type() == SearchResult::DISPLAY_TILE) |
264 return gfx::Size(kSearchTileWidth, kSearchTileHeight); | 293 return gfx::Size(kSearchTileWidth, kSearchTileHeight); |
265 } | 294 } |
266 | 295 |
267 return TileItemView::CalculatePreferredSize(); | 296 return TileItemView::CalculatePreferredSize(); |
268 } | 297 } |
269 | 298 |
270 } // namespace app_list | 299 } // namespace app_list |
OLD | NEW |