Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Side by Side Diff: ui/app_list/views/search_result_tile_item_view.cc

Issue 2949733002: Show Play Store rating and price in app list (Closed)
Patch Set: Rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ui/app_list/app_list_constants.h" 8 #include "ui/app_list/app_list_constants.h"
8 #include "ui/app_list/app_list_features.h" 9 #include "ui/app_list/app_list_features.h"
9 #include "ui/app_list/app_list_view_delegate.h" 10 #include "ui/app_list/app_list_view_delegate.h"
10 #include "ui/app_list/search_result.h" 11 #include "ui/app_list/search_result.h"
11 #include "ui/app_list/views/search_result_container_view.h" 12 #include "ui/app_list/views/search_result_container_view.h"
12 #include "ui/views/controls/image_view.h" 13 #include "ui/views/controls/image_view.h"
13 #include "ui/views/controls/label.h" 14 #include "ui/views/controls/label.h"
14 #include "ui/views/controls/menu/menu_runner.h" 15 #include "ui/views/controls/menu/menu_runner.h"
15 16
16 namespace app_list { 17 namespace app_list {
17 18
18 namespace { 19 namespace {
19 20
20 constexpr int kRecommendationTileWidth = 96; 21 constexpr int kRecommendationTileWidth = 96;
21 constexpr int kRecommendationTileHeight = 99; 22 constexpr int kRecommendationTileHeight = 99;
22 constexpr int kRecommendationIconTopPadding = 24; 23 constexpr int kRecommendationIconTopPadding = 24;
23 constexpr int kRecommendationTitleSpacing = 10; 24 constexpr int kRecommendationTitleSpacing = 10;
24 constexpr int kRecommendationTileMaxWidth = 80; 25 constexpr int kRecommendationTileMaxWidth = 80;
25 26
27 constexpr int kSearchTileWidth = 80;
28 constexpr int kSearchTileHeight = 92;
26 constexpr int kSearchTileTopPadding = 4; 29 constexpr int kSearchTileTopPadding = 4;
27 constexpr int kSearchTitleSpacing = 6; 30 constexpr int kSearchTitleSpacing = 6;
28 31
29 constexpr SkColor kRecommendationTileColor = SK_ColorWHITE; 32 constexpr SkColor kRecommendationTileColor = SK_ColorWHITE;
30 33
34 constexpr SkColor kSearchTitleColor = SkColorSetA(SK_ColorBLACK, 223);
35 constexpr SkColor kSearchAppRatingColor = SkColorSetA(SK_ColorBLACK, 143);
36 constexpr SkColor kSearchAppPriceColor = SkColorSetRGB(0x0F, 0x9D, 0x58);
37
31 } // namespace 38 } // namespace
32 39
33 SearchResultTileItemView::SearchResultTileItemView( 40 SearchResultTileItemView::SearchResultTileItemView(
34 SearchResultContainerView* result_container, 41 SearchResultContainerView* result_container,
35 AppListViewDelegate* view_delegate) 42 AppListViewDelegate* view_delegate)
36 : result_container_(result_container), 43 : result_container_(result_container),
37 item_(nullptr), 44 item_(nullptr),
45 rating_(nullptr),
46 price_(nullptr),
38 view_delegate_(view_delegate), 47 view_delegate_(view_delegate),
39 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) { 48 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) {
40 // When |item_| is null, the tile is invisible. Calling SetSearchResult with a 49 // When |item_| is null, the tile is invisible. Calling SetSearchResult with a
41 // non-null item makes the tile visible. 50 // non-null item makes the tile visible.
42 SetVisible(false); 51 SetVisible(false);
43 52
53 if (is_fullscreen_app_list_enabled_) {
54 gfx::FontList base_font =
xiyuan 2017/06/22 17:07:34 nit: gfx::FontList -> const gfx::FontList&, to sav
weidongg 2017/06/22 17:58:29 Done.
55 ui::ResourceBundle::GetSharedInstance().GetFontList(
56 ui::ResourceBundle::BaseFont);
57
58 rating_ = new views::Label;
59 rating_->SetEnabledColor(kSearchAppRatingColor);
60 rating_->SetFontList(base_font);
61 rating_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
62 rating_->SetVisible(false);
63 AddChildView(rating_);
64
65 price_ = new views::Label;
66 price_->SetEnabledColor(kSearchAppPriceColor);
67 price_->SetFontList(base_font);
68 price_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
69 price_->SetVisible(false);
70 AddChildView(price_);
71 }
72
44 set_context_menu_controller(this); 73 set_context_menu_controller(this);
45 } 74 }
46 75
47 SearchResultTileItemView::~SearchResultTileItemView() { 76 SearchResultTileItemView::~SearchResultTileItemView() {
48 if (item_) 77 if (item_)
49 item_->RemoveObserver(this); 78 item_->RemoveObserver(this);
50 } 79 }
51 80
52 void SearchResultTileItemView::SetSearchResult(SearchResult* item) { 81 void SearchResultTileItemView::SetSearchResult(SearchResult* item) {
53 // Handle the case where this may be called from a nested run loop while its 82 // Handle the case where this may be called from a nested run loop while its
54 // context menu is showing. This cancels the menu (it's for the old item). 83 // context menu is showing. This cancels the menu (it's for the old item).
55 context_menu_runner_.reset(); 84 context_menu_runner_.reset();
56 85
57 SetVisible(!!item); 86 SetVisible(!!item);
58 87
59 SearchResult* old_item = item_; 88 SearchResult* old_item = item_;
60 if (old_item) 89 if (old_item)
61 old_item->RemoveObserver(this); 90 old_item->RemoveObserver(this);
62 91
63 item_ = item; 92 item_ = item;
64 93
65 if (!item) 94 if (!item)
66 return; 95 return;
67 96
68 item_->AddObserver(this); 97 item_->AddObserver(this);
69 98
70 SetTitle(item_->title()); 99 SetTitle(item_->title());
100 SetRating(item_->rating());
101 SetPrice(item_->price());
71 102
72 // Customize title UI 103 // Customize title UI
73 gfx::FontList base_font = ui::ResourceBundle::GetSharedInstance().GetFontList( 104 gfx::FontList base_font = ui::ResourceBundle::GetSharedInstance().GetFontList(
xiyuan 2017/06/22 17:07:34 nit: ditto, const gfx::FontList& and move it insi
weidongg 2017/06/22 17:58:29 Done.
74 ui::ResourceBundle::BaseFont); 105 ui::ResourceBundle::BaseFont);
75 if (is_fullscreen_app_list_enabled_ && 106 if (is_fullscreen_app_list_enabled_) {
76 item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) { 107 if (item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) {
77 title()->SetFontList(base_font.DeriveWithSizeDelta(1)); 108 title()->SetFontList(base_font.DeriveWithSizeDelta(1));
78 title()->SetEnabledColor(kRecommendationTileColor); 109 title()->SetEnabledColor(kRecommendationTileColor);
110 } else if (item_->display_type() == SearchResult::DISPLAY_TILE) {
111 title()->SetFontList(base_font.DeriveWithSizeDelta(1));
112 title()->SetEnabledColor(kSearchTitleColor);
113 }
79 } 114 }
80 115
81 // Only refresh the icon if it's different from the old one. This prevents 116 // Only refresh the icon if it's different from the old one. This prevents
82 // flickering. 117 // flickering.
83 if (!old_item || !item->icon().BackedBySameObjectAs(old_item->icon())) { 118 if (!old_item || !item->icon().BackedBySameObjectAs(old_item->icon())) {
84 OnIconChanged(); 119 OnIconChanged();
85 } 120 }
86 } 121 }
87 122
123 void SearchResultTileItemView::SetRating(float rating) {
124 if (!rating_)
125 return;
126
127 if (rating < 0) {
128 rating_->SetVisible(false);
129 return;
130 }
131
132 rating_->SetText(base::FormatDouble(rating, 1));
133 rating_->SetVisible(true);
134 }
135
136 void SearchResultTileItemView::SetPrice(const base::string16& price) {
137 if (!price_)
138 return;
139
140 if (price.empty()) {
141 price_->SetVisible(false);
142 return;
143 }
144
145 price_->SetText(price);
146 price_->SetVisible(true);
147 }
148
88 void SearchResultTileItemView::ButtonPressed(views::Button* sender, 149 void SearchResultTileItemView::ButtonPressed(views::Button* sender,
89 const ui::Event& event) { 150 const ui::Event& event) {
90 view_delegate_->OpenSearchResult(item_, false, event.flags()); 151 view_delegate_->OpenSearchResult(item_, false, event.flags());
91 } 152 }
92 153
93 bool SearchResultTileItemView::OnKeyPressed(const ui::KeyEvent& event) { 154 bool SearchResultTileItemView::OnKeyPressed(const ui::KeyEvent& event) {
94 if (event.key_code() == ui::VKEY_RETURN) { 155 if (event.key_code() == ui::VKEY_RETURN) {
95 view_delegate_->OpenSearchResult(item_, false, event.flags()); 156 view_delegate_->OpenSearchResult(item_, false, event.flags());
96 return true; 157 return true;
97 } 158 }
98 159
99 return false; 160 return false;
100 } 161 }
101 162
102 void SearchResultTileItemView::OnIconChanged() { 163 void SearchResultTileItemView::OnIconChanged() {
103 SetIcon(item_->icon()); 164 SetIcon(item_->icon());
104 } 165 }
105 166
106 void SearchResultTileItemView::OnBadgeIconChanged() { 167 void SearchResultTileItemView::OnBadgeIconChanged() {
107 SetBadgeIcon(item_->badge_icon()); 168 SetBadgeIcon(item_->badge_icon());
108 } 169 }
109 170
171 void SearchResultTileItemView::OnRatingChanged() {
172 SetRating(item_->rating());
173 }
174
175 void SearchResultTileItemView::OnPriceChanged() {
176 SetPrice(item_->price());
177 }
178
110 void SearchResultTileItemView::OnResultDestroying() { 179 void SearchResultTileItemView::OnResultDestroying() {
111 // The menu comes from |item_|. If we're showing a menu we need to cancel it. 180 // The menu comes from |item_|. If we're showing a menu we need to cancel it.
112 context_menu_runner_.reset(); 181 context_menu_runner_.reset();
113 182
114 if (item_) 183 if (item_)
115 item_->RemoveObserver(this); 184 item_->RemoveObserver(this);
116 185
117 SetSearchResult(nullptr); 186 SetSearchResult(nullptr);
118 } 187 }
119 188
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 gfx::Size icon_size = icon()->GetImage().size(); 235 gfx::Size icon_size = icon()->GetImage().size();
167 badge_rect.Offset( 236 badge_rect.Offset(
168 (icon_size.width() - kAppBadgeIconSize) / 2, 237 (icon_size.width() - kAppBadgeIconSize) / 2,
169 icon_size.height() - kBadgeBackgroundRadius - kAppBadgeIconSize / 2); 238 icon_size.height() - kBadgeBackgroundRadius - kAppBadgeIconSize / 2);
170 badge()->SetBoundsRect(badge_rect); 239 badge()->SetBoundsRect(badge_rect);
171 } 240 }
172 241
173 rect.Inset(0, kGridIconDimension + kSearchTitleSpacing, 0, 0); 242 rect.Inset(0, kGridIconDimension + kSearchTitleSpacing, 0, 0);
174 rect.set_height(title()->GetPreferredSize().height()); 243 rect.set_height(title()->GetPreferredSize().height());
175 title()->SetBoundsRect(rect); 244 title()->SetBoundsRect(rect);
245
246 if (rating_) {
247 gfx::Rect rating_rect(rect);
248 rating_rect.Inset(0, title()->GetPreferredSize().height(), 0, 0);
249 rating_rect.set_height(rating_->GetPreferredSize().height());
250 rating_->SetBoundsRect(rating_rect);
251 }
252
253 if (price_) {
254 gfx::Rect price_rect(rect);
255 price_rect.Inset(0, title()->GetPreferredSize().height(), 0, 0);
xiyuan 2017/06/22 17:07:34 Would this overlap with |reating_rect|?
weidongg 2017/06/22 17:58:30 Yes, it is overlapping with rating_rect. I want to
xiyuan 2017/06/22 18:17:21 I see. I would recommend creating a container vie
256 price_rect.set_height(price_->GetPreferredSize().height());
257 price_->SetBoundsRect(price_rect);
258 }
176 } else { 259 } else {
177 TileItemView::Layout(); 260 TileItemView::Layout();
178 } 261 }
179 } 262 }
180 263
181 gfx::Size SearchResultTileItemView::CalculatePreferredSize() const { 264 gfx::Size SearchResultTileItemView::CalculatePreferredSize() const {
182 if (is_fullscreen_app_list_enabled_ && item_ && 265 if (is_fullscreen_app_list_enabled_ && item_) {
183 item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) { 266 if (item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION)
184 return gfx::Size(kRecommendationTileWidth, kRecommendationTileHeight); 267 return gfx::Size(kRecommendationTileWidth, kRecommendationTileHeight);
268 if (item_->display_type() == SearchResult::DISPLAY_TILE)
269 return gfx::Size(kSearchTileWidth, kSearchTileHeight);
185 } 270 }
186 271
187 return TileItemView::CalculatePreferredSize(); 272 return TileItemView::CalculatePreferredSize();
188 } 273 }
189 274
190 } // namespace app_list 275 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698