| OLD | NEW |
| 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 "ash/common/shelf/shelf_model.h" | 5 #include "ash/common/shelf/shelf_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/common/shelf/shelf_item_delegate.h" | 9 #include "ash/common/shelf/shelf_item_delegate.h" |
| 10 #include "ash/common/shelf/shelf_model_observer.h" | 10 #include "ash/common/shelf/shelf_model_observer.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 index = ValidateInsertionIndex(item.type, index); | 64 index = ValidateInsertionIndex(item.type, index); |
| 65 items_.insert(items_.begin() + index, item); | 65 items_.insert(items_.begin() + index, item); |
| 66 items_[index].id = next_id_++; | 66 items_[index].id = next_id_++; |
| 67 for (auto& observer : observers_) | 67 for (auto& observer : observers_) |
| 68 observer.ShelfItemAdded(index); | 68 observer.ShelfItemAdded(index); |
| 69 return index; | 69 return index; |
| 70 } | 70 } |
| 71 | 71 |
| 72 void ShelfModel::RemoveItemAt(int index) { | 72 void ShelfModel::RemoveItemAt(int index) { |
| 73 DCHECK(index >= 0 && index < item_count()); | 73 DCHECK(index >= 0 && index < item_count()); |
| 74 // The app list and browser shortcut can't be removed. | |
| 75 DCHECK(items_[index].type != TYPE_APP_LIST && | |
| 76 items_[index].type != TYPE_BROWSER_SHORTCUT); | |
| 77 ShelfID id = items_[index].id; | 74 ShelfID id = items_[index].id; |
| 78 items_.erase(items_.begin() + index); | 75 items_.erase(items_.begin() + index); |
| 79 RemoveShelfItemDelegate(id); | 76 RemoveShelfItemDelegate(id); |
| 80 // TODO(jamescook): Fold this into ShelfItemRemoved in existing observers. | 77 // TODO(jamescook): Fold this into ShelfItemRemoved in existing observers. |
| 81 for (auto& observer : observers_) | 78 for (auto& observer : observers_) |
| 82 observer.OnSetShelfItemDelegate(id, nullptr); | 79 observer.OnSetShelfItemDelegate(id, nullptr); |
| 83 for (auto& observer : observers_) | 80 for (auto& observer : observers_) |
| 84 observer.ShelfItemRemoved(index, id); | 81 observer.ShelfItemRemoved(index, id); |
| 85 } | 82 } |
| 86 | 83 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 205 |
| 209 return index; | 206 return index; |
| 210 } | 207 } |
| 211 | 208 |
| 212 void ShelfModel::RemoveShelfItemDelegate(ShelfID id) { | 209 void ShelfModel::RemoveShelfItemDelegate(ShelfID id) { |
| 213 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end()) | 210 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end()) |
| 214 id_to_item_delegate_map_.erase(id); | 211 id_to_item_delegate_map_.erase(id); |
| 215 } | 212 } |
| 216 | 213 |
| 217 } // namespace ash | 214 } // namespace ash |
| OLD | NEW |