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

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: Fix compile on Windows (APP_LIST_EXPORT). 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
« no previous file with comments | « ui/app_list/folder_image.h ('k') | ui/app_list/folder_image_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/strings/grit/ui_strings.h"
15
16 namespace app_list {
17
18 FolderImage::FolderImage(AppListItemList* item_list) : item_list_(item_list) {
19 item_list_->AddObserver(this);
20 }
21
22 FolderImage::~FolderImage() {
23 for (auto* item : top_items_)
24 item->RemoveObserver(this);
25 item_list_->RemoveObserver(this);
26 }
27
28 void FolderImage::UpdateIcon() {
29 for (auto* item : top_items_)
30 item->RemoveObserver(this);
31 top_items_.clear();
32
33 for (size_t i = 0; i < kNumFolderTopItems && i < item_list_->item_count();
34 ++i) {
35 AppListItem* item = item_list_->item_at(i);
36 item->AddObserver(this);
37 top_items_.push_back(item);
38 }
39 RedrawIconAndNotify();
40 }
41
42 const gfx::ImageSkia& FolderImage::GetTopIcon(size_t item_index) {
43 CHECK_LT(item_index, top_items_.size());
44 return top_items_[item_index]->icon();
45 }
46
47 gfx::Rect FolderImage::GetTargetIconRectInFolderForItem(
48 AppListItem* item,
49 const gfx::Rect& folder_icon_bounds) {
50 for (size_t i = 0; i < top_items_.size(); ++i) {
51 if (item->id() == top_items_[i]->id()) {
52 std::vector<gfx::Rect> rects =
53 FolderImageSource::GetTopIconsBounds(folder_icon_bounds);
54 return rects[i];
55 }
56 }
57
58 gfx::Rect target_rect(folder_icon_bounds);
59 target_rect.ClampToCenteredSize(FolderImageSource::ItemIconSize());
60 return target_rect;
61 }
62
63 void FolderImage::AddObserver(FolderImageObserver* observer) {
64 observers_.AddObserver(observer);
65 }
66
67 void FolderImage::RemoveObserver(FolderImageObserver* observer) {
68 observers_.RemoveObserver(observer);
69 }
70
71 void FolderImage::ItemIconChanged() {
72 // Note: Must update the image only (cannot simply call UpdateIcon), because
73 // UpdateIcon removes and re-adds the FolderImage as an observer of the
74 // AppListItems, which causes the current iterator to call ItemIconChanged
75 // again, and goes into an infinite loop.
76 RedrawIconAndNotify();
77 }
78
79 void FolderImage::OnListItemAdded(size_t index, AppListItem* item) {
80 if (index < kNumFolderTopItems)
81 UpdateIcon();
82 }
83
84 void FolderImage::OnListItemRemoved(size_t index, AppListItem* item) {
85 if (index < kNumFolderTopItems)
86 UpdateIcon();
87 }
88
89 void FolderImage::OnListItemMoved(size_t from_index,
90 size_t to_index,
91 AppListItem* item) {
92 if (from_index < kNumFolderTopItems || to_index < kNumFolderTopItems)
93 UpdateIcon();
94 }
95
96 void FolderImage::RedrawIconAndNotify() {
97 FolderImageSource::Icons top_icons;
98 for (const auto* item : top_items_)
99 top_icons.push_back(item->icon());
100
101 const gfx::Size icon_size = gfx::Size(kGridIconDimension, kGridIconDimension);
102 icon_ =
103 gfx::ImageSkia(new FolderImageSource(top_icons, icon_size), icon_size);
104
105 FOR_EACH_OBSERVER(FolderImageObserver, observers_, OnFolderImageUpdated());
106 }
107
108 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/folder_image.h ('k') | ui/app_list/folder_image_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698