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/app_list/folder_image_source.h" | |
11 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
| 11 #include "ui/gfx/image/image_skia.h" |
12 | 12 |
13 namespace app_list { | 13 namespace app_list { |
14 | 14 |
15 AppListFolderItem::AppListFolderItem(const std::string& id, | 15 AppListFolderItem::AppListFolderItem(const std::string& id, |
16 FolderType folder_type) | 16 FolderType folder_type) |
17 : AppListItem(id), | 17 : AppListItem(id), |
18 folder_type_(folder_type), | 18 folder_type_(folder_type), |
19 item_list_(new AppListItemList) { | 19 item_list_(new AppListItemList), |
20 item_list_->AddObserver(this); | 20 folder_image_(item_list_.get()) { |
| 21 folder_image_.AddObserver(this); |
21 } | 22 } |
22 | 23 |
23 AppListFolderItem::~AppListFolderItem() { | 24 AppListFolderItem::~AppListFolderItem() { |
24 for (size_t i = 0; i < top_items_.size(); ++i) | 25 folder_image_.RemoveObserver(this); |
25 top_items_[i]->RemoveObserver(this); | |
26 item_list_->RemoveObserver(this); | |
27 } | |
28 | |
29 void AppListFolderItem::UpdateIcon() { | |
30 FolderImageSource::Icons top_icons; | |
31 for (size_t i = 0; i < top_items_.size(); ++i) | |
32 top_icons.push_back(top_items_[i]->icon()); | |
33 | |
34 const gfx::Size icon_size = gfx::Size(kGridIconDimension, kGridIconDimension); | |
35 gfx::ImageSkia icon = gfx::ImageSkia( | |
36 new FolderImageSource(top_icons, icon_size), | |
37 icon_size); | |
38 SetIcon(icon, false); | |
39 } | 26 } |
40 | 27 |
41 const gfx::ImageSkia& AppListFolderItem::GetTopIcon(size_t item_index) { | 28 const gfx::ImageSkia& AppListFolderItem::GetTopIcon(size_t item_index) { |
42 CHECK_LT(item_index, top_items_.size()); | 29 return folder_image_.GetTopIcon(item_index); |
43 return top_items_[item_index]->icon(); | |
44 } | 30 } |
45 | 31 |
46 gfx::Rect AppListFolderItem::GetTargetIconRectInFolderForItem( | 32 gfx::Rect AppListFolderItem::GetTargetIconRectInFolderForItem( |
47 AppListItem* item, | 33 AppListItem* item, |
48 const gfx::Rect& folder_icon_bounds) { | 34 const gfx::Rect& folder_icon_bounds) { |
49 for (size_t i = 0; i < top_items_.size(); ++i) { | 35 return folder_image_.GetTargetIconRectInFolderForItem(item, |
50 if (item->id() == top_items_[i]->id()) { | 36 folder_icon_bounds); |
51 std::vector<gfx::Rect> rects = | |
52 FolderImageSource::GetTopIconsBounds(folder_icon_bounds); | |
53 return rects[i]; | |
54 } | |
55 } | |
56 | |
57 gfx::Rect target_rect(folder_icon_bounds); | |
58 target_rect.ClampToCenteredSize(FolderImageSource::ItemIconSize()); | |
59 return target_rect; | |
60 } | 37 } |
61 | 38 |
62 void AppListFolderItem::Activate(int event_flags) { | 39 void AppListFolderItem::Activate(int event_flags) { |
63 // Folder handling is implemented by the View, so do nothing. | 40 // Folder handling is implemented by the View, so do nothing. |
64 } | 41 } |
65 | 42 |
66 // static | 43 // static |
67 const char AppListFolderItem::kItemType[] = "FolderItem"; | 44 const char AppListFolderItem::kItemType[] = "FolderItem"; |
68 | 45 |
69 const char* AppListFolderItem::GetItemType() const { | 46 const char* AppListFolderItem::GetItemType() const { |
(...skipping 30 matching lines...) Expand all Loading... |
100 other_folder->item_list()->item_at(i))) | 77 other_folder->item_list()->item_at(i))) |
101 return false; | 78 return false; |
102 } | 79 } |
103 return true; | 80 return true; |
104 } | 81 } |
105 | 82 |
106 std::string AppListFolderItem::GenerateId() { | 83 std::string AppListFolderItem::GenerateId() { |
107 return base::GenerateGUID(); | 84 return base::GenerateGUID(); |
108 } | 85 } |
109 | 86 |
110 void AppListFolderItem::ItemIconChanged() { | 87 void AppListFolderItem::OnFolderImageUpdated() { |
111 UpdateIcon(); | 88 SetIcon(folder_image_.icon(), false); |
112 } | |
113 | |
114 void AppListFolderItem::OnListItemAdded(size_t index, | |
115 AppListItem* item) { | |
116 if (index < kNumFolderTopItems) | |
117 UpdateTopItems(); | |
118 } | |
119 | |
120 void AppListFolderItem::OnListItemRemoved(size_t index, | |
121 AppListItem* item) { | |
122 if (index < kNumFolderTopItems) | |
123 UpdateTopItems(); | |
124 } | |
125 | |
126 void AppListFolderItem::OnListItemMoved(size_t from_index, | |
127 size_t to_index, | |
128 AppListItem* item) { | |
129 if (from_index < kNumFolderTopItems || to_index < kNumFolderTopItems) | |
130 UpdateTopItems(); | |
131 } | |
132 | |
133 void AppListFolderItem::UpdateTopItems() { | |
134 for (size_t i = 0; i < top_items_.size(); ++i) | |
135 top_items_[i]->RemoveObserver(this); | |
136 top_items_.clear(); | |
137 | |
138 for (size_t i = 0; | |
139 i < kNumFolderTopItems && i < item_list_->item_count(); ++i) { | |
140 AppListItem* item = item_list_->item_at(i); | |
141 item->AddObserver(this); | |
142 top_items_.push_back(item); | |
143 } | |
144 UpdateIcon(); | |
145 } | 89 } |
146 | 90 |
147 } // namespace app_list | 91 } // namespace app_list |
OLD | NEW |