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

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: OS_WIN define in tests 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
« no previous file with comments | « ash/common/system/tiles/tiles_default_view.h ('k') | ash/common/system/tiles/tray_tiles.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
22 #include "ui/views/controls/button/custom_button.h"
21 #include "ui/views/controls/separator.h" 23 #include "ui/views/controls/separator.h"
22 #include "ui/views/layout/box_layout.h" 24 #include "ui/views/layout/box_layout.h"
23 25
24 #if defined(OS_CHROMEOS) 26 #if defined(OS_CHROMEOS)
25 #include "chromeos/dbus/dbus_thread_manager.h" 27 #include "chromeos/dbus/dbus_thread_manager.h"
26 #include "chromeos/dbus/session_manager_client.h" 28 #include "chromeos/dbus/session_manager_client.h"
27 #endif 29 #endif
28 30
29 namespace { 31 namespace {
30 32
31 // The ISO-639 code for the Hebrew locale. The help icon asset is a '?' which is 33 // The ISO-639 code for the Hebrew locale. The help icon asset is a '?' which is
32 // not mirrored in this locale. 34 // not mirrored in this locale.
33 const char kHebrewLocale[] = "he"; 35 const char kHebrewLocale[] = "he";
34 36
35 } // namespace 37 } // namespace
36 38
37 namespace ash { 39 namespace ash {
38 40
39 TilesDefaultView::TilesDefaultView(SystemTrayItem* owner) 41 TilesDefaultView::TilesDefaultView(SystemTrayItem* owner, LoginStatus login)
40 : owner_(owner), 42 : owner_(owner),
43 login_(login),
41 settings_button_(nullptr), 44 settings_button_(nullptr),
42 help_button_(nullptr), 45 help_button_(nullptr),
43 lock_button_(nullptr), 46 lock_button_(nullptr),
44 power_button_(nullptr), 47 power_button_(nullptr),
45 weak_factory_(this) {} 48 weak_factory_(this) {}
46 49
47 TilesDefaultView::~TilesDefaultView() { 50 TilesDefaultView::~TilesDefaultView() {
48 SystemTrayDelegate* system_tray_delegate = 51 SystemTrayDelegate* system_tray_delegate =
49 WmShell::Get()->system_tray_delegate(); 52 WmShell::Get()->system_tray_delegate();
50 53
51 // Perform this check since the delegate is destroyed first upon shell 54 // Perform this check since the delegate is destroyed first upon shell
52 // destruction. 55 // destruction.
53 if (system_tray_delegate) 56 if (system_tray_delegate)
54 system_tray_delegate->RemoveShutdownPolicyObserver(this); 57 system_tray_delegate->RemoveShutdownPolicyObserver(this);
55 } 58 }
56 59
57 void TilesDefaultView::Init() { 60 void TilesDefaultView::Init() {
58 WmShell* shell = WmShell::Get(); 61 WmShell* shell = WmShell::Get();
59 views::BoxLayout* box_layout = 62 views::BoxLayout* box_layout =
60 new views::BoxLayout(views::BoxLayout::kHorizontal, 4, 0, 0); 63 new views::BoxLayout(views::BoxLayout::kHorizontal, 4, 0, 0);
61 box_layout->set_main_axis_alignment( 64 box_layout->set_main_axis_alignment(
62 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); 65 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
63 box_layout->set_cross_axis_alignment( 66 box_layout->set_cross_axis_alignment(
64 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 67 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
65 SetLayoutManager(box_layout); 68 SetLayoutManager(box_layout);
66 69
67 if (shell->system_tray_delegate()->ShouldShowSettings()) { 70 // Show the buttons in this row as disabled if the user is at the login
68 settings_button_ = new SystemMenuButton(this, kSystemMenuSettingsIcon, 71 // screen, lock screen, or in a secondary account flow. The exception is
69 IDS_ASH_STATUS_TRAY_SETTINGS); 72 // |power_button_| which is always shown as enabled.
70 AddChildView(settings_button_); 73 const bool disable_buttons = !CanOpenWebUISettings(login_);
71 AddSeparator(); 74
72 } 75 settings_button_ = new SystemMenuButton(this, kSystemMenuSettingsIcon,
76 IDS_ASH_STATUS_TRAY_SETTINGS);
77 if (disable_buttons || !shell->system_tray_delegate()->ShouldShowSettings())
78 settings_button_->SetState(views::Button::STATE_DISABLED);
79 AddChildView(settings_button_);
80 AddSeparator();
73 81
74 help_button_ = 82 help_button_ =
75 new SystemMenuButton(this, kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP); 83 new SystemMenuButton(this, kSystemMenuHelpIcon, IDS_ASH_STATUS_TRAY_HELP);
76 if (base::i18n::IsRTL() && 84 if (base::i18n::IsRTL() &&
77 base::i18n::GetConfiguredLocale() == kHebrewLocale) { 85 base::i18n::GetConfiguredLocale() == kHebrewLocale) {
78 // The asset for the help button is a question mark '?'. Normally this asset 86 // 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 87 // is flipped in RTL locales, however Hebrew uses the LTR '?'. So the
80 // flipping must be disabled. (crbug.com/475237) 88 // flipping must be disabled. (crbug.com/475237)
81 help_button_->EnableCanvasFlippingForRTLUI(false); 89 help_button_->EnableCanvasFlippingForRTLUI(false);
82 } 90 }
91 if (disable_buttons)
92 help_button_->SetState(views::Button::STATE_DISABLED);
83 AddChildView(help_button_); 93 AddChildView(help_button_);
94 AddSeparator();
84 95
85 #if !defined(OS_WIN) 96 #if !defined(OS_WIN)
86 if (shell->GetSessionStateDelegate()->CanLockScreen()) { 97 lock_button_ =
87 AddSeparator(); 98 new SystemMenuButton(this, kSystemMenuLockIcon, IDS_ASH_STATUS_TRAY_LOCK);
88 lock_button_ = new SystemMenuButton(this, kSystemMenuLockIcon, 99 if (disable_buttons || !shell->GetSessionStateDelegate()->CanLockScreen())
89 IDS_ASH_STATUS_TRAY_LOCK); 100 lock_button_->SetState(views::Button::STATE_DISABLED);
90 AddChildView(lock_button_);
91 }
92 101
102 AddChildView(lock_button_);
93 AddSeparator(); 103 AddSeparator();
104
94 power_button_ = new SystemMenuButton(this, kSystemMenuPowerIcon, 105 power_button_ = new SystemMenuButton(this, kSystemMenuPowerIcon,
95 IDS_ASH_STATUS_TRAY_SHUTDOWN); 106 IDS_ASH_STATUS_TRAY_SHUTDOWN);
96 AddChildView(power_button_); 107 AddChildView(power_button_);
97
98 SystemTrayDelegate* system_tray_delegate = shell->system_tray_delegate(); 108 SystemTrayDelegate* system_tray_delegate = shell->system_tray_delegate();
99 system_tray_delegate->AddShutdownPolicyObserver(this); 109 system_tray_delegate->AddShutdownPolicyObserver(this);
100 system_tray_delegate->ShouldRebootOnShutdown(base::Bind( 110 system_tray_delegate->ShouldRebootOnShutdown(base::Bind(
101 &TilesDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr())); 111 &TilesDefaultView::OnShutdownPolicyChanged, weak_factory_.GetWeakPtr()));
102 #endif // !defined(OS_WIN) 112 #endif // !defined(OS_WIN)
103 } 113 }
104 114
105 void TilesDefaultView::ButtonPressed(views::Button* sender, 115 void TilesDefaultView::ButtonPressed(views::Button* sender,
106 const ui::Event& event) { 116 const ui::Event& event) {
107 DCHECK(sender); 117 DCHECK(sender);
(...skipping 30 matching lines...) Expand all
138 148
139 void TilesDefaultView::AddSeparator() { 149 void TilesDefaultView::AddSeparator() {
140 views::Separator* separator = 150 views::Separator* separator =
141 new views::Separator(views::Separator::HORIZONTAL); 151 new views::Separator(views::Separator::HORIZONTAL);
142 separator->SetPreferredSize(kHorizontalSeparatorHeight); 152 separator->SetPreferredSize(kHorizontalSeparatorHeight);
143 separator->SetColor(kHorizontalSeparatorColor); 153 separator->SetColor(kHorizontalSeparatorColor);
144 AddChildView(separator); 154 AddChildView(separator);
145 } 155 }
146 156
147 } // namespace ash 157 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tiles/tiles_default_view.h ('k') | ash/common/system/tiles/tray_tiles.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698