summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-17 19:21:18 +0000
committermukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-17 19:21:18 +0000
commitf89f751c3504095593e99170392dc361b1dbf0cc (patch)
tree11def2b2ad64c8afe6416b149828379d667affd1
parent5d5a35d75f4f9e514895da35b79816ea2f7ab618 (diff)
downloadchromium_src-f89f751c3504095593e99170392dc361b1dbf0cc.zip
chromium_src-f89f751c3504095593e99170392dc361b1dbf0cc.tar.gz
chromium_src-f89f751c3504095593e99170392dc361b1dbf0cc.tar.bz2
Enables storing shelf's auto_hide_behavior and alignment per display.
BUG=165419 TEST=on a dev-mode device, change the launcher's auto-hide behavior and see how it's stored in Preferences Review URL: https://codereview.chromium.org/11570017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173508 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/shell.cc6
-rw-r--r--ash/shell_observer.h8
-rw-r--r--ash/wm/app_list_controller.cc2
-rw-r--r--ash/wm/app_list_controller.h2
-rw-r--r--chrome/browser/ui/ash/chrome_launcher_prefs.cc2
-rw-r--r--chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.cc146
-rw-r--r--chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h2
-rw-r--r--chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.cc146
-rw-r--r--chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h2
-rw-r--r--chrome/common/pref_names.cc7
-rw-r--r--chrome/common/pref_names.h1
11 files changed, 236 insertions, 88 deletions
diff --git a/ash/shell.cc b/ash/shell.cc
index 65ba167..84a1b41 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -727,8 +727,10 @@ ShelfAutoHideBehavior Shell::GetShelfAutoHideBehavior(
void Shell::SetShelfAlignment(ShelfAlignment alignment,
aura::RootWindow* root_window) {
- if (GetRootWindowController(root_window)->SetShelfAlignment(alignment))
- FOR_EACH_OBSERVER(ShellObserver, observers_, OnShelfAlignmentChanged());
+ if (GetRootWindowController(root_window)->SetShelfAlignment(alignment)) {
+ FOR_EACH_OBSERVER(
+ ShellObserver, observers_, OnShelfAlignmentChanged(root_window));
+ }
}
ShelfAlignment Shell::GetShelfAlignment(aura::RootWindow* root_window) {
diff --git a/ash/shell_observer.h b/ash/shell_observer.h
index 6cbeaa7..0bdd934 100644
--- a/ash/shell_observer.h
+++ b/ash/shell_observer.h
@@ -8,6 +8,10 @@
#include "ash/ash_export.h"
#include "ash/system/user/login_status.h"
+namespace aura {
+class RootWindow;
+}
+
namespace ash {
class ASH_EXPORT ShellObserver {
@@ -25,8 +29,8 @@ class ASH_EXPORT ShellObserver {
// unlocked.
virtual void OnLockStateChanged(bool locked) {}
- // Invoked when the shelf alignment is changed.
- virtual void OnShelfAlignmentChanged() {}
+ // Invoked when the shelf alignment in |root_window| is changed.
+ virtual void OnShelfAlignmentChanged(aura::RootWindow* root_window) {}
protected:
virtual ~ShellObserver() {}
diff --git a/ash/wm/app_list_controller.cc b/ash/wm/app_list_controller.cc
index bcc85e5..3bfe4ca 100644
--- a/ash/wm/app_list_controller.cc
+++ b/ash/wm/app_list_controller.cc
@@ -285,7 +285,7 @@ void AppListController::OnWidgetClosing(views::Widget* widget) {
////////////////////////////////////////////////////////////////////////////////
// AppListController, ShellObserver implementation:
-void AppListController::OnShelfAlignmentChanged() {
+void AppListController::OnShelfAlignmentChanged(aura::RootWindow* root_window) {
if (view_) {
view_->SetBubbleArrowLocation(GetBubbleArrowLocation(
view_->GetWidget()->GetNativeView()));
diff --git a/ash/wm/app_list_controller.h b/ash/wm/app_list_controller.h
index 9111370..f396052 100644
--- a/ash/wm/app_list_controller.h
+++ b/ash/wm/app_list_controller.h
@@ -95,7 +95,7 @@ class AppListController : public ui::EventHandler,
virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE;
// ShellObserver overrides:
- virtual void OnShelfAlignmentChanged() OVERRIDE;
+ virtual void OnShelfAlignmentChanged(aura::RootWindow* root_window) OVERRIDE;
// LauncherIconObserver overrides:
virtual void OnLauncherIconPositionsChanged() OVERRIDE;
diff --git a/chrome/browser/ui/ash/chrome_launcher_prefs.cc b/chrome/browser/ui/ash/chrome_launcher_prefs.cc
index 15b6d7e..985e3e5 100644
--- a/chrome/browser/ui/ash/chrome_launcher_prefs.cc
+++ b/chrome/browser/ui/ash/chrome_launcher_prefs.cc
@@ -62,6 +62,8 @@ void RegisterChromeLauncherUserPrefs(PrefService* user_prefs) {
user_prefs->RegisterBooleanPref(prefs::kShowLogoutButtonInTray,
false,
PrefService::UNSYNCABLE_PREF);
+ user_prefs->RegisterDictionaryPref(prefs::kShelfPreferences,
+ PrefService::UNSYNCABLE_PREF);
}
base::DictionaryValue* CreateAppDict(const std::string& app_id) {
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 3e5262e..ebc70b4 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,13 +120,67 @@ class AppShortcutLauncherItemController : public LauncherItemController {
DISALLOW_COPY_AND_ASSIGN(AppShortcutLauncherItemController);
};
-// If the value of the pref at |local_path is not empty, it is returned
-// otherwise the value of the pref at |synced_path| is returned.
-std::string GetLocalOrRemotePref(PrefService* pref_service,
+std::string GetPrefKeyForRootWindow(aura::RootWindow* root_window) {
+ gfx::Display display = gfx::Screen::GetScreenFor(
+ root_window)->GetDisplayNearestWindow(root_window);
+ DCHECK(display.is_valid());
+
+ 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);
+}
+
+// Returns a pref value in |pref_service| for the display of |root_window|. The
+// pref value is stored in |local_path| and |path|, but |pref_service| may have
+// per-display preferences and the value can be specified by policy. Here is
+// the priority:
+// * A value managed by policy. This is a single value that applies to all
+// displays.
+// * A user-set value for the specified display.
+// * A user-set value in |local_path| or |path|. |local_path| is preferred. See
+// comment in |kShelfAlignment| as to why we consider two prefs and why
+// |local_path| is preferred.
+// * A value recommended by policy. This is a single value that applies to all
+// root windows.
+std::string GetPrefForRootWindow(PrefService* pref_service,
+ aura::RootWindow* root_window,
const char* local_path,
- const char* synced_path) {
+ const char* path) {
+ const PrefService::Preference* local_pref =
+ pref_service->FindPreference(local_path);
const std::string value(pref_service->GetString(local_path));
- return value.empty() ? pref_service->GetString(synced_path) : value;
+ if (local_pref->IsManaged())
+ 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(path, &per_display_value)) {
+ return per_display_value;
+ }
+ }
+
+ return value;
}
// If prefs have synced and no user-set value exists at |local_path|, the value
@@ -563,11 +619,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(),
+ GetPrefForRootWindow(profile_->GetPrefs(),
+ root_window,
prefs::kShelfAutoHideBehaviorLocal,
prefs::kShelfAutoHideBehavior));
@@ -582,7 +637,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 +851,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 +865,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 +1048,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 +1057,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 +1082,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(
+ GetPrefForRootWindow(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(
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h
index b63f4f4..7288355 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.h
@@ -248,7 +248,7 @@ class ChromeLauncherControllerPerApp
const content::NotificationDetails& details) OVERRIDE;
// Overridden from ash::ShellObserver:
- virtual void OnShelfAlignmentChanged() OVERRIDE;
+ virtual void OnShelfAlignmentChanged(aura::RootWindow* root_window) OVERRIDE;
// Overridden from PrefServiceObserver:
virtual void OnIsSyncingChanged() OVERRIDE;
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.cc
index a0a5bb1..3691d95 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.cc
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.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;
@@ -119,13 +121,67 @@ class AppShortcutLauncherItemController : public LauncherItemController {
DISALLOW_COPY_AND_ASSIGN(AppShortcutLauncherItemController);
};
-// If the value of the pref at |local_path is not empty, it is returned
-// otherwise the value of the pref at |synced_path| is returned.
-std::string GetLocalOrRemotePref(PrefService* pref_service,
+std::string GetPrefKeyForRootWindow(aura::RootWindow* root_window) {
+ gfx::Display display = gfx::Screen::GetScreenFor(
+ root_window)->GetDisplayNearestWindow(root_window);
+ DCHECK(display.is_valid());
+
+ 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);
+}
+
+// Returns a pref value in |pref_service| for the display of |root_window|. The
+// pref value is stored in |local_path| and |path|, but |pref_service| may have
+// per-display preferences and the value can be specified by policy. Here is
+// the priority:
+// * A value managed by policy. This is a single value that applies to all
+// displays.
+// * A user-set value for the specified display.
+// * A user-set value in |local_path| or |path|. |local_path| is preferred. See
+// comment in |kShelfAlignment| as to why we consider two prefs and why
+// |local_path| is preferred.
+// * A value recommended by policy. This is a single value that applies to all
+// root windows.
+std::string GetPrefForRootWindow(PrefService* pref_service,
+ aura::RootWindow* root_window,
const char* local_path,
- const char* synced_path) {
+ const char* path) {
+ const PrefService::Preference* local_pref =
+ pref_service->FindPreference(local_path);
const std::string value(pref_service->GetString(local_path));
- return value.empty() ? pref_service->GetString(synced_path) : value;
+ if (local_pref->IsManaged())
+ 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(path, &per_display_value)) {
+ return per_display_value;
+ }
+ }
+
+ return value;
}
// If prefs have synced and no user-set value exists at |local_path|, the value
@@ -570,11 +626,10 @@ bool ChromeLauncherControllerPerBrowser::CanPin() const {
ash::ShelfAutoHideBehavior
ChromeLauncherControllerPerBrowser::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(),
+ GetPrefForRootWindow(profile_->GetPrefs(),
+ root_window,
prefs::kShelfAutoHideBehaviorLocal,
prefs::kShelfAutoHideBehavior));
@@ -589,7 +644,6 @@ ash::ShelfAutoHideBehavior
bool ChromeLauncherControllerPerBrowser::CanUserModifyShelfAutoHideBehavior(
aura::RootWindow* root_window) const {
- // TODO(oshima): Support multiple launchers.
return profile_->GetPrefs()->
FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable();
}
@@ -805,11 +859,10 @@ void ChromeLauncherControllerPerBrowser::Observe(
}
}
-void ChromeLauncherControllerPerBrowser::OnShelfAlignmentChanged() {
+void ChromeLauncherControllerPerBrowser::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;
@@ -820,9 +873,15 @@ void ChromeLauncherControllerPerBrowser::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 ChromeLauncherControllerPerBrowser::OnIsSyncingChanged() {
@@ -999,10 +1058,6 @@ void ChromeLauncherControllerPerBrowser::UpdateAppLaunchersFromPref() {
void ChromeLauncherControllerPerBrowser::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:
@@ -1012,16 +1067,24 @@ void ChromeLauncherControllerPerBrowser::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 ChromeLauncherControllerPerBrowser::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 ChromeLauncherControllerPerBrowser::SetShelfAlignmentFromPrefs() {
@@ -1029,19 +1092,22 @@ void ChromeLauncherControllerPerBrowser::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(
+ GetPrefForRootWindow(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* ChromeLauncherControllerPerBrowser::GetLastActiveWebContents(
diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h
index e30c682..e961afc 100644
--- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h
+++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.h
@@ -250,7 +250,7 @@ class ChromeLauncherControllerPerBrowser
const content::NotificationDetails& details) OVERRIDE;
// Overridden from ash::ShellObserver:
- virtual void OnShelfAlignmentChanged() OVERRIDE;
+ virtual void OnShelfAlignmentChanged(aura::RootWindow* root_window) OVERRIDE;
// Overridden from PrefServiceObserver:
virtual void OnIsSyncingChanged() OVERRIDE;
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index c20b9ba..7bc0ca6 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -2103,6 +2103,8 @@ const char kMediaGalleriesRememberedGalleries[] =
// set its value is set from the synced value (once prefs have been
// synced). This gives a per-machine setting that is initialized from the last
// set value.
+// These values are default on the machine but can be overridden by per-display
+// values in kShelfPreferences (unless overridden by managed policy).
// String value corresponding to ash::Shell::ShelfAlignment.
const char kShelfAlignment[] = "shelf_alignment";
const char kShelfAlignmentLocal[] = "shelf_alignment_local";
@@ -2112,6 +2114,11 @@ const char kShelfAutoHideBehaviorLocal[] = "auto_hide_behavior_local";
const char kPinnedLauncherApps[] = "pinned_launcher_apps";
// Boolean value indicating whether to show a logout button in the ash tray.
const char kShowLogoutButtonInTray[] = "show_logout_button_in_tray";
+// Dictionary value that holds per-display preference of shelf alignment and
+// auto-hide behavior. Key of the dictionary is the id of the display, and
+// its value is a dictionary whose keys are kShelfAlignment and
+// kShelfAutoHideBehavior.
+const char kShelfPreferences[] = "shelf_preferences";
const char kFlingVelocityCap[] = "gesture.fling_velocity_cap";
const char kLongPressTimeInSeconds[] =
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 572e06a..c2a6648 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -766,6 +766,7 @@ extern const char kShelfAutoHideBehavior[];
extern const char kShelfAutoHideBehaviorLocal[];
extern const char kPinnedLauncherApps[];
extern const char kShowLogoutButtonInTray[];
+extern const char kShelfPreferences[];
extern const char kFlingVelocityCap[];
extern const char kLongPressTimeInSeconds[];