OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ash/launcher/chrome_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/desktop_background/desktop_background_controller.h" | 10 #include "ash/desktop_background/desktop_background_controller.h" |
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 void ChromeLauncherController::OnShelfDestroyed(ash::Shelf* shelf) { | 1113 void ChromeLauncherController::OnShelfDestroyed(ash::Shelf* shelf) { |
1114 shelves_.erase(shelf); | 1114 shelves_.erase(shelf); |
1115 // RemoveObserver is not called here, since by the time this method is called | 1115 // RemoveObserver is not called here, since by the time this method is called |
1116 // Shelf is already in its destructor. | 1116 // Shelf is already in its destructor. |
1117 } | 1117 } |
1118 | 1118 |
1119 void ChromeLauncherController::ShelfItemAdded(int index) { | 1119 void ChromeLauncherController::ShelfItemAdded(int index) { |
1120 // The app list launcher can get added to the shelf after we applied the | 1120 // The app list launcher can get added to the shelf after we applied the |
1121 // preferences. In that case the item might be at the wrong spot. As such we | 1121 // preferences. In that case the item might be at the wrong spot. As such we |
1122 // call the function again. | 1122 // call the function again. |
1123 if (model_->items()[index].type == ash::TYPE_APP_LIST && | 1123 if (model_->items()[index].type == ash::TYPE_APP_LIST) |
1124 ash::switches::UseAlternateShelfLayout()) | |
1125 UpdateAppLaunchersFromPref(); | 1124 UpdateAppLaunchersFromPref(); |
1126 } | 1125 } |
1127 | 1126 |
1128 void ChromeLauncherController::ShelfItemRemoved(int index, ash::LauncherID id) { | 1127 void ChromeLauncherController::ShelfItemRemoved(int index, ash::LauncherID id) { |
1129 } | 1128 } |
1130 | 1129 |
1131 void ChromeLauncherController::ShelfItemMoved(int start_index, | 1130 void ChromeLauncherController::ShelfItemMoved(int start_index, |
1132 int target_index) { | 1131 int target_index) { |
1133 const ash::LauncherItem& item = model_->items()[target_index]; | 1132 const ash::LauncherItem& item = model_->items()[target_index]; |
1134 // We remember the moved item position if it is either pinnable or | 1133 // We remember the moved item position if it is either pinnable or |
1135 // it is the app list with the alternate shelf layout. | 1134 // it is the app list with the alternate shelf layout. |
1136 if ((HasItemController(item.id) && IsPinned(item.id)) || | 1135 if ((HasItemController(item.id) && IsPinned(item.id)) || |
1137 (ash::switches::UseAlternateShelfLayout() && | 1136 item.type == ash::TYPE_APP_LIST) |
1138 item.type == ash::TYPE_APP_LIST)) | |
1139 PersistPinnedState(); | 1137 PersistPinnedState(); |
1140 } | 1138 } |
1141 | 1139 |
1142 void ChromeLauncherController::ShelfItemChanged( | 1140 void ChromeLauncherController::ShelfItemChanged( |
1143 int index, | 1141 int index, |
1144 const ash::LauncherItem& old_item) { | 1142 const ash::LauncherItem& old_item) { |
1145 } | 1143 } |
1146 | 1144 |
1147 void ChromeLauncherController::ShelfStatusChanged() { | 1145 void ChromeLauncherController::ShelfStatusChanged() { |
1148 } | 1146 } |
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1869 model_->Move(*app_list_index, target_index); | 1867 model_->Move(*app_list_index, target_index); |
1870 if (*chrome_index != -1 && | 1868 if (*chrome_index != -1 && |
1871 *app_list_index < *chrome_index && | 1869 *app_list_index < *chrome_index && |
1872 target_index > *chrome_index) | 1870 target_index > *chrome_index) |
1873 --(*chrome_index); | 1871 --(*chrome_index); |
1874 *app_list_index = -1; | 1872 *app_list_index = -1; |
1875 } | 1873 } |
1876 } | 1874 } |
1877 | 1875 |
1878 int ChromeLauncherController::FindInsertionPoint(bool is_app_list) { | 1876 int ChromeLauncherController::FindInsertionPoint(bool is_app_list) { |
1879 bool alternate = ash::switches::UseAlternateShelfLayout(); | |
1880 // Keeping this change small to backport to M33&32 (see crbug.com/329597). | 1877 // Keeping this change small to backport to M33&32 (see crbug.com/329597). |
1881 // TODO(skuhne): With the removal of the legacy shelf layout we should remove | 1878 // TODO(skuhne): With the removal of the legacy shelf layout we should remove |
1882 // the ability to move the app list item since this was never used. We should | 1879 // the ability to move the app list item since this was never used. We should |
1883 // instead ask the ShelfModel::ValidateInsertionIndex or similir for an index. | 1880 // instead ask the ShelfModel::ValidateInsertionIndex or similir for an index. |
1884 if (is_app_list && alternate) | 1881 if (is_app_list) |
1885 return 0; | 1882 return 0; |
1886 | 1883 |
1887 for (int i = model_->item_count() - 1; i > 0; --i) { | 1884 for (int i = model_->item_count() - 1; i > 0; --i) { |
1888 ash::ShelfItemType type = model_->items()[i].type; | 1885 ash::ShelfItemType type = model_->items()[i].type; |
1889 if (type == ash::TYPE_APP_SHORTCUT || | 1886 if (type == ash::TYPE_APP_SHORTCUT || |
1890 ((is_app_list || alternate) && type == ash::TYPE_APP_LIST) || | 1887 type == ash::TYPE_APP_LIST || |
1891 type == ash::TYPE_BROWSER_SHORTCUT || | 1888 type == ash::TYPE_BROWSER_SHORTCUT || |
1892 type == ash::TYPE_WINDOWED_APP) | 1889 type == ash::TYPE_WINDOWED_APP) |
1893 return i; | 1890 return i; |
1894 } | 1891 } |
1895 return 0; | 1892 return 0; |
1896 } | 1893 } |
1897 | 1894 |
1898 int ChromeLauncherController::GetChromeIconIndexForCreation() { | 1895 int ChromeLauncherController::GetChromeIconIndexForCreation() { |
1899 // We get the list of pinned apps as they currently would get pinned. | 1896 // We get the list of pinned apps as they currently would get pinned. |
1900 // Within this list the chrome icon will be the correct location. | 1897 // Within this list the chrome icon will be the correct location. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1969 } | 1966 } |
1970 } | 1967 } |
1971 } | 1968 } |
1972 | 1969 |
1973 // If not added yet, the chrome item will be the last item in the list. | 1970 // If not added yet, the chrome item will be the last item in the list. |
1974 if (!chrome_icon_added) | 1971 if (!chrome_icon_added) |
1975 pinned_apps.push_back(extension_misc::kChromeAppId); | 1972 pinned_apps.push_back(extension_misc::kChromeAppId); |
1976 | 1973 |
1977 // If not added yet, add the app list item either at the end or at the | 1974 // If not added yet, add the app list item either at the end or at the |
1978 // beginning - depending on the shelf layout. | 1975 // beginning - depending on the shelf layout. |
1979 if (!app_list_icon_added) { | 1976 if (!app_list_icon_added) |
1980 if (ash::switches::UseAlternateShelfLayout()) | 1977 pinned_apps.insert(pinned_apps.begin(), kAppLauncherIdPlaceholder); |
1981 pinned_apps.insert(pinned_apps.begin(), kAppLauncherIdPlaceholder); | |
1982 else | |
1983 pinned_apps.push_back(kAppLauncherIdPlaceholder); | |
1984 } | |
1985 return pinned_apps; | 1978 return pinned_apps; |
1986 } | 1979 } |
1987 | 1980 |
1988 bool ChromeLauncherController::IsIncognito( | 1981 bool ChromeLauncherController::IsIncognito( |
1989 const content::WebContents* web_contents) const { | 1982 const content::WebContents* web_contents) const { |
1990 const Profile* profile = | 1983 const Profile* profile = |
1991 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 1984 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
1992 return profile->IsOffTheRecord() && !profile->IsGuestSession(); | 1985 return profile->IsOffTheRecord() && !profile->IsGuestSession(); |
1993 } | 1986 } |
1994 | 1987 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2065 } | 2058 } |
2066 | 2059 |
2067 void ChromeLauncherController::ReleaseProfile() { | 2060 void ChromeLauncherController::ReleaseProfile() { |
2068 if (app_sync_ui_state_) | 2061 if (app_sync_ui_state_) |
2069 app_sync_ui_state_->RemoveObserver(this); | 2062 app_sync_ui_state_->RemoveObserver(this); |
2070 | 2063 |
2071 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); | 2064 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); |
2072 | 2065 |
2073 pref_change_registrar_.RemoveAll(); | 2066 pref_change_registrar_.RemoveAll(); |
2074 } | 2067 } |
OLD | NEW |