cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ash / system / date / date_default_view.cc
blob35b4d3659beff08bff211096045bb839dd454d60
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/date/date_default_view.h"
7 #include "ash/metrics/user_metrics_recorder.h"
8 #include "ash/session/session_state_delegate.h"
9 #include "ash/shell.h"
10 #include "ash/system/date/date_view.h"
11 #include "ash/system/tray/special_popup_row.h"
12 #include "ash/system/tray/system_tray_delegate.h"
13 #include "ash/system/tray/tray_constants.h"
14 #include "ash/system/tray/tray_popup_header_button.h"
15 #include "ash/wm/lock_state_controller.h"
16 #include "base/i18n/rtl.h"
17 #include "grit/ash_resources.h"
18 #include "grit/ash_strings.h"
19 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/views/border.h"
21 #include "ui/views/controls/button/button.h"
22 #include "ui/views/layout/fill_layout.h"
23 #include "ui/views/view.h"
25 namespace {
27 // The ISO-639 code for the Hebrew locale. The help icon asset is a '?' which is
28 // not mirrored in this locale.
29 const char kHebrewLocale[] = "he";
31 const int kPaddingVertical = 19;
33 } // namespace
35 namespace ash {
37 DateDefaultView::DateDefaultView(ash::user::LoginStatus login)
38 : help_button_(NULL),
39 shutdown_button_(NULL),
40 lock_button_(NULL),
41 date_view_(NULL),
42 weak_factory_(this) {
43 SetLayoutManager(new views::FillLayout);
45 date_view_ = new tray::DateView();
46 date_view_->SetBorder(views::Border::CreateEmptyBorder(
47 kPaddingVertical, ash::kTrayPopupPaddingHorizontal, 0, 0));
48 SpecialPopupRow* view = new SpecialPopupRow();
49 view->SetContent(date_view_);
50 AddChildView(view);
52 bool userAddingRunning = ash::Shell::GetInstance()
53 ->session_state_delegate()
54 ->IsInSecondaryLoginScreen();
56 if (login == user::LOGGED_IN_LOCKED ||
57 login == user::LOGGED_IN_NONE || userAddingRunning)
58 return;
60 date_view_->SetAction(TrayDate::SHOW_DATE_SETTINGS);
62 help_button_ = new TrayPopupHeaderButton(
63 this, IDR_AURA_UBER_TRAY_HELP, IDR_AURA_UBER_TRAY_HELP,
64 IDR_AURA_UBER_TRAY_HELP_HOVER, IDR_AURA_UBER_TRAY_HELP_HOVER,
65 IDS_ASH_STATUS_TRAY_HELP);
66 if (base::i18n::IsRTL() &&
67 base::i18n::GetConfiguredLocale() == kHebrewLocale) {
68 // The asset for the help button is a question mark '?'. Normally this asset
69 // is flipped in RTL locales, however Hebrew uses the LTR '?'. So the
70 // flipping must be disabled. (crbug.com/475237)
71 help_button_->EnableCanvasFlippingForRTLUI(false);
73 help_button_->SetTooltipText(
74 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_HELP));
75 view->AddButton(help_button_);
77 #if !defined(OS_WIN)
78 if (login != ash::user::LOGGED_IN_LOCKED) {
79 shutdown_button_ = new TrayPopupHeaderButton(
80 this, IDR_AURA_UBER_TRAY_SHUTDOWN, IDR_AURA_UBER_TRAY_SHUTDOWN,
81 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER,
82 IDS_ASH_STATUS_TRAY_SHUTDOWN);
83 shutdown_button_->SetTooltipText(
84 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN));
85 view->AddButton(shutdown_button_);
88 if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) {
89 lock_button_ = new TrayPopupHeaderButton(
90 this, IDR_AURA_UBER_TRAY_LOCKSCREEN, IDR_AURA_UBER_TRAY_LOCKSCREEN,
91 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER,
92 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, IDS_ASH_STATUS_TRAY_LOCK);
93 lock_button_->SetTooltipText(
94 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK));
95 view->AddButton(lock_button_);
97 SystemTrayDelegate* system_tray_delegate =
98 Shell::GetInstance()->system_tray_delegate();
99 system_tray_delegate->AddShutdownPolicyObserver(this);
100 system_tray_delegate->ShouldRebootOnShutdown(base::Bind(
101 &DateDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr()));
102 #endif // !defined(OS_WIN)
105 DateDefaultView::~DateDefaultView() {
106 // We need the check as on shell destruction, the delegate is destroyed first.
107 SystemTrayDelegate* system_tray_delegate =
108 Shell::GetInstance()->system_tray_delegate();
109 if (system_tray_delegate)
110 system_tray_delegate->RemoveShutdownPolicyObserver(this);
113 views::View* DateDefaultView::GetHelpButtonView() {
114 return help_button_;
117 const views::View* DateDefaultView::GetShutdownButtonViewForTest() const {
118 return shutdown_button_;
121 tray::DateView* DateDefaultView::GetDateView() {
122 return date_view_;
125 const tray::DateView* DateDefaultView::GetDateView() const {
126 return date_view_;
129 void DateDefaultView::ButtonPressed(views::Button* sender,
130 const ui::Event& event) {
131 ash::Shell* shell = ash::Shell::GetInstance();
132 ash::SystemTrayDelegate* tray_delegate = shell->system_tray_delegate();
133 if (sender == help_button_) {
134 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_HELP);
135 tray_delegate->ShowHelp();
136 } else if (sender == shutdown_button_) {
137 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_SHUT_DOWN);
138 ash::Shell::GetInstance()->lock_state_controller()->RequestShutdown();
139 } else if (sender == lock_button_) {
140 shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_LOCK_SCREEN);
141 tray_delegate->RequestLockScreen();
142 } else {
143 NOTREACHED();
147 void DateDefaultView::OnShutdownPolicyChanged(bool reboot_on_shutdown) {
148 if (!shutdown_button_)
149 return;
151 shutdown_button_->SetTooltipText(l10n_util::GetStringUTF16(
152 reboot_on_shutdown ? IDS_ASH_STATUS_TRAY_REBOOT
153 : IDS_ASH_STATUS_TRAY_SHUTDOWN));
156 } // namespace ash