Commit e948feb6 authored by tapted@chromium.org's avatar tapted@chromium.org

Hardcode applist icon dimension and shadows.

These are currently data members, but they are always the same.

This simplifies upcoming app list refactoring.

BUG=403647

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

Cr-Commit-Position: refs/heads/master@{#289520}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289520 0039d316-1c4b-4281-b951-d872f2087c98
parent 94b2d8d7
...@@ -64,7 +64,7 @@ const gfx::Tween::Type kFolderFadeOutTweenType = gfx::Tween::FAST_OUT_LINEAR_IN; ...@@ -64,7 +64,7 @@ const gfx::Tween::Type kFolderFadeOutTweenType = gfx::Tween::FAST_OUT_LINEAR_IN;
// Preferred number of columns and rows in apps grid. // Preferred number of columns and rows in apps grid.
const int kPreferredCols = 4; const int kPreferredCols = 4;
const int kPreferredRows = 4; const int kPreferredRows = 4;
const int kPreferredIconDimension = 48; const int kGridIconDimension = 48;
// Preferred search result icon sizes. // Preferred search result icon sizes.
const int kListIconSize = 32; const int kListIconSize = 32;
......
...@@ -48,7 +48,7 @@ APP_LIST_EXPORT extern const gfx::Tween::Type kFolderFadeOutTweenType; ...@@ -48,7 +48,7 @@ APP_LIST_EXPORT extern const gfx::Tween::Type kFolderFadeOutTweenType;
APP_LIST_EXPORT extern const int kPreferredCols; 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 kGridIconDimension;
APP_LIST_EXPORT extern const int kListIconSize; APP_LIST_EXPORT extern const int kListIconSize;
APP_LIST_EXPORT extern const int kTileIconSize; APP_LIST_EXPORT extern const int kTileIconSize;
......
...@@ -98,8 +98,7 @@ void AppListFolderItem::UpdateIcon() { ...@@ -98,8 +98,7 @@ void AppListFolderItem::UpdateIcon() {
for (size_t i = 0; i < top_items_.size(); ++i) for (size_t i = 0; i < top_items_.size(); ++i)
top_icons.push_back(top_items_[i]->icon()); top_icons.push_back(top_items_[i]->icon());
const gfx::Size icon_size = const gfx::Size icon_size = gfx::Size(kGridIconDimension, kGridIconDimension);
gfx::Size(kPreferredIconDimension, kPreferredIconDimension);
gfx::ImageSkia icon = gfx::ImageSkia( gfx::ImageSkia icon = gfx::ImageSkia(
new FolderImageSource(top_icons, icon_size), new FolderImageSource(top_icons, icon_size),
icon_size); icon_size);
......
...@@ -30,7 +30,7 @@ AppListTestModel::AppListTestItem::AppListTestItem( ...@@ -30,7 +30,7 @@ AppListTestModel::AppListTestItem::AppListTestItem(
AppListTestModel* model) AppListTestModel* model)
: AppListItem(id), : AppListItem(id),
model_(model) { model_(model) {
SetIcon(CreateImageSkia(kPreferredIconDimension, kPreferredIconDimension), SetIcon(CreateImageSkia(kGridIconDimension, kGridIconDimension),
false /* has_shadow */); false /* has_shadow */);
} }
......
...@@ -57,7 +57,6 @@ AppListFolderView::AppListFolderView(AppsContainerView* container_view, ...@@ -57,7 +57,6 @@ AppListFolderView::AppListFolderView(AppsContainerView* container_view,
items_grid_view_ = new AppsGridView(app_list_main_view_); items_grid_view_ = new AppsGridView(app_list_main_view_);
items_grid_view_->set_folder_delegate(this); items_grid_view_->set_folder_delegate(this);
items_grid_view_->SetLayout( items_grid_view_->SetLayout(
kPreferredIconDimension,
container_view->apps_grid_view()->cols(), container_view->apps_grid_view()->cols(),
container_view->apps_grid_view()->rows_per_page()); container_view->apps_grid_view()->rows_per_page());
items_grid_view_->SetModel(model); items_grid_view_->SetModel(model);
...@@ -203,7 +202,7 @@ gfx::Rect AppListFolderView::GetItemIconBoundsAt(int index) { ...@@ -203,7 +202,7 @@ gfx::Rect AppListFolderView::GetItemIconBoundsAt(int index) {
// Get the icon image's bound. // Get the icon image's bound.
to_folder.ClampToCenteredSize( to_folder.ClampToCenteredSize(
gfx::Size(kPreferredIconDimension, kPreferredIconDimension)); gfx::Size(kGridIconDimension, kGridIconDimension));
return to_folder; return to_folder;
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
#include "ui/gfx/shadow_value.h"
#include "ui/gfx/transform_util.h" #include "ui/gfx/transform_util.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
...@@ -60,6 +61,15 @@ const float kDraggingIconScale = 1.5f; ...@@ -60,6 +61,15 @@ const float kDraggingIconScale = 1.5f;
// Delay in milliseconds of when the dragging UI should be shown for mouse drag. // Delay in milliseconds of when the dragging UI should be shown for mouse drag.
const int kMouseDragUIDelayInMs = 200; const int kMouseDragUIDelayInMs = 200;
const gfx::ShadowValues& GetIconShadows() {
CR_DEFINE_STATIC_LOCAL(
const gfx::ShadowValues,
icon_shadows,
(1,
gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0))));
return icon_shadows;
}
} // namespace } // namespace
// static // static
...@@ -88,11 +98,6 @@ AppListItemView::AppListItemView(AppsGridView* apps_grid_view, ...@@ -88,11 +98,6 @@ AppListItemView::AppListItemView(AppsGridView* apps_grid_view,
title_->Invalidate(); title_->Invalidate();
SetTitleSubpixelAA(); SetTitleSubpixelAA();
const gfx::ShadowValue kIconShadows[] = {
gfx::ShadowValue(gfx::Point(0, 2), 2, SkColorSetARGB(0x24, 0, 0, 0)),
};
icon_shadows_.assign(kIconShadows, kIconShadows + arraysize(kIconShadows));
AddChildView(icon_); AddChildView(icon_);
AddChildView(title_); AddChildView(title_);
AddChildView(progress_bar_); AddChildView(progress_bar_);
...@@ -112,19 +117,7 @@ AppListItemView::~AppListItemView() { ...@@ -112,19 +117,7 @@ AppListItemView::~AppListItemView() {
item_->RemoveObserver(this); item_->RemoveObserver(this);
} }
void AppListItemView::SetIconSize(const gfx::Size& size) {
if (icon_size_ == size)
return;
icon_size_ = size;
UpdateIcon();
}
void AppListItemView::UpdateIcon() { void AppListItemView::UpdateIcon() {
// Skip if |icon_size_| has not been determined.
if (icon_size_.IsEmpty())
return;
gfx::ImageSkia icon = item_->icon(); gfx::ImageSkia icon = item_->icon();
// Clear icon and bail out if item icon is empty. // Clear icon and bail out if item icon is empty.
if (icon.isNull()) { if (icon.isNull()) {
...@@ -132,12 +125,13 @@ void AppListItemView::UpdateIcon() { ...@@ -132,12 +125,13 @@ void AppListItemView::UpdateIcon() {
return; return;
} }
gfx::ImageSkia resized(gfx::ImageSkiaOperations::CreateResizedImage(icon, gfx::ImageSkia resized(gfx::ImageSkiaOperations::CreateResizedImage(
skia::ImageOperations::RESIZE_BEST, icon_size_)); icon,
skia::ImageOperations::RESIZE_BEST,
gfx::Size(kGridIconDimension, kGridIconDimension)));
if (item_->has_shadow()) { if (item_->has_shadow()) {
gfx::ImageSkia shadow( gfx::ImageSkia shadow(gfx::ImageSkiaOperations::CreateImageWithDropShadow(
gfx::ImageSkiaOperations::CreateImageWithDropShadow(resized, resized, GetIconShadows()));
icon_shadows_));
icon_->SetImage(shadow); icon_->SetImage(shadow);
return; return;
} }
...@@ -313,7 +307,7 @@ void AppListItemView::Layout() { ...@@ -313,7 +307,7 @@ void AppListItemView::Layout() {
icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds())); icon_->SetBoundsRect(GetIconBoundsForTargetViewBounds(GetContentsBounds()));
const gfx::Size title_size = title_->GetPreferredSize(); const gfx::Size title_size = title_->GetPreferredSize();
gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2, gfx::Rect title_bounds(rect.x() + (rect.width() - title_size.width()) / 2,
y + icon_size_.height() + kIconTitleSpacing, y + kGridIconDimension + kIconTitleSpacing,
title_size.width(), title_size.width(),
title_size.height()); title_size.height());
title_bounds.Intersect(rect); title_bounds.Intersect(rect);
...@@ -525,8 +519,8 @@ gfx::Rect AppListItemView::GetIconBoundsForTargetViewBounds( ...@@ -525,8 +519,8 @@ gfx::Rect AppListItemView::GetIconBoundsForTargetViewBounds(
title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars); title_->font_list().GetExpectedTextWidth(kLeftRightPaddingChars);
rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0); rect.Inset(left_right_padding, kTopPadding, left_right_padding, 0);
gfx::Rect icon_bounds(rect.x(), rect.y(), rect.width(), icon_size_.height()); gfx::Rect icon_bounds(rect.x(), rect.y(), rect.width(), kGridIconDimension);
icon_bounds.Inset(gfx::ShadowValue::GetMargin(icon_shadows_)); icon_bounds.Inset(gfx::ShadowValue::GetMargin(GetIconShadows()));
return icon_bounds; return icon_bounds;
} }
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "ui/app_list/app_list_export.h" #include "ui/app_list/app_list_export.h"
#include "ui/app_list/app_list_item_observer.h" #include "ui/app_list/app_list_item_observer.h"
#include "ui/app_list/views/cached_label.h" #include "ui/app_list/views/cached_label.h"
#include "ui/gfx/shadow_value.h"
#include "ui/views/context_menu_controller.h" #include "ui/views/context_menu_controller.h"
#include "ui/views/controls/button/custom_button.h" #include "ui/views/controls/button/custom_button.h"
...@@ -41,8 +40,6 @@ class APP_LIST_EXPORT AppListItemView : public views::CustomButton, ...@@ -41,8 +40,6 @@ class APP_LIST_EXPORT AppListItemView : public views::CustomButton,
AppListItemView(AppsGridView* apps_grid_view, AppListItem* item); AppListItemView(AppsGridView* apps_grid_view, AppListItem* item);
virtual ~AppListItemView(); virtual ~AppListItemView();
void SetIconSize(const gfx::Size& size);
void Prerender(); void Prerender();
void CancelContextMenu(); void CancelContextMenu();
...@@ -139,9 +136,6 @@ class APP_LIST_EXPORT AppListItemView : public views::CustomButton, ...@@ -139,9 +136,6 @@ class APP_LIST_EXPORT AppListItemView : public views::CustomButton,
scoped_ptr<views::MenuRunner> context_menu_runner_; scoped_ptr<views::MenuRunner> context_menu_runner_;
gfx::Size icon_size_;
gfx::ShadowValues icon_shadows_;
UIState ui_state_; UIState ui_state_;
// True if scroll gestures should contribute to dragging. // True if scroll gestures should contribute to dragging.
......
...@@ -33,7 +33,7 @@ AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view, ...@@ -33,7 +33,7 @@ AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view,
cols = kExperimentalPreferredCols; cols = kExperimentalPreferredCols;
rows = kExperimentalPreferredRows; rows = kExperimentalPreferredRows;
} }
apps_grid_view_->SetLayout(kPreferredIconDimension, cols, rows); apps_grid_view_->SetLayout(cols, rows);
AddChildView(apps_grid_view_); AddChildView(apps_grid_view_);
folder_background_view_ = new FolderBackgroundView(); folder_background_view_ = new FolderBackgroundView();
......
...@@ -387,8 +387,7 @@ AppsGridView::~AppsGridView() { ...@@ -387,8 +387,7 @@ AppsGridView::~AppsGridView() {
RemoveAllChildViews(true); RemoveAllChildViews(true);
} }
void AppsGridView::SetLayout(int icon_size, int cols, int rows_per_page) { void AppsGridView::SetLayout(int cols, int rows_per_page) {
icon_size_.SetSize(icon_size, icon_size);
cols_ = cols; cols_ = cols;
rows_per_page_ = rows_per_page; rows_per_page_ = rows_per_page;
...@@ -774,7 +773,6 @@ void AppsGridView::InitiateDragFromReparentItemInRootLevelGridView( ...@@ -774,7 +773,6 @@ void AppsGridView::InitiateDragFromReparentItemInRootLevelGridView(
// Note: For testing purpose, SetFillsBoundsOpaquely can be set to true to // Note: For testing purpose, SetFillsBoundsOpaquely can be set to true to
// show the gray background. // show the gray background.
drag_view_->SetFillsBoundsOpaquely(false); drag_view_->SetFillsBoundsOpaquely(false);
drag_view_->SetIconSize(icon_size_);
drag_view_->SetBoundsRect(drag_view_rect); drag_view_->SetBoundsRect(drag_view_rect);
drag_view_->SetDragUIState(); // Hide the title of the drag_view_. drag_view_->SetDragUIState(); // Hide the title of the drag_view_.
...@@ -1016,7 +1014,6 @@ views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) { ...@@ -1016,7 +1014,6 @@ views::View* AppsGridView::CreateViewForItemAtIndex(size_t index) {
DCHECK_LE(index, item_list_->item_count()); DCHECK_LE(index, item_list_->item_count());
AppListItemView* view = new AppListItemView(this, AppListItemView* view = new AppListItemView(this,
item_list_->item_at(index)); item_list_->item_at(index));
view->SetIconSize(icon_size_);
view->SetPaintToLayer(true); view->SetPaintToLayer(true);
view->SetFillsBoundsOpaquely(false); view->SetFillsBoundsOpaquely(false);
return view; return view;
...@@ -1842,7 +1839,7 @@ void AppsGridView::CancelFolderItemReparent(AppListItemView* drag_item_view) { ...@@ -1842,7 +1839,7 @@ void AppsGridView::CancelFolderItemReparent(AppListItemView* drag_item_view) {
gfx::Rect drag_view_icon_to_grid = gfx::Rect drag_view_icon_to_grid =
drag_item_view->ConvertRectToParent(drag_item_view->GetIconBounds()); drag_item_view->ConvertRectToParent(drag_item_view->GetIconBounds());
drag_view_icon_to_grid.ClampToCenteredSize( drag_view_icon_to_grid.ClampToCenteredSize(
gfx::Size(kPreferredIconDimension, kPreferredIconDimension)); gfx::Size(kGridIconDimension, kGridIconDimension));
TopIconAnimationView* icon_view = new TopIconAnimationView( TopIconAnimationView* icon_view = new TopIconAnimationView(
drag_item_view->item()->icon(), drag_item_view->item()->icon(),
target_icon_rect, target_icon_rect,
...@@ -2029,9 +2026,8 @@ AppsGridView::Index AppsGridView::GetNearestTileForDragView() { ...@@ -2029,9 +2026,8 @@ AppsGridView::Index AppsGridView::GetNearestTileForDragView() {
CalculateNearestTileForVertex(pt, &nearest_tile, &d_min); CalculateNearestTileForVertex(pt, &nearest_tile, &d_min);
const int d_folder_dropping = const int d_folder_dropping =
kFolderDroppingCircleRadius + kPreferredIconDimension / 2; kFolderDroppingCircleRadius + kGridIconDimension / 2;
const int d_reorder = const int d_reorder = kReorderDroppingCircleRadius + kGridIconDimension / 2;
kReorderDroppingCircleRadius + kPreferredIconDimension / 2;
// If user drags an item across pages to the last page, and targets it // If user drags an item across pages to the last page, and targets it
// to the last empty slot on it, push the last item for re-ordering. // to the last empty slot on it, push the last item for re-ordering.
......
...@@ -73,7 +73,7 @@ class APP_LIST_EXPORT AppsGridView : public views::View, ...@@ -73,7 +73,7 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
// Sets fixed layout parameters. After setting this, CalculateLayout below // Sets fixed layout parameters. After setting this, CalculateLayout below
// is no longer called to dynamically choosing those layout params. // is no longer called to dynamically choosing those layout params.
void SetLayout(int icon_size, int cols, int rows_per_page); void SetLayout(int cols, int rows_per_page);
int cols() const { return cols_; } int cols() const { return cols_; }
int rows_per_page() const { return rows_per_page_; } int rows_per_page() const { return rows_per_page_; }
...@@ -464,7 +464,6 @@ class APP_LIST_EXPORT AppsGridView : public views::View, ...@@ -464,7 +464,6 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
PaginationModel pagination_model_; PaginationModel pagination_model_;
PageSwitcher* page_switcher_view_; // Owned by views hierarchy. PageSwitcher* page_switcher_view_; // Owned by views hierarchy.
gfx::Size icon_size_;
int cols_; int cols_;
int rows_per_page_; int rows_per_page_;
......
...@@ -31,7 +31,6 @@ namespace test { ...@@ -31,7 +31,6 @@ namespace test {
namespace { namespace {
const int kIconDimension = 48;
const int kCols = 2; const int kCols = 2;
const int kRows = 2; const int kRows = 2;
const int kTilesPerPage = kCols * kRows; const int kTilesPerPage = kCols * kRows;
...@@ -102,7 +101,7 @@ class AppsGridViewTest : public views::ViewsTestBase { ...@@ -102,7 +101,7 @@ class AppsGridViewTest : public views::ViewsTestBase {
model_->SetFoldersEnabled(true); model_->SetFoldersEnabled(true);
apps_grid_view_.reset(new AppsGridView(NULL)); apps_grid_view_.reset(new AppsGridView(NULL));
apps_grid_view_->SetLayout(kIconDimension, kCols, kRows); apps_grid_view_->SetLayout(kCols, kRows);
apps_grid_view_->SetBoundsRect(gfx::Rect(gfx::Size(kWidth, kHeight))); apps_grid_view_->SetBoundsRect(gfx::Rect(gfx::Size(kWidth, kHeight)));
apps_grid_view_->SetModel(model_.get()); apps_grid_view_->SetModel(model_.get());
apps_grid_view_->SetItemList(model_->top_level_item_list()); apps_grid_view_->SetItemList(model_->top_level_item_list());
...@@ -423,8 +422,8 @@ TEST_F(AppsGridViewTest, MouseDragItemReorder) { ...@@ -423,8 +422,8 @@ TEST_F(AppsGridViewTest, MouseDragItemReorder) {
gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint(); gfx::Point from = GetItemTileRectAt(0, 1).CenterPoint();
int reorder_offset = (GetItemTileRectAt(0, 1).CenterPoint() - int reorder_offset = (GetItemTileRectAt(0, 1).CenterPoint() -
GetItemTileRectAt(0, 0).CenterPoint()).Length() - GetItemTileRectAt(0, 0).CenterPoint()).Length() -
kReorderDroppingCircleRadius - kReorderDroppingCircleRadius - kGridIconDimension / 2 +
kPreferredIconDimension / 2 + 5; 5;
gfx::Point to = gfx::Point(from.x() - reorder_offset, from.y()); gfx::Point to = gfx::Point(from.x() - reorder_offset, from.y());
// Dragging item_1 closing to item_0 should leads to re-ordering these two // Dragging item_1 closing to item_0 should leads to re-ordering these two
......
...@@ -15,7 +15,7 @@ namespace app_list { ...@@ -15,7 +15,7 @@ namespace app_list {
TopIconAnimationView::TopIconAnimationView(const gfx::ImageSkia& icon, TopIconAnimationView::TopIconAnimationView(const gfx::ImageSkia& icon,
const gfx::Rect& scaled_rect, const gfx::Rect& scaled_rect,
bool open_folder) bool open_folder)
: icon_size_(kPreferredIconDimension, kPreferredIconDimension), : icon_size_(kGridIconDimension, kGridIconDimension),
icon_(new views::ImageView), icon_(new views::ImageView),
scaled_rect_(scaled_rect), scaled_rect_(scaled_rect),
open_folder_(open_folder) { open_folder_(open_folder) {
......
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