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