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

Side by Side Diff: ui/app_list/app_list_folder_item.cc

Issue 681373004: App list folder icons: Fixed off-by-one error. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ares-allapps-button
Patch Set: Fixed bad DCHECK (off-by-one; and made into a CHECK). 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/app_list/app_list_folder_item.h" 5 #include "ui/app_list/app_list_folder_item.h"
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "ui/app_list/app_list_constants.h" 8 #include "ui/app_list/app_list_constants.h"
9 #include "ui/app_list/app_list_item_list.h" 9 #include "ui/app_list/app_list_item_list.h"
10 #include "ui/app_list/folder_image_source.h" 10 #include "ui/app_list/folder_image_source.h"
(...skipping 21 matching lines...) Expand all
32 top_icons.push_back(top_items_[i]->icon()); 32 top_icons.push_back(top_items_[i]->icon());
33 33
34 const gfx::Size icon_size = gfx::Size(kGridIconDimension, kGridIconDimension); 34 const gfx::Size icon_size = gfx::Size(kGridIconDimension, kGridIconDimension);
35 gfx::ImageSkia icon = gfx::ImageSkia( 35 gfx::ImageSkia icon = gfx::ImageSkia(
36 new FolderImageSource(top_icons, icon_size), 36 new FolderImageSource(top_icons, icon_size),
37 icon_size); 37 icon_size);
38 SetIcon(icon, false); 38 SetIcon(icon, false);
39 } 39 }
40 40
41 const gfx::ImageSkia& AppListFolderItem::GetTopIcon(size_t item_index) { 41 const gfx::ImageSkia& AppListFolderItem::GetTopIcon(size_t item_index) {
42 DCHECK(item_index <= top_items_.size()); 42 CHECK_LT(item_index, top_items_.size());
43 return top_items_[item_index]->icon(); 43 return top_items_[item_index]->icon();
44 } 44 }
45 45
46 gfx::Rect AppListFolderItem::GetTargetIconRectInFolderForItem( 46 gfx::Rect AppListFolderItem::GetTargetIconRectInFolderForItem(
47 AppListItem* item, 47 AppListItem* item,
48 const gfx::Rect& folder_icon_bounds) { 48 const gfx::Rect& folder_icon_bounds) {
49 for (size_t i = 0; i < top_items_.size(); ++i) { 49 for (size_t i = 0; i < top_items_.size(); ++i) {
50 if (item->id() == top_items_[i]->id()) { 50 if (item->id() == top_items_[i]->id()) {
51 std::vector<gfx::Rect> rects = 51 std::vector<gfx::Rect> rects =
52 FolderImageSource::GetTopIconsBounds(folder_icon_bounds); 52 FolderImageSource::GetTopIconsBounds(folder_icon_bounds);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 std::string AppListFolderItem::GenerateId() { 106 std::string AppListFolderItem::GenerateId() {
107 return base::GenerateGUID(); 107 return base::GenerateGUID();
108 } 108 }
109 109
110 void AppListFolderItem::ItemIconChanged() { 110 void AppListFolderItem::ItemIconChanged() {
111 UpdateIcon(); 111 UpdateIcon();
112 } 112 }
113 113
114 void AppListFolderItem::OnListItemAdded(size_t index, 114 void AppListFolderItem::OnListItemAdded(size_t index,
115 AppListItem* item) { 115 AppListItem* item) {
116 if (index <= kNumFolderTopItems) 116 if (index < kNumFolderTopItems)
117 UpdateTopItems(); 117 UpdateTopItems();
118 } 118 }
119 119
120 void AppListFolderItem::OnListItemRemoved(size_t index, 120 void AppListFolderItem::OnListItemRemoved(size_t index,
121 AppListItem* item) { 121 AppListItem* item) {
122 if (index <= kNumFolderTopItems) 122 if (index < kNumFolderTopItems)
123 UpdateTopItems(); 123 UpdateTopItems();
124 } 124 }
125 125
126 void AppListFolderItem::OnListItemMoved(size_t from_index, 126 void AppListFolderItem::OnListItemMoved(size_t from_index,
127 size_t to_index, 127 size_t to_index,
128 AppListItem* item) { 128 AppListItem* item) {
129 if (from_index <= kNumFolderTopItems || to_index <= kNumFolderTopItems) 129 if (from_index < kNumFolderTopItems || to_index < kNumFolderTopItems)
130 UpdateTopItems(); 130 UpdateTopItems();
131 } 131 }
132 132
133 void AppListFolderItem::UpdateTopItems() { 133 void AppListFolderItem::UpdateTopItems() {
134 for (size_t i = 0; i < top_items_.size(); ++i) 134 for (size_t i = 0; i < top_items_.size(); ++i)
135 top_items_[i]->RemoveObserver(this); 135 top_items_[i]->RemoveObserver(this);
136 top_items_.clear(); 136 top_items_.clear();
137 137
138 for (size_t i = 0; 138 for (size_t i = 0;
139 i < kNumFolderTopItems && i < item_list_->item_count(); ++i) { 139 i < kNumFolderTopItems && i < item_list_->item_count(); ++i) {
140 AppListItem* item = item_list_->item_at(i); 140 AppListItem* item = item_list_->item_at(i);
141 item->AddObserver(this); 141 item->AddObserver(this);
142 top_items_.push_back(item); 142 top_items_.push_back(item);
143 } 143 }
144 UpdateIcon(); 144 UpdateIcon();
145 } 145 }
146 146
147 } // namespace app_list 147 } // namespace app_list
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698