1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/system/overview/overview_button_tray.h"
7 #include "ash/session/session_state_delegate.h"
8 #include "ash/shelf/shelf_types.h"
10 #include "ash/system/tray/system_tray_delegate.h"
11 #include "ash/system/tray/tray_utils.h"
12 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
13 #include "ash/wm/overview/window_selector_controller.h"
14 #include "grit/ash_resources.h"
15 #include "grit/ash_strings.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/views/border.h"
19 #include "ui/views/controls/image_view.h"
23 // Predefined padding for the icon used in this tray. These are to be set to the
24 // border of the icon, depending on the current shelf_alignment()
25 const int kHorizontalShelfHorizontalPadding
= 8;
26 const int kHorizontalShelfVerticalPadding
= 4;
27 const int kVerticalShelfHorizontalPadding
= 2;
28 const int kVerticalShelfVerticalPadding
= 5;
34 OverviewButtonTray::OverviewButtonTray(StatusAreaWidget
* status_area_widget
)
35 : TrayBackgroundView(status_area_widget
), icon_(NULL
) {
36 SetContentsBackground();
38 ui::ResourceBundle
& bundle
= ui::ResourceBundle::GetSharedInstance();
39 icon_
= new views::ImageView();
41 bundle
.GetImageNamed(IDR_AURA_UBER_TRAY_OVERVIEW_MODE
).ToImageSkia());
42 SetIconBorderForShelfAlignment();
43 tray_container()->AddChildView(icon_
);
45 Shell::GetInstance()->AddShellObserver(this);
46 Shell::GetInstance()->session_state_delegate()->AddSessionStateObserver(this);
49 OverviewButtonTray::~OverviewButtonTray() {
50 Shell::GetInstance()->RemoveShellObserver(this);
51 Shell::GetInstance()->session_state_delegate()->RemoveSessionStateObserver(
55 void OverviewButtonTray::UpdateAfterLoginStatusChange(
56 user::LoginStatus status
) {
57 UpdateIconVisibility();
60 bool OverviewButtonTray::PerformAction(const ui::Event
& event
) {
61 WindowSelectorController
* controller
=
62 Shell::GetInstance()->window_selector_controller();
63 controller
->ToggleOverview();
64 SetDrawBackgroundAsActive(controller
->IsSelecting());
65 Shell::GetInstance()->metrics()->RecordUserMetricsAction(UMA_TRAY_OVERVIEW
);
69 void OverviewButtonTray::SessionStateChanged(
70 SessionStateDelegate::SessionState state
) {
71 UpdateIconVisibility();
74 void OverviewButtonTray::OnMaximizeModeStarted() {
75 UpdateIconVisibility();
78 void OverviewButtonTray::OnMaximizeModeEnded() {
79 UpdateIconVisibility();
82 void OverviewButtonTray::OnOverviewModeEnded() {
83 SetDrawBackgroundAsActive(false);
86 bool OverviewButtonTray::ClickedOutsideBubble() {
87 // This class has no bubbles dismiss, but acknowledge that the message was
92 base::string16
OverviewButtonTray::GetAccessibleNameForTray() {
93 return l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME
);
96 void OverviewButtonTray::HideBubbleWithView(
97 const views::TrayBubbleView
* bubble_view
) {
98 // This class has no bubbles to hide.
101 void OverviewButtonTray::SetShelfAlignment(ShelfAlignment alignment
) {
102 if (alignment
== shelf_alignment())
105 TrayBackgroundView::SetShelfAlignment(alignment
);
106 SetIconBorderForShelfAlignment();
109 void OverviewButtonTray::SetIconBorderForShelfAlignment() {
110 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM
||
111 shelf_alignment() == SHELF_ALIGNMENT_TOP
) {
112 icon_
->SetBorder(views::Border::CreateEmptyBorder(
113 kHorizontalShelfVerticalPadding
,
114 kHorizontalShelfHorizontalPadding
,
115 kHorizontalShelfVerticalPadding
,
116 kHorizontalShelfHorizontalPadding
));
118 icon_
->SetBorder(views::Border::CreateEmptyBorder(
119 kVerticalShelfVerticalPadding
,
120 kVerticalShelfHorizontalPadding
,
121 kVerticalShelfVerticalPadding
,
122 kVerticalShelfHorizontalPadding
));
126 void OverviewButtonTray::UpdateIconVisibility() {
127 // The visibility of the OverviewButtonTray has diverge from
128 // WindowSelectorController::CanSelect. The visibility of the button should
129 // not change during transient times in which CanSelect is false. Such as when
130 // a modal dialog is present.
131 Shell
* shell
= Shell::GetInstance();
132 SessionStateDelegate
* session_state_delegate
=
133 shell
->session_state_delegate();
136 shell
->maximize_mode_controller()->IsMaximizeModeWindowManagerEnabled() &&
137 session_state_delegate
->IsActiveUserSessionStarted() &&
138 !session_state_delegate
->IsScreenLocked() &&
139 session_state_delegate
->GetSessionState() ==
140 SessionStateDelegate::SESSION_STATE_ACTIVE
&&
141 shell
->system_tray_delegate()->GetUserLoginStatus() !=
142 user::LOGGED_IN_KIOSK_APP
);