OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/views/aura/app_list/app_list_model_builder.h" | 5 #include "chrome/browser/ui/views/aura/app_list/app_list_model_builder.h" |
6 | 6 |
7 #include "ash/app_list/app_list_item_group_model.h" | 7 #include "ash/app_list/app_list_item_group_model.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
14 #include "chrome/browser/ui/views/aura/app_list/browser_command_item.h" | 14 #include "chrome/browser/ui/views/aura/app_list/browser_command_item.h" |
15 #include "chrome/browser/ui/views/aura/app_list/extension_app_item.h" | 15 #include "chrome/browser/ui/views/aura/app_list/extension_app_item.h" |
16 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 16 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Gets or creates group for given |extension| in |model|. The created group | 24 // Gets or creates group for given |extension| in |model|. The created group |
25 // is added to |model| and owned by it. | 25 // is added to |model| and owned by it. |
26 aura_shell::AppListItemGroupModel* GetOrCreateGroup( | 26 ash::AppListItemGroupModel* GetOrCreateGroup( |
27 int page_index, | 27 int page_index, |
28 const ListValue* app_page_names, | 28 const ListValue* app_page_names, |
29 aura_shell::AppListModel* model) { | 29 ash::AppListModel* model) { |
30 if (page_index >= model->group_count()) { | 30 if (page_index >= model->group_count()) { |
31 for (int i = model->group_count(); i <= page_index; ++i) { | 31 for (int i = model->group_count(); i <= page_index; ++i) { |
32 std::string title; | 32 std::string title; |
33 if (!app_page_names->GetString(i, &title)) | 33 if (!app_page_names->GetString(i, &title)) |
34 title = l10n_util::GetStringUTF8(IDS_APP_DEFAULT_PAGE_NAME); | 34 title = l10n_util::GetStringUTF8(IDS_APP_DEFAULT_PAGE_NAME); |
35 | 35 |
36 aura_shell::AppListItemGroupModel* group = | 36 ash::AppListItemGroupModel* group = |
37 new aura_shell::AppListItemGroupModel(title); | 37 new ash::AppListItemGroupModel(title); |
38 model->AddGroup(group); | 38 model->AddGroup(group); |
39 } | 39 } |
40 } | 40 } |
41 | 41 |
42 return model->GetGroup(page_index); | 42 return model->GetGroup(page_index); |
43 } | 43 } |
44 | 44 |
45 // Binary predict to sort extension apps. Smaller launch ordinal takes | 45 // Binary predict to sort extension apps. Smaller launch ordinal takes |
46 // precedence. | 46 // precedence. |
47 bool ExtensionAppPrecedes(const ExtensionAppItem* a, | 47 bool ExtensionAppPrecedes(const ExtensionAppItem* a, |
48 const ExtensionAppItem* b) { | 48 const ExtensionAppItem* b) { |
49 return a->launch_ordinal().LessThan(b->launch_ordinal()); | 49 return a->launch_ordinal().LessThan(b->launch_ordinal()); |
50 } | 50 } |
51 | 51 |
52 } // namespace | 52 } // namespace |
53 | 53 |
54 AppListModelBuilder::AppListModelBuilder(Profile* profile, | 54 AppListModelBuilder::AppListModelBuilder(Profile* profile, |
55 aura_shell::AppListModel* model) | 55 ash::AppListModel* model) |
56 : profile_(profile), | 56 : profile_(profile), |
57 model_(model) { | 57 model_(model) { |
58 } | 58 } |
59 | 59 |
60 AppListModelBuilder::~AppListModelBuilder() { | 60 AppListModelBuilder::~AppListModelBuilder() { |
61 } | 61 } |
62 | 62 |
63 void AppListModelBuilder::Build() { | 63 void AppListModelBuilder::Build() { |
64 GetExtensionApps(); | 64 GetExtensionApps(); |
65 GetBrowserCommands(); | 65 GetBrowserCommands(); |
(...skipping 18 matching lines...) Expand all Loading... |
84 | 84 |
85 // Sort by launch ordinal. | 85 // Sort by launch ordinal. |
86 std::sort(items.begin(), items.end(), &ExtensionAppPrecedes); | 86 std::sort(items.begin(), items.end(), &ExtensionAppPrecedes); |
87 | 87 |
88 // Put all items into model and group them by page ordinal. | 88 // Put all items into model and group them by page ordinal. |
89 PrefService* prefs = profile_->GetPrefs(); | 89 PrefService* prefs = profile_->GetPrefs(); |
90 const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames); | 90 const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames); |
91 for (size_t i = 0; i < items.size(); ++i) { | 91 for (size_t i = 0; i < items.size(); ++i) { |
92 ExtensionAppItem* item = items[i]; | 92 ExtensionAppItem* item = items[i]; |
93 | 93 |
94 aura_shell::AppListItemGroupModel* group = GetOrCreateGroup( | 94 ash::AppListItemGroupModel* group = GetOrCreateGroup( |
95 item->page_index(), | 95 item->page_index(), |
96 app_page_names, | 96 app_page_names, |
97 model_); | 97 model_); |
98 | 98 |
99 group->AddItem(item); | 99 group->AddItem(item); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 void AppListModelBuilder::GetBrowserCommands() { | 103 void AppListModelBuilder::GetBrowserCommands() { |
104 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); | 104 Browser* browser = BrowserList::GetLastActiveWithProfile(profile_); |
105 if (!browser) | 105 if (!browser) |
106 return; | 106 return; |
107 | 107 |
108 // Uses the first group to put browser commands | 108 // Uses the first group to put browser commands |
109 if (model_->group_count() == 0) | 109 if (model_->group_count() == 0) |
110 model_->AddGroup(new aura_shell::AppListItemGroupModel("")); | 110 model_->AddGroup(new ash::AppListItemGroupModel("")); |
111 aura_shell::AppListItemGroupModel* group = model_->GetGroup(0); | 111 ash::AppListItemGroupModel* group = model_->GetGroup(0); |
112 | 112 |
113 group->AddItem(new BrowserCommandItem(browser, | 113 group->AddItem(new BrowserCommandItem(browser, |
114 IDC_NEW_INCOGNITO_WINDOW, | 114 IDC_NEW_INCOGNITO_WINDOW, |
115 IDS_APP_LIST_INCOGNITO, | 115 IDS_APP_LIST_INCOGNITO, |
116 IDR_APP_LIST_INCOGNITO)); | 116 IDR_APP_LIST_INCOGNITO)); |
117 group->AddItem(new BrowserCommandItem(browser, | 117 group->AddItem(new BrowserCommandItem(browser, |
118 IDC_OPTIONS, | 118 IDC_OPTIONS, |
119 IDS_APP_LIST_SETTINGS, | 119 IDS_APP_LIST_SETTINGS, |
120 IDR_APP_LIST_SETTINGS)); | 120 IDR_APP_LIST_SETTINGS)); |
121 } | 121 } |
122 | 122 |
OLD | NEW |