OLD | NEW |
---|---|
(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 (const auto& item : top_items_) | |
24 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.
| |
25 item_list_->RemoveObserver(this); | |
26 } | |
27 | |
28 void FolderImage::UpdateIcon() { | |
29 for (const auto& item : top_items_) | |
calamity
2014/11/03 00:37:45
Ditto.
Matt Giuca
2014/11/03 05:23:16
Done.
| |
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 UpdateImageOnly(); | |
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 UpdateImageOnly(); | |
73 } | |
74 | |
75 void FolderImage::OnListItemAdded(size_t index, AppListItem* item) { | |
76 if (index < kNumFolderTopItems) | |
77 UpdateIcon(); | |
78 } | |
79 | |
80 void FolderImage::OnListItemRemoved(size_t index, AppListItem* item) { | |
81 if (index < kNumFolderTopItems) | |
82 UpdateIcon(); | |
83 } | |
84 | |
85 void FolderImage::OnListItemMoved(size_t from_index, | |
86 size_t to_index, | |
87 AppListItem* item) { | |
88 if (from_index < kNumFolderTopItems || to_index < kNumFolderTopItems) | |
89 UpdateIcon(); | |
90 } | |
91 | |
92 void FolderImage::UpdateImageOnly() { | |
93 FolderImageSource::Icons top_icons; | |
94 for (const auto& item : top_items_) | |
95 top_icons.push_back(item->icon()); | |
calamity
2014/11/03 00:37:45
Ditto.
Matt Giuca
2014/11/03 05:23:16
Done.
| |
96 | |
97 const gfx::Size icon_size = gfx::Size(kGridIconDimension, kGridIconDimension); | |
98 icon_ = | |
99 gfx::ImageSkia(new FolderImageSource(top_icons, icon_size), icon_size); | |
100 | |
101 FOR_EACH_OBSERVER(FolderImageObserver, observers_, OnFolderImageUpdated()); | |
102 } | |
103 | |
104 } // namespace app_list | |
OLD | NEW |