OLD | NEW |
| (Empty) |
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/common/system/date/date_default_view.h" | |
6 | |
7 #include "ash/common/metrics/user_metrics_action.h" | |
8 #include "ash/common/session/session_state_delegate.h" | |
9 #include "ash/common/shutdown_controller.h" | |
10 #include "ash/common/system/date/date_view.h" | |
11 #include "ash/common/system/tray/special_popup_row.h" | |
12 #include "ash/common/system/tray/system_tray.h" | |
13 #include "ash/common/system/tray/system_tray_controller.h" | |
14 #include "ash/common/system/tray/tray_constants.h" | |
15 #include "ash/common/system/tray/tray_popup_header_button.h" | |
16 #include "ash/common/wm_shell.h" | |
17 #include "ash/resources/grit/ash_resources.h" | |
18 #include "ash/shell.h" | |
19 #include "ash/strings/grit/ash_strings.h" | |
20 #include "ash/wm/lock_state_controller.h" | |
21 #include "base/i18n/rtl.h" | |
22 #include "chromeos/dbus/dbus_thread_manager.h" | |
23 #include "chromeos/dbus/session_manager_client.h" | |
24 #include "ui/base/l10n/l10n_util.h" | |
25 #include "ui/views/border.h" | |
26 #include "ui/views/controls/button/button.h" | |
27 #include "ui/views/layout/fill_layout.h" | |
28 #include "ui/views/view.h" | |
29 | |
30 namespace { | |
31 | |
32 // The ISO-639 code for the Hebrew locale. The help icon asset is a '?' which is | |
33 // not mirrored in this locale. | |
34 const char kHebrewLocale[] = "he"; | |
35 | |
36 const int kPaddingVertical = 19; | |
37 | |
38 } // namespace | |
39 | |
40 namespace ash { | |
41 | |
42 DateDefaultView::DateDefaultView(SystemTrayItem* owner, LoginStatus login) | |
43 : help_button_(nullptr), | |
44 shutdown_button_(nullptr), | |
45 lock_button_(nullptr), | |
46 date_view_(nullptr) { | |
47 SetLayoutManager(new views::FillLayout); | |
48 | |
49 date_view_ = new tray::DateView(owner); | |
50 date_view_->SetBorder(views::CreateEmptyBorder( | |
51 kPaddingVertical, ash::kTrayPopupPaddingHorizontal, 0, 0)); | |
52 SpecialPopupRow* view = new SpecialPopupRow(); | |
53 view->SetContent(date_view_); | |
54 AddChildView(view); | |
55 | |
56 WmShell* shell = WmShell::Get(); | |
57 const bool adding_user = | |
58 shell->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); | |
59 | |
60 if (login == LoginStatus::LOCKED || login == LoginStatus::NOT_LOGGED_IN || | |
61 adding_user) | |
62 return; | |
63 | |
64 date_view_->SetAction(tray::DateView::DateAction::SHOW_DATE_SETTINGS); | |
65 | |
66 help_button_ = new TrayPopupHeaderButton( | |
67 this, IDR_AURA_UBER_TRAY_HELP, IDR_AURA_UBER_TRAY_HELP, | |
68 IDR_AURA_UBER_TRAY_HELP_HOVER, IDR_AURA_UBER_TRAY_HELP_HOVER, | |
69 IDS_ASH_STATUS_TRAY_HELP); | |
70 | |
71 if (base::i18n::IsRTL() && | |
72 base::i18n::GetConfiguredLocale() == kHebrewLocale) { | |
73 // The asset for the help button is a question mark '?'. Normally this asset | |
74 // is flipped in RTL locales, however Hebrew uses the LTR '?'. So the | |
75 // flipping must be disabled. (crbug.com/475237) | |
76 help_button_->EnableCanvasFlippingForRTLUI(false); | |
77 } | |
78 help_button_->SetTooltipText( | |
79 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_HELP)); | |
80 view->AddViewToRowNonMd(help_button_, true); | |
81 | |
82 if (login != LoginStatus::LOCKED) { | |
83 shutdown_button_ = new TrayPopupHeaderButton( | |
84 this, IDR_AURA_UBER_TRAY_SHUTDOWN, IDR_AURA_UBER_TRAY_SHUTDOWN, | |
85 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, | |
86 IDS_ASH_STATUS_TRAY_SHUTDOWN); | |
87 shutdown_button_->SetTooltipText( | |
88 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN)); | |
89 view->AddViewToRowNonMd(shutdown_button_, true); | |
90 // This object is recreated every time the menu opens. Don't bother updating | |
91 // the tooltip if the shutdown policy changes while the menu is open. | |
92 bool reboot = WmShell::Get()->shutdown_controller()->reboot_on_shutdown(); | |
93 shutdown_button_->SetTooltipText(l10n_util::GetStringUTF16( | |
94 reboot ? IDS_ASH_STATUS_TRAY_REBOOT : IDS_ASH_STATUS_TRAY_SHUTDOWN)); | |
95 } | |
96 | |
97 if (shell->GetSessionStateDelegate()->CanLockScreen()) { | |
98 lock_button_ = new TrayPopupHeaderButton( | |
99 this, IDR_AURA_UBER_TRAY_LOCKSCREEN, IDR_AURA_UBER_TRAY_LOCKSCREEN, | |
100 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, | |
101 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, IDS_ASH_STATUS_TRAY_LOCK); | |
102 lock_button_->SetTooltipText( | |
103 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK)); | |
104 view->AddViewToRowNonMd(lock_button_, true); | |
105 } | |
106 } | |
107 | |
108 DateDefaultView::~DateDefaultView() {} | |
109 | |
110 views::View* DateDefaultView::GetHelpButtonView() { | |
111 return help_button_; | |
112 } | |
113 | |
114 const views::View* DateDefaultView::GetShutdownButtonViewForTest() const { | |
115 return shutdown_button_; | |
116 } | |
117 | |
118 tray::DateView* DateDefaultView::GetDateView() { | |
119 return date_view_; | |
120 } | |
121 | |
122 const tray::DateView* DateDefaultView::GetDateView() const { | |
123 return date_view_; | |
124 } | |
125 | |
126 void DateDefaultView::ButtonPressed(views::Button* sender, | |
127 const ui::Event& event) { | |
128 WmShell* shell = WmShell::Get(); | |
129 if (sender == help_button_) { | |
130 shell->RecordUserMetricsAction(UMA_TRAY_HELP); | |
131 shell->system_tray_controller()->ShowHelp(); | |
132 } else if (sender == shutdown_button_) { | |
133 shell->RecordUserMetricsAction(UMA_TRAY_SHUT_DOWN); | |
134 Shell::GetInstance()->lock_state_controller()->RequestShutdown(); | |
135 } else if (sender == lock_button_) { | |
136 shell->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN); | |
137 chromeos::DBusThreadManager::Get() | |
138 ->GetSessionManagerClient() | |
139 ->RequestLockScreen(); | |
140 } else { | |
141 NOTREACHED(); | |
142 } | |
143 date_view_->CloseSystemBubble(); | |
144 } | |
145 | |
146 } // namespace ash | |
OLD | NEW |