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/shelf/shelf_types.h"
9 #include "ash/system/tray/system_tray_delegate.h"
10 #include "ash/system/tray/tray_utils.h"
11 #include "ash/wm/overview/window_selector_controller.h"
12 #include "grit/ash_resources.h"
13 #include "grit/ash_strings.h"
14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/views/border.h"
17 #include "ui/views/controls/image_view.h"
21 // Predefined padding for the icon used in this tray. These are to be set to the
22 // border of the icon, depending on the current shelf_alignment()
23 const int kHorizontalShelfHorizontalPadding = 8;
24 const int kHorizontalShelfVerticalPadding = 4;
25 const int kVerticalShelfHorizontalPadding = 2;
26 const int kVerticalShelfVerticalPadding = 5;
32 OverviewButtonTray::OverviewButtonTray(StatusAreaWidget* status_area_widget)
33 : TrayBackgroundView(status_area_widget), icon_(NULL) {
34 SetContentsBackground();
36 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
37 icon_ = new views::ImageView();
39 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_OVERVIEW_MODE).ToImageSkia());
40 SetIconBorderForShelfAlignment();
41 tray_container()->AddChildView(icon_);
43 UpdateIconVisibility(Shell::GetInstance()->
44 IsMaximizeModeWindowManagerEnabled());
46 Shell::GetInstance()->AddShellObserver(this);
49 OverviewButtonTray::~OverviewButtonTray() {
50 Shell::GetInstance()->RemoveShellObserver(this);
53 void OverviewButtonTray::UpdateAfterLoginStatusChange(
54 user::LoginStatus status) {
55 UpdateIconVisibility(Shell::GetInstance()->
56 IsMaximizeModeWindowManagerEnabled());
59 bool OverviewButtonTray::PerformAction(const ui::Event& event) {
60 Shell::GetInstance()->window_selector_controller()->ToggleOverview();
64 void OverviewButtonTray::OnMaximizeModeStarted() {
65 // TODO(flackr): once maximize mode has been refactored remove this so that
66 // UpdateIconVisibility polls Shell for the status directly
67 UpdateIconVisibility(/* maximize_mode_enabled */ true);
70 void OverviewButtonTray::OnMaximizeModeEnded() {
71 UpdateIconVisibility(/* maximize_mode_enabled */ false);
74 bool OverviewButtonTray::ClickedOutsideBubble() {
75 // This class has no bubbles dismiss, but acknowledge that the message was
80 base::string16 OverviewButtonTray::GetAccessibleNameForTray() {
81 return l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME);
84 void OverviewButtonTray::HideBubbleWithView(
85 const views::TrayBubbleView* bubble_view) {
86 // This class has no bubbles to hide.
89 void OverviewButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
90 if (alignment == shelf_alignment())
93 TrayBackgroundView::SetShelfAlignment(alignment);
94 SetIconBorderForShelfAlignment();
97 void OverviewButtonTray::SetIconBorderForShelfAlignment() {
98 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM ||
99 shelf_alignment() == SHELF_ALIGNMENT_TOP) {
100 icon_->SetBorder(views::Border::CreateEmptyBorder(
101 kHorizontalShelfVerticalPadding,
102 kHorizontalShelfHorizontalPadding,
103 kHorizontalShelfVerticalPadding,
104 kHorizontalShelfHorizontalPadding));
106 icon_->SetBorder(views::Border::CreateEmptyBorder(
107 kVerticalShelfVerticalPadding,
108 kVerticalShelfHorizontalPadding,
109 kVerticalShelfVerticalPadding,
110 kVerticalShelfHorizontalPadding));
114 void OverviewButtonTray::UpdateIconVisibility(bool maximize_mode_enabled) {
115 SetVisible(maximize_mode_enabled &&
116 Shell::GetInstance()->window_selector_controller()->CanSelect());