Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: ash/launcher/launcher_model.cc

Issue 10534142: Add support for pinning platform apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed review issue. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ash/launcher/launcher_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // TODO: this needs to enforce valid ranges. 83 // TODO: this needs to enforce valid ranges.
84 LauncherItem item(items_[index]); 84 LauncherItem item(items_[index]);
85 items_.erase(items_.begin() + index); 85 items_.erase(items_.begin() + index);
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 int new_index = item.type == items_[index].type ?
94 index : ValidateInsertionIndex(item.type, index);
95
93 LauncherItem old_item(items_[index]); 96 LauncherItem old_item(items_[index]);
94 items_[index] = item; 97 items_[index] = item;
95 items_[index].id = old_item.id; 98 items_[index].id = old_item.id;
96 items_[index].type = old_item.type;
97 FOR_EACH_OBSERVER(LauncherModelObserver, observers_, 99 FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
98 LauncherItemChanged(index, old_item)); 100 LauncherItemChanged(index, old_item));
101
102 // If the type changes confirm that the item is still in the right order.
103 if (new_index != index)
104 Move(index, new_index);
sky 2012/06/13 23:43:27 nit: spacing is off.
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
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
OLDNEW
« no previous file with comments | « no previous file | ash/launcher/launcher_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698