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

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

Issue 2518423003: Combine shelf platform and windowed app types. (Closed)
Patch Set: Fix kInvalidShelfID typo. Created 4 years 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_item_types.h ('k') | ash/common/shelf/shelf_model_unittest.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 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"
11 11
12 namespace ash { 12 namespace ash {
13 13
14 namespace { 14 namespace {
15 15
16 int ShelfItemTypeToWeight(ShelfItemType type) { 16 int ShelfItemTypeToWeight(ShelfItemType type) {
17 switch (type) { 17 switch (type) {
18 case TYPE_APP_LIST: 18 case TYPE_APP_LIST:
19 // 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
20 // to be a fallthrough. 20 // to be a fallthrough.
21 return 0; 21 return 0;
22 case TYPE_BROWSER_SHORTCUT: 22 case TYPE_BROWSER_SHORTCUT:
23 case TYPE_APP_SHORTCUT: 23 case TYPE_APP_SHORTCUT:
24 return 1; 24 return 1;
25 case TYPE_WINDOWED_APP: 25 case TYPE_APP:
26 case TYPE_PLATFORM_APP:
27 return 2; 26 return 2;
28 case TYPE_DIALOG: 27 case TYPE_DIALOG:
29 return 3; 28 return 3;
30 case TYPE_APP_PANEL: 29 case TYPE_APP_PANEL:
31 return 4; 30 return 4;
32 case TYPE_IME_MENU: 31 case TYPE_IME_MENU:
33 return 5; 32 return 5;
34 case TYPE_UNDEFINED: 33 case TYPE_UNDEFINED:
35 NOTREACHED() << "ShelfItemType must be set"; 34 NOTREACHED() << "ShelfItemType must be set";
36 return -1; 35 return -1;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 133
135 ShelfItems::const_iterator ShelfModel::ItemByID(int id) const { 134 ShelfItems::const_iterator ShelfModel::ItemByID(int id) const {
136 for (ShelfItems::const_iterator i = items_.begin(); i != items_.end(); ++i) { 135 for (ShelfItems::const_iterator i = items_.begin(); i != items_.end(); ++i) {
137 if (i->id == id) 136 if (i->id == id)
138 return i; 137 return i;
139 } 138 }
140 return items_.end(); 139 return items_.end();
141 } 140 }
142 141
143 int ShelfModel::FirstRunningAppIndex() const { 142 int ShelfModel::FirstRunningAppIndex() const {
144 // Since lower_bound only checks weights against each other, we do not need
145 // to explicitly change different running application types.
146 DCHECK_EQ(ShelfItemTypeToWeight(TYPE_WINDOWED_APP),
147 ShelfItemTypeToWeight(TYPE_PLATFORM_APP));
148 ShelfItem weight_dummy; 143 ShelfItem weight_dummy;
149 weight_dummy.type = TYPE_WINDOWED_APP; 144 weight_dummy.type = TYPE_APP;
150 return std::lower_bound(items_.begin(), items_.end(), weight_dummy, 145 return std::lower_bound(items_.begin(), items_.end(), weight_dummy,
151 CompareByWeight) - 146 CompareByWeight) -
152 items_.begin(); 147 items_.begin();
153 } 148 }
154 149
155 int ShelfModel::FirstPanelIndex() const { 150 int ShelfModel::FirstPanelIndex() const {
156 ShelfItem weight_dummy; 151 ShelfItem weight_dummy;
157 weight_dummy.type = TYPE_APP_PANEL; 152 weight_dummy.type = TYPE_APP_PANEL;
158 return std::lower_bound(items_.begin(), items_.end(), weight_dummy, 153 return std::lower_bound(items_.begin(), items_.end(), weight_dummy,
159 CompareByWeight) - 154 CompareByWeight) -
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 200
206 return index; 201 return index;
207 } 202 }
208 203
209 void ShelfModel::RemoveShelfItemDelegate(ShelfID id) { 204 void ShelfModel::RemoveShelfItemDelegate(ShelfID id) {
210 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end()) 205 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end())
211 id_to_item_delegate_map_.erase(id); 206 id_to_item_delegate_map_.erase(id);
212 } 207 }
213 208
214 } // namespace ash 209 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_item_types.h ('k') | ash/common/shelf/shelf_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698