OLD | NEW |
---|---|
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 if (ash::switches::UseAlternateShelfLayout()) { | 17 switch (type) { |
18 switch (type) { | 18 case TYPE_APP_LIST: |
19 case TYPE_APP_LIST: | 19 // TODO(skuhne): If the app list item becomes movable again, this need |
20 // TODO(skuhne): If the app list item becomes movable again, this need | 20 // to be a fallthrough. |
21 // to be a fallthrough. | 21 return 0; |
22 return 0; | 22 case TYPE_BROWSER_SHORTCUT: |
23 case TYPE_BROWSER_SHORTCUT: | 23 case TYPE_APP_SHORTCUT: |
24 case TYPE_APP_SHORTCUT: | 24 return 1; |
25 return 1; | 25 case TYPE_WINDOWED_APP: |
26 case TYPE_WINDOWED_APP: | 26 case TYPE_PLATFORM_APP: |
27 case TYPE_PLATFORM_APP: | 27 return 2; |
28 return 2; | 28 case TYPE_DIALOG: |
29 case TYPE_DIALOG: | 29 return 3; |
30 return 3; | 30 case TYPE_APP_PANEL: |
31 case TYPE_APP_PANEL: | 31 return 4; |
32 return 4; | 32 case TYPE_UNDEFINED: |
33 case TYPE_UNDEFINED: | 33 NOTREACHED() << "LauncherItemType must be set"; |
Mr4D (OOO till 08-26)
2014/01/23 19:25:08
ShelfItemType - not LauncherItemType any more.
Harry McCleave
2014/01/24 22:48:47
Done, grumble grumble rebase...
| |
34 NOTREACHED() << "ShelfItemType must be set"; | 34 return -1; |
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 } | |
55 } | 35 } |
56 | 36 |
57 NOTREACHED() << "Invalid type " << type; | 37 NOTREACHED() << "Invalid type " << type; |
58 return 1; | 38 return 1; |
59 } | 39 } |
60 | 40 |
61 bool CompareByWeight(const LauncherItem& a, const LauncherItem& b) { | 41 bool CompareByWeight(const LauncherItem& a, const LauncherItem& b) { |
62 return ShelfItemTypeToWeight(a.type) < ShelfItemTypeToWeight(b.type); | 42 return ShelfItemTypeToWeight(a.type) < ShelfItemTypeToWeight(b.type); |
63 } | 43 } |
64 | 44 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 | 160 |
181 void ShelfModel::AddObserver(ShelfModelObserver* observer) { | 161 void ShelfModel::AddObserver(ShelfModelObserver* observer) { |
182 observers_.AddObserver(observer); | 162 observers_.AddObserver(observer); |
183 } | 163 } |
184 | 164 |
185 void ShelfModel::RemoveObserver(ShelfModelObserver* observer) { | 165 void ShelfModel::RemoveObserver(ShelfModelObserver* observer) { |
186 observers_.RemoveObserver(observer); | 166 observers_.RemoveObserver(observer); |
187 } | 167 } |
188 | 168 |
189 int ShelfModel::ValidateInsertionIndex(ShelfItemType type, int index) const { | 169 int ShelfModel::ValidateInsertionIndex(ShelfItemType type, int index) const { |
190 DCHECK(index >= 0 && index <= item_count() + | 170 DCHECK(index >= 0 && index <= item_count() + 1); |
191 (ash::switches::UseAlternateShelfLayout() ? 1 : 0)); | |
192 | 171 |
193 // Clamp |index| to the allowed range for the type as determined by |weight|. | 172 // Clamp |index| to the allowed range for the type as determined by |weight|. |
194 LauncherItem weight_dummy; | 173 LauncherItem weight_dummy; |
195 weight_dummy.type = type; | 174 weight_dummy.type = type; |
196 index = std::max(std::lower_bound(items_.begin(), items_.end(), weight_dummy, | 175 index = std::max(std::lower_bound(items_.begin(), items_.end(), weight_dummy, |
197 CompareByWeight) - items_.begin(), | 176 CompareByWeight) - items_.begin(), |
198 static_cast<LauncherItems::difference_type>(index)); | 177 static_cast<LauncherItems::difference_type>(index)); |
199 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy, | 178 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy, |
200 CompareByWeight) - items_.begin(), | 179 CompareByWeight) - items_.begin(), |
201 static_cast<LauncherItems::difference_type>(index)); | 180 static_cast<LauncherItems::difference_type>(index)); |
202 | 181 |
203 return index; | 182 return index; |
204 } | 183 } |
205 | 184 |
206 } // namespace ash | 185 } // namespace ash |
OLD | NEW |