1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/user/accounts_detailed_view.h"
#include <vector>
#include "ash/multi_profile_uma.h"
#include "ash/shell.h"
#include "ash/system/tray/fixed_sized_scroll_view.h"
#include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_popup_header_button.h"
#include "ash/system/user/config.h"
#include "ash/system/user/tray_user.h"
#include "base/strings/utf_string_conversions.h"
#include "grit/ash_resources.h"
#include "grit/ui_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/border.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/grid_layout.h"
namespace ash {
namespace tray {
namespace {
const int kAccountsViewVerticalPadding = 12;
const int kPrimaryAccountColumnSetID = 0;
const int kSecondaryAccountColumnSetID = 1;
const int kPaddingBetweenAccounts = 20;
} // namespace
AccountsDetailedView::AccountsDetailedView(TrayUser* owner,
user::LoginStatus login_status)
: TrayDetailsView(owner),
delegate_(NULL),
account_list_(NULL),
add_account_button_(NULL),
add_user_button_(NULL) {
std::string user_id =
Shell::GetInstance()->session_state_delegate()->GetUserID(0);
delegate_ =
Shell::GetInstance()->system_tray_delegate()->GetUserAccountsDelegate(
user_id);
delegate_->AddObserver(this);
AddHeader(login_status);
CreateScrollableList();
AddAccountList();
AddAddAccountButton();
AddFooter();
}
AccountsDetailedView::~AccountsDetailedView() {
delegate_->RemoveObserver(this);
}
void AccountsDetailedView::OnViewClicked(views::View* sender) {
if (sender == footer()->content())
TransitionToDefaultView();
else if (sender == add_account_button_)
delegate_->LaunchAddAccountDialog();
else
NOTREACHED();
}
void AccountsDetailedView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
std::map<views::View*, std::string>::iterator it =
delete_button_to_account_id_.find(sender);
if (it != delete_button_to_account_id_.end()) {
delegate_->DeleteAccount(it->second);
} else if (add_user_button_ && add_user_button_ == sender) {
MultiProfileUMA::RecordSigninUser(MultiProfileUMA::SIGNIN_USER_BY_TRAY);
Shell::GetInstance()->system_tray_delegate()->ShowUserLogin();
owner()->system_tray()->CloseSystemBubble();
} else {
NOTREACHED();
}
}
void AccountsDetailedView::AccountListChanged() { UpdateAccountList(); }
void AccountsDetailedView::AddHeader(user::LoginStatus login_status) {
views::View* user_view_container = new views::View;
user_view_container->SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
user_view_container->SetBorder(
views::Border::CreateSolidSidedBorder(0, 0, 1, 0, kBorderLightColor));
user_view_container->AddChildView(
new tray::UserView(owner(), login_status, 0, true));
AddChildView(user_view_container);
}
void AccountsDetailedView::AddAccountList() {
scroll_content()->SetBorder(
views::Border::CreateEmptyBorder(kAccountsViewVerticalPadding,
kTrayPopupPaddingHorizontal,
kAccountsViewVerticalPadding,
kTrayPopupPaddingHorizontal));
views::Label* account_list_title = new views::Label(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCOUNT_LIST_TITLE));
account_list_title->SetEnabledColor(SkColorSetARGB(0x7f, 0, 0, 0));
account_list_title->SetHorizontalAlignment(gfx::ALIGN_LEFT);
scroll_content()->AddChildView(account_list_title);
account_list_ = new views::View();
UpdateAccountList();
scroll_content()->AddChildView(account_list_);
}
void AccountsDetailedView::AddAddAccountButton() {
SessionStateDelegate* session_state_delegate =
Shell::GetInstance()->session_state_delegate();
HoverHighlightView* add_account_button = new HoverHighlightView(this);
base::string16 user_name = session_state_delegate->GetUserGivenName(0);
if (user_name.empty())
user_name = session_state_delegate->GetUserDisplayName(0);
if (user_name.empty())
user_name = base::ASCIIToUTF16(session_state_delegate->GetUserEmail(0));
add_account_button->AddLabel(
l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_ADD_ACCOUNT_LABEL,
user_name),
gfx::ALIGN_CENTER,
gfx::Font::NORMAL);
AddChildView(add_account_button);
add_account_button_ = add_account_button;
}
void AccountsDetailedView::AddFooter() {
CreateSpecialRow(IDS_ASH_STATUS_TRAY_ACCOUNTS_TITLE, this);
if (!IsMultiProfileSupportedAndUserActive())
return;
TrayPopupHeaderButton* add_user_button =
new TrayPopupHeaderButton(this,
IDR_AURA_UBER_TRAY_NETWORK_INFO,
IDR_AURA_UBER_TRAY_NETWORK_INFO,
IDR_AURA_UBER_TRAY_NETWORK_INFO_HOVER,
IDR_AURA_UBER_TRAY_NETWORK_INFO_HOVER,
IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT);
add_user_button->SetTooltipText(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
footer()->AddButton(add_user_button);
add_user_button_ = add_user_button;
}
void AccountsDetailedView::UpdateAccountList() {
// Clear existing view.
delete_button_to_account_id_.clear();
account_list_->RemoveAllChildViews(true);
// Configuring layout manager.
views::GridLayout* layout = new views::GridLayout(account_list_);
account_list_->SetLayoutManager(layout);
views::ColumnSet* primary_account_row =
layout->AddColumnSet(kPrimaryAccountColumnSetID);
primary_account_row->AddColumn(views::GridLayout::LEADING,
views::GridLayout::BASELINE,
1.0,
views::GridLayout::USE_PREF,
0,
0);
views::ColumnSet* secondary_account_row =
layout->AddColumnSet(kSecondaryAccountColumnSetID);
secondary_account_row->AddColumn(views::GridLayout::FILL,
views::GridLayout::BASELINE,
1.0,
views::GridLayout::USE_PREF,
0,
0);
secondary_account_row->AddPaddingColumn(0.0, kTrayPopupPaddingBetweenItems);
secondary_account_row->AddColumn(views::GridLayout::FILL,
views::GridLayout::BASELINE,
0.0,
views::GridLayout::USE_PREF,
0,
0);
// Adding primary account.
layout->AddPaddingRow(0.0, kPaddingBetweenAccounts);
layout->StartRow(0.0, kPrimaryAccountColumnSetID);
const std::string& primary_account = delegate_->GetPrimaryAccount();
views::Label* primary_account_label =
new views::Label(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_PRIMARY_ACCOUNT_LABEL,
base::ASCIIToUTF16(
delegate_->GetAccountDisplayName(primary_account))));
layout->AddView(primary_account_label);
// Adding secondary accounts.
const std::vector<std::string>& secondary_accounts =
delegate_->GetSecondaryAccountsList();
for (size_t i = 0; i < secondary_accounts.size(); ++i) {
layout->AddPaddingRow(0.0, kPaddingBetweenAccounts);
layout->StartRow(0.0, kSecondaryAccountColumnSetID);
const std::string& account_id = secondary_accounts[i];
views::Label* account_label = new views::Label(
base::ASCIIToUTF16(delegate_->GetAccountDisplayName(account_id)));
account_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
layout->AddView(account_label);
views::View* delete_button = CreateDeleteButton();
delete_button_to_account_id_[delete_button] = account_id;
layout->AddView(delete_button);
}
scroll_content()->SizeToPreferredSize();
scroller()->Layout();
}
views::View* AccountsDetailedView::CreateDeleteButton() {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
views::ImageButton* delete_button = new views::ImageButton(this);
delete_button->SetImage(views::Button::STATE_NORMAL,
rb.GetImageNamed(IDR_CLOSE_2).ToImageSkia());
delete_button->SetImage(views::Button::STATE_HOVERED,
rb.GetImageNamed(IDR_CLOSE_2_H).ToImageSkia());
delete_button->SetImage(views::Button::STATE_PRESSED,
rb.GetImageNamed(IDR_CLOSE_2_P).ToImageSkia());
return delete_button;
}
} // namespace tray
} // namespace ash
|