Chromium Code Reviews| Index: ui/app_list/folder_image.cc |
| diff --git a/ui/app_list/folder_image.cc b/ui/app_list/folder_image.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8e4f27225bf3c7bacf1ab68476d5109af93e85e2 |
| --- /dev/null |
| +++ b/ui/app_list/folder_image.cc |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/app_list/folder_image.h" |
| + |
| +#include "ui/app_list/app_list_constants.h" |
| +#include "ui/app_list/app_list_item.h" |
| +#include "ui/app_list/app_list_item_list.h" |
| +#include "ui/app_list/folder_image_source.h" |
| +#include "ui/app_list/views/contents_view.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/gfx/geometry/rect.h" |
| +#include "ui/strings/grit/ui_strings.h" |
| + |
| +namespace app_list { |
| + |
| +FolderImage::FolderImage(AppListItemList* item_list) : item_list_(item_list) { |
| + item_list_->AddObserver(this); |
| +} |
| + |
| +FolderImage::~FolderImage() { |
| + for (const auto& item : top_items_) |
| + item->RemoveObserver(this); |
|
calamity
2014/11/03 00:37:45
I think you're supposed to use for (auto* ...) her
Matt Giuca
2014/11/03 05:23:16
This is why I don't like auto.
Done.
|
| + item_list_->RemoveObserver(this); |
| +} |
| + |
| +void FolderImage::UpdateIcon() { |
| + for (const auto& item : top_items_) |
|
calamity
2014/11/03 00:37:45
Ditto.
Matt Giuca
2014/11/03 05:23:16
Done.
|
| + item->RemoveObserver(this); |
| + top_items_.clear(); |
| + |
| + for (size_t i = 0; i < kNumFolderTopItems && i < item_list_->item_count(); |
| + ++i) { |
| + AppListItem* item = item_list_->item_at(i); |
| + item->AddObserver(this); |
| + top_items_.push_back(item); |
| + } |
| + UpdateImageOnly(); |
| +} |
| + |
| +const gfx::ImageSkia& FolderImage::GetTopIcon(size_t item_index) { |
| + CHECK_LT(item_index, top_items_.size()); |
| + return top_items_[item_index]->icon(); |
| +} |
| + |
| +gfx::Rect FolderImage::GetTargetIconRectInFolderForItem( |
| + AppListItem* item, |
| + const gfx::Rect& folder_icon_bounds) { |
| + for (size_t i = 0; i < top_items_.size(); ++i) { |
| + if (item->id() == top_items_[i]->id()) { |
| + std::vector<gfx::Rect> rects = |
| + FolderImageSource::GetTopIconsBounds(folder_icon_bounds); |
| + return rects[i]; |
| + } |
| + } |
| + |
| + gfx::Rect target_rect(folder_icon_bounds); |
| + target_rect.ClampToCenteredSize(FolderImageSource::ItemIconSize()); |
| + return target_rect; |
| +} |
| + |
| +void FolderImage::AddObserver(FolderImageObserver* observer) { |
| + observers_.AddObserver(observer); |
| +} |
| + |
| +void FolderImage::RemoveObserver(FolderImageObserver* observer) { |
| + observers_.RemoveObserver(observer); |
| +} |
| + |
| +void FolderImage::ItemIconChanged() { |
| + UpdateImageOnly(); |
| +} |
| + |
| +void FolderImage::OnListItemAdded(size_t index, AppListItem* item) { |
| + if (index < kNumFolderTopItems) |
| + UpdateIcon(); |
| +} |
| + |
| +void FolderImage::OnListItemRemoved(size_t index, AppListItem* item) { |
| + if (index < kNumFolderTopItems) |
| + UpdateIcon(); |
| +} |
| + |
| +void FolderImage::OnListItemMoved(size_t from_index, |
| + size_t to_index, |
| + AppListItem* item) { |
| + if (from_index < kNumFolderTopItems || to_index < kNumFolderTopItems) |
| + UpdateIcon(); |
| +} |
| + |
| +void FolderImage::UpdateImageOnly() { |
| + FolderImageSource::Icons top_icons; |
| + for (const auto& item : top_items_) |
| + top_icons.push_back(item->icon()); |
|
calamity
2014/11/03 00:37:45
Ditto.
Matt Giuca
2014/11/03 05:23:16
Done.
|
| + |
| + const gfx::Size icon_size = gfx::Size(kGridIconDimension, kGridIconDimension); |
| + icon_ = |
| + gfx::ImageSkia(new FolderImageSource(top_icons, icon_size), icon_size); |
| + |
| + FOR_EACH_OBSERVER(FolderImageObserver, observers_, OnFolderImageUpdated()); |
| +} |
| + |
| +} // namespace app_list |