Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / ash / system / overview / overview_button_tray.cc
blobec2912fa209d008cc62ac4496737993227e6a4e5
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"
8 #include "ash/shell.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"
20 namespace {
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;
29 } // namespace
31 namespace ash {
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();
39 icon_->SetImage(
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());
61 return true;
64 void OverviewButtonTray::OnMaximizeModeStarted() {
65 UpdateIconVisibility();
68 void OverviewButtonTray::OnMaximizeModeEnded() {
69 UpdateIconVisibility();
72 void OverviewButtonTray::OnOverviewModeEnded() {
73 SetDrawBackgroundAsActive(false);
76 bool OverviewButtonTray::ClickedOutsideBubble() {
77 // This class has no bubbles dismiss, but acknowledge that the message was
78 // handled.
79 return true;
82 base::string16 OverviewButtonTray::GetAccessibleNameForTray() {
83 return l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME);
86 void OverviewButtonTray::HideBubbleWithView(
87 const views::TrayBubbleView* bubble_view) {
88 // This class has no bubbles to hide.
91 void OverviewButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
92 if (alignment == shelf_alignment())
93 return;
95 TrayBackgroundView::SetShelfAlignment(alignment);
96 SetIconBorderForShelfAlignment();
99 void OverviewButtonTray::SetIconBorderForShelfAlignment() {
100 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM ||
101 shelf_alignment() == SHELF_ALIGNMENT_TOP) {
102 icon_->SetBorder(views::Border::CreateEmptyBorder(
103 kHorizontalShelfVerticalPadding,
104 kHorizontalShelfHorizontalPadding,
105 kHorizontalShelfVerticalPadding,
106 kHorizontalShelfHorizontalPadding));
107 } else {
108 icon_->SetBorder(views::Border::CreateEmptyBorder(
109 kVerticalShelfVerticalPadding,
110 kVerticalShelfHorizontalPadding,
111 kVerticalShelfVerticalPadding,
112 kVerticalShelfHorizontalPadding));
116 void OverviewButtonTray::UpdateIconVisibility() {
117 SetVisible(Shell::GetInstance()->maximize_mode_controller()->
118 IsMaximizeModeWindowManagerEnabled() &&
119 Shell::GetInstance()->window_selector_controller()->CanSelect());
122 } // namespace ash