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,
is_platform_app_ = extension->is_platform_app();
icon_.reset(new extensions::IconImage(
profile_,
extension,
extensions::IconsInfo::GetIcons(extension),
display_type() == DISPLAY_TILE ? extension_misc::EXTENSION_ICON_MEDIUM
: extension_misc::EXTENSION_ICON_SMALL,
extensions::util::GetDefaultAppIcon(),
this));
icon_.reset(
new extensions::IconImage(profile_,
extension,
extensions::IconsInfo::GetIcons(extension),
GetPreferredIconDimension(),
extensions::util::GetDefaultAppIcon(),
this));
UpdateIcon();
StartObservingExtensionRegistry();
......
......@@ -33,7 +33,6 @@ using extensions::api::hangouts_private::HangoutRequest;
namespace {
const int kIconSize = 32;
const char kImageSizePath[] = "s64-p/";
const char kEmailUrlPrefix[] = "mailto:";
......@@ -71,14 +70,15 @@ PeopleResult::PeopleResult(Profile* profile, scoped_ptr<Person> person)
RefreshHangoutsExtensionId();
SetDefaultActions();
int icon_size = GetPreferredIconDimension();
image_ = gfx::ImageSkia(
new UrlIconSource(base::Bind(&PeopleResult::OnIconLoaded,
weak_factory_.GetWeakPtr()),
profile_->GetRequestContext(),
GetImageUrl(person_->image_url),
kIconSize,
IDR_PROFILE_PICTURE_LOADING),
gfx::Size(kIconSize, kIconSize));
new UrlIconSource(
base::Bind(&PeopleResult::OnIconLoaded, weak_factory_.GetWeakPtr()),
profile_->GetRequestContext(),
GetImageUrl(person_->image_url),
icon_size,
IDR_PROFILE_PICTURE_LOADING),
gfx::Size(icon_size, icon_size));
SetIcon(image_);
}
......
......@@ -34,16 +34,13 @@
namespace {
const int kIconSize = 32;
const int kLaunchEphemeralAppAction = 1;
// BadgedImageSource adds a webstore badge to a webstore app icon.
class BadgedIconSource : public gfx::CanvasImageSource {
public:
explicit BadgedIconSource(const gfx::ImageSkia& icon)
: CanvasImageSource(gfx::Size(kIconSize, kIconSize), false),
icon_(icon) {
}
BadgedIconSource(const gfx::ImageSkia& icon, const gfx::Size& icon_size)
: CanvasImageSource(icon_size, false), icon_(icon) {}
virtual void Draw(gfx::Canvas* canvas) OVERRIDE {
canvas->DrawImageInt(icon_, 0, 0);
......@@ -89,14 +86,15 @@ WebstoreResult::WebstoreResult(Profile* profile,
InitAndStartObserving();
UpdateActions();
int icon_dimension = GetPreferredIconDimension();
icon_ = gfx::ImageSkia(
new UrlIconSource(base::Bind(&WebstoreResult::OnIconLoaded,
weak_factory_.GetWeakPtr()),
profile_->GetRequestContext(),
icon_url_,
kIconSize,
IDR_WEBSTORE_ICON_32),
gfx::Size(kIconSize, kIconSize));
new UrlIconSource(
base::Bind(&WebstoreResult::OnIconLoaded, weak_factory_.GetWeakPtr()),
profile_->GetRequestContext(),
icon_url_,
icon_dimension,
IDR_WEBSTORE_ICON_32),
gfx::Size(icon_dimension, icon_dimension));
SetIcon(icon_);
}
......@@ -203,9 +201,9 @@ void WebstoreResult::OnIconLoaded() {
const std::vector<gfx::ImageSkiaRep>& image_reps = icon_.image_reps();
for (size_t i = 0; i < image_reps.size(); ++i)
icon_.RemoveRepresentation(image_reps[i].scale());
icon_ = gfx::ImageSkia(new BadgedIconSource(icon_),
gfx::Size(kIconSize, kIconSize));
int icon_dimension = GetPreferredIconDimension();
gfx::Size icon_size(icon_dimension, icon_dimension);
icon_ = gfx::ImageSkia(new BadgedIconSource(icon_, icon_size), icon_size);
SetIcon(icon_);
}
......
......@@ -66,6 +66,10 @@ const int kPreferredCols = 4;
const int kPreferredRows = 4;
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.
const int kExperimentalPreferredCols = 6;
const int kExperimentalPreferredRows = 3;
......
......@@ -50,6 +50,9 @@ APP_LIST_EXPORT extern const int kPreferredCols;
APP_LIST_EXPORT extern const int kPreferredRows;
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 kExperimentalPreferredRows;
......
......@@ -4,6 +4,7 @@
#include "ui/app_list/search_result.h"
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/search_result_observer.h"
namespace app_list {
......@@ -67,6 +68,17 @@ void SearchResult::SetPercentDownloaded(int percent_downloaded) {
OnPercentDownloadedChanged());
}
int SearchResult::GetPreferredIconDimension() const {
switch (display_type_) {
case DISPLAY_TILE:
return kTileIconSize;
case DISPLAY_LIST:
return kListIconSize;
}
NOTREACHED();
return 0;
}
void SearchResult::NotifyItemInstalled() {
FOR_EACH_OBSERVER(SearchResultObserver, observers_, OnItemInstalled());
}
......
......@@ -109,6 +109,9 @@ class APP_LIST_EXPORT SearchResult {
int percent_downloaded() const { return 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 NotifyItemUninstalled();
......
......@@ -25,15 +25,17 @@ namespace {
const int kPreferredWidth = 300;
const int kPreferredHeight = 52;
const int kIconDimension = 32;
const int kIconPadding = 14;
const int kIconViewWidth = kIconDimension + 2 * kIconPadding;
const int kTextTrailPadding = kIconPadding;
const int kBorderSize = 1;
// Extra margin at the right of the rightmost action icon.
const int kActionButtonRightMargin = 8;
int GetIconViewWidth() {
return kListIconSize + 2 * kIconPadding;
}
// Creates a RenderText of given |text| and |styles|. Caller takes ownership
// of returned RenderText.
gfx::RenderText* CreateRenderText(const base::string16& text,
......@@ -143,8 +145,8 @@ void SearchResultView::Layout() {
return;
gfx::Rect icon_bounds(rect);
icon_bounds.set_width(kIconViewWidth);
icon_bounds.Inset(kIconPadding, (rect.height() - kIconDimension) / 2);
icon_bounds.set_width(GetIconViewWidth());
icon_bounds.Inset(kIconPadding, (rect.height() - kListIconSize) / 2);
icon_bounds.Intersect(rect);
icon_->SetBoundsRect(icon_bounds);
......@@ -221,16 +223,16 @@ void SearchResultView::OnPaint(gfx::Canvas* canvas) {
canvas->FillRect(border_bottom, kResultBorderColor);
gfx::Rect text_bounds(rect);
text_bounds.set_x(kIconViewWidth);
text_bounds.set_x(GetIconViewWidth());
if (actions_view_->visible()) {
text_bounds.set_width(
rect.width() - kIconViewWidth - kTextTrailPadding -
rect.width() - GetIconViewWidth() - kTextTrailPadding -
actions_view_->bounds().width() -
(actions_view_->has_children() ? kActionButtonRightMargin : 0));
} else {
text_bounds.set_width(
rect.width() - kIconViewWidth - kTextTrailPadding -
progress_bar_->bounds().width() - kActionButtonRightMargin);
text_bounds.set_width(rect.width() - GetIconViewWidth() -
kTextTrailPadding - progress_bar_->bounds().width() -
kActionButtonRightMargin);
}
text_bounds.set_x(GetMirroredXWithWidthInView(text_bounds.x(),
text_bounds.width()));
......@@ -279,11 +281,11 @@ void SearchResultView::OnIconChanged() {
return;
// 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,
skia::ImageOperations::RESIZE_BEST,
gfx::Size(kIconDimension, kIconDimension));
gfx::Size(kListIconSize, kListIconSize));
} else {
icon_->ResetImageSize();
}
......
......@@ -22,7 +22,6 @@ namespace {
const int kTileSize = 90;
const int kTileHorizontalPadding = 10;
const int kTileImageSize = 48;
const SkColor kTileBackgroundColor = SK_ColorWHITE;
const int kTileColorStripHeight = 2;
......@@ -85,7 +84,7 @@ TileItemView::TileItemView()
views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER);
SetLayoutManager(layout_manager);
icon_->SetImageSize(gfx::Size(kTileImageSize, kTileImageSize));
icon_->SetImageSize(gfx::Size(kTileIconSize, kTileIconSize));
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
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