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 1073 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1084 void ChromeLauncherController::OnShelfDestroyed(ash::Shelf* shelf) { | 1084 void ChromeLauncherController::OnShelfDestroyed(ash::Shelf* shelf) { |
1085 shelves_.erase(shelf); | 1085 shelves_.erase(shelf); |
1086 // RemoveObserver is not called here, since by the time this method is called | 1086 // RemoveObserver is not called here, since by the time this method is called |
1087 // Shelf is already in its destructor. | 1087 // Shelf is already in its destructor. |
1088 } | 1088 } |
1089 | 1089 |
1090 void ChromeLauncherController::ShelfItemAdded(int index) { | 1090 void ChromeLauncherController::ShelfItemAdded(int index) { |
1091 // The app list launcher can get added to the shelf after we applied the | 1091 // The app list launcher can get added to the shelf after we applied the |
1092 // preferences. In that case the item might be at the wrong spot. As such we | 1092 // preferences. In that case the item might be at the wrong spot. As such we |
1093 // call the function again. | 1093 // call the function again. |
1094 if (model_->items()[index].type == ash::TYPE_APP_LIST && | 1094 if (model_->items()[index].type == ash::TYPE_APP_LIST) |
1095 ash::switches::UseAlternateShelfLayout()) | |
1096 UpdateAppLaunchersFromPref(); | 1095 UpdateAppLaunchersFromPref(); |
1097 } | 1096 } |
1098 | 1097 |
1099 void ChromeLauncherController::ShelfItemRemoved(int index, ash::ShelfID id) { | 1098 void ChromeLauncherController::ShelfItemRemoved(int index, ash::ShelfID id) { |
1100 } | 1099 } |
1101 | 1100 |
1102 void ChromeLauncherController::ShelfItemMoved(int start_index, | 1101 void ChromeLauncherController::ShelfItemMoved(int start_index, |
1103 int target_index) { | 1102 int target_index) { |
1104 const ash::ShelfItem& item = model_->items()[target_index]; | 1103 const ash::ShelfItem& item = model_->items()[target_index]; |
1105 // We remember the moved item position if it is either pinnable or | 1104 // We remember the moved item position if it is either pinnable or |
1106 // it is the app list with the alternate shelf layout. | 1105 // it is the app list with the alternate shelf layout. |
1107 if ((HasItemController(item.id) && IsPinned(item.id)) || | 1106 if ((HasItemController(item.id) && IsPinned(item.id)) || |
1108 (ash::switches::UseAlternateShelfLayout() && | 1107 item.type == ash::TYPE_APP_LIST) |
1109 item.type == ash::TYPE_APP_LIST)) | |
1110 PersistPinnedState(); | 1108 PersistPinnedState(); |
1111 } | 1109 } |
1112 | 1110 |
1113 void ChromeLauncherController::ShelfItemChanged( | 1111 void ChromeLauncherController::ShelfItemChanged( |
1114 int index, | 1112 int index, |
1115 const ash::ShelfItem& old_item) { | 1113 const ash::ShelfItem& old_item) { |
1116 } | 1114 } |
1117 | 1115 |
1118 void ChromeLauncherController::ShelfStatusChanged() { | 1116 void ChromeLauncherController::ShelfStatusChanged() { |
1119 } | 1117 } |
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1862 model_->Move(*app_list_index, target_index); | 1860 model_->Move(*app_list_index, target_index); |
1863 if (*chrome_index != -1 && | 1861 if (*chrome_index != -1 && |
1864 *app_list_index < *chrome_index && | 1862 *app_list_index < *chrome_index && |
1865 target_index > *chrome_index) | 1863 target_index > *chrome_index) |
1866 --(*chrome_index); | 1864 --(*chrome_index); |
1867 *app_list_index = -1; | 1865 *app_list_index = -1; |
1868 } | 1866 } |
1869 } | 1867 } |
1870 | 1868 |
1871 int ChromeLauncherController::FindInsertionPoint(bool is_app_list) { | 1869 int ChromeLauncherController::FindInsertionPoint(bool is_app_list) { |
1872 bool alternate = ash::switches::UseAlternateShelfLayout(); | |
1873 // Keeping this change small to backport to M33&32 (see crbug.com/329597). | 1870 // Keeping this change small to backport to M33&32 (see crbug.com/329597). |
1874 // TODO(skuhne): With the removal of the legacy shelf layout we should remove | 1871 // TODO(skuhne): With the removal of the legacy shelf layout we should remove |
1875 // the ability to move the app list item since this was never used. We should | 1872 // the ability to move the app list item since this was never used. We should |
1876 // instead ask the ShelfModel::ValidateInsertionIndex or similir for an index. | 1873 // instead ask the ShelfModel::ValidateInsertionIndex or similir for an index. |
1877 if (is_app_list && alternate) | 1874 if (is_app_list) |
1878 return 0; | 1875 return 0; |
1879 | 1876 |
1880 for (int i = model_->item_count() - 1; i > 0; --i) { | 1877 for (int i = model_->item_count() - 1; i > 0; --i) { |
1881 ash::ShelfItemType type = model_->items()[i].type; | 1878 ash::ShelfItemType type = model_->items()[i].type; |
1882 if (type == ash::TYPE_APP_SHORTCUT || | 1879 if (type == ash::TYPE_APP_SHORTCUT || |
1883 ((is_app_list || alternate) && type == ash::TYPE_APP_LIST) || | 1880 type == ash::TYPE_APP_LIST || |
1884 type == ash::TYPE_BROWSER_SHORTCUT || | 1881 type == ash::TYPE_BROWSER_SHORTCUT || |
1885 type == ash::TYPE_WINDOWED_APP) | 1882 type == ash::TYPE_WINDOWED_APP) |
1886 return i; | 1883 return i; |
1887 } | 1884 } |
1888 return 0; | 1885 return 0; |
1889 } | 1886 } |
1890 | 1887 |
1891 int ChromeLauncherController::GetChromeIconIndexForCreation() { | 1888 int ChromeLauncherController::GetChromeIconIndexForCreation() { |
1892 // We get the list of pinned apps as they currently would get pinned. | 1889 // We get the list of pinned apps as they currently would get pinned. |
1893 // Within this list the chrome icon will be the correct location. | 1890 // Within this list the chrome icon will be the correct location. |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1962 } | 1959 } |
1963 } | 1960 } |
1964 } | 1961 } |
1965 | 1962 |
1966 // If not added yet, the chrome item will be the last item in the list. | 1963 // If not added yet, the chrome item will be the last item in the list. |
1967 if (!chrome_icon_added) | 1964 if (!chrome_icon_added) |
1968 pinned_apps.push_back(extension_misc::kChromeAppId); | 1965 pinned_apps.push_back(extension_misc::kChromeAppId); |
1969 | 1966 |
1970 // If not added yet, add the app list item either at the end or at the | 1967 // If not added yet, add the app list item either at the end or at the |
1971 // beginning - depending on the shelf layout. | 1968 // beginning - depending on the shelf layout. |
1972 if (!app_list_icon_added) { | 1969 if (!app_list_icon_added) |
1973 if (ash::switches::UseAlternateShelfLayout()) | 1970 pinned_apps.insert(pinned_apps.begin(), kAppShelfIdPlaceholder); |
1974 pinned_apps.insert(pinned_apps.begin(), kAppShelfIdPlaceholder); | |
1975 else | |
1976 pinned_apps.push_back(kAppShelfIdPlaceholder); | |
1977 } | |
1978 return pinned_apps; | 1971 return pinned_apps; |
1979 } | 1972 } |
1980 | 1973 |
1981 bool ChromeLauncherController::IsIncognito( | 1974 bool ChromeLauncherController::IsIncognito( |
1982 const content::WebContents* web_contents) const { | 1975 const content::WebContents* web_contents) const { |
1983 const Profile* profile = | 1976 const Profile* profile = |
1984 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 1977 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
1985 return profile->IsOffTheRecord() && !profile->IsGuestSession(); | 1978 return profile->IsOffTheRecord() && !profile->IsGuestSession(); |
1986 } | 1979 } |
1987 | 1980 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2058 } | 2051 } |
2059 | 2052 |
2060 void ChromeLauncherController::ReleaseProfile() { | 2053 void ChromeLauncherController::ReleaseProfile() { |
2061 if (app_sync_ui_state_) | 2054 if (app_sync_ui_state_) |
2062 app_sync_ui_state_->RemoveObserver(this); | 2055 app_sync_ui_state_->RemoveObserver(this); |
2063 | 2056 |
2064 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); | 2057 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); |
2065 | 2058 |
2066 pref_change_registrar_.RemoveAll(); | 2059 pref_change_registrar_.RemoveAll(); |
2067 } | 2060 } |
OLD | NEW |