| Index: ash/common/system/chromeos/palette/palette_tray.cc
|
| diff --git a/ash/common/system/chromeos/palette/palette_tray.cc b/ash/common/system/chromeos/palette/palette_tray.cc
|
| index 95db0eb52129b14519923333ddcda48946a8de90..3aa6bfe85e386d088db5bbdb22fa9d60d547fabe 100644
|
| --- a/ash/common/system/chromeos/palette/palette_tray.cc
|
| +++ b/ash/common/system/chromeos/palette/palette_tray.cc
|
| @@ -4,6 +4,7 @@
|
|
|
| #include "ash/common/system/chromeos/palette/palette_tray.h"
|
|
|
| +#include "ash/common/palette_delegate.h"
|
| #include "ash/common/shelf/shelf_constants.h"
|
| #include "ash/common/shelf/wm_shelf.h"
|
| #include "ash/common/shelf/wm_shelf_util.h"
|
| @@ -117,7 +118,11 @@ class TitleView : public views::View, public views::ButtonListener {
|
|
|
| PaletteTray::PaletteTray(WmShelf* wm_shelf)
|
| : TrayBackgroundView(wm_shelf),
|
| - palette_tool_manager_(new PaletteToolManager(this)) {
|
| + palette_tool_manager_(new PaletteToolManager(this)),
|
| + weak_factory_(this) {
|
| + // PaletteTray should only be instantiated if the palette feature is enabled.
|
| + DCHECK(IsPaletteFeatureEnabled());
|
| +
|
| PaletteTool::RegisterToolInstances(palette_tool_manager_.get());
|
|
|
| SetContentsBackground();
|
| @@ -132,7 +137,12 @@ PaletteTray::PaletteTray(WmShelf* wm_shelf)
|
| WmShell::Get()->AddShellObserver(this);
|
| WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this);
|
|
|
| - UpdateIconVisibility();
|
| + // OnPaletteEnabledPrefChanged will get called with the initial pref value,
|
| + // which will take care of showing the palette.
|
| + palette_enabled_ =
|
| + WmShell::Get()->palette_delegate()->AddPaletteEnableListener(
|
| + base::Bind(&PaletteTray::OnPaletteEnabledPrefChanged,
|
| + weak_factory_.GetWeakPtr()));
|
| }
|
|
|
| PaletteTray::~PaletteTray() {
|
| @@ -308,10 +318,14 @@ void PaletteTray::UpdateTrayIcon() {
|
| icon_->SetImage(CreateVectorIcon(icon, kShelfIconColor));
|
| }
|
|
|
| -void PaletteTray::UpdateIconVisibility() {
|
| - if (!IsPaletteEnabled())
|
| - return;
|
| +void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) {
|
| + if (!enabled)
|
| + SetVisible(false);
|
| + else
|
| + UpdateIconVisibility();
|
| +}
|
|
|
| +void PaletteTray::UpdateIconVisibility() {
|
| SessionStateDelegate* session_state_delegate =
|
| WmShell::Get()->GetSessionStateDelegate();
|
|
|
|
|