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 | 11 |
11 namespace ash { | 12 namespace ash { |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 int LauncherItemTypeToWeight(LauncherItemType type) { | 16 int LauncherItemTypeToWeight(LauncherItemType type) { |
16 switch (type) { | 17 switch (type) { |
17 case TYPE_BROWSER_SHORTCUT: | 18 case TYPE_BROWSER_SHORTCUT: |
18 return 0; | 19 return 0; |
19 case TYPE_APP_SHORTCUT: | 20 case TYPE_APP_SHORTCUT: |
20 return 1; | 21 return 1; |
21 case TYPE_TABBED: | 22 case TYPE_TABBED: |
22 case TYPE_APP_PANEL: | 23 case TYPE_APP_PANEL: |
23 case TYPE_PLATFORM_APP: | 24 case TYPE_PLATFORM_APP: |
24 return 2; | 25 return 2; |
25 case TYPE_APP_LIST: | 26 case TYPE_APP_LIST: |
26 return 3; | 27 return 3; |
27 } | 28 } |
28 | 29 |
29 NOTREACHED() << "Invalid type " << type; | 30 NOTREACHED() << "Invalid type " << type; |
30 return 2; | 31 return 2; |
31 } | 32 } |
32 | 33 |
33 bool CompareByWeight(const LauncherItem& a, const LauncherItem& b) { | 34 bool CompareByWeight(const LauncherItem& a, const LauncherItem& b) { |
34 return LauncherItemTypeToWeight(a.type) < LauncherItemTypeToWeight(b.type); | 35 return LauncherItemTypeToWeight(a.type) < LauncherItemTypeToWeight(b.type); |
35 } | 36 } |
36 | 37 |
37 } // namespace | 38 } // namespace |
38 | 39 |
39 LauncherModel::LauncherModel() : next_id_(1), status_(STATUS_NORMAL) { | 40 LauncherModel::LauncherModel() : next_id_(1) { |
40 LauncherItem app_list; | 41 LauncherItem app_list; |
41 app_list.type = TYPE_APP_LIST; | 42 app_list.type = TYPE_APP_LIST; |
42 app_list.is_incognito = false; | 43 app_list.is_incognito = false; |
43 | 44 |
44 LauncherItem browser_shortcut; | 45 LauncherItem browser_shortcut; |
45 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; | 46 browser_shortcut.type = TYPE_BROWSER_SHORTCUT; |
46 browser_shortcut.is_incognito = false; | 47 browser_shortcut.is_incognito = false; |
47 | 48 |
48 AddAt(0, browser_shortcut); | 49 AddAt(0, browser_shortcut); |
49 AddAt(1, app_list); | 50 AddAt(1, app_list); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 111 |
111 LauncherItems::const_iterator LauncherModel::ItemByID(int id) const { | 112 LauncherItems::const_iterator LauncherModel::ItemByID(int id) const { |
112 for (LauncherItems::const_iterator i = items_.begin(); | 113 for (LauncherItems::const_iterator i = items_.begin(); |
113 i != items_.end(); ++i) { | 114 i != items_.end(); ++i) { |
114 if (i->id == id) | 115 if (i->id == id) |
115 return i; | 116 return i; |
116 } | 117 } |
117 return items_.end(); | 118 return items_.end(); |
118 } | 119 } |
119 | 120 |
120 void LauncherModel::SetStatus(Status status) { | |
121 if (status_ == status) | |
122 return; | |
123 | |
124 status_ = status; | |
125 FOR_EACH_OBSERVER(LauncherModelObserver, observers_, | |
126 LauncherStatusChanged()); | |
127 } | |
128 | |
129 void LauncherModel::AddObserver(LauncherModelObserver* observer) { | 121 void LauncherModel::AddObserver(LauncherModelObserver* observer) { |
130 observers_.AddObserver(observer); | 122 observers_.AddObserver(observer); |
131 } | 123 } |
132 | 124 |
133 void LauncherModel::RemoveObserver(LauncherModelObserver* observer) { | 125 void LauncherModel::RemoveObserver(LauncherModelObserver* observer) { |
134 observers_.RemoveObserver(observer); | 126 observers_.RemoveObserver(observer); |
135 } | 127 } |
136 | 128 |
137 int LauncherModel::ValidateInsertionIndex(LauncherItemType type, | 129 int LauncherModel::ValidateInsertionIndex(LauncherItemType type, |
138 int index) const { | 130 int index) const { |
139 DCHECK(index >= 0 && index <= item_count()); | 131 DCHECK(index >= 0 && index <= item_count()); |
140 | 132 |
141 // Clamp |index| to the allowed range for the type as determined by |weight|. | 133 // Clamp |index| to the allowed range for the type as determined by |weight|. |
142 LauncherItem weight_dummy; | 134 LauncherItem weight_dummy; |
143 weight_dummy.type = type; | 135 weight_dummy.type = type; |
144 index = std::max(std::lower_bound(items_.begin(), items_.end(), weight_dummy, | 136 index = std::max(std::lower_bound(items_.begin(), items_.end(), weight_dummy, |
145 CompareByWeight) - items_.begin(), | 137 CompareByWeight) - items_.begin(), |
146 static_cast<LauncherItems::difference_type>(index)); | 138 static_cast<LauncherItems::difference_type>(index)); |
147 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, |
148 CompareByWeight) - items_.begin(), | 140 CompareByWeight) - items_.begin(), |
149 static_cast<LauncherItems::difference_type>(index)); | 141 static_cast<LauncherItems::difference_type>(index)); |
150 | 142 |
151 return index; | 143 return index; |
152 } | 144 } |
153 | 145 |
154 } // namespace ash | 146 } // namespace ash |
OLD | NEW |