| Index: ui/app_list/folder_image.cc
|
| diff --git a/ui/app_list/folder_image.cc b/ui/app_list/folder_image.cc
|
| index 515db07d46cd8601ba0b0115f34154f259aac8c3..c6ea1fe1b877559284d254e45c78c18a5aa42174 100644
|
| --- a/ui/app_list/folder_image.cc
|
| +++ b/ui/app_list/folder_image.cc
|
| @@ -4,17 +4,111 @@
|
|
|
| #include "ui/app_list/folder_image.h"
|
|
|
| +#include <vector>
|
| +
|
| #include "ui/app_list/app_list_constants.h"
|
| #include "ui/app_list/app_list_item.h"
|
| #include "ui/app_list/app_list_item_list.h"
|
| -#include "ui/app_list/folder_image_source.h"
|
| #include "ui/app_list/views/contents_view.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| +#include "ui/gfx/canvas.h"
|
| +#include "ui/gfx/geometry/point.h"
|
| #include "ui/gfx/geometry/rect.h"
|
| +#include "ui/gfx/geometry/size.h"
|
| +#include "ui/gfx/image/canvas_image_source.h"
|
| +#include "ui/gfx/image/image_skia.h"
|
| +#include "ui/gfx/image/image_skia_operations.h"
|
| #include "ui/strings/grit/ui_strings.h"
|
|
|
| namespace app_list {
|
|
|
| +namespace {
|
| +
|
| +const int kItemIconDimension = 16;
|
| +
|
| +// Gets the size of a small app icon inside the folder icon.
|
| +gfx::Size ItemIconSize() {
|
| + return gfx::Size(kItemIconDimension, kItemIconDimension);
|
| +}
|
| +
|
| +// Generates the folder icon with the top 4 child item icons laid in 2x2 tile.
|
| +class FolderImageSource : public gfx::CanvasImageSource {
|
| + public:
|
| + typedef std::vector<gfx::ImageSkia> Icons;
|
| +
|
| + FolderImageSource(const Icons& icons, const gfx::Size& size);
|
| + ~FolderImageSource() override;
|
| +
|
| + private:
|
| + void DrawIcon(gfx::Canvas* canvas,
|
| + const gfx::ImageSkia& icon,
|
| + const gfx::Size icon_size,
|
| + int x,
|
| + int y);
|
| +
|
| + // gfx::CanvasImageSource overrides:
|
| + void Draw(gfx::Canvas* canvas) override;
|
| +
|
| + Icons icons_;
|
| + gfx::Size size_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FolderImageSource);
|
| +};
|
| +
|
| +FolderImageSource::FolderImageSource(const Icons& icons, const gfx::Size& size)
|
| + : gfx::CanvasImageSource(size, false), icons_(icons), size_(size) {
|
| + DCHECK(icons.size() <= kNumFolderTopItems);
|
| +}
|
| +
|
| +FolderImageSource::~FolderImageSource() {
|
| +}
|
| +
|
| +void FolderImageSource::DrawIcon(gfx::Canvas* canvas,
|
| + const gfx::ImageSkia& icon,
|
| + const gfx::Size icon_size,
|
| + int x,
|
| + int y) {
|
| + if (icon.isNull())
|
| + return;
|
| +
|
| + gfx::ImageSkia resized(gfx::ImageSkiaOperations::CreateResizedImage(
|
| + icon, skia::ImageOperations::RESIZE_BEST, icon_size));
|
| + canvas->DrawImageInt(resized, 0, 0, resized.width(), resized.height(), x, y,
|
| + resized.width(), resized.height(), true);
|
| +}
|
| +
|
| +void FolderImageSource::Draw(gfx::Canvas* canvas) {
|
| + // Draw circle for folder shadow.
|
| + gfx::PointF shadow_center(size().width() / 2, size().height() / 2);
|
| + SkPaint paint;
|
| + paint.setStyle(SkPaint::kFill_Style);
|
| + paint.setAntiAlias(true);
|
| + paint.setColor(kFolderShadowColor);
|
| + canvas->sk_canvas()->drawCircle(shadow_center.x(), shadow_center.y(),
|
| + kFolderShadowRadius, paint);
|
| + // Draw circle for folder bubble.
|
| + gfx::PointF bubble_center(shadow_center);
|
| + bubble_center.Offset(0, -kFolderShadowOffsetY);
|
| + paint.setColor(kFolderBubbleColor);
|
| + canvas->sk_canvas()->drawCircle(bubble_center.x(), bubble_center.y(),
|
| + kFolderBubbleRadius, paint);
|
| +
|
| + if (icons_.size() == 0)
|
| + return;
|
| +
|
| + // Draw top items' icons.
|
| + const gfx::Size item_icon_size(ItemIconSize());
|
| + std::vector<gfx::Rect> top_icon_bounds =
|
| + FolderImage::GetTopIconsBounds(gfx::Rect(size()));
|
| +
|
| + for (size_t i = 0; i < kNumFolderTopItems && i < icons_.size(); ++i) {
|
| + DrawIcon(canvas, icons_[i], item_icon_size, top_icon_bounds[i].x(),
|
| + top_icon_bounds[i].y());
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| FolderImage::FolderImage(AppListItemList* item_list) : item_list_(item_list) {
|
| item_list_->AddObserver(this);
|
| }
|
| @@ -44,19 +138,50 @@ const gfx::ImageSkia& FolderImage::GetTopIcon(size_t item_index) {
|
| return top_items_[item_index]->icon();
|
| }
|
|
|
| +// static
|
| +std::vector<gfx::Rect> FolderImage::GetTopIconsBounds(
|
| + const gfx::Rect& folder_icon_bounds) {
|
| + const int delta_to_center = 1;
|
| + gfx::Point icon_center = folder_icon_bounds.CenterPoint();
|
| + std::vector<gfx::Rect> top_icon_bounds;
|
| +
|
| + // Get the top left icon bounds.
|
| + int left_x = icon_center.x() - kItemIconDimension - delta_to_center;
|
| + int top_y = icon_center.y() - kItemIconDimension - delta_to_center;
|
| + gfx::Rect top_left(left_x, top_y, kItemIconDimension, kItemIconDimension);
|
| + top_icon_bounds.push_back(top_left);
|
| +
|
| + // Get the top right icon bounds.
|
| + int right_x = icon_center.x() + delta_to_center;
|
| + gfx::Rect top_right(right_x, top_y, kItemIconDimension, kItemIconDimension);
|
| + top_icon_bounds.push_back(top_right);
|
| +
|
| + // Get the bottom left icon bounds.
|
| + int bottom_y = icon_center.y() + delta_to_center;
|
| + gfx::Rect bottom_left(left_x, bottom_y, kItemIconDimension,
|
| + kItemIconDimension);
|
| + top_icon_bounds.push_back(bottom_left);
|
| +
|
| + // Get the bottom right icon bounds.
|
| + gfx::Rect bottom_right(right_x, bottom_y, kItemIconDimension,
|
| + kItemIconDimension);
|
| + top_icon_bounds.push_back(bottom_right);
|
| +
|
| + return top_icon_bounds;
|
| +}
|
| +
|
| gfx::Rect FolderImage::GetTargetIconRectInFolderForItem(
|
| AppListItem* item,
|
| const gfx::Rect& folder_icon_bounds) {
|
| for (size_t i = 0; i < top_items_.size(); ++i) {
|
| if (item->id() == top_items_[i]->id()) {
|
| - std::vector<gfx::Rect> rects =
|
| - FolderImageSource::GetTopIconsBounds(folder_icon_bounds);
|
| + std::vector<gfx::Rect> rects = GetTopIconsBounds(folder_icon_bounds);
|
| return rects[i];
|
| }
|
| }
|
|
|
| gfx::Rect target_rect(folder_icon_bounds);
|
| - target_rect.ClampToCenteredSize(FolderImageSource::ItemIconSize());
|
| + target_rect.ClampToCenteredSize(ItemIconSize());
|
| return target_rect;
|
| }
|
|
|
|
|