OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_item_list.h" | 5 #include "ui/app_list/app_list_item_list.h" |
6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
7 #include "ui/app_list/app_list_item.h" | 8 #include "ui/app_list/app_list_item.h" |
8 | 9 |
9 namespace app_list { | 10 namespace app_list { |
10 | 11 |
11 AppListItemList::AppListItemList() { | 12 AppListItemList::AppListItemList() { |
12 } | 13 } |
13 | 14 |
14 AppListItemList::~AppListItemList() { | 15 AppListItemList::~AppListItemList() { |
15 } | 16 } |
16 | 17 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 165 } |
165 } | 166 } |
166 if (index == 0) | 167 if (index == 0) |
167 return app_list_items_[0]->position().CreateBefore(); | 168 return app_list_items_[0]->position().CreateBefore(); |
168 if (index == nitems) | 169 if (index == nitems) |
169 return app_list_items_[nitems - 1]->position().CreateAfter(); | 170 return app_list_items_[nitems - 1]->position().CreateAfter(); |
170 return app_list_items_[index - 1]->position().CreateBetween( | 171 return app_list_items_[index - 1]->position().CreateBetween( |
171 app_list_items_[index]->position()); | 172 app_list_items_[index]->position()); |
172 } | 173 } |
173 | 174 |
174 AppListItem* AppListItemList::AddItem(scoped_ptr<AppListItem> item_ptr) { | 175 AppListItem* AppListItemList::AddItem(std::unique_ptr<AppListItem> item_ptr) { |
175 AppListItem* item = item_ptr.get(); | 176 AppListItem* item = item_ptr.get(); |
176 CHECK(std::find(app_list_items_.begin(), app_list_items_.end(), item) | 177 CHECK(std::find(app_list_items_.begin(), app_list_items_.end(), item) |
177 == app_list_items_.end()); | 178 == app_list_items_.end()); |
178 EnsureValidItemPosition(item); | 179 EnsureValidItemPosition(item); |
179 size_t index = GetItemSortOrderIndex(item->position(), item->id()); | 180 size_t index = GetItemSortOrderIndex(item->position(), item->id()); |
180 app_list_items_.insert(app_list_items_.begin() + index, item_ptr.release()); | 181 app_list_items_.insert(app_list_items_.begin() + index, item_ptr.release()); |
181 FOR_EACH_OBSERVER(AppListItemListObserver, | 182 FOR_EACH_OBSERVER(AppListItemListObserver, |
182 observers_, | 183 observers_, |
183 OnListItemAdded(index, item)); | 184 OnListItemAdded(index, item)); |
184 | 185 |
185 if (item->id() == highlighted_id_) { | 186 if (item->id() == highlighted_id_) { |
186 // Item not present when highlight requested, so highlight it now. | 187 // Item not present when highlight requested, so highlight it now. |
187 item->set_highlighted(true); | 188 item->set_highlighted(true); |
188 FOR_EACH_OBSERVER(AppListItemListObserver, | 189 FOR_EACH_OBSERVER(AppListItemListObserver, |
189 observers_, | 190 observers_, |
190 OnAppListItemHighlight(index, true)); | 191 OnAppListItemHighlight(index, true)); |
191 } | 192 } |
192 return item; | 193 return item; |
193 } | 194 } |
194 | 195 |
195 void AppListItemList::DeleteItem(const std::string& id) { | 196 void AppListItemList::DeleteItem(const std::string& id) { |
196 scoped_ptr<AppListItem> item = RemoveItem(id); | 197 std::unique_ptr<AppListItem> item = RemoveItem(id); |
197 // |item| will be deleted on destruction. | 198 // |item| will be deleted on destruction. |
198 } | 199 } |
199 | 200 |
200 scoped_ptr<AppListItem> AppListItemList::RemoveItem(const std::string& id) { | 201 std::unique_ptr<AppListItem> AppListItemList::RemoveItem( |
| 202 const std::string& id) { |
201 size_t index; | 203 size_t index; |
202 if (!FindItemIndex(id, &index)) | 204 if (!FindItemIndex(id, &index)) |
203 LOG(FATAL) << "RemoveItem: Not found: " << id; | 205 LOG(FATAL) << "RemoveItem: Not found: " << id; |
204 return RemoveItemAt(index); | 206 return RemoveItemAt(index); |
205 } | 207 } |
206 | 208 |
207 scoped_ptr<AppListItem> AppListItemList::RemoveItemAt(size_t index) { | 209 std::unique_ptr<AppListItem> AppListItemList::RemoveItemAt(size_t index) { |
208 CHECK_LT(index, item_count()); | 210 CHECK_LT(index, item_count()); |
209 AppListItem* item = app_list_items_[index]; | 211 AppListItem* item = app_list_items_[index]; |
210 app_list_items_.weak_erase(app_list_items_.begin() + index); | 212 app_list_items_.weak_erase(app_list_items_.begin() + index); |
211 FOR_EACH_OBSERVER(AppListItemListObserver, | 213 FOR_EACH_OBSERVER(AppListItemListObserver, |
212 observers_, | 214 observers_, |
213 OnListItemRemoved(index, item)); | 215 OnListItemRemoved(index, item)); |
214 return make_scoped_ptr<AppListItem>(item); | 216 return base::WrapUnique<AppListItem>(item); |
215 } | 217 } |
216 | 218 |
217 void AppListItemList::DeleteItemAt(size_t index) { | 219 void AppListItemList::DeleteItemAt(size_t index) { |
218 scoped_ptr<AppListItem> item = RemoveItemAt(index); | 220 std::unique_ptr<AppListItem> item = RemoveItemAt(index); |
219 // |item| will be deleted on destruction. | 221 // |item| will be deleted on destruction. |
220 } | 222 } |
221 | 223 |
222 void AppListItemList::EnsureValidItemPosition(AppListItem* item) { | 224 void AppListItemList::EnsureValidItemPosition(AppListItem* item) { |
223 syncer::StringOrdinal position = item->position(); | 225 syncer::StringOrdinal position = item->position(); |
224 if (position.IsValid()) | 226 if (position.IsValid()) |
225 return; | 227 return; |
226 size_t nitems = app_list_items_.size(); | 228 size_t nitems = app_list_items_.size(); |
227 if (nitems == 0) { | 229 if (nitems == 0) { |
228 position = syncer::StringOrdinal::CreateInitialOrdinal(); | 230 position = syncer::StringOrdinal::CreateInitialOrdinal(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 else | 269 else |
268 cur->set_position(prev->position().CreateAfter()); | 270 cur->set_position(prev->position().CreateAfter()); |
269 prev = cur; | 271 prev = cur; |
270 } | 272 } |
271 FOR_EACH_OBSERVER(AppListItemListObserver, | 273 FOR_EACH_OBSERVER(AppListItemListObserver, |
272 observers_, | 274 observers_, |
273 OnListItemMoved(index, index, app_list_items_[index])); | 275 OnListItemMoved(index, index, app_list_items_[index])); |
274 } | 276 } |
275 | 277 |
276 } // namespace app_list | 278 } // namespace app_list |
OLD | NEW |