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" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 124 |
125 Move(index, new_index); | 125 Move(index, new_index); |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 int ShelfModel::ItemIndexByID(LauncherID id) const { | 129 int ShelfModel::ItemIndexByID(LauncherID id) const { |
130 LauncherItems::const_iterator i = ItemByID(id); | 130 LauncherItems::const_iterator i = ItemByID(id); |
131 return i == items_.end() ? -1 : static_cast<int>(i - items_.begin()); | 131 return i == items_.end() ? -1 : static_cast<int>(i - items_.begin()); |
132 } | 132 } |
133 | 133 |
| 134 int ShelfModel::GetItemIndexForType(LauncherItemType type) { |
| 135 for (size_t i = 0; i < items_.size(); ++i) { |
| 136 if (items_[i].type == type) |
| 137 return i; |
| 138 } |
| 139 return -1; |
| 140 } |
| 141 |
134 LauncherItems::const_iterator ShelfModel::ItemByID(int id) const { | 142 LauncherItems::const_iterator ShelfModel::ItemByID(int id) const { |
135 for (LauncherItems::const_iterator i = items_.begin(); | 143 for (LauncherItems::const_iterator i = items_.begin(); |
136 i != items_.end(); ++i) { | 144 i != items_.end(); ++i) { |
137 if (i->id == id) | 145 if (i->id == id) |
138 return i; | 146 return i; |
139 } | 147 } |
140 return items_.end(); | 148 return items_.end(); |
141 } | 149 } |
142 | 150 |
143 int ShelfModel::FirstPanelIndex() const { | 151 int ShelfModel::FirstPanelIndex() const { |
(...skipping 30 matching lines...) Expand all Loading... |
174 CompareByWeight) - items_.begin(), | 182 CompareByWeight) - items_.begin(), |
175 static_cast<LauncherItems::difference_type>(index)); | 183 static_cast<LauncherItems::difference_type>(index)); |
176 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy, | 184 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy, |
177 CompareByWeight) - items_.begin(), | 185 CompareByWeight) - items_.begin(), |
178 static_cast<LauncherItems::difference_type>(index)); | 186 static_cast<LauncherItems::difference_type>(index)); |
179 | 187 |
180 return index; | 188 return index; |
181 } | 189 } |
182 | 190 |
183 } // namespace ash | 191 } // namespace ash |
OLD | NEW |