OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/folder_image.h" | 5 #include "ui/app_list/folder_image.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ui/app_list/app_list_constants.h" | 9 #include "ui/app_list/app_list_constants.h" |
10 #include "ui/app_list/app_list_item.h" | 10 #include "ui/app_list/app_list_item.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 125 |
126 for (size_t i = 0; i < kNumFolderTopItems && i < item_list_->item_count(); | 126 for (size_t i = 0; i < kNumFolderTopItems && i < item_list_->item_count(); |
127 ++i) { | 127 ++i) { |
128 AppListItem* item = item_list_->item_at(i); | 128 AppListItem* item = item_list_->item_at(i); |
129 item->AddObserver(this); | 129 item->AddObserver(this); |
130 top_items_.push_back(item); | 130 top_items_.push_back(item); |
131 } | 131 } |
132 RedrawIconAndNotify(); | 132 RedrawIconAndNotify(); |
133 } | 133 } |
134 | 134 |
135 const gfx::ImageSkia& FolderImage::GetTopIcon(size_t item_index) { | 135 const gfx::ImageSkia& FolderImage::GetTopIcon(size_t item_index) const { |
136 CHECK_LT(item_index, top_items_.size()); | 136 CHECK_LT(item_index, top_items_.size()); |
137 return top_items_[item_index]->icon(); | 137 return top_items_[item_index]->icon(); |
138 } | 138 } |
139 | 139 |
140 // static | 140 // static |
141 std::vector<gfx::Rect> FolderImage::GetTopIconsBounds( | 141 std::vector<gfx::Rect> FolderImage::GetTopIconsBounds( |
142 const gfx::Rect& folder_icon_bounds) { | 142 const gfx::Rect& folder_icon_bounds) { |
143 const int delta_to_center = 1; | 143 const int delta_to_center = 1; |
144 gfx::Point icon_center = folder_icon_bounds.CenterPoint(); | 144 gfx::Point icon_center = folder_icon_bounds.CenterPoint(); |
145 std::vector<gfx::Rect> top_icon_bounds; | 145 std::vector<gfx::Rect> top_icon_bounds; |
(...skipping 18 matching lines...) Expand all Loading... |
164 // Get the bottom right icon bounds. | 164 // Get the bottom right icon bounds. |
165 gfx::Rect bottom_right(right_x, bottom_y, kItemIconDimension, | 165 gfx::Rect bottom_right(right_x, bottom_y, kItemIconDimension, |
166 kItemIconDimension); | 166 kItemIconDimension); |
167 top_icon_bounds.push_back(bottom_right); | 167 top_icon_bounds.push_back(bottom_right); |
168 | 168 |
169 return top_icon_bounds; | 169 return top_icon_bounds; |
170 } | 170 } |
171 | 171 |
172 gfx::Rect FolderImage::GetTargetIconRectInFolderForItem( | 172 gfx::Rect FolderImage::GetTargetIconRectInFolderForItem( |
173 AppListItem* item, | 173 AppListItem* item, |
174 const gfx::Rect& folder_icon_bounds) { | 174 const gfx::Rect& folder_icon_bounds) const { |
175 for (size_t i = 0; i < top_items_.size(); ++i) { | 175 for (size_t i = 0; i < top_items_.size(); ++i) { |
176 if (item->id() == top_items_[i]->id()) { | 176 if (item->id() == top_items_[i]->id()) { |
177 std::vector<gfx::Rect> rects = GetTopIconsBounds(folder_icon_bounds); | 177 std::vector<gfx::Rect> rects = GetTopIconsBounds(folder_icon_bounds); |
178 return rects[i]; | 178 return rects[i]; |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 gfx::Rect target_rect(folder_icon_bounds); | 182 gfx::Rect target_rect(folder_icon_bounds); |
183 target_rect.ClampToCenteredSize(ItemIconSize()); | 183 target_rect.ClampToCenteredSize(ItemIconSize()); |
184 return target_rect; | 184 return target_rect; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 top_icons.push_back(item->icon()); | 223 top_icons.push_back(item->icon()); |
224 | 224 |
225 const gfx::Size icon_size = gfx::Size(kGridIconDimension, kGridIconDimension); | 225 const gfx::Size icon_size = gfx::Size(kGridIconDimension, kGridIconDimension); |
226 icon_ = | 226 icon_ = |
227 gfx::ImageSkia(new FolderImageSource(top_icons, icon_size), icon_size); | 227 gfx::ImageSkia(new FolderImageSource(top_icons, icon_size), icon_size); |
228 | 228 |
229 FOR_EACH_OBSERVER(FolderImageObserver, observers_, OnFolderImageUpdated()); | 229 FOR_EACH_OBSERVER(FolderImageObserver, observers_, OnFolderImageUpdated()); |
230 } | 230 } |
231 | 231 |
232 } // namespace app_list | 232 } // namespace app_list |
OLD | NEW |