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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // static | 95 // static |
96 ChromeLauncherController* ChromeLauncherController::instance_ = NULL; | 96 ChromeLauncherController* ChromeLauncherController::instance_ = NULL; |
97 | 97 |
98 namespace { | 98 namespace { |
99 | 99 |
100 // This will be used as placeholder in the list of the pinned applciatons. | 100 // This will be used as placeholder in the list of the pinned applciatons. |
101 // Note that this is NOT a valid extension identifier so that pre M31 versions | 101 // Note that this is NOT a valid extension identifier so that pre M31 versions |
102 // will ignore it. | 102 // will ignore it. |
103 const char kAppLauncherIdPlaceholder[] = "AppLauncherIDPlaceholder--------"; | 103 const char kAppLauncherIdPlaceholder[] = "AppLauncherIDPlaceholder--------"; |
104 | 104 |
105 std::string GetPrefKeyForRootWindow(aura::RootWindow* root_window) { | 105 std::string GetPrefKeyForRootWindow(aura::Window* root_window) { |
106 gfx::Display display = gfx::Screen::GetScreenFor( | 106 gfx::Display display = gfx::Screen::GetScreenFor( |
107 root_window)->GetDisplayNearestWindow(root_window); | 107 root_window)->GetDisplayNearestWindow(root_window); |
108 DCHECK(display.is_valid()); | 108 DCHECK(display.is_valid()); |
109 | 109 |
110 return base::Int64ToString(display.id()); | 110 return base::Int64ToString(display.id()); |
111 } | 111 } |
112 | 112 |
113 void UpdatePerDisplayPref(PrefService* pref_service, | 113 void UpdatePerDisplayPref(PrefService* pref_service, |
114 aura::RootWindow* root_window, | 114 aura::Window* root_window, |
115 const char* pref_key, | 115 const char* pref_key, |
116 const std::string& value) { | 116 const std::string& value) { |
117 std::string key = GetPrefKeyForRootWindow(root_window); | 117 std::string key = GetPrefKeyForRootWindow(root_window); |
118 if (key.empty()) | 118 if (key.empty()) |
119 return; | 119 return; |
120 | 120 |
121 DictionaryPrefUpdate update(pref_service, prefs::kShelfPreferences); | 121 DictionaryPrefUpdate update(pref_service, prefs::kShelfPreferences); |
122 base::DictionaryValue* shelf_prefs = update.Get(); | 122 base::DictionaryValue* shelf_prefs = update.Get(); |
123 base::DictionaryValue* prefs = NULL; | 123 base::DictionaryValue* prefs = NULL; |
124 if (!shelf_prefs->GetDictionary(key, &prefs)) { | 124 if (!shelf_prefs->GetDictionary(key, &prefs)) { |
(...skipping 12 matching lines...) Expand all Loading... |
137 // * A user-set value for the specified display. | 137 // * A user-set value for the specified display. |
138 // * A user-set value in |local_path| or |path|, if no per-display settings are | 138 // * A user-set value in |local_path| or |path|, if no per-display settings are |
139 // ever specified (see http://crbug.com/173719 for why). |local_path| is | 139 // ever specified (see http://crbug.com/173719 for why). |local_path| is |
140 // preferred. See comment in |kShelfAlignment| as to why we consider two | 140 // preferred. See comment in |kShelfAlignment| as to why we consider two |
141 // prefs and why |local_path| is preferred. | 141 // prefs and why |local_path| is preferred. |
142 // * A value recommended by policy. This is a single value that applies to all | 142 // * A value recommended by policy. This is a single value that applies to all |
143 // root windows. | 143 // root windows. |
144 // * The default value for |local_path| if the value is not recommended by | 144 // * The default value for |local_path| if the value is not recommended by |
145 // policy. | 145 // policy. |
146 std::string GetPrefForRootWindow(PrefService* pref_service, | 146 std::string GetPrefForRootWindow(PrefService* pref_service, |
147 aura::RootWindow* root_window, | 147 aura::Window* root_window, |
148 const char* local_path, | 148 const char* local_path, |
149 const char* path) { | 149 const char* path) { |
150 const PrefService::Preference* local_pref = | 150 const PrefService::Preference* local_pref = |
151 pref_service->FindPreference(local_path); | 151 pref_service->FindPreference(local_path); |
152 const std::string value(pref_service->GetString(local_path)); | 152 const std::string value(pref_service->GetString(local_path)); |
153 if (local_pref->IsManaged()) | 153 if (local_pref->IsManaged()) |
154 return value; | 154 return value; |
155 | 155 |
156 std::string pref_key = GetPrefKeyForRootWindow(root_window); | 156 std::string pref_key = GetPrefKeyForRootWindow(root_window); |
157 bool has_per_display_prefs = false; | 157 bool has_per_display_prefs = false; |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 if (index == -1) | 664 if (index == -1) |
665 continue; | 665 continue; |
666 ash::LauncherItem item = model_->items()[index]; | 666 ash::LauncherItem item = model_->items()[index]; |
667 item.image = image; | 667 item.image = image; |
668 model_->Set(index, item); | 668 model_->Set(index, item); |
669 // It's possible we're waiting on more than one item, so don't break. | 669 // It's possible we're waiting on more than one item, so don't break. |
670 } | 670 } |
671 } | 671 } |
672 | 672 |
673 void ChromeLauncherController::OnAutoHideBehaviorChanged( | 673 void ChromeLauncherController::OnAutoHideBehaviorChanged( |
674 aura::RootWindow* root_window, | 674 aura::Window* root_window, |
675 ash::ShelfAutoHideBehavior new_behavior) { | 675 ash::ShelfAutoHideBehavior new_behavior) { |
676 SetShelfAutoHideBehaviorPrefs(new_behavior, root_window); | 676 SetShelfAutoHideBehaviorPrefs(new_behavior, root_window); |
677 } | 677 } |
678 | 678 |
679 void ChromeLauncherController::SetLauncherItemImage( | 679 void ChromeLauncherController::SetLauncherItemImage( |
680 ash::LauncherID launcher_id, | 680 ash::LauncherID launcher_id, |
681 const gfx::ImageSkia& image) { | 681 const gfx::ImageSkia& image) { |
682 int index = model_->ItemIndexByID(launcher_id); | 682 int index = model_->ItemIndexByID(launcher_id); |
683 if (index == -1) | 683 if (index == -1) |
684 return; | 684 return; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 | 795 |
796 ash::LauncherModel* ChromeLauncherController::model() { | 796 ash::LauncherModel* ChromeLauncherController::model() { |
797 return model_; | 797 return model_; |
798 } | 798 } |
799 | 799 |
800 Profile* ChromeLauncherController::profile() { | 800 Profile* ChromeLauncherController::profile() { |
801 return profile_; | 801 return profile_; |
802 } | 802 } |
803 | 803 |
804 ash::ShelfAutoHideBehavior ChromeLauncherController::GetShelfAutoHideBehavior( | 804 ash::ShelfAutoHideBehavior ChromeLauncherController::GetShelfAutoHideBehavior( |
805 aura::RootWindow* root_window) const { | 805 aura::Window* root_window) const { |
806 // Don't show the shelf in app mode. | 806 // Don't show the shelf in app mode. |
807 if (chrome::IsRunningInAppMode()) | 807 if (chrome::IsRunningInAppMode()) |
808 return ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN; | 808 return ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN; |
809 | 809 |
810 // See comment in |kShelfAlignment| as to why we consider two prefs. | 810 // See comment in |kShelfAlignment| as to why we consider two prefs. |
811 const std::string behavior_value( | 811 const std::string behavior_value( |
812 GetPrefForRootWindow(profile_->GetPrefs(), | 812 GetPrefForRootWindow(profile_->GetPrefs(), |
813 root_window, | 813 root_window, |
814 prefs::kShelfAutoHideBehaviorLocal, | 814 prefs::kShelfAutoHideBehaviorLocal, |
815 prefs::kShelfAutoHideBehavior)); | 815 prefs::kShelfAutoHideBehavior)); |
816 | 816 |
817 // Note: To maintain sync compatibility with old images of chrome/chromeos | 817 // Note: To maintain sync compatibility with old images of chrome/chromeos |
818 // the set of values that may be encountered includes the now-extinct | 818 // the set of values that may be encountered includes the now-extinct |
819 // "Default" as well as "Never" and "Always", "Default" should now | 819 // "Default" as well as "Never" and "Always", "Default" should now |
820 // be treated as "Never" (http://crbug.com/146773). | 820 // be treated as "Never" (http://crbug.com/146773). |
821 if (behavior_value == ash::kShelfAutoHideBehaviorAlways) | 821 if (behavior_value == ash::kShelfAutoHideBehaviorAlways) |
822 return ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; | 822 return ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
823 return ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; | 823 return ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; |
824 } | 824 } |
825 | 825 |
826 bool ChromeLauncherController::CanUserModifyShelfAutoHideBehavior( | 826 bool ChromeLauncherController::CanUserModifyShelfAutoHideBehavior( |
827 aura::RootWindow* root_window) const { | 827 aura::Window* root_window) const { |
828 return profile_->GetPrefs()-> | 828 return profile_->GetPrefs()-> |
829 FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable(); | 829 FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable(); |
830 } | 830 } |
831 | 831 |
832 void ChromeLauncherController::ToggleShelfAutoHideBehavior( | 832 void ChromeLauncherController::ToggleShelfAutoHideBehavior( |
833 aura::RootWindow* root_window) { | 833 aura::Window* root_window) { |
834 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) == | 834 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) == |
835 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? | 835 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? |
836 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER : | 836 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER : |
837 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; | 837 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
838 SetShelfAutoHideBehaviorPrefs(behavior, root_window); | 838 SetShelfAutoHideBehaviorPrefs(behavior, root_window); |
839 return; | 839 return; |
840 } | 840 } |
841 | 841 |
842 void ChromeLauncherController::RemoveTabFromRunningApp( | 842 void ChromeLauncherController::RemoveTabFromRunningApp( |
843 WebContents* tab, | 843 WebContents* tab, |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 } | 1077 } |
1078 } | 1078 } |
1079 break; | 1079 break; |
1080 } | 1080 } |
1081 default: | 1081 default: |
1082 NOTREACHED() << "Unexpected notification type=" << type; | 1082 NOTREACHED() << "Unexpected notification type=" << type; |
1083 } | 1083 } |
1084 } | 1084 } |
1085 | 1085 |
1086 void ChromeLauncherController::OnShelfAlignmentChanged( | 1086 void ChromeLauncherController::OnShelfAlignmentChanged( |
1087 aura::RootWindow* root_window) { | 1087 aura::Window* root_window) { |
1088 const char* pref_value = NULL; | 1088 const char* pref_value = NULL; |
1089 switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) { | 1089 switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) { |
1090 case ash::SHELF_ALIGNMENT_BOTTOM: | 1090 case ash::SHELF_ALIGNMENT_BOTTOM: |
1091 pref_value = ash::kShelfAlignmentBottom; | 1091 pref_value = ash::kShelfAlignmentBottom; |
1092 break; | 1092 break; |
1093 case ash::SHELF_ALIGNMENT_LEFT: | 1093 case ash::SHELF_ALIGNMENT_LEFT: |
1094 pref_value = ash::kShelfAlignmentLeft; | 1094 pref_value = ash::kShelfAlignmentLeft; |
1095 break; | 1095 break; |
1096 case ash::SHELF_ALIGNMENT_RIGHT: | 1096 case ash::SHELF_ALIGNMENT_RIGHT: |
1097 pref_value = ash::kShelfAlignmentRight; | 1097 pref_value = ash::kShelfAlignmentRight; |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 } else { | 1512 } else { |
1513 int target_index = FindInsertionPoint(is_app_list); | 1513 int target_index = FindInsertionPoint(is_app_list); |
1514 MoveChromeOrApplistToFinalPosition( | 1514 MoveChromeOrApplistToFinalPosition( |
1515 is_chrome, is_app_list, target_index, &chrome_index, &app_list_index); | 1515 is_chrome, is_app_list, target_index, &chrome_index, &app_list_index); |
1516 } | 1516 } |
1517 } | 1517 } |
1518 } | 1518 } |
1519 | 1519 |
1520 void ChromeLauncherController::SetShelfAutoHideBehaviorPrefs( | 1520 void ChromeLauncherController::SetShelfAutoHideBehaviorPrefs( |
1521 ash::ShelfAutoHideBehavior behavior, | 1521 ash::ShelfAutoHideBehavior behavior, |
1522 aura::RootWindow* root_window) { | 1522 aura::Window* root_window) { |
1523 const char* value = NULL; | 1523 const char* value = NULL; |
1524 switch (behavior) { | 1524 switch (behavior) { |
1525 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: | 1525 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
1526 value = ash::kShelfAutoHideBehaviorAlways; | 1526 value = ash::kShelfAutoHideBehaviorAlways; |
1527 break; | 1527 break; |
1528 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER: | 1528 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
1529 value = ash::kShelfAutoHideBehaviorNever; | 1529 value = ash::kShelfAutoHideBehaviorNever; |
1530 break; | 1530 break; |
1531 case ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN: | 1531 case ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN: |
1532 // This one should not be a valid preference option for now. We only want | 1532 // This one should not be a valid preference option for now. We only want |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1946 } | 1946 } |
1947 } | 1947 } |
1948 } | 1948 } |
1949 } | 1949 } |
1950 | 1950 |
1951 // Finally we update the browser state itself. | 1951 // Finally we update the browser state itself. |
1952 browser_status_monitor_->UpdateBrowserItemState(); | 1952 browser_status_monitor_->UpdateBrowserItemState(); |
1953 #endif | 1953 #endif |
1954 } | 1954 } |
1955 | 1955 |
OLD | NEW |