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

Side by Side Diff: ash/common/shelf/shelf_model.cc

Issue 2791803002: mash: Move LauncherItemController to ash, rename ShelfItemDelegate. (Closed)
Patch Set: Sync and rebase. Created 3 years, 8 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 | « ash/common/shelf/shelf_model.h ('k') | ash/common/shelf/shelf_model_observer.h » ('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 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_model_observer.h" 9 #include "ash/common/shelf/shelf_model_observer.h"
10 #include "ash/public/cpp/shelf_item_delegate.h"
10 11
11 namespace ash { 12 namespace ash {
12 13
13 namespace { 14 namespace {
14 15
15 int ShelfItemTypeToWeight(ShelfItemType type) { 16 int ShelfItemTypeToWeight(ShelfItemType type) {
16 switch (type) { 17 switch (type) {
17 case TYPE_APP_LIST: 18 case TYPE_APP_LIST:
18 // TODO(skuhne): If the app list item becomes movable again, this need 19 // TODO(skuhne): If the app list item becomes movable again, this need
19 // to be a fallthrough. 20 // to be a fallthrough.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 int ShelfModel::FirstPanelIndex() const { 152 int ShelfModel::FirstPanelIndex() const {
152 ShelfItem weight_dummy; 153 ShelfItem weight_dummy;
153 weight_dummy.type = TYPE_APP_PANEL; 154 weight_dummy.type = TYPE_APP_PANEL;
154 return std::lower_bound(items_.begin(), items_.end(), weight_dummy, 155 return std::lower_bound(items_.begin(), items_.end(), weight_dummy,
155 CompareByWeight) - 156 CompareByWeight) -
156 items_.begin(); 157 items_.begin();
157 } 158 }
158 159
159 void ShelfModel::SetShelfItemDelegate( 160 void ShelfModel::SetShelfItemDelegate(
160 ShelfID id, 161 ShelfID id,
161 std::unique_ptr<mojom::ShelfItemDelegate> item_delegate) { 162 std::unique_ptr<ShelfItemDelegate> item_delegate) {
162 // If another ShelfItemDelegate is already registered for |id|, we assume 163 // If another ShelfItemDelegate is already registered for |id|, we assume
163 // that this request is replacing ShelfItemDelegate for |id| with 164 // that this request is replacing ShelfItemDelegate for |id| with
164 // |item_delegate|. 165 // |item_delegate|.
165 RemoveShelfItemDelegate(id); 166 RemoveShelfItemDelegate(id);
166 167
167 for (auto& observer : observers_) 168 for (auto& observer : observers_)
168 observer.OnSetShelfItemDelegate(id, item_delegate.get()); 169 observer.OnSetShelfItemDelegate(id, item_delegate.get());
169 170
170 id_to_item_delegate_map_[id] = std::move(item_delegate); 171 id_to_item_delegate_map_[id] = std::move(item_delegate);
171 } 172 }
172 173
173 mojom::ShelfItemDelegate* ShelfModel::GetShelfItemDelegate(ShelfID id) { 174 ShelfItemDelegate* ShelfModel::GetShelfItemDelegate(ShelfID id) {
174 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end()) 175 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end())
175 return id_to_item_delegate_map_[id].get(); 176 return id_to_item_delegate_map_[id].get();
176 return nullptr; 177 return nullptr;
177 } 178 }
178 179
179 void ShelfModel::AddObserver(ShelfModelObserver* observer) { 180 void ShelfModel::AddObserver(ShelfModelObserver* observer) {
180 observers_.AddObserver(observer); 181 observers_.AddObserver(observer);
181 } 182 }
182 183
183 void ShelfModel::RemoveObserver(ShelfModelObserver* observer) { 184 void ShelfModel::RemoveObserver(ShelfModelObserver* observer) {
(...skipping 17 matching lines...) Expand all
201 202
202 return index; 203 return index;
203 } 204 }
204 205
205 void ShelfModel::RemoveShelfItemDelegate(ShelfID id) { 206 void ShelfModel::RemoveShelfItemDelegate(ShelfID id) {
206 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end()) 207 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end())
207 id_to_item_delegate_map_.erase(id); 208 id_to_item_delegate_map_.erase(id);
208 } 209 }
209 210
210 } // namespace ash 211 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_model.h ('k') | ash/common/shelf/shelf_model_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698