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" | |
8 #include "ash/common/shelf/shelf_constants.h" | 7 #include "ash/common/shelf/shelf_constants.h" |
9 #include "ash/common/shelf/wm_shelf.h" | 8 #include "ash/common/shelf/wm_shelf.h" |
10 #include "ash/common/shelf/wm_shelf_util.h" | 9 #include "ash/common/shelf/wm_shelf_util.h" |
11 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
12 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" | 11 #include "ash/common/system/chromeos/palette/palette_tool_manager.h" |
13 #include "ash/common/system/chromeos/palette/palette_utils.h" | 12 #include "ash/common/system/chromeos/palette/palette_utils.h" |
14 #include "ash/common/system/tray/system_tray_delegate.h" | 13 #include "ash/common/system/tray/system_tray_delegate.h" |
15 #include "ash/common/system/tray/tray_bubble_wrapper.h" | 14 #include "ash/common/system/tray/tray_bubble_wrapper.h" |
16 #include "ash/common/system/tray/tray_constants.h" | 15 #include "ash/common/system/tray/tray_constants.h" |
17 #include "ash/common/system/tray/tray_popup_header_button.h" | 16 #include "ash/common/system/tray/tray_popup_header_button.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 116 |
118 DISALLOW_COPY_AND_ASSIGN(TitleView); | 117 DISALLOW_COPY_AND_ASSIGN(TitleView); |
119 }; | 118 }; |
120 | 119 |
121 } // namespace | 120 } // namespace |
122 | 121 |
123 PaletteTray::PaletteTray(WmShelf* wm_shelf) | 122 PaletteTray::PaletteTray(WmShelf* wm_shelf) |
124 : TrayBackgroundView(wm_shelf), | 123 : TrayBackgroundView(wm_shelf), |
125 palette_tool_manager_(new PaletteToolManager(this)), | 124 palette_tool_manager_(new PaletteToolManager(this)), |
126 weak_factory_(this) { | 125 weak_factory_(this) { |
| 126 // PaletteTray should only be instantiated if the palette feature is enabled. |
| 127 DCHECK(IsPaletteFeatureEnabled()); |
| 128 |
127 PaletteTool::RegisterToolInstances(palette_tool_manager_.get()); | 129 PaletteTool::RegisterToolInstances(palette_tool_manager_.get()); |
128 | 130 |
129 SetContentsBackground(); | 131 SetContentsBackground(); |
130 | 132 |
131 SetLayoutManager(new views::FillLayout()); | 133 SetLayoutManager(new views::FillLayout()); |
132 icon_ = new views::ImageView(); | 134 icon_ = new views::ImageView(); |
133 UpdateTrayIcon(); | 135 UpdateTrayIcon(); |
134 | 136 |
135 SetIconBorderForShelfAlignment(); | 137 SetIconBorderForShelfAlignment(); |
136 tray_container()->AddChildView(icon_); | 138 tray_container()->AddChildView(icon_); |
137 | 139 |
138 WmShell::Get()->AddShellObserver(this); | 140 WmShell::Get()->AddShellObserver(this); |
139 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this); | 141 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this); |
140 if (WmShell::Get()->palette_delegate()) { | 142 if (WmShell::Get()->palette_delegate()) { |
141 WmShell::Get()->palette_delegate()->SetStylusStateChangedCallback( | 143 WmShell::Get()->palette_delegate()->SetStylusStateChangedCallback( |
142 base::Bind(&PaletteTray::OnStylusStateChanged, | 144 base::Bind(&PaletteTray::OnStylusStateChanged, |
143 weak_factory_.GetWeakPtr())); | 145 weak_factory_.GetWeakPtr())); |
144 } | 146 } |
145 | 147 |
146 UpdateIconVisibility(); | 148 // OnPaletteEnabledPrefChanged will get called with the initial pref value, |
| 149 // which will take care of showing the palette. |
| 150 palette_enabled_subscription_ = |
| 151 WmShell::Get()->palette_delegate()->AddPaletteEnableListener( |
| 152 base::Bind(&PaletteTray::OnPaletteEnabledPrefChanged, |
| 153 weak_factory_.GetWeakPtr())); |
147 } | 154 } |
148 | 155 |
149 PaletteTray::~PaletteTray() { | 156 PaletteTray::~PaletteTray() { |
150 if (bubble_) | 157 if (bubble_) |
151 bubble_->bubble_view()->reset_delegate(); | 158 bubble_->bubble_view()->reset_delegate(); |
152 | 159 |
153 WmShell::Get()->RemoveShellObserver(this); | 160 WmShell::Get()->RemoveShellObserver(this); |
154 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); | 161 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); |
155 } | 162 } |
156 | 163 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { | 333 void PaletteTray::OnStylusStateChanged(ui::StylusState stylus_state) { |
327 if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette()) | 334 if (!WmShell::Get()->palette_delegate()->ShouldAutoOpenPalette()) |
328 return; | 335 return; |
329 | 336 |
330 if (stylus_state == ui::StylusState::REMOVED && !bubble_) | 337 if (stylus_state == ui::StylusState::REMOVED && !bubble_) |
331 OpenBubble(); | 338 OpenBubble(); |
332 else if (stylus_state == ui::StylusState::INSERTED && bubble_) | 339 else if (stylus_state == ui::StylusState::INSERTED && bubble_) |
333 bubble_.reset(); | 340 bubble_.reset(); |
334 } | 341 } |
335 | 342 |
| 343 void PaletteTray::OnPaletteEnabledPrefChanged(bool enabled) { |
| 344 if (!enabled) |
| 345 SetVisible(false); |
| 346 else |
| 347 UpdateIconVisibility(); |
| 348 } |
| 349 |
336 void PaletteTray::UpdateIconVisibility() { | 350 void PaletteTray::UpdateIconVisibility() { |
337 if (!IsPaletteEnabled()) | |
338 return; | |
339 | |
340 SessionStateDelegate* session_state_delegate = | 351 SessionStateDelegate* session_state_delegate = |
341 WmShell::Get()->GetSessionStateDelegate(); | 352 WmShell::Get()->GetSessionStateDelegate(); |
342 | 353 |
343 SetVisible(!session_state_delegate->IsScreenLocked() && | 354 SetVisible(!session_state_delegate->IsScreenLocked() && |
344 session_state_delegate->GetSessionState() == | 355 session_state_delegate->GetSessionState() == |
345 SessionStateDelegate::SESSION_STATE_ACTIVE && | 356 SessionStateDelegate::SESSION_STATE_ACTIVE && |
346 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != | 357 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus() != |
347 LoginStatus::KIOSK_APP); | 358 LoginStatus::KIOSK_APP); |
348 } | 359 } |
349 | 360 |
350 } // namespace ash | 361 } // namespace ash |
OLD | NEW |