Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ash / system / overview / overview_button_tray.cc
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.
4
5 #include "ash/system/overview/overview_button_tray.h"
6
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/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"
18
19 namespace {
20
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;
27
28 }  // namespace
29
30 namespace ash {
31
32 OverviewButtonTray::OverviewButtonTray(StatusAreaWidget* status_area_widget)
33     : TrayBackgroundView(status_area_widget), icon_(NULL) {
34   SetContentsBackground();
35
36   ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
37   icon_ = new views::ImageView();
38   icon_->SetImage(
39       bundle.GetImageNamed(IDR_AURA_UBER_TRAY_OVERVIEW_MODE).ToImageSkia());
40   SetIconBorderForShelfAlignment();
41   tray_container()->AddChildView(icon_);
42
43   UpdateIconVisibility(Shell::GetInstance()->
44       IsMaximizeModeWindowManagerEnabled());
45
46   Shell::GetInstance()->AddShellObserver(this);
47 }
48
49 OverviewButtonTray::~OverviewButtonTray() {
50   Shell::GetInstance()->RemoveShellObserver(this);
51 }
52
53 void OverviewButtonTray::UpdateAfterLoginStatusChange(
54     user::LoginStatus status) {
55   UpdateIconVisibility(Shell::GetInstance()->
56       IsMaximizeModeWindowManagerEnabled());
57 }
58
59 bool OverviewButtonTray::PerformAction(const ui::Event& event) {
60   Shell::GetInstance()->window_selector_controller()->ToggleOverview();
61   return true;
62 }
63
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);
68 }
69
70 void OverviewButtonTray::OnMaximizeModeEnded() {
71   UpdateIconVisibility(/* maximize_mode_enabled */ false);
72 }
73
74 bool OverviewButtonTray::ClickedOutsideBubble() {
75   // This class has no bubbles dismiss, but acknowledge that the message was
76   // handled.
77   return true;
78 }
79
80 base::string16 OverviewButtonTray::GetAccessibleNameForTray() {
81   return l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME);
82 }
83
84 void OverviewButtonTray::HideBubbleWithView(
85     const views::TrayBubbleView* bubble_view) {
86   // This class has no bubbles to hide.
87 }
88
89 void OverviewButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
90   if (alignment == shelf_alignment())
91     return;
92
93   TrayBackgroundView::SetShelfAlignment(alignment);
94   SetIconBorderForShelfAlignment();
95 }
96
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));
105   } else {
106     icon_->SetBorder(views::Border::CreateEmptyBorder(
107         kVerticalShelfVerticalPadding,
108         kVerticalShelfHorizontalPadding,
109         kVerticalShelfVerticalPadding,
110         kVerticalShelfHorizontalPadding));
111   }
112 }
113
114 void OverviewButtonTray::UpdateIconVisibility(bool maximize_mode_enabled) {
115   SetVisible(maximize_mode_enabled &&
116              Shell::GetInstance()->window_selector_controller()->CanSelect());
117 }
118
119 }  // namespace ash