| 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 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 void ChromeLauncherController::OnShelfDestroyed(ash::Shelf* shelf) { | 1047 void ChromeLauncherController::OnShelfDestroyed(ash::Shelf* shelf) { |
| 1048 shelves_.erase(shelf); | 1048 shelves_.erase(shelf); |
| 1049 // RemoveObserver is not called here, since by the time this method is called | 1049 // RemoveObserver is not called here, since by the time this method is called |
| 1050 // Shelf is already in its destructor. | 1050 // Shelf is already in its destructor. |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 void ChromeLauncherController::ShelfItemAdded(int index) { | 1053 void ChromeLauncherController::ShelfItemAdded(int index) { |
| 1054 // The app list launcher can get added to the shelf after we applied the | 1054 // The app list launcher can get added to the shelf after we applied the |
| 1055 // preferences. In that case the item might be at the wrong spot. As such we | 1055 // preferences. In that case the item might be at the wrong spot. As such we |
| 1056 // call the function again. | 1056 // call the function again. |
| 1057 if (model_->items()[index].type == ash::TYPE_APP_LIST && | 1057 if (model_->items()[index].type == ash::TYPE_APP_LIST) |
| 1058 ash::switches::UseAlternateShelfLayout()) | |
| 1059 UpdateAppLaunchersFromPref(); | 1058 UpdateAppLaunchersFromPref(); |
| 1060 } | 1059 } |
| 1061 | 1060 |
| 1062 void ChromeLauncherController::ShelfItemRemoved(int index, ash::ShelfID id) { | 1061 void ChromeLauncherController::ShelfItemRemoved(int index, ash::ShelfID id) { |
| 1063 } | 1062 } |
| 1064 | 1063 |
| 1065 void ChromeLauncherController::ShelfItemMoved(int start_index, | 1064 void ChromeLauncherController::ShelfItemMoved(int start_index, |
| 1066 int target_index) { | 1065 int target_index) { |
| 1067 const ash::ShelfItem& item = model_->items()[target_index]; | 1066 const ash::ShelfItem& item = model_->items()[target_index]; |
| 1068 // We remember the moved item position if it is either pinnable or | 1067 // We remember the moved item position if it is either pinnable or |
| 1069 // it is the app list with the alternate shelf layout. | 1068 // it is the app list with the alternate shelf layout. |
| 1070 if ((HasItemController(item.id) && IsPinned(item.id)) || | 1069 if ((HasItemController(item.id) && IsPinned(item.id)) || |
| 1071 (ash::switches::UseAlternateShelfLayout() && | 1070 item.type == ash::TYPE_APP_LIST) |
| 1072 item.type == ash::TYPE_APP_LIST)) | |
| 1073 PersistPinnedState(); | 1071 PersistPinnedState(); |
| 1074 } | 1072 } |
| 1075 | 1073 |
| 1076 void ChromeLauncherController::ShelfItemChanged( | 1074 void ChromeLauncherController::ShelfItemChanged( |
| 1077 int index, | 1075 int index, |
| 1078 const ash::ShelfItem& old_item) { | 1076 const ash::ShelfItem& old_item) { |
| 1079 } | 1077 } |
| 1080 | 1078 |
| 1081 void ChromeLauncherController::ShelfStatusChanged() { | 1079 void ChromeLauncherController::ShelfStatusChanged() { |
| 1082 } | 1080 } |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1810 model_->Move(*app_list_index, target_index); | 1808 model_->Move(*app_list_index, target_index); |
| 1811 if (*chrome_index != -1 && | 1809 if (*chrome_index != -1 && |
| 1812 *app_list_index < *chrome_index && | 1810 *app_list_index < *chrome_index && |
| 1813 target_index > *chrome_index) | 1811 target_index > *chrome_index) |
| 1814 --(*chrome_index); | 1812 --(*chrome_index); |
| 1815 *app_list_index = -1; | 1813 *app_list_index = -1; |
| 1816 } | 1814 } |
| 1817 } | 1815 } |
| 1818 | 1816 |
| 1819 int ChromeLauncherController::FindInsertionPoint(bool is_app_list) { | 1817 int ChromeLauncherController::FindInsertionPoint(bool is_app_list) { |
| 1820 bool alternate = ash::switches::UseAlternateShelfLayout(); | |
| 1821 // Keeping this change small to backport to M33&32 (see crbug.com/329597). | 1818 // Keeping this change small to backport to M33&32 (see crbug.com/329597). |
| 1822 // TODO(skuhne): With the removal of the legacy shelf layout we should remove | 1819 // TODO(skuhne): With the removal of the legacy shelf layout we should remove |
| 1823 // the ability to move the app list item since this was never used. We should | 1820 // the ability to move the app list item since this was never used. We should |
| 1824 // instead ask the ShelfModel::ValidateInsertionIndex or similir for an index. | 1821 // instead ask the ShelfModel::ValidateInsertionIndex or similir for an index. |
| 1825 if (is_app_list && alternate) | 1822 if (is_app_list) |
| 1826 return 0; | 1823 return 0; |
| 1827 | 1824 |
| 1828 for (int i = model_->item_count() - 1; i > 0; --i) { | 1825 for (int i = model_->item_count() - 1; i > 0; --i) { |
| 1829 ash::ShelfItemType type = model_->items()[i].type; | 1826 ash::ShelfItemType type = model_->items()[i].type; |
| 1830 if (type == ash::TYPE_APP_SHORTCUT || | 1827 if (type == ash::TYPE_APP_SHORTCUT || |
| 1831 ((is_app_list || alternate) && type == ash::TYPE_APP_LIST) || | 1828 (is_app_list && type == ash::TYPE_APP_LIST) || |
| 1832 type == ash::TYPE_BROWSER_SHORTCUT) { | 1829 type == ash::TYPE_BROWSER_SHORTCUT) { |
| 1833 return i; | 1830 return i; |
| 1834 } | 1831 } |
| 1835 } | 1832 } |
| 1836 return 0; | 1833 return 0; |
| 1837 } | 1834 } |
| 1838 | 1835 |
| 1839 int ChromeLauncherController::GetChromeIconIndexForCreation() { | 1836 int ChromeLauncherController::GetChromeIconIndexForCreation() { |
| 1840 // We get the list of pinned apps as they currently would get pinned. | 1837 // We get the list of pinned apps as they currently would get pinned. |
| 1841 // Within this list the chrome icon will be the correct location. | 1838 // Within this list the chrome icon will be the correct location. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1911 } | 1908 } |
| 1912 } | 1909 } |
| 1913 | 1910 |
| 1914 // If not added yet, the chrome item will be the last item in the list. | 1911 // If not added yet, the chrome item will be the last item in the list. |
| 1915 if (!chrome_icon_added) | 1912 if (!chrome_icon_added) |
| 1916 pinned_apps.push_back(extension_misc::kChromeAppId); | 1913 pinned_apps.push_back(extension_misc::kChromeAppId); |
| 1917 | 1914 |
| 1918 // If not added yet, add the app list item either at the end or at the | 1915 // If not added yet, add the app list item either at the end or at the |
| 1919 // beginning - depending on the shelf layout. | 1916 // beginning - depending on the shelf layout. |
| 1920 if (!app_list_icon_added) { | 1917 if (!app_list_icon_added) { |
| 1921 if (ash::switches::UseAlternateShelfLayout()) | 1918 pinned_apps.insert(pinned_apps.begin(), kAppShelfIdPlaceholder); |
| 1922 pinned_apps.insert(pinned_apps.begin(), kAppShelfIdPlaceholder); | |
| 1923 else | |
| 1924 pinned_apps.push_back(kAppShelfIdPlaceholder); | |
| 1925 } | 1919 } |
| 1926 return pinned_apps; | 1920 return pinned_apps; |
| 1927 } | 1921 } |
| 1928 | 1922 |
| 1929 bool ChromeLauncherController::IsIncognito( | 1923 bool ChromeLauncherController::IsIncognito( |
| 1930 const content::WebContents* web_contents) const { | 1924 const content::WebContents* web_contents) const { |
| 1931 const Profile* profile = | 1925 const Profile* profile = |
| 1932 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 1926 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 1933 return profile->IsOffTheRecord() && !profile->IsGuestSession(); | 1927 return profile->IsOffTheRecord() && !profile->IsGuestSession(); |
| 1934 } | 1928 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2006 } | 2000 } |
| 2007 | 2001 |
| 2008 void ChromeLauncherController::ReleaseProfile() { | 2002 void ChromeLauncherController::ReleaseProfile() { |
| 2009 if (app_sync_ui_state_) | 2003 if (app_sync_ui_state_) |
| 2010 app_sync_ui_state_->RemoveObserver(this); | 2004 app_sync_ui_state_->RemoveObserver(this); |
| 2011 | 2005 |
| 2012 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); | 2006 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); |
| 2013 | 2007 |
| 2014 pref_change_registrar_.RemoveAll(); | 2008 pref_change_registrar_.RemoveAll(); |
| 2015 } | 2009 } |
| OLD | NEW |