Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / app_list / app_list_folder_item.cc
blobda2cc09de33d07bc6196aac4a584ff3e603d849b
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
3 // found in the LICENSE file.
5 #include "ui/app_list/app_list_folder_item.h"
7 #include "base/guid.h"
8 #include "ui/app_list/app_list_constants.h"
9 #include "ui/app_list/app_list_item_list.h"
10 #include "ui/gfx/geometry/rect.h"
11 #include "ui/gfx/image/image_skia.h"
13 namespace app_list {
15 AppListFolderItem::AppListFolderItem(const std::string& id,
16 FolderType folder_type)
17 : AppListItem(id),
18 folder_type_(folder_type),
19 item_list_(new AppListItemList),
20 folder_image_(item_list_.get()) {
21 folder_image_.AddObserver(this);
24 AppListFolderItem::~AppListFolderItem() {
25 folder_image_.RemoveObserver(this);
28 const gfx::ImageSkia& AppListFolderItem::GetTopIcon(size_t item_index) {
29 return folder_image_.GetTopIcon(item_index);
32 gfx::Rect AppListFolderItem::GetTargetIconRectInFolderForItem(
33 AppListItem* item,
34 const gfx::Rect& folder_icon_bounds) {
35 return folder_image_.GetTargetIconRectInFolderForItem(item,
36 folder_icon_bounds);
39 void AppListFolderItem::Activate(int event_flags) {
40 // Folder handling is implemented by the View, so do nothing.
43 // static
44 const char AppListFolderItem::kItemType[] = "FolderItem";
46 const char* AppListFolderItem::GetItemType() const {
47 return AppListFolderItem::kItemType;
50 ui::MenuModel* AppListFolderItem::GetContextMenuModel() {
51 // TODO(stevenjb/jennyz): Implement.
52 return NULL;
55 AppListItem* AppListFolderItem::FindChildItem(const std::string& id) {
56 return item_list_->FindItem(id);
59 size_t AppListFolderItem::ChildItemCount() const {
60 return item_list_->item_count();
63 void AppListFolderItem::OnExtensionPreferenceChanged() {
64 for (size_t i = 0; i < item_list_->item_count(); ++i)
65 item_list_->item_at(i)->OnExtensionPreferenceChanged();
68 bool AppListFolderItem::CompareForTest(const AppListItem* other) const {
69 if (!AppListItem::CompareForTest(other))
70 return false;
71 const AppListFolderItem* other_folder =
72 static_cast<const AppListFolderItem*>(other);
73 if (other_folder->item_list()->item_count() != item_list_->item_count())
74 return false;
75 for (size_t i = 0; i < item_list_->item_count(); ++i) {
76 if (!item_list()->item_at(i)->CompareForTest(
77 other_folder->item_list()->item_at(i)))
78 return false;
80 return true;
83 std::string AppListFolderItem::GenerateId() {
84 return base::GenerateGUID();
87 void AppListFolderItem::OnFolderImageUpdated() {
88 SetIcon(folder_image_.icon());
91 } // namespace app_list