| 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/common/shelf/shelf_model.h" | 5 #include "ash/common/shelf/shelf_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/common/shelf/shelf_item_delegate.h" | |
| 10 #include "ash/common/shelf/shelf_model_observer.h" | 9 #include "ash/common/shelf/shelf_model_observer.h" |
| 11 | 10 |
| 12 namespace ash { | 11 namespace ash { |
| 13 | 12 |
| 14 namespace { | 13 namespace { |
| 15 | 14 |
| 16 int ShelfItemTypeToWeight(ShelfItemType type) { | 15 int ShelfItemTypeToWeight(ShelfItemType type) { |
| 17 switch (type) { | 16 switch (type) { |
| 18 case TYPE_APP_LIST: | 17 case TYPE_APP_LIST: |
| 19 // TODO(skuhne): If the app list item becomes movable again, this need | 18 // TODO(skuhne): If the app list item becomes movable again, this need |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 int ShelfModel::FirstPanelIndex() const { | 151 int ShelfModel::FirstPanelIndex() const { |
| 153 ShelfItem weight_dummy; | 152 ShelfItem weight_dummy; |
| 154 weight_dummy.type = TYPE_APP_PANEL; | 153 weight_dummy.type = TYPE_APP_PANEL; |
| 155 return std::lower_bound(items_.begin(), items_.end(), weight_dummy, | 154 return std::lower_bound(items_.begin(), items_.end(), weight_dummy, |
| 156 CompareByWeight) - | 155 CompareByWeight) - |
| 157 items_.begin(); | 156 items_.begin(); |
| 158 } | 157 } |
| 159 | 158 |
| 160 void ShelfModel::SetShelfItemDelegate( | 159 void ShelfModel::SetShelfItemDelegate( |
| 161 ShelfID id, | 160 ShelfID id, |
| 162 std::unique_ptr<ShelfItemDelegate> item_delegate) { | 161 std::unique_ptr<mojom::ShelfItemDelegate> item_delegate) { |
| 163 // If another ShelfItemDelegate is already registered for |id|, we assume | 162 // If another ShelfItemDelegate is already registered for |id|, we assume |
| 164 // that this request is replacing ShelfItemDelegate for |id| with | 163 // that this request is replacing ShelfItemDelegate for |id| with |
| 165 // |item_delegate|. | 164 // |item_delegate|. |
| 166 RemoveShelfItemDelegate(id); | 165 RemoveShelfItemDelegate(id); |
| 167 | 166 |
| 168 for (auto& observer : observers_) | 167 for (auto& observer : observers_) |
| 169 observer.OnSetShelfItemDelegate(id, item_delegate.get()); | 168 observer.OnSetShelfItemDelegate(id, item_delegate.get()); |
| 170 | 169 |
| 171 id_to_item_delegate_map_[id] = std::move(item_delegate); | 170 id_to_item_delegate_map_[id] = std::move(item_delegate); |
| 172 } | 171 } |
| 173 | 172 |
| 174 ShelfItemDelegate* ShelfModel::GetShelfItemDelegate(ShelfID id) { | 173 mojom::ShelfItemDelegate* ShelfModel::GetShelfItemDelegate(ShelfID id) { |
| 175 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end()) | 174 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end()) |
| 176 return id_to_item_delegate_map_[id].get(); | 175 return id_to_item_delegate_map_[id].get(); |
| 177 return nullptr; | 176 return nullptr; |
| 178 } | 177 } |
| 179 | 178 |
| 180 void ShelfModel::AddObserver(ShelfModelObserver* observer) { | 179 void ShelfModel::AddObserver(ShelfModelObserver* observer) { |
| 181 observers_.AddObserver(observer); | 180 observers_.AddObserver(observer); |
| 182 } | 181 } |
| 183 | 182 |
| 184 void ShelfModel::RemoveObserver(ShelfModelObserver* observer) { | 183 void ShelfModel::RemoveObserver(ShelfModelObserver* observer) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 202 | 201 |
| 203 return index; | 202 return index; |
| 204 } | 203 } |
| 205 | 204 |
| 206 void ShelfModel::RemoveShelfItemDelegate(ShelfID id) { | 205 void ShelfModel::RemoveShelfItemDelegate(ShelfID id) { |
| 207 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end()) | 206 if (id_to_item_delegate_map_.find(id) != id_to_item_delegate_map_.end()) |
| 208 id_to_item_delegate_map_.erase(id); | 207 id_to_item_delegate_map_.erase(id); |
| 209 } | 208 } |
| 210 | 209 |
| 211 } // namespace ash | 210 } // namespace ash |
| OLD | NEW |