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

Side by Side Diff: ash/common/system/tiles/tiles_default_view.cc

Issue 2429923002: Implement all system menu title row buttons for Ash MD (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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/tiles/tiles_default_view.h" 5 #include "ash/common/system/tiles/tiles_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/system/tray/system_menu_button.h" 9 #include "ash/common/system/tray/system_menu_button.h"
10 #include "ash/common/system/tray/system_tray.h" 10 #include "ash/common/system/tray/system_tray.h"
11 #include "ash/common/system/tray/system_tray_controller.h" 11 #include "ash/common/system/tray/system_tray_controller.h"
12 #include "ash/common/system/tray/system_tray_delegate.h" 12 #include "ash/common/system/tray/system_tray_delegate.h"
13 #include "ash/common/system/tray/system_tray_item.h" 13 #include "ash/common/system/tray/system_tray_item.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_utils.h"
15 #include "ash/common/wm_shell.h" 16 #include "ash/common/wm_shell.h"
16 #include "ash/resources/vector_icons/vector_icons.h" 17 #include "ash/resources/vector_icons/vector_icons.h"
17 #include "grit/ash_strings.h" 18 #include "grit/ash_strings.h"
18 #include "ui/base/l10n/l10n_util.h" 19 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/gfx/geometry/insets.h" 20 #include "ui/gfx/geometry/insets.h"
20 #include "ui/views/border.h" 21 #include "ui/views/border.h"
21 #include "ui/views/controls/separator.h" 22 #include "ui/views/controls/separator.h"
22 #include "ui/views/layout/box_layout.h" 23 #include "ui/views/layout/box_layout.h"
23 24
24 #if defined(OS_CHROMEOS) 25 #if defined(OS_CHROMEOS)
25 #include "chromeos/dbus/dbus_thread_manager.h" 26 #include "chromeos/dbus/dbus_thread_manager.h"
26 #include "chromeos/dbus/session_manager_client.h" 27 #include "chromeos/dbus/session_manager_client.h"
27 #endif 28 #endif
28 29
29 namespace { 30 namespace {
30 31
31 // The ISO-639 code for the Hebrew locale. The help icon asset is a '?' which is 32 // The ISO-639 code for the Hebrew locale. The help icon asset is a '?' which is
32 // not mirrored in this locale. 33 // not mirrored in this locale.
33 const char kHebrewLocale[] = "he"; 34 const char kHebrewLocale[] = "he";
34 35
35 } // namespace 36 } // namespace
36 37
37 namespace ash { 38 namespace ash {
38 39
39 TilesDefaultView::TilesDefaultView(SystemTrayItem* owner) 40 TilesDefaultView::TilesDefaultView(SystemTrayItem* owner, LoginStatus login)
40 : owner_(owner), 41 : owner_(owner),
42 login_(login),
41 settings_button_(nullptr), 43 settings_button_(nullptr),
42 help_button_(nullptr), 44 help_button_(nullptr),
43 lock_button_(nullptr), 45 lock_button_(nullptr),
44 power_button_(nullptr), 46 power_button_(nullptr),
45 weak_factory_(this) {} 47 weak_factory_(this) {}
46 48
47 TilesDefaultView::~TilesDefaultView() { 49 TilesDefaultView::~TilesDefaultView() {
48 SystemTrayDelegate* system_tray_delegate = 50 SystemTrayDelegate* system_tray_delegate =
49 WmShell::Get()->system_tray_delegate(); 51 WmShell::Get()->system_tray_delegate();
50 52
51 // Perform this check since the delegate is destroyed first upon shell 53 // Perform this check since the delegate is destroyed first upon shell
52 // destruction. 54 // destruction.
53 if (system_tray_delegate) 55 if (system_tray_delegate)
54 system_tray_delegate->RemoveShutdownPolicyObserver(this); 56 system_tray_delegate->RemoveShutdownPolicyObserver(this);
55 } 57 }
56 58
57 void TilesDefaultView::Init() { 59 void TilesDefaultView::Init() {
58 WmShell* shell = WmShell::Get(); 60 WmShell* shell = WmShell::Get();
59 views::BoxLayout* box_layout = 61 views::BoxLayout* box_layout =
60 new views::BoxLayout(views::BoxLayout::kHorizontal, 4, 0, 0); 62 new views::BoxLayout(views::BoxLayout::kHorizontal, 4, 0, 0);
61 box_layout->set_main_axis_alignment( 63 box_layout->set_main_axis_alignment(
62 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); 64 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
63 box_layout->set_cross_axis_alignment( 65 box_layout->set_cross_axis_alignment(
64 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 66 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
65 SetLayoutManager(box_layout); 67 SetLayoutManager(box_layout);
66 68
67 if (shell->system_tray_delegate()->ShouldShowSettings()) { 69 // Show the buttons in this row as disabled if the user is at the login
68 settings_button_ = new SystemMenuButton(this, kSystemMenuSettingsIcon, 70 // screen, lock screen, or in a secondary account flow. The exception is
69 IDS_ASH_STATUS_TRAY_SETTINGS); 71 // |power_button_| which is always shown as enabled.
70 AddChildView(settings_button_); 72 const bool disable_buttons = !CanOpenWebUISettings(login_);
71 AddSeparator(); 73
72 } 74 settings_button_ = new SystemMenuButton(this, kSystemMenuSettingsIcon,
75 IDS_ASH_STATUS_TRAY_SETTINGS);
76 if (disable_buttons || !shell->system_tray_delegate()->ShouldShowSettings())
77 settings_button_->SetState(views::Button::STATE_DISABLED);
78 AddChildView(settings_button_);
79 AddSeparator();
73 80
74 help_button_ = 81 help_button_ =
75 new SystemMenuButton(this, kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP); 82 new SystemMenuButton(this, kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP);
76 if (base::i18n::IsRTL() && 83 if (base::i18n::IsRTL() &&
77 base::i18n::GetConfiguredLocale() == kHebrewLocale) { 84 base::i18n::GetConfiguredLocale() == kHebrewLocale) {
78 // The asset for the help button is a question mark '?'. Normally this asset 85 // The asset for the help button is a question mark '?'. Normally this asset
79 // is flipped in RTL locales, however Hebrew uses the LTR '?'. So the 86 // is flipped in RTL locales, however Hebrew uses the LTR '?'. So the
80 // flipping must be disabled. (crbug.com/475237) 87 // flipping must be disabled. (crbug.com/475237)
81 help_button_->EnableCanvasFlippingForRTLUI(false); 88 help_button_->EnableCanvasFlippingForRTLUI(false);
82 } 89 }
90 if (disable_buttons)
91 help_button_->SetState(views::Button::STATE_DISABLED);
83 AddChildView(help_button_); 92 AddChildView(help_button_);
93 AddSeparator();
84 94
85 #if !defined(OS_WIN) 95 #if !defined(OS_WIN)
86 if (shell->GetSessionStateDelegate()->CanLockScreen()) { 96 lock_button_ =
87 AddSeparator(); 97 new SystemMenuButton(this, kSystemMenuLockIcon, IDS_ASH_STATUS_TRAY_LOCK);
88 lock_button_ = new SystemMenuButton(this, kSystemMenuLockIcon, 98 if (disable_buttons || !shell->GetSessionStateDelegate()->CanLockScreen())
89 IDS_ASH_STATUS_TRAY_LOCK); 99 lock_button_->SetState(views::Button::STATE_DISABLED);
90 AddChildView(lock_button_);
91 }
92 100
101 AddChildView(lock_button_);
93 AddSeparator(); 102 AddSeparator();
103
94 power_button_ = new SystemMenuButton(this, kSystemMenuPowerIcon, 104 power_button_ = new SystemMenuButton(this, kSystemMenuPowerIcon,
95 IDS_ASH_STATUS_TRAY_SHUTDOWN); 105 IDS_ASH_STATUS_TRAY_SHUTDOWN);
96 AddChildView(power_button_); 106 AddChildView(power_button_);
97
98 SystemTrayDelegate* system_tray_delegate = shell->system_tray_delegate(); 107 SystemTrayDelegate* system_tray_delegate = shell->system_tray_delegate();
99 system_tray_delegate->AddShutdownPolicyObserver(this); 108 system_tray_delegate->AddShutdownPolicyObserver(this);
100 system_tray_delegate->ShouldRebootOnShutdown(base::Bind( 109 system_tray_delegate->ShouldRebootOnShutdown(base::Bind(
101 &TilesDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr())); 110 &TilesDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr()));
102 #endif // !defined(OS_WIN) 111 #endif // !defined(OS_WIN)
103 } 112 }
104 113
105 void TilesDefaultView::ButtonPressed(views::Button* sender, 114 void TilesDefaultView::ButtonPressed(views::Button* sender,
106 const ui::Event& event) { 115 const ui::Event& event) {
107 DCHECK(sender); 116 DCHECK(sender);
(...skipping 30 matching lines...) Expand all
138 147
139 void TilesDefaultView::AddSeparator() { 148 void TilesDefaultView::AddSeparator() {
140 views::Separator* separator = 149 views::Separator* separator =
141 new views::Separator(views::Separator::HORIZONTAL); 150 new views::Separator(views::Separator::HORIZONTAL);
142 separator->SetPreferredSize(kHorizontalSeparatorHeight); 151 separator->SetPreferredSize(kHorizontalSeparatorHeight);
143 separator->SetColor(kHorizontalSeparatorColor); 152 separator->SetColor(kHorizontalSeparatorColor);
144 AddChildView(separator); 153 AddChildView(separator);
145 } 154 }
146 155
147 } // namespace ash 156 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698