OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/common/system/chromeos/palette/palette_tray.h" | 5 #include "ash/common/system/chromeos/palette/palette_tray.h" |
6 | 6 |
| 7 #include "ash/common/palette_delegate.h" |
7 #include "ash/common/shelf/shelf_constants.h" | 8 #include "ash/common/shelf/shelf_constants.h" |
8 #include "ash/common/shelf/wm_shelf.h" | 9 #include "ash/common/shelf/wm_shelf.h" |
9 #include "ash/common/shelf/wm_shelf_util.h" | 10 #include "ash/common/shelf/wm_shelf_util.h" |
10 #include "ash/common/shell_window_ids.h" | 11 #include "ash/common/shell_window_ids.h" |
11 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" | 12 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" |
12 #include "ash/common/system/chromeos/palette/palette_utils.h" | 13 #include "ash/common/system/chromeos/palette/palette_utils.h" |
13 #include "ash/common/system/tray/system_tray_delegate.h" | 14 #include "ash/common/system/tray/system_tray_delegate.h" |
14 #include "ash/common/system/tray/tray_bubble_wrapper.h" | 15 #include "ash/common/system/tray/tray_bubble_wrapper.h" |
15 #include "ash/common/system/tray/tray_constants.h" | 16 #include "ash/common/system/tray/tray_constants.h" |
16 #include "ash/common/system/tray/tray_popup_header_button.h" | 17 #include "ash/common/system/tray/tray_popup_header_button.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 ash::TrayPopupHeaderButton* help_button_; | 111 ash::TrayPopupHeaderButton* help_button_; |
111 PaletteTray* palette_tray_; | 112 PaletteTray* palette_tray_; |
112 | 113 |
113 DISALLOW_COPY_AND_ASSIGN(TitleView); | 114 DISALLOW_COPY_AND_ASSIGN(TitleView); |
114 }; | 115 }; |
115 | 116 |
116 } // namespace | 117 } // namespace |
117 | 118 |
118 PaletteTray::PaletteTray(WmShelf* wm_shelf) | 119 PaletteTray::PaletteTray(WmShelf* wm_shelf) |
119 : TrayBackgroundView(wm_shelf), | 120 : TrayBackgroundView(wm_shelf), |
120 palette_tool_manager_(new PaletteToolManager(this)) { | 121 palette_tool_manager_(new PaletteToolManager(this)), |
| 122 weak_factory_(this) { |
| 123 // PaletteTray should only be instantiated if the palette feature is enabled. |
| 124 DCHECK(IsPaletteFeatureEnabled()); |
| 125 |
121 PaletteTool::RegisterToolInstances(palette_tool_manager_.get()); | 126 PaletteTool::RegisterToolInstances(palette_tool_manager_.get()); |
122 | 127 |
123 SetContentsBackground(); | 128 SetContentsBackground(); |
124 | 129 |
125 SetLayoutManager(new views::FillLayout()); | 130 SetLayoutManager(new views::FillLayout()); |
126 icon_ = new views::ImageView(); | 131 icon_ = new views::ImageView(); |
127 UpdateTrayIcon(); | 132 UpdateTrayIcon(); |
128 | 133 |
129 SetIconBorderForShelfAlignment(); | 134 SetIconBorderForShelfAlignment(); |
130 tray_container()->AddChildView(icon_); | 135 tray_container()->AddChildView(icon_); |
131 | 136 |
132 WmShell::Get()->AddShellObserver(this); | 137 WmShell::Get()->AddShellObserver(this); |
133 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this); | 138 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this); |
134 | 139 |
135 UpdateIconVisibility(); | 140 // OnPaletteEnabledPrefChanged will get called with the initial pref value, |
| 141 // which will take care of showing the palette. |
| 142 palette_enabled_ = |
| 143 WmShell::Get()->palette_delegate()->AddPaletteEnableListener( |
| 144 base::Bind(&PaletteTray::OnPaletteEnabledPrefChanged, |
| 145 weak_factory_.GetWeakPtr())); |
136 } | 146 } |
137 | 147 |
138 PaletteTray::~PaletteTray() { | 148 PaletteTray::~PaletteTray() { |
139 if (bubble_) | 149 if (bubble_) |
140 bubble_->bubble_view()->reset_delegate(); | 150 bubble_->bubble_view()->reset_delegate(); |
141 | 151 |
142 WmShell::Get()->RemoveShellObserver(this); | 152 WmShell::Get()->RemoveShellObserver(this); |
143 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); | 153 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); |
144 } | 154 } |
145 | 155 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 kVerticalShelfVerticalPadding, kVerticalShelfHorizontalPadding))); | 311 kVerticalShelfVerticalPadding, kVerticalShelfHorizontalPadding))); |
302 } | 312 } |
303 } | 313 } |
304 | 314 |
305 void PaletteTray::UpdateTrayIcon() { | 315 void PaletteTray::UpdateTrayIcon() { |
306 gfx::VectorIconId icon = palette_tool_manager_->GetActiveTrayIcon( | 316 gfx::VectorIconId icon = palette_tool_manager_->GetActiveTrayIcon( |
307 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)); | 317 palette_tool_manager_->GetActiveTool(ash::PaletteGroup::MODE)); |
308 icon_->SetImage(CreateVectorIcon(icon, kShelfIconColor)); | 318 icon_->SetImage(CreateVectorIcon(icon, kShelfIconColor)); |
309 } | 319 } |
310 | 320 |
| 321 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { |
| 322 if (!enabled) |
| 323 SetVisible(false); |
| 324 else |
| 325 UpdateIconVisibility(); |
| 326 } |
| 327 |
311 void PaletteTray::UpdateIconVisibility() { | 328 void PaletteTray::UpdateIconVisibility() { |
312 if (!IsPaletteEnabled()) | |
313 return; | |
314 | |
315 SessionStateDelegate* session_state_delegate = | 329 SessionStateDelegate* session_state_delegate = |
316 WmShell::Get()->GetSessionStateDelegate(); | 330 WmShell::Get()->GetSessionStateDelegate(); |
317 | 331 |
318 SetVisible(!session_state_delegate->IsScreenLocked() && | 332 SetVisible(!session_state_delegate->IsScreenLocked() && |
319 session_state_delegate->GetSessionState() == | 333 session_state_delegate->GetSessionState() == |
320 SessionStateDelegate::SESSION_STATE_ACTIVE && | 334 SessionStateDelegate::SESSION_STATE_ACTIVE && |
321 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != | 335 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != |
322 LoginStatus::KIOSK_APP); | 336 LoginStatus::KIOSK_APP); |
323 } | 337 } |
324 | 338 |
325 } // namespace ash | 339 } // namespace ash |
OLD | NEW |