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

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

Issue 198063003: Revert of Shelf Cleanup (- binary files) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « ash/shelf/shelf_layout_manager.cc ('k') | ash/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/shelf/shelf_model.h" 5 #include "ash/shelf/shelf_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/shelf/shelf_model_observer.h" 10 #include "ash/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 if (ash::switches::UseAlternateShelfLayout()) {
18 case TYPE_APP_LIST: 18 switch (type) {
19 // TODO(skuhne): If the app list item becomes movable again, this need 19 case TYPE_APP_LIST:
20 // to be a fallthrough. 20 // TODO(skuhne): If the app list item becomes movable again, this need
21 return 0; 21 // to be a fallthrough.
22 case TYPE_BROWSER_SHORTCUT: 22 return 0;
23 case TYPE_APP_SHORTCUT: 23 case TYPE_BROWSER_SHORTCUT:
24 return 1; 24 case TYPE_APP_SHORTCUT:
25 case TYPE_WINDOWED_APP: 25 return 1;
26 case TYPE_PLATFORM_APP: 26 case TYPE_WINDOWED_APP:
27 return 2; 27 case TYPE_PLATFORM_APP:
28 case TYPE_DIALOG: 28 return 2;
29 return 3; 29 case TYPE_DIALOG:
30 case TYPE_APP_PANEL: 30 return 3;
31 return 4; 31 case TYPE_APP_PANEL:
32 case TYPE_UNDEFINED: 32 return 4;
33 NOTREACHED() << "ShelfItemType must be set"; 33 case TYPE_UNDEFINED:
34 return -1; 34 NOTREACHED() << "ShelfItemType must be set";
35 return -1;
36 }
37 } else {
38 switch (type) {
39 case TYPE_BROWSER_SHORTCUT:
40 case TYPE_APP_SHORTCUT:
41 return 0;
42 case TYPE_WINDOWED_APP:
43 case TYPE_PLATFORM_APP:
44 return 1;
45 case TYPE_APP_LIST:
46 return 2;
47 case TYPE_DIALOG:
48 return 3;
49 case TYPE_APP_PANEL:
50 return 4;
51 case TYPE_UNDEFINED:
52 NOTREACHED() << "ShelfItemType must be set";
53 return -1;
54 }
35 } 55 }
36 56
37 NOTREACHED() << "Invalid type " << type; 57 NOTREACHED() << "Invalid type " << type;
38 return 1; 58 return 1;
39 } 59 }
40 60
41 bool CompareByWeight(const ShelfItem& a, const ShelfItem& b) { 61 bool CompareByWeight(const ShelfItem& a, const ShelfItem& b) {
42 return ShelfItemTypeToWeight(a.type) < ShelfItemTypeToWeight(b.type); 62 return ShelfItemTypeToWeight(a.type) < ShelfItemTypeToWeight(b.type);
43 } 63 }
44 64
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 180
161 void ShelfModel::AddObserver(ShelfModelObserver* observer) { 181 void ShelfModel::AddObserver(ShelfModelObserver* observer) {
162 observers_.AddObserver(observer); 182 observers_.AddObserver(observer);
163 } 183 }
164 184
165 void ShelfModel::RemoveObserver(ShelfModelObserver* observer) { 185 void ShelfModel::RemoveObserver(ShelfModelObserver* observer) {
166 observers_.RemoveObserver(observer); 186 observers_.RemoveObserver(observer);
167 } 187 }
168 188
169 int ShelfModel::ValidateInsertionIndex(ShelfItemType type, int index) const { 189 int ShelfModel::ValidateInsertionIndex(ShelfItemType type, int index) const {
170 DCHECK(index >= 0 && index <= item_count() + 1); 190 DCHECK(index >= 0 && index <= item_count() +
191 (ash::switches::UseAlternateShelfLayout() ? 1 : 0));
171 192
172 // Clamp |index| to the allowed range for the type as determined by |weight|. 193 // Clamp |index| to the allowed range for the type as determined by |weight|.
173 ShelfItem weight_dummy; 194 ShelfItem weight_dummy;
174 weight_dummy.type = type; 195 weight_dummy.type = type;
175 index = std::max(std::lower_bound(items_.begin(), items_.end(), weight_dummy, 196 index = std::max(std::lower_bound(items_.begin(), items_.end(), weight_dummy,
176 CompareByWeight) - items_.begin(), 197 CompareByWeight) - items_.begin(),
177 static_cast<ShelfItems::difference_type>(index)); 198 static_cast<ShelfItems::difference_type>(index));
178 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy, 199 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy,
179 CompareByWeight) - items_.begin(), 200 CompareByWeight) - items_.begin(),
180 static_cast<ShelfItems::difference_type>(index)); 201 static_cast<ShelfItems::difference_type>(index));
181 202
182 return index; 203 return index;
183 } 204 }
184 205
185 } // namespace ash 206 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_layout_manager.cc ('k') | ash/shelf/shelf_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698