| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef UI_BASE_MODELS_LIST_MODEL_H_ | 5 #ifndef UI_BASE_MODELS_LIST_MODEL_H_ |
| 6 #define UI_BASE_MODELS_LIST_MODEL_H_ | 6 #define UI_BASE_MODELS_LIST_MODEL_H_ |
| 7 | 7 |
| 8 #include <utility> |
| 9 |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 12 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
| 13 #include "ui/base/models/list_model_observer.h" | 15 #include "ui/base/models/list_model_observer.h" |
| 14 | 16 |
| 15 namespace ui { | 17 namespace ui { |
| 16 | 18 |
| 17 // A list model that manages a list of ItemType pointers. Items added to the | 19 // A list model that manages a list of ItemType pointers. Items added to the |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 55 } |
| 54 | 56 |
| 55 // Removes the item at |index| from |items_| and deletes it. | 57 // Removes the item at |index| from |items_| and deletes it. |
| 56 void DeleteAt(size_t index) { | 58 void DeleteAt(size_t index) { |
| 57 scoped_ptr<ItemType> item = RemoveAt(index); | 59 scoped_ptr<ItemType> item = RemoveAt(index); |
| 58 // |item| will be deleted on destruction. | 60 // |item| will be deleted on destruction. |
| 59 } | 61 } |
| 60 | 62 |
| 61 // Removes and deletes all items from the model. | 63 // Removes and deletes all items from the model. |
| 62 void DeleteAll() { | 64 void DeleteAll() { |
| 63 ScopedVector<ItemType> to_be_deleted(items_.Pass()); | 65 ScopedVector<ItemType> to_be_deleted(std::move(items_)); |
| 64 NotifyItemsRemoved(0, to_be_deleted.size()); | 66 NotifyItemsRemoved(0, to_be_deleted.size()); |
| 65 } | 67 } |
| 66 | 68 |
| 67 // Moves the item at |index| to |target_index|. |target_index| is in terms | 69 // Moves the item at |index| to |target_index|. |target_index| is in terms |
| 68 // of the model *after* the item at |index| is removed. | 70 // of the model *after* the item at |index| is removed. |
| 69 void Move(size_t index, size_t target_index) { | 71 void Move(size_t index, size_t target_index) { |
| 70 DCHECK_LT(index, item_count()); | 72 DCHECK_LT(index, item_count()); |
| 71 DCHECK_LT(target_index, item_count()); | 73 DCHECK_LT(target_index, item_count()); |
| 72 | 74 |
| 73 if (index == target_index) | 75 if (index == target_index) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 private: | 137 private: |
| 136 ScopedVector<ItemType> items_; | 138 ScopedVector<ItemType> items_; |
| 137 base::ObserverList<ListModelObserver> observers_; | 139 base::ObserverList<ListModelObserver> observers_; |
| 138 | 140 |
| 139 DISALLOW_COPY_AND_ASSIGN(ListModel<ItemType>); | 141 DISALLOW_COPY_AND_ASSIGN(ListModel<ItemType>); |
| 140 }; | 142 }; |
| 141 | 143 |
| 142 } // namespace ui | 144 } // namespace ui |
| 143 | 145 |
| 144 #endif // UI_BASE_MODELS_LIST_MODEL_H_ | 146 #endif // UI_BASE_MODELS_LIST_MODEL_H_ |
| OLD | NEW |