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

Side by Side 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: Fix GN. 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 unified diff | Download patch
« no previous file with comments | « ui/app_list/folder_image_source.h ('k') | ui/app_list/views/apps_container_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 folder circle.
92 gfx::Point center = gfx::Point(size().width() / 2, size().height() / 2);
93 SkPaint paint;
94 paint.setStyle(SkPaint::kFill_Style);
95 paint.setAntiAlias(true);
96 paint.setColor(kFolderBubbleColor);
97 canvas->DrawCircle(center, size().width() / 2, paint);
98
99 if (icons_.size() == 0)
100 return;
101
102 // Draw top items' icons.
103 const gfx::Size item_icon_size(ItemIconSize());
104 std::vector<gfx::Rect> top_icon_bounds = GetTopIconsBounds(gfx::Rect(size()));
105
106 for (size_t i = 0; i < kNumFolderTopItems && i < icons_.size(); ++i) {
107 DrawIcon(canvas,
108 icons_[i],
109 item_icon_size,
110 top_icon_bounds[i].x(),
111 top_icon_bounds[i].y());
112 }
113 }
114
115 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/folder_image_source.h ('k') | ui/app_list/views/apps_container_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698