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

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

Issue 17673004: Insert panel icons on the left of other panel icons. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix test assertions. Created 7 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
« no previous file with comments | « ash/launcher/launcher_model.h ('k') | ash/launcher/launcher_model_unittest.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 10
(...skipping 19 matching lines...) Expand all
30 NOTREACHED() << "Invalid type " << type; 30 NOTREACHED() << "Invalid type " << type;
31 return 1; 31 return 1;
32 } 32 }
33 33
34 bool CompareByWeight(const LauncherItem& a, const LauncherItem& b) { 34 bool CompareByWeight(const LauncherItem& a, const LauncherItem& b) {
35 return LauncherItemTypeToWeight(a.type) < LauncherItemTypeToWeight(b.type); 35 return LauncherItemTypeToWeight(a.type) < LauncherItemTypeToWeight(b.type);
36 } 36 }
37 37
38 } // namespace 38 } // namespace
39 39
40 const int LauncherModel::kAutomaticIndex = -1;
41
40 LauncherModel::LauncherModel() : next_id_(1), status_(STATUS_NORMAL) { 42 LauncherModel::LauncherModel() : next_id_(1), status_(STATUS_NORMAL) {
41 LauncherItem app_list; 43 LauncherItem app_list;
42 app_list.type = TYPE_APP_LIST; 44 app_list.type = TYPE_APP_LIST;
43 app_list.is_incognito = false; 45 app_list.is_incognito = false;
44 AddAt(0, app_list); 46 AddAt(0, app_list);
45 } 47 }
46 48
47 LauncherModel::~LauncherModel() { 49 LauncherModel::~LauncherModel() {
48 } 50 }
49 51
50 int LauncherModel::Add(const LauncherItem& item) { 52 int LauncherModel::Add(const LauncherItem& item) {
51 return AddAt(items_.size(), item); 53 return AddAt(kAutomaticIndex, item);
52 } 54 }
53 55
54 int LauncherModel::AddAt(int index, const LauncherItem& item) { 56 int LauncherModel::AddAt(int index, const LauncherItem& item) {
57 // Panel icons are by default inserted to the left of other panel icons since
58 // they are right aligned.
59 if (index == kAutomaticIndex)
sky 2013/06/25 16:19:45 Can we move this magic to where we create panel it
flackr 2013/06/25 17:40:52 Sure, done.
60 index = item.type == TYPE_APP_PANEL ? 0 : items_.size();
55 index = ValidateInsertionIndex(item.type, index); 61 index = ValidateInsertionIndex(item.type, index);
56 items_.insert(items_.begin() + index, item); 62 items_.insert(items_.begin() + index, item);
57 items_[index].id = next_id_++; 63 items_[index].id = next_id_++;
58 FOR_EACH_OBSERVER(LauncherModelObserver, observers_, 64 FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
59 LauncherItemAdded(index)); 65 LauncherItemAdded(index));
60 return index; 66 return index;
61 } 67 }
62 68
63 void LauncherModel::RemoveItemAt(int index) { 69 void LauncherModel::RemoveItemAt(int index) {
64 DCHECK(index >= 0 && index < item_count()); 70 DCHECK(index >= 0 && index < item_count());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 CompareByWeight) - items_.begin(), 163 CompareByWeight) - items_.begin(),
158 static_cast<LauncherItems::difference_type>(index)); 164 static_cast<LauncherItems::difference_type>(index));
159 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy, 165 index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy,
160 CompareByWeight) - items_.begin(), 166 CompareByWeight) - items_.begin(),
161 static_cast<LauncherItems::difference_type>(index)); 167 static_cast<LauncherItems::difference_type>(index));
162 168
163 return index; 169 return index;
164 } 170 }
165 171
166 } // namespace ash 172 } // namespace ash
OLDNEW
« no previous file with comments | « ash/launcher/launcher_model.h ('k') | ash/launcher/launcher_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698