OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/launcher/launcher_model.h" | 5 #include "ash/launcher/launcher_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/launcher/launcher_model_observer.h" | 9 #include "ash/launcher/launcher_model_observer.h" |
10 | 10 |
11 namespace ash { | 11 namespace ash { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 int LauncherItemTypeToWeight(LauncherItemType type) { | 15 int LauncherItemTypeToWeight(LauncherItemType type) { |
16 switch (type) { | 16 switch (type) { |
17 case TYPE_BROWSER_SHORTCUT: | 17 case TYPE_BROWSER_SHORTCUT: |
18 return 0; | 18 return 0; |
19 case TYPE_APP_SHORTCUT: | 19 case TYPE_APP_SHORTCUT: |
20 return 1; | 20 return 1; |
21 case TYPE_TABBED: | 21 case TYPE_TABBED: |
| 22 case TYPE_APP_PANEL: |
22 case TYPE_PLATFORM_APP: | 23 case TYPE_PLATFORM_APP: |
23 return 2; | 24 return 2; |
24 case TYPE_APP_LIST: | 25 case TYPE_APP_LIST: |
25 return 3; | 26 return 3; |
26 case TYPE_APP_PANEL: | |
27 return 4; | |
28 } | 27 } |
29 | 28 |
30 NOTREACHED() << "Invalid type " << type; | 29 NOTREACHED() << "Invalid type " << type; |
31 return 2; | 30 return 2; |
32 } | 31 } |
33 | 32 |
34 bool CompareByWeight(const LauncherItem& a, const LauncherItem& b) { | 33 bool CompareByWeight(const LauncherItem& a, const LauncherItem& b) { |
35 return LauncherItemTypeToWeight(a.type) < LauncherItemTypeToWeight(b.type); | 34 return LauncherItemTypeToWeight(a.type) < LauncherItemTypeToWeight(b.type); |
36 } | 35 } |
37 | 36 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 110 |
112 LauncherItems::const_iterator LauncherModel::ItemByID(int id) const { | 111 LauncherItems::const_iterator LauncherModel::ItemByID(int id) const { |
113 for (LauncherItems::const_iterator i = items_.begin(); | 112 for (LauncherItems::const_iterator i = items_.begin(); |
114 i != items_.end(); ++i) { | 113 i != items_.end(); ++i) { |
115 if (i->id == id) | 114 if (i->id == id) |
116 return i; | 115 return i; |
117 } | 116 } |
118 return items_.end(); | 117 return items_.end(); |
119 } | 118 } |
120 | 119 |
121 int LauncherModel::FirstPanelIndex() const { | |
122 LauncherItem weight_dummy; | |
123 weight_dummy.type = TYPE_APP_PANEL; | |
124 return std::lower_bound(items_.begin(), items_.end(), weight_dummy, | |
125 CompareByWeight) - items_.begin(); | |
126 } | |
127 | |
128 void LauncherModel::SetStatus(Status status) { | 120 void LauncherModel::SetStatus(Status status) { |
129 if (status_ == status) | 121 if (status_ == status) |
130 return; | 122 return; |
131 | 123 |
132 status_ = status; | 124 status_ = status; |
133 FOR_EACH_OBSERVER(LauncherModelObserver, observers_, | 125 FOR_EACH_OBSERVER(LauncherModelObserver, observers_, |
134 LauncherStatusChanged()); | 126 LauncherStatusChanged()); |
135 } | 127 } |
136 | 128 |
137 void LauncherModel::AddObserver(LauncherModelObserver* observer) { | 129 void LauncherModel::AddObserver(LauncherModelObserver* observer) { |
(...skipping 15 matching lines...) Expand all Loading... |
153 CompareByWeight) - items_.begin(), | 145 CompareByWeight) - items_.begin(), |
154 static_cast<LauncherItems::difference_type>(index)); | 146 static_cast<LauncherItems::difference_type>(index)); |
155 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy, | 147 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy, |
156 CompareByWeight) - items_.begin(), | 148 CompareByWeight) - items_.begin(), |
157 static_cast<LauncherItems::difference_type>(index)); | 149 static_cast<LauncherItems::difference_type>(index)); |
158 | 150 |
159 return index; | 151 return index; |
160 } | 152 } |
161 | 153 |
162 } // namespace ash | 154 } // namespace ash |
OLD | NEW |