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

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

Issue 2949733002: Show Play Store rating and price in app list (Closed)
Patch Set: 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/tile_item_view.h" 5 #include "ui/app_list/views/tile_item_view.h"
6 6
7 #include "ui/app_list/app_list_constants.h" 7 #include "ui/app_list/app_list_constants.h"
8 #include "ui/app_list/app_list_features.h" 8 #include "ui/app_list/app_list_features.h"
9 #include "ui/app_list/views/app_list_main_view.h" 9 #include "ui/app_list/views/app_list_main_view.h"
10 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
11 #include "ui/gfx/font_list.h"
11 #include "ui/gfx/image/canvas_image_source.h" 12 #include "ui/gfx/image/canvas_image_source.h"
12 #include "ui/gfx/image/image_skia_operations.h" 13 #include "ui/gfx/image/image_skia_operations.h"
13 #include "ui/views/background.h" 14 #include "ui/views/background.h"
14 #include "ui/views/controls/image_view.h" 15 #include "ui/views/controls/image_view.h"
15 #include "ui/views/controls/label.h" 16 #include "ui/views/controls/label.h"
16 #include "ui/views/layout/box_layout.h" 17 #include "ui/views/layout/box_layout.h"
17 18
18 namespace { 19 namespace {
19 20
20 constexpr int kTopPadding = 5; 21 constexpr int kTopPadding = 5;
21 constexpr int kTileSize = 90; 22 constexpr int kTileSize = 90;
22 constexpr int kIconTitleSpacing = 6; 23 constexpr int kIconTitleSpacing = 6;
23 24
24 constexpr int kBadgeBackgroundRadius = 10; 25 constexpr int kBadgeBackgroundRadius = 10;
25 26
27 // Layout constants used when fullscreen app list feature is enabled.
28 constexpr int kItemTopPadding = 4;
29 constexpr int kItemWidth = 80;
30 constexpr int kItemHeight = 90;
31
26 // The background image source for badge. 32 // The background image source for badge.
27 class BadgeBackgroundImageSource : public gfx::CanvasImageSource { 33 class BadgeBackgroundImageSource : public gfx::CanvasImageSource {
28 public: 34 public:
29 explicit BadgeBackgroundImageSource(int size) 35 explicit BadgeBackgroundImageSource(int size)
30 : CanvasImageSource(gfx::Size(size, size), false), 36 : CanvasImageSource(gfx::Size(size, size), false),
31 radius_(static_cast<float>(size / 2)) {} 37 radius_(static_cast<float>(size / 2)) {}
32 ~BadgeBackgroundImageSource() override = default; 38 ~BadgeBackgroundImageSource() override = default;
33 39
34 private: 40 private:
35 // gfx::CanvasImageSource overrides: 41 // gfx::CanvasImageSource overrides:
(...skipping 12 matching lines...) Expand all
48 54
49 } // namespace 55 } // namespace
50 56
51 namespace app_list { 57 namespace app_list {
52 58
53 TileItemView::TileItemView() 59 TileItemView::TileItemView()
54 : views::CustomButton(this), 60 : views::CustomButton(this),
55 parent_background_color_(SK_ColorTRANSPARENT), 61 parent_background_color_(SK_ColorTRANSPARENT),
56 icon_(new views::ImageView), 62 icon_(new views::ImageView),
57 badge_(nullptr), 63 badge_(nullptr),
58 title_(new views::Label) { 64 title_(new views::Label),
65 price_(nullptr),
66 rating_(nullptr),
67 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) {
59 // Prevent the icon view from interfering with our mouse events. 68 // Prevent the icon view from interfering with our mouse events.
60 icon_->set_can_process_events_within_subtree(false); 69 icon_->set_can_process_events_within_subtree(false);
61 icon_->SetVerticalAlignment(views::ImageView::LEADING); 70 icon_->SetVerticalAlignment(views::ImageView::LEADING);
62 71
63 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 72 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
64 title_->SetAutoColorReadabilityEnabled(false); 73 title_->SetAutoColorReadabilityEnabled(false);
65 title_->SetEnabledColor(kGridTitleColor); 74 title_->SetEnabledColor(kGridTitleColor);
66 title_->SetFontList(rb.GetFontList(kItemTextFontStyle)); 75 title_->SetFontList(rb.GetFontList(kItemTextFontStyle));
67 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 76 title_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
68 title_->SetHandlesTooltips(false); 77 title_->SetHandlesTooltips(false);
69 78
70 AddChildView(icon_); 79 AddChildView(icon_);
71 if (features::IsFullscreenAppListEnabled()) { 80 AddChildView(title_);
81
82 if (is_fullscreen_app_list_enabled_) {
72 badge_ = new views::ImageView(); 83 badge_ = new views::ImageView();
73 badge_->set_can_process_events_within_subtree(false); 84 badge_->set_can_process_events_within_subtree(false);
74 badge_->SetVerticalAlignment(views::ImageView::LEADING); 85 badge_->SetVerticalAlignment(views::ImageView::LEADING);
75 AddChildView(badge_); 86 AddChildView(badge_);
87
88 price_ = new views::Label;
89 price_->SetEnabledColor(kAppPriceColor);
90 price_->SetFontList(gfx::FontList(kAppPriceFontList));
xiyuan 2017/06/20 22:19:23 Roboto is the current default UI font. Let's try n
weidongg 2017/06/22 00:59:16 Good to know, thanks. Done.
91 price_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
92 AddChildView(price_);
93
94 rating_ = new views::Label;
95 rating_->SetEnabledColor(kAppRatingColor);
96 rating_->SetFontList(gfx::FontList(kAppRatingFontList));
97 rating_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
98 AddChildView(rating_);
76 } 99 }
77 AddChildView(title_);
78 } 100 }
79 101
80 TileItemView::~TileItemView() = default; 102 TileItemView::~TileItemView() = default;
81 103
82 void TileItemView::SetSelected(bool selected) { 104 void TileItemView::SetSelected(bool selected) {
83 if (selected == selected_) 105 if (selected == selected_)
84 return; 106 return;
85 107
86 selected_ = selected; 108 selected_ = selected;
87 UpdateBackgroundColor(); 109 UpdateBackgroundColor();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 badge_->SetImage(gfx::ImageSkiaOperations::CreateImageWithDropShadow( 163 badge_->SetImage(gfx::ImageSkiaOperations::CreateImageWithDropShadow(
142 icon_with_background, shadow_values)); 164 icon_with_background, shadow_values));
143 badge_->SetVisible(true); 165 badge_->SetVisible(true);
144 } 166 }
145 167
146 void TileItemView::SetTitle(const base::string16& title) { 168 void TileItemView::SetTitle(const base::string16& title) {
147 title_->SetText(title); 169 title_->SetText(title);
148 SetAccessibleName(title); 170 SetAccessibleName(title);
149 } 171 }
150 172
173 void TileItemView::SetPrice(const base::string16& price) {
174 if (!price_)
175 return;
176 price_->SetText(price);
177 }
178
179 void TileItemView::SetRating(const base::string16& rating) {
180 if (!rating_)
181 return;
182 rating_->SetText(rating);
183 }
184
151 void TileItemView::StateChanged(ButtonState old_state) { 185 void TileItemView::StateChanged(ButtonState old_state) {
152 UpdateBackgroundColor(); 186 UpdateBackgroundColor();
153 } 187 }
154 188
155 void TileItemView::Layout() { 189 void TileItemView::Layout() {
Qiang(Joe) Xu 2017/06/21 17:43:12 I think we would better not do Layout here. TileIt
weidongg 2017/06/22 00:59:16 Yes, agree. Rebased to your change.
156 gfx::Rect rect(GetContentsBounds()); 190 gfx::Rect rect(GetContentsBounds());
157 if (rect.IsEmpty()) 191 if (rect.IsEmpty())
158 return; 192 return;
159 193
160 rect.Inset(0, kTopPadding, 0, 0); 194 rect.Inset(0, is_fullscreen_app_list_enabled_ ? kItemTopPadding : kTopPadding,
195 0, 0);
161 icon_->SetBoundsRect(rect); 196 icon_->SetBoundsRect(rect);
162 197
163 if (badge_) { 198 if (badge_) {
164 gfx::Rect badge_rect(rect); 199 gfx::Rect badge_rect(rect);
165 gfx::Size icon_size = icon_->GetImage().size(); 200 gfx::Size icon_size = icon_->GetImage().size();
166 badge_rect.Offset( 201 badge_rect.Offset(
167 (icon_size.width() - kAppBadgeIconSize) / 2, 202 (icon_size.width() - kAppBadgeIconSize) / 2,
168 icon_size.height() - kBadgeBackgroundRadius - kAppBadgeIconSize / 2); 203 icon_size.height() - kBadgeBackgroundRadius - kAppBadgeIconSize / 2);
169 badge_->SetBoundsRect(badge_rect); 204 badge_->SetBoundsRect(badge_rect);
170 } 205 }
171 206
172 rect.Inset(0, kGridIconDimension + kIconTitleSpacing, 0, 0); 207 rect.Inset(0, kGridIconDimension + kIconTitleSpacing, 0, 0);
173 rect.set_height(title_->GetPreferredSize().height()); 208 rect.set_height(title_->GetPreferredSize().height());
174 title_->SetBoundsRect(rect); 209 title_->SetBoundsRect(rect);
210
211 if (price_) {
212 gfx::Rect price_rect(rect);
213 price_rect.Inset(0, title_->GetPreferredSize().height(), 0, 0);
214 price_rect.set_height(price_->GetPreferredSize().height());
215 price_->SetBoundsRect(price_rect);
216 }
217
218 if (rating_) {
219 gfx::Rect rating_rect(rect);
220 rating_rect.Inset(0, title_->GetPreferredSize().height(), 0, 0);
221 rating_rect.set_height(rating_->GetPreferredSize().height());
222 rating_->SetBoundsRect(rating_rect);
223 }
175 } 224 }
176 225
177 const char* TileItemView::GetClassName() const { 226 const char* TileItemView::GetClassName() const {
178 return "TileItemView"; 227 return "TileItemView";
179 } 228 }
180 229
181 void TileItemView::ImageShadowAnimationProgressed( 230 void TileItemView::ImageShadowAnimationProgressed(
182 ImageShadowAnimator* animator) { 231 ImageShadowAnimator* animator) {
183 icon_->SetImage(animator->shadow_image()); 232 icon_->SetImage(animator->shadow_image());
184 } 233 }
(...skipping 18 matching lines...) Expand all
203 // Tell the label what color it will be drawn onto. It will use whether the 252 // Tell the label what color it will be drawn onto. It will use whether the
204 // background color is opaque or transparent to decide whether to use subpixel 253 // background color is opaque or transparent to decide whether to use subpixel
205 // rendering. Does not actually set the label's background color. 254 // rendering. Does not actually set the label's background color.
206 title_->SetBackgroundColor(background_color); 255 title_->SetBackgroundColor(background_color);
207 256
208 SetBackground(std::move(background)); 257 SetBackground(std::move(background));
209 SchedulePaint(); 258 SchedulePaint();
210 } 259 }
211 260
212 gfx::Size TileItemView::CalculatePreferredSize() const { 261 gfx::Size TileItemView::CalculatePreferredSize() const {
213 return gfx::Size(kTileSize, kTileSize); 262 if (is_fullscreen_app_list_enabled_)
263 return gfx::Size(kItemWidth, kItemHeight);
264 else
xiyuan 2017/06/20 22:19:23 Don't use else after return. See https://chromium
weidongg 2017/06/22 00:59:16 Done.
265 return gfx::Size(kTileSize, kTileSize);
214 } 266 }
215 267
216 bool TileItemView::GetTooltipText(const gfx::Point& p, 268 bool TileItemView::GetTooltipText(const gfx::Point& p,
217 base::string16* tooltip) const { 269 base::string16* tooltip) const {
218 // Use the label to generate a tooltip, so that it will consider its text 270 // Use the label to generate a tooltip, so that it will consider its text
219 // truncation in making the tooltip. We do not want the label itself to have a 271 // truncation in making the tooltip. We do not want the label itself to have a
220 // tooltip, so we only temporarily enable it to get the tooltip text from the 272 // tooltip, so we only temporarily enable it to get the tooltip text from the
221 // label, then disable it again. 273 // label, then disable it again.
222 title_->SetHandlesTooltips(true); 274 title_->SetHandlesTooltips(true);
223 bool handled = title_->GetTooltipText(p, tooltip); 275 bool handled = title_->GetTooltipText(p, tooltip);
224 title_->SetHandlesTooltips(false); 276 title_->SetHandlesTooltips(false);
225 return handled; 277 return handled;
226 } 278 }
227 279
228 } // namespace app_list 280 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698