| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/system/date/date_default_view.h" | 5 #include "ash/common/system/date/date_default_view.h" |
| 6 | 6 |
| 7 #include "ash/common/metrics/user_metrics_action.h" | 7 #include "ash/common/metrics/user_metrics_action.h" |
| 8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/shutdown_controller.h" |
| 9 #include "ash/common/system/date/date_view.h" | 10 #include "ash/common/system/date/date_view.h" |
| 10 #include "ash/common/system/tray/special_popup_row.h" | 11 #include "ash/common/system/tray/special_popup_row.h" |
| 11 #include "ash/common/system/tray/system_tray.h" | 12 #include "ash/common/system/tray/system_tray.h" |
| 12 #include "ash/common/system/tray/system_tray_controller.h" | 13 #include "ash/common/system/tray/system_tray_controller.h" |
| 13 #include "ash/common/system/tray/system_tray_delegate.h" | |
| 14 #include "ash/common/system/tray/tray_constants.h" | 14 #include "ash/common/system/tray/tray_constants.h" |
| 15 #include "ash/common/system/tray/tray_popup_header_button.h" | 15 #include "ash/common/system/tray/tray_popup_header_button.h" |
| 16 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
| 17 #include "base/i18n/rtl.h" | 17 #include "base/i18n/rtl.h" |
| 18 #include "grit/ash_resources.h" | 18 #include "grit/ash_resources.h" |
| 19 #include "grit/ash_strings.h" | 19 #include "grit/ash_strings.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/views/border.h" | 21 #include "ui/views/border.h" |
| 22 #include "ui/views/controls/button/button.h" | 22 #include "ui/views/controls/button/button.h" |
| 23 #include "ui/views/layout/fill_layout.h" | 23 #include "ui/views/layout/fill_layout.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 37 const int kPaddingVertical = 19; | 37 const int kPaddingVertical = 19; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 namespace ash { | 41 namespace ash { |
| 42 | 42 |
| 43 DateDefaultView::DateDefaultView(SystemTrayItem* owner, LoginStatus login) | 43 DateDefaultView::DateDefaultView(SystemTrayItem* owner, LoginStatus login) |
| 44 : help_button_(nullptr), | 44 : help_button_(nullptr), |
| 45 shutdown_button_(nullptr), | 45 shutdown_button_(nullptr), |
| 46 lock_button_(nullptr), | 46 lock_button_(nullptr), |
| 47 date_view_(nullptr), | 47 date_view_(nullptr) { |
| 48 weak_factory_(this) { | |
| 49 SetLayoutManager(new views::FillLayout); | 48 SetLayoutManager(new views::FillLayout); |
| 50 | 49 |
| 51 date_view_ = new tray::DateView(owner); | 50 date_view_ = new tray::DateView(owner); |
| 52 date_view_->SetBorder(views::CreateEmptyBorder( | 51 date_view_->SetBorder(views::CreateEmptyBorder( |
| 53 kPaddingVertical, ash::kTrayPopupPaddingHorizontal, 0, 0)); | 52 kPaddingVertical, ash::kTrayPopupPaddingHorizontal, 0, 0)); |
| 54 SpecialPopupRow* view = new SpecialPopupRow(); | 53 SpecialPopupRow* view = new SpecialPopupRow(); |
| 55 view->SetContent(date_view_); | 54 view->SetContent(date_view_); |
| 56 AddChildView(view); | 55 AddChildView(view); |
| 57 | 56 |
| 58 WmShell* shell = WmShell::Get(); | 57 WmShell* shell = WmShell::Get(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 83 | 82 |
| 84 #if !defined(OS_WIN) | 83 #if !defined(OS_WIN) |
| 85 if (login != LoginStatus::LOCKED) { | 84 if (login != LoginStatus::LOCKED) { |
| 86 shutdown_button_ = new TrayPopupHeaderButton( | 85 shutdown_button_ = new TrayPopupHeaderButton( |
| 87 this, IDR_AURA_UBER_TRAY_SHUTDOWN, IDR_AURA_UBER_TRAY_SHUTDOWN, | 86 this, IDR_AURA_UBER_TRAY_SHUTDOWN, IDR_AURA_UBER_TRAY_SHUTDOWN, |
| 88 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, | 87 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, |
| 89 IDS_ASH_STATUS_TRAY_SHUTDOWN); | 88 IDS_ASH_STATUS_TRAY_SHUTDOWN); |
| 90 shutdown_button_->SetTooltipText( | 89 shutdown_button_->SetTooltipText( |
| 91 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN)); | 90 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN)); |
| 92 view->AddViewToRowNonMd(shutdown_button_, true); | 91 view->AddViewToRowNonMd(shutdown_button_, true); |
| 92 // This object is recreated every time the menu opens. Don't bother updating |
| 93 // the tooltip if the shutdown policy changes while the menu is open. |
| 94 bool reboot = WmShell::Get()->shutdown_controller()->reboot_on_shutdown(); |
| 95 shutdown_button_->SetTooltipText(l10n_util::GetStringUTF16( |
| 96 reboot ? IDS_ASH_STATUS_TRAY_REBOOT : IDS_ASH_STATUS_TRAY_SHUTDOWN)); |
| 93 } | 97 } |
| 94 | 98 |
| 95 if (shell->GetSessionStateDelegate()->CanLockScreen()) { | 99 if (shell->GetSessionStateDelegate()->CanLockScreen()) { |
| 96 lock_button_ = new TrayPopupHeaderButton( | 100 lock_button_ = new TrayPopupHeaderButton( |
| 97 this, IDR_AURA_UBER_TRAY_LOCKSCREEN, IDR_AURA_UBER_TRAY_LOCKSCREEN, | 101 this, IDR_AURA_UBER_TRAY_LOCKSCREEN, IDR_AURA_UBER_TRAY_LOCKSCREEN, |
| 98 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, | 102 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, |
| 99 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, IDS_ASH_STATUS_TRAY_LOCK); | 103 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, IDS_ASH_STATUS_TRAY_LOCK); |
| 100 lock_button_->SetTooltipText( | 104 lock_button_->SetTooltipText( |
| 101 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK)); | 105 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK)); |
| 102 view->AddViewToRowNonMd(lock_button_, true); | 106 view->AddViewToRowNonMd(lock_button_, true); |
| 103 } | 107 } |
| 104 SystemTrayDelegate* system_tray_delegate = shell->system_tray_delegate(); | |
| 105 system_tray_delegate->AddShutdownPolicyObserver(this); | |
| 106 system_tray_delegate->ShouldRebootOnShutdown(base::Bind( | |
| 107 &DateDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr())); | |
| 108 #endif // !defined(OS_WIN) | 108 #endif // !defined(OS_WIN) |
| 109 } | 109 } |
| 110 | 110 |
| 111 DateDefaultView::~DateDefaultView() { | 111 DateDefaultView::~DateDefaultView() {} |
| 112 // We need the check as on shell destruction, the delegate is destroyed first. | |
| 113 SystemTrayDelegate* system_tray_delegate = | |
| 114 WmShell::Get()->system_tray_delegate(); | |
| 115 if (system_tray_delegate) | |
| 116 system_tray_delegate->RemoveShutdownPolicyObserver(this); | |
| 117 } | |
| 118 | 112 |
| 119 views::View* DateDefaultView::GetHelpButtonView() { | 113 views::View* DateDefaultView::GetHelpButtonView() { |
| 120 return help_button_; | 114 return help_button_; |
| 121 } | 115 } |
| 122 | 116 |
| 123 const views::View* DateDefaultView::GetShutdownButtonViewForTest() const { | 117 const views::View* DateDefaultView::GetShutdownButtonViewForTest() const { |
| 124 return shutdown_button_; | 118 return shutdown_button_; |
| 125 } | 119 } |
| 126 | 120 |
| 127 tray::DateView* DateDefaultView::GetDateView() { | 121 tray::DateView* DateDefaultView::GetDateView() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 147 chromeos::DBusThreadManager::Get() | 141 chromeos::DBusThreadManager::Get() |
| 148 ->GetSessionManagerClient() | 142 ->GetSessionManagerClient() |
| 149 ->RequestLockScreen(); | 143 ->RequestLockScreen(); |
| 150 #endif | 144 #endif |
| 151 } else { | 145 } else { |
| 152 NOTREACHED(); | 146 NOTREACHED(); |
| 153 } | 147 } |
| 154 date_view_->CloseSystemBubble(); | 148 date_view_->CloseSystemBubble(); |
| 155 } | 149 } |
| 156 | 150 |
| 157 void DateDefaultView::OnShutdownPolicyChanged(bool reboot_on_shutdown) { | |
| 158 if (!shutdown_button_) | |
| 159 return; | |
| 160 | |
| 161 shutdown_button_->SetTooltipText(l10n_util::GetStringUTF16( | |
| 162 reboot_on_shutdown ? IDS_ASH_STATUS_TRAY_REBOOT | |
| 163 : IDS_ASH_STATUS_TRAY_SHUTDOWN)); | |
| 164 } | |
| 165 | |
| 166 } // namespace ash | 151 } // namespace ash |
| OLD | NEW |