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/maximize_mode/maximize_mode_controller.h"
12 #include "ash/wm/overview/window_selector_controller.h"
13 #include "grit/ash_resources.h"
14 #include "grit/ash_strings.h"
15 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/views/border.h"
18 #include "ui/views/controls/image_view.h"
22 // Predefined padding for the icon used in this tray. These are to be set to the
23 // border of the icon, depending on the current shelf_alignment()
24 const int kHorizontalShelfHorizontalPadding = 8;
25 const int kHorizontalShelfVerticalPadding = 4;
26 const int kVerticalShelfHorizontalPadding = 2;
27 const int kVerticalShelfVerticalPadding = 5;
33 OverviewButtonTray::OverviewButtonTray(StatusAreaWidget* status_area_widget)
34 : TrayBackgroundView(status_area_widget), icon_(NULL) {
35 SetContentsBackground();
37 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
38 icon_ = new views::ImageView();
40 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_OVERVIEW_MODE).ToImageSkia());
41 SetIconBorderForShelfAlignment();
42 tray_container()->AddChildView(icon_);
44 Shell::GetInstance()->AddShellObserver(this);
47 OverviewButtonTray::~OverviewButtonTray() {
48 Shell::GetInstance()->RemoveShellObserver(this);
51 void OverviewButtonTray::UpdateAfterLoginStatusChange(
52 user::LoginStatus status) {
53 UpdateIconVisibility();
56 bool OverviewButtonTray::PerformAction(const ui::Event& event) {
57 WindowSelectorController* controller =
58 Shell::GetInstance()->window_selector_controller();
59 controller->ToggleOverview();
60 SetDrawBackgroundAsActive(controller->IsSelecting());
64 void OverviewButtonTray::OnMaximizeModeStarted() {
65 UpdateIconVisibility();
68 void OverviewButtonTray::OnMaximizeModeEnded() {
69 UpdateIconVisibility();
72 bool OverviewButtonTray::ClickedOutsideBubble() {
73 // This class has no bubbles dismiss, but acknowledge that the message was
78 base::string16 OverviewButtonTray::GetAccessibleNameForTray() {
79 return l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME);
82 void OverviewButtonTray::HideBubbleWithView(
83 const views::TrayBubbleView* bubble_view) {
84 // This class has no bubbles to hide.
87 void OverviewButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
88 if (alignment == shelf_alignment())
91 TrayBackgroundView::SetShelfAlignment(alignment);
92 SetIconBorderForShelfAlignment();
95 void OverviewButtonTray::SetIconBorderForShelfAlignment() {
96 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM ||
97 shelf_alignment() == SHELF_ALIGNMENT_TOP) {
98 icon_->SetBorder(views::Border::CreateEmptyBorder(
99 kHorizontalShelfVerticalPadding,
100 kHorizontalShelfHorizontalPadding,
101 kHorizontalShelfVerticalPadding,
102 kHorizontalShelfHorizontalPadding));
104 icon_->SetBorder(views::Border::CreateEmptyBorder(
105 kVerticalShelfVerticalPadding,
106 kVerticalShelfHorizontalPadding,
107 kVerticalShelfVerticalPadding,
108 kVerticalShelfHorizontalPadding));
112 void OverviewButtonTray::UpdateIconVisibility() {
113 SetVisible(Shell::GetInstance()->maximize_mode_controller()->
114 IsMaximizeModeWindowManagerEnabled() &&
115 Shell::GetInstance()->window_selector_controller()->CanSelect());