Commit 29cece34 authored by calamity@chromium.org's avatar calamity@chromium.org

Move app list search result icon sizes to app_list_constants.

This CL is a pure refactor of app list search result icon sizes which were
previously constants scattered about the codebase. This CL puts the icon
size as a static function in SearchResult so that there is only one place
the size needs to be changed.

BUG=391348

Review URL: https://codereview.chromium.org/458983004

Cr-Commit-Position: refs/heads/master@{#289517}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289517 0039d316-1c4b-4281-b951-d872f2087c98
parent c5700bb9
...@@ -47,14 +47,13 @@ AppResult::AppResult(Profile* profile, ...@@ -47,14 +47,13 @@ AppResult::AppResult(Profile* profile,
is_platform_app_ = extension->is_platform_app(); is_platform_app_ = extension->is_platform_app();
icon_.reset(new extensions::IconImage( icon_.reset(
profile_, new extensions::IconImage(profile_,
extension, extension,
extensions::IconsInfo::GetIcons(extension), extensions::IconsInfo::GetIcons(extension),
display_type() == DISPLAY_TILE ? extension_misc::EXTENSION_ICON_MEDIUM GetPreferredIconDimension(),
: extension_misc::EXTENSION_ICON_SMALL, extensions::util::GetDefaultAppIcon(),
extensions::util::GetDefaultAppIcon(), this));
this));
UpdateIcon(); UpdateIcon();
StartObservingExtensionRegistry(); StartObservingExtensionRegistry();
......
...@@ -33,7 +33,6 @@ using extensions::api::hangouts_private::HangoutRequest; ...@@ -33,7 +33,6 @@ using extensions::api::hangouts_private::HangoutRequest;
namespace { namespace {
const int kIconSize = 32;
const char kImageSizePath[] = "s64-p/"; const char kImageSizePath[] = "s64-p/";
const char kEmailUrlPrefix[] = "mailto:"; const char kEmailUrlPrefix[] = "mailto:";
...@@ -71,14 +70,15 @@ PeopleResult::PeopleResult(Profile* profile, scoped_ptr<Person> person) ...@@ -71,14 +70,15 @@ PeopleResult::PeopleResult(Profile* profile, scoped_ptr<Person> person)
RefreshHangoutsExtensionId(); RefreshHangoutsExtensionId();
SetDefaultActions(); SetDefaultActions();
int icon_size = GetPreferredIconDimension();
image_ = gfx::ImageSkia( image_ = gfx::ImageSkia(
new UrlIconSource(base::Bind(&PeopleResult::OnIconLoaded, new UrlIconSource(
weak_factory_.GetWeakPtr()), base::Bind(&PeopleResult::OnIconLoaded, weak_factory_.GetWeakPtr()),
profile_->GetRequestContext(), profile_->GetRequestContext(),
GetImageUrl(person_->image_url), GetImageUrl(person_->image_url),
kIconSize, icon_size,
IDR_PROFILE_PICTURE_LOADING), IDR_PROFILE_PICTURE_LOADING),
gfx::Size(kIconSize, kIconSize)); gfx::Size(icon_size, icon_size));
SetIcon(image_); SetIcon(image_);
} }
......
...@@ -34,16 +34,13 @@ ...@@ -34,16 +34,13 @@
namespace { namespace {
const int kIconSize = 32;
const int kLaunchEphemeralAppAction = 1; const int kLaunchEphemeralAppAction = 1;
// BadgedImageSource adds a webstore badge to a webstore app icon. // BadgedImageSource adds a webstore badge to a webstore app icon.
class BadgedIconSource : public gfx::CanvasImageSource { class BadgedIconSource : public gfx::CanvasImageSource {
public: public:
explicit BadgedIconSource(const gfx::ImageSkia& icon) BadgedIconSource(const gfx::ImageSkia& icon, const gfx::Size& icon_size)
: CanvasImageSource(gfx::Size(kIconSize, kIconSize), false), : CanvasImageSource(icon_size, false), icon_(icon) {}
icon_(icon) {
}
virtual void Draw(gfx::Canvas* canvas) OVERRIDE { virtual void Draw(gfx::Canvas* canvas) OVERRIDE {
canvas->DrawImageInt(icon_, 0, 0); canvas->DrawImageInt(icon_, 0, 0);
...@@ -89,14 +86,15 @@ WebstoreResult::WebstoreResult(Profile* profile, ...@@ -89,14 +86,15 @@ WebstoreResult::WebstoreResult(Profile* profile,
InitAndStartObserving(); InitAndStartObserving();
UpdateActions(); UpdateActions();
int icon_dimension = GetPreferredIconDimension();
icon_ = gfx::ImageSkia( icon_ = gfx::ImageSkia(
new UrlIconSource(base::Bind(&WebstoreResult::OnIconLoaded, new UrlIconSource(
weak_factory_.GetWeakPtr()), base::Bind(&WebstoreResult::OnIconLoaded, weak_factory_.GetWeakPtr()),
profile_->GetRequestContext(), profile_->GetRequestContext(),
icon_url_, icon_url_,
kIconSize, icon_dimension,
IDR_WEBSTORE_ICON_32), IDR_WEBSTORE_ICON_32),
gfx::Size(kIconSize, kIconSize)); gfx::Size(icon_dimension, icon_dimension));
SetIcon(icon_); SetIcon(icon_);
} }
...@@ -203,9 +201,9 @@ void WebstoreResult::OnIconLoaded() { ...@@ -203,9 +201,9 @@ void WebstoreResult::OnIconLoaded() {
const std::vector<gfx::ImageSkiaRep>& image_reps = icon_.image_reps(); const std::vector<gfx::ImageSkiaRep>& image_reps = icon_.image_reps();
for (size_t i = 0; i < image_reps.size(); ++i) for (size_t i = 0; i < image_reps.size(); ++i)
icon_.RemoveRepresentation(image_reps[i].scale()); icon_.RemoveRepresentation(image_reps[i].scale());
int icon_dimension = GetPreferredIconDimension();
icon_ = gfx::ImageSkia(new BadgedIconSource(icon_), gfx::Size icon_size(icon_dimension, icon_dimension);
gfx::Size(kIconSize, kIconSize)); icon_ = gfx::ImageSkia(new BadgedIconSource(icon_, icon_size), icon_size);
SetIcon(icon_); SetIcon(icon_);
} }
......
...@@ -66,6 +66,10 @@ const int kPreferredCols = 4; ...@@ -66,6 +66,10 @@ const int kPreferredCols = 4;
const int kPreferredRows = 4; const int kPreferredRows = 4;
const int kPreferredIconDimension = 48; const int kPreferredIconDimension = 48;
// Preferred search result icon sizes.
const int kListIconSize = 32;
const int kTileIconSize = 48;
// Preferred number of columns and rows in the experimental app list apps grid. // Preferred number of columns and rows in the experimental app list apps grid.
const int kExperimentalPreferredCols = 6; const int kExperimentalPreferredCols = 6;
const int kExperimentalPreferredRows = 3; const int kExperimentalPreferredRows = 3;
......
...@@ -50,6 +50,9 @@ APP_LIST_EXPORT extern const int kPreferredCols; ...@@ -50,6 +50,9 @@ APP_LIST_EXPORT extern const int kPreferredCols;
APP_LIST_EXPORT extern const int kPreferredRows; APP_LIST_EXPORT extern const int kPreferredRows;
APP_LIST_EXPORT extern const int kPreferredIconDimension; APP_LIST_EXPORT extern const int kPreferredIconDimension;
APP_LIST_EXPORT extern const int kListIconSize;
APP_LIST_EXPORT extern const int kTileIconSize;
APP_LIST_EXPORT extern const int kExperimentalPreferredCols; APP_LIST_EXPORT extern const int kExperimentalPreferredCols;
APP_LIST_EXPORT extern const int kExperimentalPreferredRows; APP_LIST_EXPORT extern const int kExperimentalPreferredRows;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ui/app_list/search_result.h" #include "ui/app_list/search_result.h"
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/search_result_observer.h" #include "ui/app_list/search_result_observer.h"
namespace app_list { namespace app_list {
...@@ -67,6 +68,17 @@ void SearchResult::SetPercentDownloaded(int percent_downloaded) { ...@@ -67,6 +68,17 @@ void SearchResult::SetPercentDownloaded(int percent_downloaded) {
OnPercentDownloadedChanged()); OnPercentDownloadedChanged());
} }
int SearchResult::GetPreferredIconDimension() const {
switch (display_type_) {
case DISPLAY_TILE:
return kTileIconSize;
case DISPLAY_LIST:
return kListIconSize;
}
NOTREACHED();
return 0;
}
void SearchResult::NotifyItemInstalled() { void SearchResult::NotifyItemInstalled() {
FOR_EACH_OBSERVER(SearchResultObserver, observers_, OnItemInstalled()); FOR_EACH_OBSERVER(SearchResultObserver, observers_, OnItemInstalled());
} }
......
...@@ -109,6 +109,9 @@ class APP_LIST_EXPORT SearchResult { ...@@ -109,6 +109,9 @@ class APP_LIST_EXPORT SearchResult {
int percent_downloaded() const { return percent_downloaded_; } int percent_downloaded() const { return percent_downloaded_; }
void SetPercentDownloaded(int percent_downloaded); void SetPercentDownloaded(int percent_downloaded);
// Returns the dimension at which this result's icon should be displayed.
int GetPreferredIconDimension() const;
void NotifyItemInstalled(); void NotifyItemInstalled();
void NotifyItemUninstalled(); void NotifyItemUninstalled();
......
...@@ -25,15 +25,17 @@ namespace { ...@@ -25,15 +25,17 @@ namespace {
const int kPreferredWidth = 300; const int kPreferredWidth = 300;
const int kPreferredHeight = 52; const int kPreferredHeight = 52;
const int kIconDimension = 32;
const int kIconPadding = 14; const int kIconPadding = 14;
const int kIconViewWidth = kIconDimension + 2 * kIconPadding;
const int kTextTrailPadding = kIconPadding; const int kTextTrailPadding = kIconPadding;
const int kBorderSize = 1; const int kBorderSize = 1;
// Extra margin at the right of the rightmost action icon. // Extra margin at the right of the rightmost action icon.
const int kActionButtonRightMargin = 8; const int kActionButtonRightMargin = 8;
int GetIconViewWidth() {
return kListIconSize + 2 * kIconPadding;
}
// Creates a RenderText of given |text| and |styles|. Caller takes ownership // Creates a RenderText of given |text| and |styles|. Caller takes ownership
// of returned RenderText. // of returned RenderText.
gfx::RenderText* CreateRenderText(const base::string16& text, gfx::RenderText* CreateRenderText(const base::string16& text,
...@@ -143,8 +145,8 @@ void SearchResultView::Layout() { ...@@ -143,8 +145,8 @@ void SearchResultView::Layout() {
return; return;
gfx::Rect icon_bounds(rect); gfx::Rect icon_bounds(rect);
icon_bounds.set_width(kIconViewWidth); icon_bounds.set_width(GetIconViewWidth());
icon_bounds.Inset(kIconPadding, (rect.height() - kIconDimension) / 2); icon_bounds.Inset(kIconPadding, (rect.height() - kListIconSize) / 2);
icon_bounds.Intersect(rect); icon_bounds.Intersect(rect);
icon_->SetBoundsRect(icon_bounds); icon_->SetBoundsRect(icon_bounds);
...@@ -221,16 +223,16 @@ void SearchResultView::OnPaint(gfx::Canvas* canvas) { ...@@ -221,16 +223,16 @@ void SearchResultView::OnPaint(gfx::Canvas* canvas) {
canvas->FillRect(border_bottom, kResultBorderColor); canvas->FillRect(border_bottom, kResultBorderColor);
gfx::Rect text_bounds(rect); gfx::Rect text_bounds(rect);
text_bounds.set_x(kIconViewWidth); text_bounds.set_x(GetIconViewWidth());
if (actions_view_->visible()) { if (actions_view_->visible()) {
text_bounds.set_width( text_bounds.set_width(
rect.width() - kIconViewWidth - kTextTrailPadding - rect.width() - GetIconViewWidth() - kTextTrailPadding -
actions_view_->bounds().width() - actions_view_->bounds().width() -
(actions_view_->has_children() ? kActionButtonRightMargin : 0)); (actions_view_->has_children() ? kActionButtonRightMargin : 0));
} else { } else {
text_bounds.set_width( text_bounds.set_width(rect.width() - GetIconViewWidth() -
rect.width() - kIconViewWidth - kTextTrailPadding - kTextTrailPadding - progress_bar_->bounds().width() -
progress_bar_->bounds().width() - kActionButtonRightMargin); kActionButtonRightMargin);
} }
text_bounds.set_x(GetMirroredXWithWidthInView(text_bounds.x(), text_bounds.set_x(GetMirroredXWithWidthInView(text_bounds.x(),
text_bounds.width())); text_bounds.width()));
...@@ -279,11 +281,11 @@ void SearchResultView::OnIconChanged() { ...@@ -279,11 +281,11 @@ void SearchResultView::OnIconChanged() {
return; return;
// Scales down big icons but leave small ones unchanged. // Scales down big icons but leave small ones unchanged.
if (image.width() > kIconDimension || image.height() > kIconDimension) { if (image.width() > kListIconSize || image.height() > kListIconSize) {
image = gfx::ImageSkiaOperations::CreateResizedImage( image = gfx::ImageSkiaOperations::CreateResizedImage(
image, image,
skia::ImageOperations::RESIZE_BEST, skia::ImageOperations::RESIZE_BEST,
gfx::Size(kIconDimension, kIconDimension)); gfx::Size(kListIconSize, kListIconSize));
} else { } else {
icon_->ResetImageSize(); icon_->ResetImageSize();
} }
......
...@@ -22,7 +22,6 @@ namespace { ...@@ -22,7 +22,6 @@ namespace {
const int kTileSize = 90; const int kTileSize = 90;
const int kTileHorizontalPadding = 10; const int kTileHorizontalPadding = 10;
const int kTileImageSize = 48;
const SkColor kTileBackgroundColor = SK_ColorWHITE; const SkColor kTileBackgroundColor = SK_ColorWHITE;
const int kTileColorStripHeight = 2; const int kTileColorStripHeight = 2;
...@@ -85,7 +84,7 @@ TileItemView::TileItemView() ...@@ -85,7 +84,7 @@ TileItemView::TileItemView()
views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
SetLayoutManager(layout_manager); SetLayoutManager(layout_manager);
icon_->SetImageSize(gfx::Size(kTileImageSize, kTileImageSize)); icon_->SetImageSize(gfx::Size(kTileIconSize, kTileIconSize));
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
title_->SetAutoColorReadabilityEnabled(false); title_->SetAutoColorReadabilityEnabled(false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment