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

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

Issue 2422873002: Remove usage of FOR_EACH_OBSERVER macro in ui/app_list (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « ui/app_list/app_list_item.cc ('k') | ui/app_list/app_list_model.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/memory/ptr_util.h"
8 #include "ui/app_list/app_list_item.h" 8 #include "ui/app_list/app_list_item.h"
9 9
10 namespace app_list { 10 namespace app_list {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 target_item->set_position(new_position); 78 target_item->set_position(new_position);
79 79
80 DVLOG(2) << "Move: " 80 DVLOG(2) << "Move: "
81 << " Prev: " << (prev ? prev->position().ToDebugString() : "(none)") 81 << " Prev: " << (prev ? prev->position().ToDebugString() : "(none)")
82 << " Next: " << (next ? next->position().ToDebugString() : "(none)") 82 << " Next: " << (next ? next->position().ToDebugString() : "(none)")
83 << " -> " << new_position.ToDebugString(); 83 << " -> " << new_position.ToDebugString();
84 84
85 // Insert the item and notify observers. 85 // Insert the item and notify observers.
86 app_list_items_.insert(app_list_items_.begin() + to_index, target_item); 86 app_list_items_.insert(app_list_items_.begin() + to_index, target_item);
87 FOR_EACH_OBSERVER(AppListItemListObserver, 87 for (auto& observer : observers_)
88 observers_, 88 observer.OnListItemMoved(from_index, to_index, target_item);
89 OnListItemMoved(from_index, to_index, target_item));
90 } 89 }
91 90
92 void AppListItemList::SetItemPosition(AppListItem* item, 91 void AppListItemList::SetItemPosition(AppListItem* item,
93 syncer::StringOrdinal new_position) { 92 syncer::StringOrdinal new_position) {
94 DCHECK(item); 93 DCHECK(item);
95 size_t from_index; 94 size_t from_index;
96 if (!FindItemIndex(item->id(), &from_index)) { 95 if (!FindItemIndex(item->id(), &from_index)) {
97 LOG(ERROR) << "SetItemPosition: Not in list: " << item->id().substr(0, 8); 96 LOG(ERROR) << "SetItemPosition: Not in list: " << item->id().substr(0, 8);
98 return; 97 return;
99 } 98 }
(...skipping 13 matching lines...) Expand all
113 return; 112 return;
114 } 113 }
115 // Remove the item and get the updated to index. 114 // Remove the item and get the updated to index.
116 app_list_items_.weak_erase(app_list_items_.begin() + from_index); 115 app_list_items_.weak_erase(app_list_items_.begin() + from_index);
117 to_index = GetItemSortOrderIndex(new_position, item->id()); 116 to_index = GetItemSortOrderIndex(new_position, item->id());
118 DVLOG(2) << "SetItemPosition: " << item->id().substr(0, 8) << " -> " 117 DVLOG(2) << "SetItemPosition: " << item->id().substr(0, 8) << " -> "
119 << new_position.ToDebugString() << " From: " << from_index 118 << new_position.ToDebugString() << " From: " << from_index
120 << " To: " << to_index; 119 << " To: " << to_index;
121 item->set_position(new_position); 120 item->set_position(new_position);
122 app_list_items_.insert(app_list_items_.begin() + to_index, item); 121 app_list_items_.insert(app_list_items_.begin() + to_index, item);
123 FOR_EACH_OBSERVER(AppListItemListObserver, 122 for (auto& observer : observers_)
124 observers_, 123 observer.OnListItemMoved(from_index, to_index, item);
125 OnListItemMoved(from_index, to_index, item));
126 } 124 }
127 125
128 void AppListItemList::HighlightItemInstalledFromUI(const std::string& id) { 126 void AppListItemList::HighlightItemInstalledFromUI(const std::string& id) {
129 // Items within folders are not highlighted (apps are never installed to a 127 // Items within folders are not highlighted (apps are never installed to a
130 // folder initially). So just search the top-level list. 128 // folder initially). So just search the top-level list.
131 size_t index; 129 size_t index;
132 if (FindItemIndex(highlighted_id_, &index)) { 130 if (FindItemIndex(highlighted_id_, &index)) {
133 item_at(index)->set_highlighted(false); 131 item_at(index)->set_highlighted(false);
134 FOR_EACH_OBSERVER(AppListItemListObserver, 132 for (auto& observer : observers_)
135 observers_, 133 observer.OnAppListItemHighlight(index, false);
136 OnAppListItemHighlight(index, false));
137 } 134 }
138 highlighted_id_ = id; 135 highlighted_id_ = id;
139 if (!FindItemIndex(highlighted_id_, &index)) { 136 if (!FindItemIndex(highlighted_id_, &index)) {
140 // If the item isin't in the app list yet, it will be highlighted later, in 137 // If the item isin't in the app list yet, it will be highlighted later, in
141 // AddItem(). 138 // AddItem().
142 return; 139 return;
143 } 140 }
144 141
145 item_at(index)->set_highlighted(true); 142 item_at(index)->set_highlighted(true);
146 FOR_EACH_OBSERVER( 143 for (auto& observer : observers_)
147 AppListItemListObserver, observers_, OnAppListItemHighlight(index, true)); 144 observer.OnAppListItemHighlight(index, true);
148 } 145 }
149 146
150 // AppListItemList private 147 // AppListItemList private
151 148
152 syncer::StringOrdinal AppListItemList::CreatePositionBefore( 149 syncer::StringOrdinal AppListItemList::CreatePositionBefore(
153 const syncer::StringOrdinal& position) { 150 const syncer::StringOrdinal& position) {
154 if (app_list_items_.empty()) 151 if (app_list_items_.empty())
155 return syncer::StringOrdinal::CreateInitialOrdinal(); 152 return syncer::StringOrdinal::CreateInitialOrdinal();
156 153
157 size_t nitems = app_list_items_.size(); 154 size_t nitems = app_list_items_.size();
(...skipping 14 matching lines...) Expand all
172 app_list_items_[index]->position()); 169 app_list_items_[index]->position());
173 } 170 }
174 171
175 AppListItem* AppListItemList::AddItem(std::unique_ptr<AppListItem> item_ptr) { 172 AppListItem* AppListItemList::AddItem(std::unique_ptr<AppListItem> item_ptr) {
176 AppListItem* item = item_ptr.get(); 173 AppListItem* item = item_ptr.get();
177 CHECK(std::find(app_list_items_.begin(), app_list_items_.end(), item) 174 CHECK(std::find(app_list_items_.begin(), app_list_items_.end(), item)
178 == app_list_items_.end()); 175 == app_list_items_.end());
179 EnsureValidItemPosition(item); 176 EnsureValidItemPosition(item);
180 size_t index = GetItemSortOrderIndex(item->position(), item->id()); 177 size_t index = GetItemSortOrderIndex(item->position(), item->id());
181 app_list_items_.insert(app_list_items_.begin() + index, item_ptr.release()); 178 app_list_items_.insert(app_list_items_.begin() + index, item_ptr.release());
182 FOR_EACH_OBSERVER(AppListItemListObserver, 179 for (auto& observer : observers_)
183 observers_, 180 observer.OnListItemAdded(index, item);
184 OnListItemAdded(index, item));
185 181
186 if (item->id() == highlighted_id_) { 182 if (item->id() == highlighted_id_) {
187 // Item not present when highlight requested, so highlight it now. 183 // Item not present when highlight requested, so highlight it now.
188 item->set_highlighted(true); 184 item->set_highlighted(true);
189 FOR_EACH_OBSERVER(AppListItemListObserver, 185 for (auto& observer : observers_)
190 observers_, 186 observer.OnAppListItemHighlight(index, true);
191 OnAppListItemHighlight(index, true));
192 } 187 }
193 return item; 188 return item;
194 } 189 }
195 190
196 void AppListItemList::DeleteItem(const std::string& id) { 191 void AppListItemList::DeleteItem(const std::string& id) {
197 std::unique_ptr<AppListItem> item = RemoveItem(id); 192 std::unique_ptr<AppListItem> item = RemoveItem(id);
198 // |item| will be deleted on destruction. 193 // |item| will be deleted on destruction.
199 } 194 }
200 195
201 std::unique_ptr<AppListItem> AppListItemList::RemoveItem( 196 std::unique_ptr<AppListItem> AppListItemList::RemoveItem(
202 const std::string& id) { 197 const std::string& id) {
203 size_t index; 198 size_t index;
204 if (!FindItemIndex(id, &index)) 199 if (!FindItemIndex(id, &index))
205 LOG(FATAL) << "RemoveItem: Not found: " << id; 200 LOG(FATAL) << "RemoveItem: Not found: " << id;
206 return RemoveItemAt(index); 201 return RemoveItemAt(index);
207 } 202 }
208 203
209 std::unique_ptr<AppListItem> AppListItemList::RemoveItemAt(size_t index) { 204 std::unique_ptr<AppListItem> AppListItemList::RemoveItemAt(size_t index) {
210 CHECK_LT(index, item_count()); 205 CHECK_LT(index, item_count());
211 AppListItem* item = app_list_items_[index]; 206 AppListItem* item = app_list_items_[index];
212 app_list_items_.weak_erase(app_list_items_.begin() + index); 207 app_list_items_.weak_erase(app_list_items_.begin() + index);
213 FOR_EACH_OBSERVER(AppListItemListObserver, 208 for (auto& observer : observers_)
214 observers_, 209 observer.OnListItemRemoved(index, item);
215 OnListItemRemoved(index, item));
216 return base::WrapUnique<AppListItem>(item); 210 return base::WrapUnique<AppListItem>(item);
217 } 211 }
218 212
219 void AppListItemList::DeleteItemAt(size_t index) { 213 void AppListItemList::DeleteItemAt(size_t index) {
220 std::unique_ptr<AppListItem> item = RemoveItemAt(index); 214 std::unique_ptr<AppListItem> item = RemoveItemAt(index);
221 // |item| will be deleted on destruction. 215 // |item| will be deleted on destruction.
222 } 216 }
223 217
224 void AppListItemList::EnsureValidItemPosition(AppListItem* item) { 218 void AppListItemList::EnsureValidItemPosition(AppListItem* item) {
225 syncer::StringOrdinal position = item->position(); 219 syncer::StringOrdinal position = item->position();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 257 }
264 AppListItem* last = last_index < nitems ? app_list_items_[last_index] : NULL; 258 AppListItem* last = last_index < nitems ? app_list_items_[last_index] : NULL;
265 for (size_t i = index; i < last_index; ++i) { 259 for (size_t i = index; i < last_index; ++i) {
266 AppListItem* cur = app_list_items_[i]; 260 AppListItem* cur = app_list_items_[i];
267 if (last) 261 if (last)
268 cur->set_position(prev->position().CreateBetween(last->position())); 262 cur->set_position(prev->position().CreateBetween(last->position()));
269 else 263 else
270 cur->set_position(prev->position().CreateAfter()); 264 cur->set_position(prev->position().CreateAfter());
271 prev = cur; 265 prev = cur;
272 } 266 }
273 FOR_EACH_OBSERVER(AppListItemListObserver, 267 for (auto& observer : observers_)
274 observers_, 268 observer.OnListItemMoved(index, index, app_list_items_[index]);
275 OnListItemMoved(index, index, app_list_items_[index]));
276 } 269 }
277 270
278 } // namespace app_list 271 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/app_list_item.cc ('k') | ui/app_list/app_list_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698