Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: ash/system/date/date_default_view.cc

Issue 2061123004: mash: Move //ash/system/date to //ash/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@uma
Patch Set: rebase again Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/system/date/date_default_view.h ('k') | ash/system/date/date_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/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/system/tray/special_popup_row.h"
10 #include "ash/common/system/tray/system_tray_delegate.h"
11 #include "ash/common/system/tray/tray_constants.h"
12 #include "ash/common/system/tray/tray_popup_header_button.h"
13 #include "ash/common/wm_shell.h"
14 #include "ash/system/date/date_view.h"
15 #include "base/i18n/rtl.h"
16 #include "grit/ash_resources.h"
17 #include "grit/ash_strings.h"
18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/views/border.h"
20 #include "ui/views/controls/button/button.h"
21 #include "ui/views/layout/fill_layout.h"
22 #include "ui/views/view.h"
23
24 namespace {
25
26 // The ISO-639 code for the Hebrew locale. The help icon asset is a '?' which is
27 // not mirrored in this locale.
28 const char kHebrewLocale[] = "he";
29
30 const int kPaddingVertical = 19;
31
32 } // namespace
33
34 namespace ash {
35
36 DateDefaultView::DateDefaultView(LoginStatus login)
37 : help_button_(NULL),
38 shutdown_button_(NULL),
39 lock_button_(NULL),
40 date_view_(NULL),
41 weak_factory_(this) {
42 SetLayoutManager(new views::FillLayout);
43
44 date_view_ = new tray::DateView();
45 date_view_->SetBorder(views::Border::CreateEmptyBorder(
46 kPaddingVertical, ash::kTrayPopupPaddingHorizontal, 0, 0));
47 SpecialPopupRow* view = new SpecialPopupRow();
48 view->SetContent(date_view_);
49 AddChildView(view);
50
51 WmShell* shell = WmShell::Get();
52 const bool adding_user =
53 shell->GetSessionStateDelegate()->IsInSecondaryLoginScreen();
54
55 if (login == LoginStatus::LOCKED || login == LoginStatus::NOT_LOGGED_IN ||
56 adding_user)
57 return;
58
59 date_view_->SetAction(TrayDate::SHOW_DATE_SETTINGS);
60
61 help_button_ = new TrayPopupHeaderButton(
62 this, IDR_AURA_UBER_TRAY_HELP, IDR_AURA_UBER_TRAY_HELP,
63 IDR_AURA_UBER_TRAY_HELP_HOVER, IDR_AURA_UBER_TRAY_HELP_HOVER,
64 IDS_ASH_STATUS_TRAY_HELP);
65 if (base::i18n::IsRTL() &&
66 base::i18n::GetConfiguredLocale() == kHebrewLocale) {
67 // The asset for the help button is a question mark '?'. Normally this asset
68 // is flipped in RTL locales, however Hebrew uses the LTR '?'. So the
69 // flipping must be disabled. (crbug.com/475237)
70 help_button_->EnableCanvasFlippingForRTLUI(false);
71 }
72 help_button_->SetTooltipText(
73 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_HELP));
74 view->AddButton(help_button_);
75
76 #if !defined(OS_WIN)
77 if (login != LoginStatus::LOCKED) {
78 shutdown_button_ = new TrayPopupHeaderButton(
79 this, IDR_AURA_UBER_TRAY_SHUTDOWN, IDR_AURA_UBER_TRAY_SHUTDOWN,
80 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER,
81 IDS_ASH_STATUS_TRAY_SHUTDOWN);
82 shutdown_button_->SetTooltipText(
83 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN));
84 view->AddButton(shutdown_button_);
85 }
86
87 if (shell->GetSessionStateDelegate()->CanLockScreen()) {
88 lock_button_ = new TrayPopupHeaderButton(
89 this, IDR_AURA_UBER_TRAY_LOCKSCREEN, IDR_AURA_UBER_TRAY_LOCKSCREEN,
90 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER,
91 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, IDS_ASH_STATUS_TRAY_LOCK);
92 lock_button_->SetTooltipText(
93 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK));
94 view->AddButton(lock_button_);
95 }
96 SystemTrayDelegate* system_tray_delegate = shell->system_tray_delegate();
97 system_tray_delegate->AddShutdownPolicyObserver(this);
98 system_tray_delegate->ShouldRebootOnShutdown(base::Bind(
99 &DateDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr()));
100 #endif // !defined(OS_WIN)
101 }
102
103 DateDefaultView::~DateDefaultView() {
104 // We need the check as on shell destruction, the delegate is destroyed first.
105 SystemTrayDelegate* system_tray_delegate =
106 WmShell::Get()->system_tray_delegate();
107 if (system_tray_delegate)
108 system_tray_delegate->RemoveShutdownPolicyObserver(this);
109 }
110
111 views::View* DateDefaultView::GetHelpButtonView() {
112 return help_button_;
113 }
114
115 const views::View* DateDefaultView::GetShutdownButtonViewForTest() const {
116 return shutdown_button_;
117 }
118
119 tray::DateView* DateDefaultView::GetDateView() {
120 return date_view_;
121 }
122
123 const tray::DateView* DateDefaultView::GetDateView() const {
124 return date_view_;
125 }
126
127 void DateDefaultView::ButtonPressed(views::Button* sender,
128 const ui::Event& event) {
129 WmShell* shell = WmShell::Get();
130 SystemTrayDelegate* tray_delegate = shell->system_tray_delegate();
131 if (sender == help_button_) {
132 shell->RecordUserMetricsAction(UMA_TRAY_HELP);
133 tray_delegate->ShowHelp();
134 } else if (sender == shutdown_button_) {
135 shell->RecordUserMetricsAction(UMA_TRAY_SHUT_DOWN);
136 tray_delegate->RequestShutdown();
137 } else if (sender == lock_button_) {
138 shell->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN);
139 tray_delegate->RequestLockScreen();
140 } else {
141 NOTREACHED();
142 }
143 }
144
145 void DateDefaultView::OnShutdownPolicyChanged(bool reboot_on_shutdown) {
146 if (!shutdown_button_)
147 return;
148
149 shutdown_button_->SetTooltipText(l10n_util::GetStringUTF16(
150 reboot_on_shutdown ? IDS_ASH_STATUS_TRAY_REBOOT
151 : IDS_ASH_STATUS_TRAY_SHUTDOWN));
152 }
153
154 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/date/date_default_view.h ('k') | ash/system/date/date_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698