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

Side by Side Diff: ui/app_list/folder_image.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/app_list/folder_image.h"
6
7 #include "ui/app_list/app_list_constants.h"
8 #include "ui/app_list/app_list_item.h"
9 #include "ui/app_list/app_list_item_list.h"
10 #include "ui/app_list/folder_image_source.h"
11 #include "ui/app_list/views/contents_view.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/image/image_skia.h"
15 #include "ui/strings/grit/ui_strings.h"
16
17 namespace app_list {
18
19 FolderImage::FolderImage(AppListItemList* item_list) : item_list_(item_list) {
20 item_list_->AddObserver(this);
21 }
22
23 FolderImage::~FolderImage() {
24 for (size_t i = 0; i < top_items_.size(); ++i)
25 top_items_[i]->RemoveObserver(this);
26 item_list_->RemoveObserver(this);
27 }
28
29 void FolderImage::UpdateIcon() {
30 for (size_t i = 0; i < top_items_.size(); ++i)
31 top_items_[i]->RemoveObserver(this);
32 top_items_.clear();
33
34 for (size_t i = 0; i < kNumFolderTopItems && i < item_list_->item_count();
35 ++i) {
36 AppListItem* item = item_list_->item_at(i);
37 item->AddObserver(this);
38 top_items_.push_back(item);
39 }
40 UpdateImageOnly();
calamity 2014/10/28 05:12:57 As discussed, avoiding a copy of 4 pointers is pro
Matt Giuca 2014/10/29 07:11:23 Done.
calamity 2014/11/03 00:37:45 I think this got missed.
Matt Giuca 2014/11/03 05:23:16 Sorry, I misunderstood this (thought it was about
41 }
42
43 const gfx::ImageSkia& FolderImage::GetTopIcon(size_t item_index) {
44 DCHECK(item_index <= top_items_.size());
45 return top_items_[item_index]->icon();
46 }
47
48 gfx::Rect FolderImage::GetTargetIconRectInFolderForItem(
49 AppListItem* item,
50 const gfx::Rect& folder_icon_bounds) {
51 for (size_t i = 0; i < top_items_.size(); ++i) {
52 if (item->id() == top_items_[i]->id()) {
53 std::vector<gfx::Rect> rects =
54 FolderImageSource::GetTopIconsBounds(folder_icon_bounds);
55 return rects[i];
56 }
57 }
58
59 gfx::Rect target_rect(folder_icon_bounds);
60 target_rect.ClampToCenteredSize(FolderImageSource::ItemIconSize());
61 return target_rect;
62 }
63
64 void FolderImage::AddObserver(FolderImageObserver* observer) {
65 observers_.AddObserver(observer);
66 }
67
68 void FolderImage::RemoveObserver(FolderImageObserver* observer) {
69 observers_.RemoveObserver(observer);
70 }
71
72 void FolderImage::ItemIconChanged() {
73 UpdateImageOnly();
74 }
75
76 void FolderImage::OnListItemAdded(size_t index, AppListItem* item) {
77 if (index <= kNumFolderTopItems)
78 UpdateIcon();
79 }
80
81 void FolderImage::OnListItemRemoved(size_t index, AppListItem* item) {
82 if (index <= kNumFolderTopItems)
83 UpdateIcon();
84 }
85
86 void FolderImage::OnListItemMoved(size_t from_index,
87 size_t to_index,
88 AppListItem* item) {
89 if (from_index <= kNumFolderTopItems || to_index <= kNumFolderTopItems)
90 UpdateIcon();
91 }
92
93 void FolderImage::UpdateImageOnly() {
94 FolderImageSource::Icons top_icons;
95 for (size_t i = 0; i < top_items_.size(); ++i)
96 top_icons.push_back(top_items_[i]->icon());
97
98 const gfx::Size icon_size = gfx::Size(kGridIconDimension, kGridIconDimension);
99 gfx::ImageSkia icon =
100 gfx::ImageSkia(new FolderImageSource(top_icons, icon_size), icon_size);
101
102 FOR_EACH_OBSERVER(
103 FolderImageObserver, observers_, OnFolderImageUpdated(icon));
104 }
105
106 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698