| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/app_list/folder_image_source.h" | |
| 6 | |
| 7 #include "ui/app_list/app_list_constants.h" | |
| 8 #include "ui/gfx/canvas.h" | |
| 9 #include "ui/gfx/geometry/point.h" | |
| 10 #include "ui/gfx/geometry/rect.h" | |
| 11 #include "ui/gfx/geometry/size.h" | |
| 12 #include "ui/gfx/image/image_skia.h" | |
| 13 #include "ui/gfx/image/image_skia_operations.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 const int kItemIconDimension = 16; | |
| 18 | |
| 19 } // namespace | |
| 20 | |
| 21 namespace app_list { | |
| 22 | |
| 23 FolderImageSource::FolderImageSource(const Icons& icons, const gfx::Size& size) | |
| 24 : gfx::CanvasImageSource(size, false), icons_(icons), size_(size) { | |
| 25 DCHECK(icons.size() <= kNumFolderTopItems); | |
| 26 } | |
| 27 | |
| 28 FolderImageSource::~FolderImageSource() { | |
| 29 } | |
| 30 | |
| 31 // static | |
| 32 gfx::Size FolderImageSource::ItemIconSize() { | |
| 33 return gfx::Size(kItemIconDimension, kItemIconDimension); | |
| 34 } | |
| 35 | |
| 36 // static | |
| 37 std::vector<gfx::Rect> FolderImageSource::GetTopIconsBounds( | |
| 38 const gfx::Rect& folder_icon_bounds) { | |
| 39 const int delta_to_center = 1; | |
| 40 gfx::Point icon_center = folder_icon_bounds.CenterPoint(); | |
| 41 std::vector<gfx::Rect> top_icon_bounds; | |
| 42 | |
| 43 // Get the top left icon bounds. | |
| 44 int left_x = icon_center.x() - kItemIconDimension - delta_to_center; | |
| 45 int top_y = icon_center.y() - kItemIconDimension - delta_to_center; | |
| 46 gfx::Rect top_left(left_x, top_y, kItemIconDimension, kItemIconDimension); | |
| 47 top_icon_bounds.push_back(top_left); | |
| 48 | |
| 49 // Get the top right icon bounds. | |
| 50 int right_x = icon_center.x() + delta_to_center; | |
| 51 gfx::Rect top_right(right_x, top_y, kItemIconDimension, kItemIconDimension); | |
| 52 top_icon_bounds.push_back(top_right); | |
| 53 | |
| 54 // Get the bottom left icon bounds. | |
| 55 int bottom_y = icon_center.y() + delta_to_center; | |
| 56 gfx::Rect bottom_left( | |
| 57 left_x, bottom_y, kItemIconDimension, kItemIconDimension); | |
| 58 top_icon_bounds.push_back(bottom_left); | |
| 59 | |
| 60 // Get the bottom right icon bounds. | |
| 61 gfx::Rect bottom_right( | |
| 62 right_x, bottom_y, kItemIconDimension, kItemIconDimension); | |
| 63 top_icon_bounds.push_back(bottom_right); | |
| 64 | |
| 65 return top_icon_bounds; | |
| 66 } | |
| 67 | |
| 68 void FolderImageSource::DrawIcon(gfx::Canvas* canvas, | |
| 69 const gfx::ImageSkia& icon, | |
| 70 const gfx::Size icon_size, | |
| 71 int x, | |
| 72 int y) { | |
| 73 if (icon.isNull()) | |
| 74 return; | |
| 75 | |
| 76 gfx::ImageSkia resized(gfx::ImageSkiaOperations::CreateResizedImage( | |
| 77 icon, skia::ImageOperations::RESIZE_BEST, icon_size)); | |
| 78 canvas->DrawImageInt(resized, | |
| 79 0, | |
| 80 0, | |
| 81 resized.width(), | |
| 82 resized.height(), | |
| 83 x, | |
| 84 y, | |
| 85 resized.width(), | |
| 86 resized.height(), | |
| 87 true); | |
| 88 } | |
| 89 | |
| 90 void FolderImageSource::Draw(gfx::Canvas* canvas) { | |
| 91 // Draw circle for folder shadow. | |
| 92 gfx::PointF shadow_center(size().width() / 2, size().height() / 2); | |
| 93 SkPaint paint; | |
| 94 paint.setStyle(SkPaint::kFill_Style); | |
| 95 paint.setAntiAlias(true); | |
| 96 paint.setColor(kFolderShadowColor); | |
| 97 canvas->sk_canvas()->drawCircle( | |
| 98 shadow_center.x(), shadow_center.y(), kFolderShadowRadius, paint); | |
| 99 // Draw circle for folder bubble. | |
| 100 gfx::PointF bubble_center(shadow_center); | |
| 101 bubble_center.Offset(0, -kFolderShadowOffsetY); | |
| 102 paint.setColor(kFolderBubbleColor); | |
| 103 canvas->sk_canvas()->drawCircle( | |
| 104 bubble_center.x(), bubble_center.y(), kFolderBubbleRadius, paint); | |
| 105 | |
| 106 if (icons_.size() == 0) | |
| 107 return; | |
| 108 | |
| 109 // Draw top items' icons. | |
| 110 const gfx::Size item_icon_size(ItemIconSize()); | |
| 111 std::vector<gfx::Rect> top_icon_bounds = GetTopIconsBounds(gfx::Rect(size())); | |
| 112 | |
| 113 for (size_t i = 0; i < kNumFolderTopItems && i < icons_.size(); ++i) { | |
| 114 DrawIcon(canvas, | |
| 115 icons_[i], | |
| 116 item_icon_size, | |
| 117 top_icon_bounds[i].x(), | |
| 118 top_icon_bounds[i].y()); | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 } // namespace app_list | |
| OLD | NEW |