Chromium Code Reviews| Index: chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc |
| diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc |
| index 3e5262e4154c068f90e4ce04cd1ecd04f8f79578..256632b926d715724f86de650308587a22267e4d 100644 |
| --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc |
| +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc |
| @@ -10,6 +10,7 @@ |
| #include "ash/shell.h" |
| #include "ash/wm/window_util.h" |
| #include "base/command_line.h" |
| +#include "base/string_number_conversions.h" |
| #include "base/values.h" |
| #include "chrome/browser/defaults.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| @@ -44,6 +45,7 @@ |
| #include "content/public/browser/web_contents.h" |
| #include "extensions/common/url_pattern.h" |
| #include "grit/theme_resources.h" |
| +#include "ui/aura/root_window.h" |
| #include "ui/aura/window.h" |
| using content::WebContents; |
| @@ -118,12 +120,58 @@ class AppShortcutLauncherItemController : public LauncherItemController { |
| DISALLOW_COPY_AND_ASSIGN(AppShortcutLauncherItemController); |
| }; |
| +std::string GetPrefKeyForRootWindow(aura::RootWindow* root_window) { |
| + if (!root_window) |
|
oshima
2012/12/14 11:03:55
can this be NULL?
Jun Mukai
2012/12/14 18:47:16
no... removed.
|
| + return std::string(); |
| + |
| + gfx::Display display = gfx::Screen::GetScreenFor( |
| + root_window)->GetDisplayNearestWindow(root_window); |
| + if (!display.is_valid()) |
| + return std::string(); |
|
oshima
2012/12/14 11:03:55
This shouldn't really happen. Can you add DCHECK()
Jun Mukai
2012/12/14 18:47:16
Done.
|
| + |
| + return base::Int64ToString(display.id()); |
| +} |
| + |
| +void UpdatePerDisplayPref(PrefService* pref_service, |
| + aura::RootWindow* root_window, |
| + const char* pref_key, |
| + const std::string& value) { |
| + std::string key = GetPrefKeyForRootWindow(root_window); |
| + if (key.empty()) |
| + return; |
| + |
| + DictionaryPrefUpdate update(pref_service, prefs::kShelfPreferences); |
| + base::DictionaryValue* shelf_prefs = update.Get(); |
| + base::DictionaryValue* prefs = NULL; |
| + if (!shelf_prefs->GetDictionary(key, &prefs)) { |
| + prefs = new base::DictionaryValue(); |
| + shelf_prefs->Set(key, prefs); |
| + } |
| + prefs->SetStringWithoutPathExpansion(pref_key, value); |
| +} |
| + |
| // If the value of the pref at |local_path is not empty, it is returned |
|
bartfab (slow)
2012/12/14 09:46:10
Nit (not your fault, but nice to fix): |local_path
Jun Mukai
2012/12/14 18:47:16
Done.
|
| // otherwise the value of the pref at |synced_path| is returned. |
| std::string GetLocalOrRemotePref(PrefService* pref_service, |
| + aura::RootWindow* root_window, |
| const char* local_path, |
| const char* synced_path) { |
| const std::string value(pref_service->GetString(local_path)); |
| + if (pref_service->FindPreference(local_path)->IsRecommended()) |
|
bartfab (slow)
2012/12/14 09:46:10
This should be IsManaged(). The logic should be, i
Jun Mukai
2012/12/14 18:47:16
Done.
|
| + return value; |
| + |
| + std::string pref_key = GetPrefKeyForRootWindow(root_window); |
| + if (!pref_key.empty()) { |
| + const base::DictionaryValue* shelf_prefs = pref_service->GetDictionary( |
| + prefs::kShelfPreferences); |
| + const base::DictionaryValue* display_pref = NULL; |
| + std::string per_display_value; |
| + if (shelf_prefs->GetDictionary(pref_key, &display_pref) && |
| + display_pref->GetString(synced_path, &per_display_value)) { |
|
bartfab (slow)
2012/12/14 09:46:10
You should renamed |synced_path| here and elsewher
Jun Mukai
2012/12/14 18:47:16
renamed to just 'path'
|
| + return per_display_value; |
| + } |
| + } |
| + |
| return value.empty() ? pref_service->GetString(synced_path) : value; |
| } |
| @@ -563,11 +611,10 @@ bool ChromeLauncherControllerPerApp::CanPin() const { |
| ash::ShelfAutoHideBehavior |
| ChromeLauncherControllerPerApp::GetShelfAutoHideBehavior( |
| aura::RootWindow* root_window) const { |
| - // TODO(oshima): Support multiple launchers. |
| - |
| // See comment in |kShelfAlignment| as to why we consider two prefs. |
| const std::string behavior_value( |
| GetLocalOrRemotePref(profile_->GetPrefs(), |
| + root_window, |
| prefs::kShelfAutoHideBehaviorLocal, |
| prefs::kShelfAutoHideBehavior)); |
| @@ -582,7 +629,6 @@ ash::ShelfAutoHideBehavior |
| bool ChromeLauncherControllerPerApp::CanUserModifyShelfAutoHideBehavior( |
| aura::RootWindow* root_window) const { |
| - // TODO(oshima): Support multiple launchers. |
| return profile_->GetPrefs()-> |
| FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable(); |
| } |
| @@ -797,11 +843,10 @@ void ChromeLauncherControllerPerApp::Observe( |
| } |
| } |
| -void ChromeLauncherControllerPerApp::OnShelfAlignmentChanged() { |
| +void ChromeLauncherControllerPerApp::OnShelfAlignmentChanged( |
| + aura::RootWindow* root_window) { |
| const char* pref_value = NULL; |
| - // TODO(oshima): Support multiple displays. |
| - switch (ash::Shell::GetInstance()->GetShelfAlignment( |
| - ash::Shell::GetPrimaryRootWindow())) { |
| + switch (ash::Shell::GetInstance()->GetShelfAlignment(root_window)) { |
| case ash::SHELF_ALIGNMENT_BOTTOM: |
| pref_value = ash::kShelfAlignmentBottom; |
| break; |
| @@ -812,9 +857,15 @@ void ChromeLauncherControllerPerApp::OnShelfAlignmentChanged() { |
| pref_value = ash::kShelfAlignmentRight; |
| break; |
| } |
| - // See comment in |kShelfAlignment| about why we have two prefs here. |
| - profile_->GetPrefs()->SetString(prefs::kShelfAlignmentLocal, pref_value); |
| - profile_->GetPrefs()->SetString(prefs::kShelfAlignment, pref_value); |
| + |
| + UpdatePerDisplayPref( |
| + profile_->GetPrefs(), root_window, prefs::kShelfAlignment, pref_value); |
| + |
| + if (root_window == ash::Shell::GetPrimaryRootWindow()) { |
| + // See comment in |kShelfAlignment| about why we have two prefs here. |
| + profile_->GetPrefs()->SetString(prefs::kShelfAlignmentLocal, pref_value); |
| + profile_->GetPrefs()->SetString(prefs::kShelfAlignment, pref_value); |
| + } |
| } |
| void ChromeLauncherControllerPerApp::OnIsSyncingChanged() { |
| @@ -989,10 +1040,6 @@ void ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref() { |
| void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorPrefs( |
| ash::ShelfAutoHideBehavior behavior, |
| aura::RootWindow* root_window) { |
| - // TODO(oshima): Support multiple launchers. |
| - if (root_window != ash::Shell::GetPrimaryRootWindow()) |
| - return; |
| - |
| const char* value = NULL; |
| switch (behavior) { |
| case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
| @@ -1002,16 +1049,24 @@ void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorPrefs( |
| value = ash::kShelfAutoHideBehaviorNever; |
| break; |
| } |
| - // See comment in |kShelfAlignment| about why we have two prefs here. |
| - profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value); |
| - profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value); |
| + |
| + UpdatePerDisplayPref( |
| + profile_->GetPrefs(), root_window, prefs::kShelfAutoHideBehavior, value); |
| + |
| + if (root_window == ash::Shell::GetPrimaryRootWindow()) { |
| + // See comment in |kShelfAlignment| about why we have two prefs here. |
| + profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value); |
| + profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value); |
| + } |
| } |
| void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorFromPrefs() { |
| - // TODO(oshima): Support multiple displays. |
| - aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow(); |
| - ash::Shell::GetInstance()->SetShelfAutoHideBehavior( |
| - GetShelfAutoHideBehavior(root_window), root_window); |
| + ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows(); |
| + for (ash::Shell::RootWindowList::const_iterator iter = root_windows.begin(); |
| + iter != root_windows.end(); ++iter) { |
| + ash::Shell::GetInstance()->SetShelfAutoHideBehavior( |
| + GetShelfAutoHideBehavior(*iter), *iter); |
| + } |
| } |
| void ChromeLauncherControllerPerApp::SetShelfAlignmentFromPrefs() { |
| @@ -1019,19 +1074,22 @@ void ChromeLauncherControllerPerApp::SetShelfAlignmentFromPrefs() { |
| switches::kShowLauncherAlignmentMenu)) |
| return; |
| - // See comment in |kShelfAlignment| as to why we consider two prefs. |
| - const std::string alignment_value( |
| - GetLocalOrRemotePref(profile_->GetPrefs(), |
| - prefs::kShelfAlignmentLocal, |
| - prefs::kShelfAlignment)); |
| - ash::ShelfAlignment alignment = ash::SHELF_ALIGNMENT_BOTTOM; |
| - if (alignment_value == ash::kShelfAlignmentLeft) |
| - alignment = ash::SHELF_ALIGNMENT_LEFT; |
| - else if (alignment_value == ash::kShelfAlignmentRight) |
| - alignment = ash::SHELF_ALIGNMENT_RIGHT; |
| - // TODO(oshima): Support multiple displays. |
| - ash::Shell::GetInstance()->SetShelfAlignment( |
| - alignment, ash::Shell::GetPrimaryRootWindow()); |
| + ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows(); |
| + for (ash::Shell::RootWindowList::const_iterator iter = root_windows.begin(); |
| + iter != root_windows.end(); ++iter) { |
| + // See comment in |kShelfAlignment| as to why we consider two prefs. |
| + const std::string alignment_value( |
| + GetLocalOrRemotePref(profile_->GetPrefs(), |
| + *iter, |
| + prefs::kShelfAlignmentLocal, |
| + prefs::kShelfAlignment)); |
| + ash::ShelfAlignment alignment = ash::SHELF_ALIGNMENT_BOTTOM; |
| + if (alignment_value == ash::kShelfAlignmentLeft) |
| + alignment = ash::SHELF_ALIGNMENT_LEFT; |
| + else if (alignment_value == ash::kShelfAlignmentRight) |
| + alignment = ash::SHELF_ALIGNMENT_RIGHT; |
| + ash::Shell::GetInstance()->SetShelfAlignment(alignment, *iter); |
| + } |
| } |
| WebContents* ChromeLauncherControllerPerApp::GetLastActiveWebContents( |