Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Unified Diff: ui/app_list/folder_image_source.cc

Issue 657793004: Moved FolderImageSource class to a separate file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/app-list-typedefs-iwyu
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/app_list/folder_image_source.cc
diff --git a/ui/app_list/folder_image_source.cc b/ui/app_list/folder_image_source.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ac3f1089277cadf3ae48990a3f53ba8b2b76f135
--- /dev/null
+++ b/ui/app_list/folder_image_source.cc
@@ -0,0 +1,115 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/app_list/folder_image_source.h"
+
+#include "ui/app_list/app_list_constants.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/image_skia.h"
+#include "ui/gfx/image/image_skia_operations.h"
+
+namespace {
+
+const int kItemIconDimension = 16;
+
+} // namespace
+
+namespace app_list {
+
+FolderImageSource::FolderImageSource(const Icons& icons, const gfx::Size& size)
+ : gfx::CanvasImageSource(size, false), icons_(icons), size_(size) {
+ DCHECK(icons.size() <= kNumFolderTopItems);
+}
+
+FolderImageSource::~FolderImageSource() {
+}
+
+// static
+gfx::Size FolderImageSource::ItemIconSize() {
+ return gfx::Size(kItemIconDimension, kItemIconDimension);
+}
+
+// static
+std::vector<gfx::Rect> FolderImageSource::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;
+}
+
+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 folder circle.
+ gfx::Point center = gfx::Point(size().width() / 2, size().height() / 2);
+ SkPaint paint;
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setAntiAlias(true);
+ paint.setColor(kFolderBubbleColor);
+ canvas->DrawCircle(center, size().width() / 2, paint);
+
+ if (icons_.size() == 0)
+ return;
+
+ // Draw top items' icons.
+ const gfx::Size item_icon_size(ItemIconSize());
+ std::vector<gfx::Rect> top_icon_bounds = 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 app_list

Powered by Google App Engine
This is Rietveld 408576698