| Index: ui/app_list/views/search_result_tile_item_view.cc
|
| diff --git a/ui/app_list/views/search_result_tile_item_view.cc b/ui/app_list/views/search_result_tile_item_view.cc
|
| index 088e638b811295a7a463e12ede36f9360a316c4c..6df3a3b0d87ca28e322f6877a570fb86d92f917b 100644
|
| --- a/ui/app_list/views/search_result_tile_item_view.cc
|
| +++ b/ui/app_list/views/search_result_tile_item_view.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "ui/app_list/views/search_result_tile_item_view.h"
|
|
|
| +#include "base/i18n/number_formatting.h"
|
| #include "ui/app_list/app_list_constants.h"
|
| #include "ui/app_list/app_list_features.h"
|
| #include "ui/app_list/app_list_view_delegate.h"
|
| @@ -23,24 +24,52 @@ constexpr int kRecommendationIconTopPadding = 24;
|
| constexpr int kRecommendationTitleSpacing = 10;
|
| constexpr int kRecommendationTileMaxWidth = 80;
|
|
|
| +constexpr int kSearchTileWidth = 80;
|
| +constexpr int kSearchTileHeight = 92;
|
| constexpr int kSearchTileTopPadding = 4;
|
| constexpr int kSearchTitleSpacing = 6;
|
|
|
| constexpr SkColor kRecommendationTileColor = SK_ColorWHITE;
|
|
|
| +constexpr SkColor kSearchTitleColor =
|
| + SkColorSetARGBMacro(0xDF, 0x00, 0x00, 0x00);
|
| +constexpr SkColor kSearchAppRatingColor =
|
| + SkColorSetARGBMacro(0x8F, 0x00, 0x00, 0x00);
|
| +constexpr SkColor kSearchAppPriceColor =
|
| + SkColorSetARGBMacro(0xFF, 0x0F, 0x9D, 0x58);
|
| +
|
| } // namespace
|
|
|
| SearchResultTileItemView::SearchResultTileItemView(
|
| SearchResultContainerView* result_container,
|
| AppListViewDelegate* view_delegate)
|
| : result_container_(result_container),
|
| - item_(nullptr),
|
| view_delegate_(view_delegate),
|
| is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) {
|
| // When |item_| is null, the tile is invisible. Calling SetSearchResult with a
|
| // non-null item makes the tile visible.
|
| SetVisible(false);
|
|
|
| + if (is_fullscreen_app_list_enabled_) {
|
| + const gfx::FontList& base_font =
|
| + ui::ResourceBundle::GetSharedInstance().GetFontList(
|
| + ui::ResourceBundle::BaseFont);
|
| +
|
| + rating_ = new views::Label;
|
| + rating_->SetEnabledColor(kSearchAppRatingColor);
|
| + rating_->SetFontList(base_font);
|
| + rating_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
|
| + rating_->SetVisible(false);
|
| + AddChildView(rating_);
|
| +
|
| + price_ = new views::Label;
|
| + price_->SetEnabledColor(kSearchAppPriceColor);
|
| + price_->SetFontList(base_font);
|
| + price_->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
|
| + price_->SetVisible(false);
|
| + AddChildView(price_);
|
| + }
|
| +
|
| set_context_menu_controller(this);
|
| }
|
|
|
| @@ -68,14 +97,22 @@ void SearchResultTileItemView::SetSearchResult(SearchResult* item) {
|
| item_->AddObserver(this);
|
|
|
| SetTitle(item_->title());
|
| -
|
| - // Customize title UI
|
| - gfx::FontList base_font = ui::ResourceBundle::GetSharedInstance().GetFontList(
|
| - ui::ResourceBundle::BaseFont);
|
| - if (is_fullscreen_app_list_enabled_ &&
|
| - item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) {
|
| - title()->SetFontList(base_font.DeriveWithSizeDelta(1));
|
| - title()->SetEnabledColor(kRecommendationTileColor);
|
| + SetRating(item_->rating());
|
| + SetPrice(item_->formatted_price());
|
| +
|
| + if (is_fullscreen_app_list_enabled_) {
|
| + const gfx::FontList& base_font =
|
| + ui::ResourceBundle::GetSharedInstance().GetFontList(
|
| + ui::ResourceBundle::BaseFont);
|
| +
|
| + // Customize title UI
|
| + if (item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) {
|
| + title()->SetFontList(base_font.DeriveWithSizeDelta(1));
|
| + title()->SetEnabledColor(kRecommendationTileColor);
|
| + } else if (item_->display_type() == SearchResult::DISPLAY_TILE) {
|
| + title()->SetFontList(base_font.DeriveWithSizeDelta(1));
|
| + title()->SetEnabledColor(kSearchTitleColor);
|
| + }
|
| }
|
|
|
| // Only refresh the icon if it's different from the old one. This prevents
|
| @@ -85,6 +122,32 @@ void SearchResultTileItemView::SetSearchResult(SearchResult* item) {
|
| }
|
| }
|
|
|
| +void SearchResultTileItemView::SetRating(float rating) {
|
| + if (!rating_)
|
| + return;
|
| +
|
| + if (rating < 0) {
|
| + rating_->SetVisible(false);
|
| + return;
|
| + }
|
| +
|
| + rating_->SetText(base::FormatDouble(rating, 1));
|
| + rating_->SetVisible(true);
|
| +}
|
| +
|
| +void SearchResultTileItemView::SetPrice(const base::string16& price) {
|
| + if (!price_)
|
| + return;
|
| +
|
| + if (price.empty()) {
|
| + price_->SetVisible(false);
|
| + return;
|
| + }
|
| +
|
| + price_->SetText(price);
|
| + price_->SetVisible(true);
|
| +}
|
| +
|
| void SearchResultTileItemView::ButtonPressed(views::Button* sender,
|
| const ui::Event& event) {
|
| view_delegate_->OpenSearchResult(item_, false, event.flags());
|
| @@ -107,6 +170,14 @@ void SearchResultTileItemView::OnBadgeIconChanged() {
|
| SetBadgeIcon(item_->badge_icon());
|
| }
|
|
|
| +void SearchResultTileItemView::OnRatingChanged() {
|
| + SetRating(item_->rating());
|
| +}
|
| +
|
| +void SearchResultTileItemView::OnFormattedPriceChanged() {
|
| + SetPrice(item_->formatted_price());
|
| +}
|
| +
|
| void SearchResultTileItemView::OnResultDestroying() {
|
| // The menu comes from |item_|. If we're showing a menu we need to cancel it.
|
| context_menu_runner_.reset();
|
| @@ -173,15 +244,31 @@ void SearchResultTileItemView::Layout() {
|
| rect.Inset(0, kGridIconDimension + kSearchTitleSpacing, 0, 0);
|
| rect.set_height(title()->GetPreferredSize().height());
|
| title()->SetBoundsRect(rect);
|
| +
|
| + if (rating_) {
|
| + gfx::Rect rating_rect(rect);
|
| + rating_rect.Inset(0, title()->GetPreferredSize().height(), 0, 0);
|
| + rating_rect.set_height(rating_->GetPreferredSize().height());
|
| + rating_->SetBoundsRect(rating_rect);
|
| + }
|
| +
|
| + if (price_) {
|
| + gfx::Rect price_rect(rect);
|
| + price_rect.Inset(0, title()->GetPreferredSize().height(), 0, 0);
|
| + price_rect.set_height(price_->GetPreferredSize().height());
|
| + price_->SetBoundsRect(price_rect);
|
| + }
|
| } else {
|
| TileItemView::Layout();
|
| }
|
| }
|
|
|
| gfx::Size SearchResultTileItemView::CalculatePreferredSize() const {
|
| - if (is_fullscreen_app_list_enabled_ && item_ &&
|
| - item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION) {
|
| - return gfx::Size(kRecommendationTileWidth, kRecommendationTileHeight);
|
| + if (is_fullscreen_app_list_enabled_ && item_) {
|
| + if (item_->display_type() == SearchResult::DISPLAY_RECOMMENDATION)
|
| + return gfx::Size(kRecommendationTileWidth, kRecommendationTileHeight);
|
| + if (item_->display_type() == SearchResult::DISPLAY_TILE)
|
| + return gfx::Size(kSearchTileWidth, kSearchTileHeight);
|
| }
|
|
|
| return TileItemView::CalculatePreferredSize();
|
|
|