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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 CompareByWeight) - items_.begin(); | 143 CompareByWeight) - items_.begin(); |
144 } | 144 } |
145 | 145 |
146 int ShelfModel::FirstPanelIndex() const { | 146 int ShelfModel::FirstPanelIndex() const { |
147 ShelfItem weight_dummy; | 147 ShelfItem weight_dummy; |
148 weight_dummy.type = TYPE_APP_PANEL; | 148 weight_dummy.type = TYPE_APP_PANEL; |
149 return std::lower_bound(items_.begin(), items_.end(), weight_dummy, | 149 return std::lower_bound(items_.begin(), items_.end(), weight_dummy, |
150 CompareByWeight) - items_.begin(); | 150 CompareByWeight) - items_.begin(); |
151 } | 151 } |
152 | 152 |
153 void ShelfModel::SetStatus(Status status) { | |
154 if (status_ == status) | |
155 return; | |
156 | |
157 status_ = status; | |
158 FOR_EACH_OBSERVER(ShelfModelObserver, observers_, ShelfStatusChanged()); | |
159 } | |
160 | |
161 void ShelfModel::AddObserver(ShelfModelObserver* observer) { | 153 void ShelfModel::AddObserver(ShelfModelObserver* observer) { |
162 observers_.AddObserver(observer); | 154 observers_.AddObserver(observer); |
163 } | 155 } |
164 | 156 |
165 void ShelfModel::RemoveObserver(ShelfModelObserver* observer) { | 157 void ShelfModel::RemoveObserver(ShelfModelObserver* observer) { |
166 observers_.RemoveObserver(observer); | 158 observers_.RemoveObserver(observer); |
167 } | 159 } |
168 | 160 |
169 int ShelfModel::ValidateInsertionIndex(ShelfItemType type, int index) const { | 161 int ShelfModel::ValidateInsertionIndex(ShelfItemType type, int index) const { |
170 DCHECK(index >= 0 && index <= item_count() + 1); | 162 DCHECK(index >= 0 && index <= item_count() + 1); |
171 | 163 |
172 // Clamp |index| to the allowed range for the type as determined by |weight|. | 164 // Clamp |index| to the allowed range for the type as determined by |weight|. |
173 ShelfItem weight_dummy; | 165 ShelfItem weight_dummy; |
174 weight_dummy.type = type; | 166 weight_dummy.type = type; |
175 index = std::max(std::lower_bound(items_.begin(), items_.end(), weight_dummy, | 167 index = std::max(std::lower_bound(items_.begin(), items_.end(), weight_dummy, |
176 CompareByWeight) - items_.begin(), | 168 CompareByWeight) - items_.begin(), |
177 static_cast<ShelfItems::difference_type>(index)); | 169 static_cast<ShelfItems::difference_type>(index)); |
178 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy, | 170 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy, |
179 CompareByWeight) - items_.begin(), | 171 CompareByWeight) - items_.begin(), |
180 static_cast<ShelfItems::difference_type>(index)); | 172 static_cast<ShelfItems::difference_type>(index)); |
181 | 173 |
182 return index; | 174 return index; |
183 } | 175 } |
184 | 176 |
185 } // namespace ash | 177 } // namespace ash |
OLD | NEW |