| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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/tiles/tiles_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/tray/system_menu_button.h" | |
| 11 #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_delegate.h" | |
| 14 #include "ash/common/system/tray/system_tray_item.h" | |
| 15 #include "ash/common/system/tray/tray_constants.h" | |
| 16 #include "ash/common/system/tray/tray_popup_utils.h" | |
| 17 #include "ash/common/wm_shell.h" | |
| 18 #include "ash/resources/vector_icons/vector_icons.h" | |
| 19 #include "ash/shell.h" | |
| 20 #include "ash/strings/grit/ash_strings.h" | |
| 21 #include "ash/wm/lock_state_controller.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/gfx/geometry/insets.h" | |
| 26 #include "ui/views/border.h" | |
| 27 #include "ui/views/controls/button/custom_button.h" | |
| 28 #include "ui/views/controls/separator.h" | |
| 29 #include "ui/views/layout/box_layout.h" | |
| 30 | |
| 31 namespace { | |
| 32 | |
| 33 // The ISO-639 code for the Hebrew locale. The help icon asset is a '?' which is | |
| 34 // not mirrored in this locale. | |
| 35 const char kHebrewLocale[] = "he"; | |
| 36 | |
| 37 } // namespace | |
| 38 | |
| 39 namespace ash { | |
| 40 | |
| 41 TilesDefaultView::TilesDefaultView(SystemTrayItem* owner, LoginStatus login) | |
| 42 : owner_(owner), | |
| 43 login_(login), | |
| 44 settings_button_(nullptr), | |
| 45 help_button_(nullptr), | |
| 46 lock_button_(nullptr), | |
| 47 power_button_(nullptr) {} | |
| 48 | |
| 49 TilesDefaultView::~TilesDefaultView() {} | |
| 50 | |
| 51 void TilesDefaultView::Init() { | |
| 52 WmShell* shell = WmShell::Get(); | |
| 53 views::BoxLayout* box_layout = | |
| 54 new views::BoxLayout(views::BoxLayout::kHorizontal, 4, 0, 0); | |
| 55 box_layout->set_main_axis_alignment( | |
| 56 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | |
| 57 box_layout->set_cross_axis_alignment( | |
| 58 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
| 59 SetLayoutManager(box_layout); | |
| 60 | |
| 61 // Show the buttons in this row as disabled if the user is at the login | |
| 62 // screen, lock screen, or in a secondary account flow. The exception is | |
| 63 // |power_button_| which is always shown as enabled. | |
| 64 const bool disable_buttons = !TrayPopupUtils::CanOpenWebUISettings(login_); | |
| 65 | |
| 66 settings_button_ = new SystemMenuButton( | |
| 67 this, TrayPopupInkDropStyle::HOST_CENTERED, kSystemMenuSettingsIcon, | |
| 68 IDS_ASH_STATUS_TRAY_SETTINGS); | |
| 69 if (disable_buttons || !shell->system_tray_delegate()->ShouldShowSettings()) | |
| 70 settings_button_->SetEnabled(false); | |
| 71 AddChildView(settings_button_); | |
| 72 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); | |
| 73 | |
| 74 help_button_ = | |
| 75 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, | |
| 76 kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP); | |
| 77 if (base::i18n::IsRTL() && | |
| 78 base::i18n::GetConfiguredLocale() == kHebrewLocale) { | |
| 79 // The asset for the help button is a question mark '?'. Normally this asset | |
| 80 // is flipped in RTL locales, however Hebrew uses the LTR '?'. So the | |
| 81 // flipping must be disabled. (crbug.com/475237) | |
| 82 help_button_->EnableCanvasFlippingForRTLUI(false); | |
| 83 } | |
| 84 if (disable_buttons) | |
| 85 help_button_->SetEnabled(false); | |
| 86 AddChildView(help_button_); | |
| 87 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); | |
| 88 | |
| 89 lock_button_ = | |
| 90 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, | |
| 91 kSystemMenuLockIcon, IDS_ASH_STATUS_TRAY_LOCK); | |
| 92 if (disable_buttons || !shell->GetSessionStateDelegate()->CanLockScreen()) | |
| 93 lock_button_->SetEnabled(false); | |
| 94 | |
| 95 AddChildView(lock_button_); | |
| 96 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); | |
| 97 | |
| 98 power_button_ = | |
| 99 new SystemMenuButton(this, TrayPopupInkDropStyle::HOST_CENTERED, | |
| 100 kSystemMenuPowerIcon, IDS_ASH_STATUS_TRAY_SHUTDOWN); | |
| 101 AddChildView(power_button_); | |
| 102 // This object is recreated every time the menu opens. Don't bother updating | |
| 103 // the tooltip if the shutdown policy changes while the menu is open. | |
| 104 bool reboot = WmShell::Get()->shutdown_controller()->reboot_on_shutdown(); | |
| 105 power_button_->SetTooltipText(l10n_util::GetStringUTF16( | |
| 106 reboot ? IDS_ASH_STATUS_TRAY_REBOOT : IDS_ASH_STATUS_TRAY_SHUTDOWN)); | |
| 107 } | |
| 108 | |
| 109 void TilesDefaultView::ButtonPressed(views::Button* sender, | |
| 110 const ui::Event& event) { | |
| 111 DCHECK(sender); | |
| 112 WmShell* shell = WmShell::Get(); | |
| 113 if (sender == settings_button_) { | |
| 114 shell->RecordUserMetricsAction(UMA_TRAY_SETTINGS); | |
| 115 shell->system_tray_controller()->ShowSettings(); | |
| 116 } else if (sender == help_button_) { | |
| 117 shell->RecordUserMetricsAction(UMA_TRAY_HELP); | |
| 118 shell->system_tray_controller()->ShowHelp(); | |
| 119 } else if (sender == lock_button_) { | |
| 120 shell->RecordUserMetricsAction(UMA_TRAY_LOCK_SCREEN); | |
| 121 chromeos::DBusThreadManager::Get() | |
| 122 ->GetSessionManagerClient() | |
| 123 ->RequestLockScreen(); | |
| 124 } else if (sender == power_button_) { | |
| 125 shell->RecordUserMetricsAction(UMA_TRAY_SHUT_DOWN); | |
| 126 Shell::GetInstance()->lock_state_controller()->RequestShutdown(); | |
| 127 } | |
| 128 | |
| 129 owner_->system_tray()->CloseSystemBubble(); | |
| 130 } | |
| 131 | |
| 132 views::View* TilesDefaultView::GetHelpButtonView() const { | |
| 133 return help_button_; | |
| 134 } | |
| 135 | |
| 136 const views::CustomButton* TilesDefaultView::GetShutdownButtonViewForTest() | |
| 137 const { | |
| 138 return power_button_; | |
| 139 } | |
| 140 | |
| 141 } // namespace ash | |
| OLD | NEW |