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

Side by Side Diff: ui/app_list/app_list_folder_item.cc

Issue 682843004: Experimental app list: "All apps" button has a folder-like icon. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ares-allapps-button
Patch Set: Created 6 years, 1 month 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
OLDNEW
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" 10 #include "ui/app_list/folder_image_source.h"
11 #include "ui/gfx/geometry/rect.h" 11 #include "ui/gfx/geometry/rect.h"
12 #include "ui/gfx/image/image_skia.h"
12 13
13 namespace app_list { 14 namespace app_list {
14 15
15 AppListFolderItem::AppListFolderItem(const std::string& id, 16 AppListFolderItem::AppListFolderItem(const std::string& id,
16 FolderType folder_type) 17 FolderType folder_type)
17 : AppListItem(id), 18 : AppListItem(id),
18 folder_type_(folder_type), 19 folder_type_(folder_type),
19 item_list_(new AppListItemList) { 20 item_list_(new AppListItemList),
20 item_list_->AddObserver(this); 21 folder_image_(item_list_.get()) {
22 folder_image_.AddObserver(this);
21 } 23 }
22 24
23 AppListFolderItem::~AppListFolderItem() { 25 AppListFolderItem::~AppListFolderItem() {
24 for (size_t i = 0; i < top_items_.size(); ++i) 26 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 } 27 }
40 28
41 const gfx::ImageSkia& AppListFolderItem::GetTopIcon(size_t item_index) { 29 const gfx::ImageSkia& AppListFolderItem::GetTopIcon(size_t item_index) {
42 DCHECK(item_index <= top_items_.size()); 30 return folder_image_.GetTopIcon(item_index);
43 return top_items_[item_index]->icon();
44 } 31 }
45 32
46 gfx::Rect AppListFolderItem::GetTargetIconRectInFolderForItem( 33 gfx::Rect AppListFolderItem::GetTargetIconRectInFolderForItem(
47 AppListItem* item, 34 AppListItem* item,
48 const gfx::Rect& folder_icon_bounds) { 35 const gfx::Rect& folder_icon_bounds) {
49 for (size_t i = 0; i < top_items_.size(); ++i) { 36 return folder_image_.GetTargetIconRectInFolderForItem(item,
50 if (item->id() == top_items_[i]->id()) { 37 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 } 38 }
61 39
62 void AppListFolderItem::Activate(int event_flags) { 40 void AppListFolderItem::Activate(int event_flags) {
63 // Folder handling is implemented by the View, so do nothing. 41 // Folder handling is implemented by the View, so do nothing.
64 } 42 }
65 43
66 // static 44 // static
67 const char AppListFolderItem::kItemType[] = "FolderItem"; 45 const char AppListFolderItem::kItemType[] = "FolderItem";
68 46
69 const char* AppListFolderItem::GetItemType() const { 47 const char* AppListFolderItem::GetItemType() const {
(...skipping 30 matching lines...) Expand all
100 other_folder->item_list()->item_at(i))) 78 other_folder->item_list()->item_at(i)))
101 return false; 79 return false;
102 } 80 }
103 return true; 81 return true;
104 } 82 }
105 83
106 std::string AppListFolderItem::GenerateId() { 84 std::string AppListFolderItem::GenerateId() {
107 return base::GenerateGUID(); 85 return base::GenerateGUID();
108 } 86 }
109 87
110 void AppListFolderItem::ItemIconChanged() { 88 void AppListFolderItem::OnFolderImageUpdated(const gfx::ImageSkia& icon) {
111 UpdateIcon(); 89 SetIcon(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 } 90 }
146 91
147 } // namespace app_list 92 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698