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

Unified Diff: ui/base/models/list_model.h

Issue 10956052: Add a ListModel::Move. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + nit in #2 Created 8 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/app_list/search_result_list_view.cc ('k') | ui/base/models/list_model_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/models/list_model.h
diff --git a/ui/base/models/list_model.h b/ui/base/models/list_model.h
index dbbd689f96c481912469d0b156ecd1cffd2dfb6d..9b4440d9a020d2db41d8bfb7adade37fe2ec173e 100644
--- a/ui/base/models/list_model.h
+++ b/ui/base/models/list_model.h
@@ -62,6 +62,21 @@ class ListModel {
NotifyItemsRemoved(0, to_be_deleted.size());
}
+ // Moves the item at |index| to |target_index|. |target_index| is in terms
+ // of the model *after* the item at |index| is removed.
+ void Move(size_t index, size_t target_index) {
+ DCHECK_LT(index, item_count());
+ DCHECK_LT(target_index, item_count());
+
+ if (index == target_index)
+ return;
+
+ ItemType* item = items_[index];
+ items_.weak_erase(items_.begin() + index);
+ items_.insert(items_.begin() + target_index, item);
+ NotifyItemMoved(index, target_index);
+ }
+
void AddObserver(ListModelObserver* observer) {
observers_.AddObserver(observer);
}
@@ -82,6 +97,12 @@ class ListModel {
ListItemsRemoved(start, count));
}
+ void NotifyItemMoved(size_t index, size_t target_index) {
+ FOR_EACH_OBSERVER(ListModelObserver,
+ observers_,
+ ListItemMoved(index, target_index));
+ }
+
void NotifyItemsChanged(size_t start, size_t count) {
FOR_EACH_OBSERVER(ListModelObserver,
observers_,
« no previous file with comments | « ui/app_list/search_result_list_view.cc ('k') | ui/base/models/list_model_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698