Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc

Issue 22429004: Refactor LauncherDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add some comments Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.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/launcher/launcher.h" 10 #include "ash/launcher/launcher.h"
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 void ChromeLauncherControllerPerApp::CreateNewWindow() { 693 void ChromeLauncherControllerPerApp::CreateNewWindow() {
694 chrome::NewEmptyWindow( 694 chrome::NewEmptyWindow(
695 GetProfileForNewWindows(), chrome::HOST_DESKTOP_TYPE_ASH); 695 GetProfileForNewWindows(), chrome::HOST_DESKTOP_TYPE_ASH);
696 } 696 }
697 697
698 void ChromeLauncherControllerPerApp::CreateNewIncognitoWindow() { 698 void ChromeLauncherControllerPerApp::CreateNewIncognitoWindow() {
699 chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile(), 699 chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile(),
700 chrome::HOST_DESKTOP_TYPE_ASH); 700 chrome::HOST_DESKTOP_TYPE_ASH);
701 } 701 }
702 702
703 bool ChromeLauncherControllerPerApp::CanPin() const {
704 const PrefService::Preference* pref =
705 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps);
706 return pref && pref->IsUserModifiable();
707 }
708
709 void ChromeLauncherControllerPerApp::PersistPinnedState() { 703 void ChromeLauncherControllerPerApp::PersistPinnedState() {
710 if (ignore_persist_pinned_state_change_) 704 if (ignore_persist_pinned_state_change_)
711 return; 705 return;
712 // It is a coding error to call PersistPinnedState() if the pinned apps are 706 // It is a coding error to call PersistPinnedState() if the pinned apps are
713 // not user-editable. The code should check earlier and not perform any 707 // not user-editable. The code should check earlier and not perform any
714 // modification actions that trigger persisting the state. 708 // modification actions that trigger persisting the state.
715 if (!CanPin()) { 709 if (!CanPin()) {
716 NOTREACHED() << "Can't pin but pinned state being updated"; 710 NOTREACHED() << "Can't pin but pinned state being updated";
717 return; 711 return;
718 } 712 }
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 return new LauncherContextMenu(this, &item, root_window); 932 return new LauncherContextMenu(this, &item, root_window);
939 } 933 }
940 934
941 ash::LauncherMenuModel* ChromeLauncherControllerPerApp::CreateApplicationMenu( 935 ash::LauncherMenuModel* ChromeLauncherControllerPerApp::CreateApplicationMenu(
942 const ash::LauncherItem& item, 936 const ash::LauncherItem& item,
943 int event_flags) { 937 int event_flags) {
944 return new LauncherApplicationMenuItemModel(GetApplicationList(item, 938 return new LauncherApplicationMenuItemModel(GetApplicationList(item,
945 event_flags)); 939 event_flags));
946 } 940 }
947 941
942 bool ChromeLauncherControllerPerApp::IsDraggable(
943 const ash::LauncherItem& item) {
944 return (item.type == ash::TYPE_APP_SHORTCUT ||
945 item.type == ash::TYPE_WINDOWED_APP) ? CanPin() : true;
946 }
947
948 bool ChromeLauncherControllerPerApp::ShouldShowTooltip(
949 const ash::LauncherItem& item) {
950 if (item.type == ash::TYPE_APP_PANEL &&
951 id_to_item_controller_map_[item.id]->IsVisible())
952 return false;
953 return true;
954 }
955
948 ash::LauncherID ChromeLauncherControllerPerApp::GetIDByWindow( 956 ash::LauncherID ChromeLauncherControllerPerApp::GetIDByWindow(
949 aura::Window* window) { 957 aura::Window* window) {
950 for (IDToItemControllerMap::const_iterator i = 958 for (IDToItemControllerMap::const_iterator i =
951 id_to_item_controller_map_.begin(); 959 id_to_item_controller_map_.begin();
952 i != id_to_item_controller_map_.end(); ++i) { 960 i != id_to_item_controller_map_.end(); ++i) {
953 if (i->second->HasWindow(window)) { 961 if (i->second->HasWindow(window)) {
954 // Since this might be a reserved index, there might be no item in the 962 // Since this might be a reserved index, there might be no item in the
955 // launcher for it. 963 // launcher for it.
956 if (model_->ItemIndexByID(i->first) < 0) 964 if (model_->ItemIndexByID(i->first) < 0)
957 break; 965 break;
958 return i->first; 966 return i->first;
959 } 967 }
960 } 968 }
961 if (window->type() == aura::client::WINDOW_TYPE_NORMAL) { 969 if (window->type() == aura::client::WINDOW_TYPE_NORMAL) {
962 // Coming here we are looking for the associated browser item as the 970 // Coming here we are looking for the associated browser item as the
963 // default. 971 // default.
964 // TODO(flackr): This shouldn't return a default icon if no window is found. 972 // TODO(flackr): This shouldn't return a default icon if no window is found.
965 // The browser launcher item controller should know which windows it is 973 // The browser launcher item controller should know which windows it is
966 // managing so that it is identified as the ID in the above loop. 974 // managing so that it is identified as the ID in the above loop.
967 int browser_index = ash::launcher::GetBrowserItemIndex(*model_); 975 int browser_index = ash::launcher::GetBrowserItemIndex(*model_);
968 // Note that there should always be a browser item in the launcher. 976 // Note that there should always be a browser item in the launcher.
969 DCHECK_GE(browser_index, 0); 977 DCHECK_GE(browser_index, 0);
970 return model_->items()[browser_index].id; 978 return model_->items()[browser_index].id;
971 } 979 }
972 return 0; 980 return 0;
973 } 981 }
974 982
975 bool ChromeLauncherControllerPerApp::IsDraggable(
976 const ash::LauncherItem& item) {
977 return (item.type == ash::TYPE_APP_SHORTCUT ||
978 item.type == ash::TYPE_WINDOWED_APP) ? CanPin() : true;
979 }
980
981 bool ChromeLauncherControllerPerApp::ShouldShowTooltip(
982 const ash::LauncherItem& item) {
983 if (item.type == ash::TYPE_APP_PANEL &&
984 id_to_item_controller_map_[item.id]->IsVisible())
985 return false;
986 return true;
987 }
988
989 void ChromeLauncherControllerPerApp::OnLauncherCreated( 983 void ChromeLauncherControllerPerApp::OnLauncherCreated(
990 ash::Launcher* launcher) { 984 ash::Launcher* launcher) {
991 launchers_.insert(launcher); 985 launchers_.insert(launcher);
992 launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this); 986 launcher->shelf_widget()->shelf_layout_manager()->AddObserver(this);
993 } 987 }
994 988
995 void ChromeLauncherControllerPerApp::OnLauncherDestroyed( 989 void ChromeLauncherControllerPerApp::OnLauncherDestroyed(
996 ash::Launcher* launcher) { 990 ash::Launcher* launcher) {
997 launchers_.erase(launcher); 991 launchers_.erase(launcher);
998 // RemoveObserver is not called here, since by the time this method is called 992 // RemoveObserver is not called here, since by the time this method is called
999 // Launcher is already in its destructor. 993 // Launcher is already in its destructor.
1000 } 994 }
1001 995
996 // TODO: Remove LauncherItemDelegate interface from
997 // ChromeLauncherControllerPerApp. LauncherItemDelegate should be derived by
998 // LauncherItemController after removing PerBrowserLauncher.
999 ash::LauncherItemDelegate*
1000 ChromeLauncherControllerPerApp::GetLauncherItemDelegate(
1001 const ash::LauncherItem& item) {
1002 IDToItemControllerMap::iterator iter =
1003 id_to_item_controller_map_.find(item.id);
1004 return iter != id_to_item_controller_map_.end() ? this : NULL;
1005 }
1006
1007 bool ChromeLauncherControllerPerApp::CanPin() const {
1008 const PrefService::Preference* pref =
1009 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps);
1010 return pref && pref->IsUserModifiable();
1011 }
1012
1002 void ChromeLauncherControllerPerApp::LauncherItemAdded(int index) { 1013 void ChromeLauncherControllerPerApp::LauncherItemAdded(int index) {
1003 } 1014 }
1004 1015
1005 void ChromeLauncherControllerPerApp::LauncherItemRemoved( 1016 void ChromeLauncherControllerPerApp::LauncherItemRemoved(
1006 int index, 1017 int index,
1007 ash::LauncherID id) { 1018 ash::LauncherID id) {
1008 } 1019 }
1009 1020
1010 void ChromeLauncherControllerPerApp::LauncherItemMoved( 1021 void ChromeLauncherControllerPerApp::LauncherItemMoved(
1011 int start_index, 1022 int start_index,
1012 int target_index) { 1023 int target_index) {
1013 ash::LauncherID id = model_->items()[target_index].id; 1024 ash::LauncherID id = model_->items()[target_index].id;
1014 if (HasItemController(id) && IsPinned(id)) 1025 if (HasItemController(id) && IsPinned(id))
1015 PersistPinnedState(); 1026 PersistPinnedState();
1016 } 1027 }
1017 1028
1018 void ChromeLauncherControllerPerApp::LauncherItemChanged( 1029 void ChromeLauncherControllerPerApp::LauncherItemChanged(
1019 int index, 1030 int index,
1020 const ash::LauncherItem& old_item) { 1031 const ash::LauncherItem& old_item) {
1021 ash::LauncherID id = model_->items()[index].id; 1032 ash::LauncherID id = model_->items()[index].id;
1022 DCHECK(HasItemController(id)); 1033 if (HasItemController(id))
Mr4D (OOO till 08-26) 2013/08/13 18:18:24 Do you know why this is necessary? We shouldn't co
simonhong_ 2013/08/13 19:54:56 This is needed because we have two LauncherDelegat
Mr4D (OOO till 08-26) 2013/08/14 15:52:19 Which 2? Are you talking about the "Ash" and the "
simonhong_ 2013/08/14 23:47:51 Sorry, I wrote wrong answer. Yes, currently we can
Mr4D (OOO till 08-26) 2013/08/15 15:53:19 So we plan that we do not have a ChromeLauncherCon
1023 id_to_item_controller_map_[id]->LauncherItemChanged(index, old_item); 1034 id_to_item_controller_map_[id]->LauncherItemChanged(index, old_item);
1024 } 1035 }
1025 1036
1026 void ChromeLauncherControllerPerApp::LauncherStatusChanged() { 1037 void ChromeLauncherControllerPerApp::LauncherStatusChanged() {
1027 } 1038 }
1028 1039
1029 void ChromeLauncherControllerPerApp::Observe( 1040 void ChromeLauncherControllerPerApp::Observe(
1030 int type, 1041 int type,
1031 const content::NotificationSource& source, 1042 const content::NotificationSource& source,
1032 const content::NotificationDetails& details) { 1043 const content::NotificationDetails& details) {
1033 switch (type) { 1044 switch (type) {
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
1680 browser_to_close.pop_back(); 1691 browser_to_close.pop_back();
1681 } 1692 }
1682 } 1693 }
1683 1694
1684 void 1695 void
1685 ChromeLauncherControllerPerApp::MoveItemWithoutPinnedStateChangeNotification( 1696 ChromeLauncherControllerPerApp::MoveItemWithoutPinnedStateChangeNotification(
1686 int source_index, int target_index) { 1697 int source_index, int target_index) {
1687 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true); 1698 base::AutoReset<bool> auto_reset(&ignore_persist_pinned_state_change_, true);
1688 model_->Move(source_index, target_index); 1699 model_->Move(source_index, target_index);
1689 } 1700 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698