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 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 items_.insert(items_.begin() + target_index, item); | 86 items_.insert(items_.begin() + target_index, item); |
87 FOR_EACH_OBSERVER(LauncherModelObserver, observers_, | 87 FOR_EACH_OBSERVER(LauncherModelObserver, observers_, |
88 LauncherItemMoved(index, target_index)); | 88 LauncherItemMoved(index, target_index)); |
89 } | 89 } |
90 | 90 |
91 void LauncherModel::Set(int index, const LauncherItem& item) { | 91 void LauncherModel::Set(int index, const LauncherItem& item) { |
92 DCHECK(index >= 0 && index < item_count()); | 92 DCHECK(index >= 0 && index < item_count()); |
93 LauncherItem old_item(items_[index]); | 93 LauncherItem old_item(items_[index]); |
94 items_[index] = item; | 94 items_[index] = item; |
95 items_[index].id = old_item.id; | 95 items_[index].id = old_item.id; |
96 items_[index].type = old_item.type; | |
97 FOR_EACH_OBSERVER(LauncherModelObserver, observers_, | 96 FOR_EACH_OBSERVER(LauncherModelObserver, observers_, |
98 LauncherItemChanged(index, old_item)); | 97 LauncherItemChanged(index, old_item)); |
98 | |
99 // If the type changes confirm that the item is still in the right order. | |
100 if (items_[index].type != old_item.type) { | |
101 int new_index = ValidateInsertionIndex(items_[index].type, index); | |
sky
2012/06/13 21:20:53
By updating the item then validating you've broken
DaveMoore
2012/06/13 22:30:16
Done.
| |
102 if (new_index != index) | |
103 Move(index, new_index); | |
104 } | |
99 } | 105 } |
100 | 106 |
101 int LauncherModel::ItemIndexByID(LauncherID id) { | 107 int LauncherModel::ItemIndexByID(LauncherID id) { |
102 LauncherItems::const_iterator i = ItemByID(id); | 108 LauncherItems::const_iterator i = ItemByID(id); |
103 return i == items_.end() ? -1 : static_cast<int>(i - items_.begin()); | 109 return i == items_.end() ? -1 : static_cast<int>(i - items_.begin()); |
104 } | 110 } |
105 | 111 |
106 LauncherItems::const_iterator LauncherModel::ItemByID(int id) const { | 112 LauncherItems::const_iterator LauncherModel::ItemByID(int id) const { |
107 for (LauncherItems::const_iterator i = items_.begin(); | 113 for (LauncherItems::const_iterator i = items_.begin(); |
108 i != items_.end(); ++i) { | 114 i != items_.end(); ++i) { |
(...skipping 22 matching lines...) Expand all Loading... | |
131 CompareByWeight) - items_.begin(), | 137 CompareByWeight) - items_.begin(), |
132 static_cast<LauncherItems::difference_type>(index)); | 138 static_cast<LauncherItems::difference_type>(index)); |
133 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy, | 139 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy, |
134 CompareByWeight) - items_.begin(), | 140 CompareByWeight) - items_.begin(), |
135 static_cast<LauncherItems::difference_type>(index)); | 141 static_cast<LauncherItems::difference_type>(index)); |
136 | 142 |
137 return index; | 143 return index; |
138 } | 144 } |
139 | 145 |
140 } // namespace ash | 146 } // namespace ash |
OLD | NEW |