OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/app_list/app_list_folder_item.h" | 5 #include "ui/app_list/app_list_folder_item.h" |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 #include "ui/app_list/app_list_constants.h" | 8 #include "ui/app_list/app_list_constants.h" |
9 #include "ui/app_list/app_list_item_list.h" | 9 #include "ui/app_list/app_list_item_list.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/geometry/rect.h" |
11 #include "ui/gfx/image/canvas_image_source.h" | 12 #include "ui/gfx/image/canvas_image_source.h" |
12 #include "ui/gfx/image/image_skia_operations.h" | 13 #include "ui/gfx/image/image_skia_operations.h" |
13 | 14 |
14 namespace app_list { | 15 namespace app_list { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 const int kItemIconDimension = 16; | 19 const int kItemIconDimension = 16; |
19 | 20 |
20 // Generates the folder icon with the top 4 child item icons laid in 2x2 tile. | 21 // Generates the folder icon with the top 4 child item icons laid in 2x2 tile. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 paint.setAntiAlias(true); | 56 paint.setAntiAlias(true); |
56 paint.setColor(kFolderBubbleColor); | 57 paint.setColor(kFolderBubbleColor); |
57 canvas->DrawCircle(center, size().width() / 2, paint); | 58 canvas->DrawCircle(center, size().width() / 2, paint); |
58 | 59 |
59 if (icons_.size() == 0) | 60 if (icons_.size() == 0) |
60 return; | 61 return; |
61 | 62 |
62 // Draw top items' icons. | 63 // Draw top items' icons. |
63 const gfx::Size item_icon_size = | 64 const gfx::Size item_icon_size = |
64 gfx::Size(kItemIconDimension, kItemIconDimension); | 65 gfx::Size(kItemIconDimension, kItemIconDimension); |
65 Rects top_icon_bounds = | 66 std::vector<gfx::Rect> top_icon_bounds = |
66 AppListFolderItem::GetTopIconsBounds(gfx::Rect(size())); | 67 AppListFolderItem::GetTopIconsBounds(gfx::Rect(size())); |
67 | 68 |
68 for (size_t i= 0; i < kNumFolderTopItems && i < icons_.size(); ++i) { | 69 for (size_t i= 0; i < kNumFolderTopItems && i < icons_.size(); ++i) { |
69 DrawIcon(canvas, icons_[i], item_icon_size, | 70 DrawIcon(canvas, icons_[i], item_icon_size, |
70 top_icon_bounds[i].x(), top_icon_bounds[i].y()); | 71 top_icon_bounds[i].x(), top_icon_bounds[i].y()); |
71 } | 72 } |
72 } | 73 } |
73 | 74 |
74 Icons icons_; | 75 Icons icons_; |
75 gfx::Size size_; | 76 gfx::Size size_; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 const gfx::ImageSkia& AppListFolderItem::GetTopIcon(size_t item_index) { | 109 const gfx::ImageSkia& AppListFolderItem::GetTopIcon(size_t item_index) { |
109 DCHECK(item_index <= top_items_.size()); | 110 DCHECK(item_index <= top_items_.size()); |
110 return top_items_[item_index]->icon(); | 111 return top_items_[item_index]->icon(); |
111 } | 112 } |
112 | 113 |
113 gfx::Rect AppListFolderItem::GetTargetIconRectInFolderForItem( | 114 gfx::Rect AppListFolderItem::GetTargetIconRectInFolderForItem( |
114 AppListItem* item, | 115 AppListItem* item, |
115 const gfx::Rect& folder_icon_bounds) { | 116 const gfx::Rect& folder_icon_bounds) { |
116 for (size_t i = 0; i < top_items_.size(); ++i) { | 117 for (size_t i = 0; i < top_items_.size(); ++i) { |
117 if (item->id() == top_items_[i]->id()) { | 118 if (item->id() == top_items_[i]->id()) { |
118 Rects rects = AppListFolderItem::GetTopIconsBounds(folder_icon_bounds); | 119 std::vector<gfx::Rect> rects = |
| 120 AppListFolderItem::GetTopIconsBounds(folder_icon_bounds); |
119 return rects[i]; | 121 return rects[i]; |
120 } | 122 } |
121 } | 123 } |
122 | 124 |
123 gfx::Rect target_rect(folder_icon_bounds); | 125 gfx::Rect target_rect(folder_icon_bounds); |
124 target_rect.ClampToCenteredSize( | 126 target_rect.ClampToCenteredSize( |
125 gfx::Size(kItemIconDimension, kItemIconDimension)); | 127 gfx::Size(kItemIconDimension, kItemIconDimension)); |
126 return target_rect; | 128 return target_rect; |
127 } | 129 } |
128 | 130 |
129 void AppListFolderItem::Activate(int event_flags) { | 131 void AppListFolderItem::Activate(int event_flags) { |
130 // Folder handling is implemented by the View, so do nothing. | 132 // Folder handling is implemented by the View, so do nothing. |
131 } | 133 } |
132 | 134 |
133 // static | 135 // static |
134 const char AppListFolderItem::kItemType[] = "FolderItem"; | 136 const char AppListFolderItem::kItemType[] = "FolderItem"; |
135 | 137 |
136 // static | 138 // static |
137 Rects AppListFolderItem::GetTopIconsBounds( | 139 std::vector<gfx::Rect> AppListFolderItem::GetTopIconsBounds( |
138 const gfx::Rect& folder_icon_bounds) { | 140 const gfx::Rect& folder_icon_bounds) { |
139 const int delta_to_center = 1; | 141 const int delta_to_center = 1; |
140 gfx::Point icon_center = folder_icon_bounds.CenterPoint(); | 142 gfx::Point icon_center = folder_icon_bounds.CenterPoint(); |
141 Rects top_icon_bounds; | 143 std::vector<gfx::Rect> top_icon_bounds; |
142 | 144 |
143 // Get the top left icon bounds. | 145 // Get the top left icon bounds. |
144 int left_x = icon_center.x() - kItemIconDimension - delta_to_center; | 146 int left_x = icon_center.x() - kItemIconDimension - delta_to_center; |
145 int top_y = icon_center.y() - kItemIconDimension - delta_to_center; | 147 int top_y = icon_center.y() - kItemIconDimension - delta_to_center; |
146 gfx::Rect top_left(left_x, top_y, kItemIconDimension, kItemIconDimension); | 148 gfx::Rect top_left(left_x, top_y, kItemIconDimension, kItemIconDimension); |
147 top_icon_bounds.push_back(top_left); | 149 top_icon_bounds.push_back(top_left); |
148 | 150 |
149 // Get the top right icon bounds. | 151 // Get the top right icon bounds. |
150 int right_x = icon_center.x() + delta_to_center; | 152 int right_x = icon_center.x() + delta_to_center; |
151 gfx::Rect top_right(right_x, top_y, kItemIconDimension, kItemIconDimension); | 153 gfx::Rect top_right(right_x, top_y, kItemIconDimension, kItemIconDimension); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 for (size_t i = 0; | 239 for (size_t i = 0; |
238 i < kNumFolderTopItems && i < item_list_->item_count(); ++i) { | 240 i < kNumFolderTopItems && i < item_list_->item_count(); ++i) { |
239 AppListItem* item = item_list_->item_at(i); | 241 AppListItem* item = item_list_->item_at(i); |
240 item->AddObserver(this); | 242 item->AddObserver(this); |
241 top_items_.push_back(item); | 243 top_items_.push_back(item); |
242 } | 244 } |
243 UpdateIcon(); | 245 UpdateIcon(); |
244 } | 246 } |
245 | 247 |
246 } // namespace app_list | 248 } // namespace app_list |
OLD | NEW |