OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/system/user/tray_user.h" | 5 #include "ash/system/user/tray_user.h" |
6 | 6 |
7 #include "ash/common/ash_switches.h" | 7 #include "ash/common/ash_switches.h" |
8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
9 #include "ash/common/shelf/wm_shelf_util.h" | 9 #include "ash/common/shelf/wm_shelf_util.h" |
10 #include "ash/common/system/tray/system_tray_delegate.h" | 10 #include "ash/common/system/tray/system_tray_delegate.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 73 } |
74 | 74 |
75 void TrayUser::UpdateAfterLoginStatusChangeForTest(LoginStatus status) { | 75 void TrayUser::UpdateAfterLoginStatusChangeForTest(LoginStatus status) { |
76 UpdateAfterLoginStatusChange(status); | 76 UpdateAfterLoginStatusChange(status); |
77 } | 77 } |
78 | 78 |
79 views::View* TrayUser::CreateTrayView(LoginStatus status) { | 79 views::View* TrayUser::CreateTrayView(LoginStatus status) { |
80 CHECK(layout_view_ == nullptr); | 80 CHECK(layout_view_ == nullptr); |
81 | 81 |
82 layout_view_ = new views::View; | 82 layout_view_ = new views::View; |
83 layout_view_->SetLayoutManager( | 83 layout_view_->SetLayoutManager(new views::BoxLayout( |
84 new views::BoxLayout(views::BoxLayout::kHorizontal, | 84 views::BoxLayout::kHorizontal, 0, 0, kUserLabelToIconPadding)); |
85 0, 0, kUserLabelToIconPadding)); | |
86 UpdateAfterLoginStatusChange(status); | 85 UpdateAfterLoginStatusChange(status); |
87 return layout_view_; | 86 return layout_view_; |
88 } | 87 } |
89 | 88 |
90 views::View* TrayUser::CreateDefaultView(LoginStatus status) { | 89 views::View* TrayUser::CreateDefaultView(LoginStatus status) { |
91 if (status == LoginStatus::NOT_LOGGED_IN) | 90 if (status == LoginStatus::NOT_LOGGED_IN) |
92 return nullptr; | 91 return nullptr; |
93 const SessionStateDelegate* session_state_delegate = | 92 const SessionStateDelegate* session_state_delegate = |
94 WmShell::Get()->GetSessionStateDelegate(); | 93 WmShell::Get()->GetSessionStateDelegate(); |
95 | 94 |
(...skipping 28 matching lines...) Expand all Loading... |
124 void TrayUser::UpdateAfterLoginStatusChange(LoginStatus status) { | 123 void TrayUser::UpdateAfterLoginStatusChange(LoginStatus status) { |
125 // Only the active user is represented in the tray. | 124 // Only the active user is represented in the tray. |
126 if (!layout_view_) | 125 if (!layout_view_) |
127 return; | 126 return; |
128 if (user_index_ > 0) | 127 if (user_index_ > 0) |
129 return; | 128 return; |
130 bool need_label = false; | 129 bool need_label = false; |
131 bool need_avatar = false; | 130 bool need_avatar = false; |
132 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 131 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
133 if (delegate->IsUserSupervised()) | 132 if (delegate->IsUserSupervised()) |
134 need_label = true; | 133 need_label = true; |
135 switch (status) { | 134 switch (status) { |
136 case LoginStatus::LOCKED: | 135 case LoginStatus::LOCKED: |
137 case LoginStatus::USER: | 136 case LoginStatus::USER: |
138 case LoginStatus::OWNER: | 137 case LoginStatus::OWNER: |
139 case LoginStatus::PUBLIC: | 138 case LoginStatus::PUBLIC: |
140 need_avatar = true; | 139 need_avatar = true; |
141 break; | 140 break; |
142 case LoginStatus::SUPERVISED: | 141 case LoginStatus::SUPERVISED: |
143 need_avatar = true; | 142 need_avatar = true; |
144 need_label = true; | 143 need_label = true; |
(...skipping 25 matching lines...) Expand all Loading... |
170 } | 169 } |
171 | 170 |
172 if (delegate->IsUserSupervised()) { | 171 if (delegate->IsUserSupervised()) { |
173 label_->SetText( | 172 label_->SetText( |
174 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL)); | 173 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL)); |
175 } else if (status == LoginStatus::GUEST) { | 174 } else if (status == LoginStatus::GUEST) { |
176 label_->SetText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)); | 175 label_->SetText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)); |
177 } | 176 } |
178 | 177 |
179 if (avatar_) { | 178 if (avatar_) { |
180 avatar_->SetCornerRadii( | 179 avatar_->SetCornerRadii(0, kTrayAvatarCornerRadius, kTrayAvatarCornerRadius, |
181 0, kTrayAvatarCornerRadius, kTrayAvatarCornerRadius, 0); | 180 0); |
182 avatar_->SetBorder(views::Border::NullBorder()); | 181 avatar_->SetBorder(views::Border::NullBorder()); |
183 } | 182 } |
184 UpdateAvatarImage(status); | 183 UpdateAvatarImage(status); |
185 | 184 |
186 // Update layout after setting label_ and avatar_ with new login status. | 185 // Update layout after setting label_ and avatar_ with new login status. |
187 UpdateLayoutOfItem(); | 186 UpdateLayoutOfItem(); |
188 } | 187 } |
189 | 188 |
190 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 189 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
191 // Inactive users won't have a layout. | 190 // Inactive users won't have a layout. |
192 if (!layout_view_) | 191 if (!layout_view_) |
193 return; | 192 return; |
194 if (IsHorizontalAlignment(alignment)) { | 193 if (IsHorizontalAlignment(alignment)) { |
195 if (avatar_) { | 194 if (avatar_) { |
196 avatar_->SetBorder(views::Border::NullBorder()); | 195 avatar_->SetBorder(views::Border::NullBorder()); |
197 avatar_->SetCornerRadii( | 196 avatar_->SetCornerRadii(0, kTrayAvatarCornerRadius, |
198 0, kTrayAvatarCornerRadius, kTrayAvatarCornerRadius, 0); | 197 kTrayAvatarCornerRadius, 0); |
199 } | 198 } |
200 if (label_) { | 199 if (label_) { |
201 // If label_ hasn't figured out its size yet, do that first. | 200 // If label_ hasn't figured out its size yet, do that first. |
202 if (label_->GetContentsBounds().height() == 0) | 201 if (label_->GetContentsBounds().height() == 0) |
203 label_->SizeToPreferredSize(); | 202 label_->SizeToPreferredSize(); |
204 int height = label_->GetContentsBounds().height(); | 203 int height = label_->GetContentsBounds().height(); |
205 int vertical_pad = (kTrayItemSize - height) / 2; | 204 int vertical_pad = (kTrayItemSize - height) / 2; |
206 int remainder = height % 2; | 205 int remainder = height % 2; |
207 label_->SetBorder(views::Border::CreateEmptyBorder( | 206 label_->SetBorder(views::Border::CreateEmptyBorder( |
208 vertical_pad + remainder, | 207 vertical_pad + remainder, |
209 kTrayLabelItemHorizontalPaddingBottomAlignment, | 208 kTrayLabelItemHorizontalPaddingBottomAlignment, vertical_pad, |
210 vertical_pad, | |
211 kTrayLabelItemHorizontalPaddingBottomAlignment)); | 209 kTrayLabelItemHorizontalPaddingBottomAlignment)); |
212 } | 210 } |
213 layout_view_->SetLayoutManager( | 211 layout_view_->SetLayoutManager(new views::BoxLayout( |
214 new views::BoxLayout(views::BoxLayout::kHorizontal, | 212 views::BoxLayout::kHorizontal, 0, 0, kUserLabelToIconPadding)); |
215 0, 0, kUserLabelToIconPadding)); | |
216 } else { | 213 } else { |
217 if (avatar_) { | 214 if (avatar_) { |
218 avatar_->SetBorder(views::Border::NullBorder()); | 215 avatar_->SetBorder(views::Border::NullBorder()); |
219 avatar_->SetCornerRadii( | 216 avatar_->SetCornerRadii(0, 0, kTrayAvatarCornerRadius, |
220 0, 0, kTrayAvatarCornerRadius, kTrayAvatarCornerRadius); | 217 kTrayAvatarCornerRadius); |
221 } | 218 } |
222 if (label_) { | 219 if (label_) { |
223 label_->SetBorder(views::Border::CreateEmptyBorder( | 220 label_->SetBorder(views::Border::CreateEmptyBorder( |
224 kTrayLabelItemVerticalPaddingVerticalAlignment, | 221 kTrayLabelItemVerticalPaddingVerticalAlignment, |
225 kTrayLabelItemHorizontalPaddingBottomAlignment, | 222 kTrayLabelItemHorizontalPaddingBottomAlignment, |
226 kTrayLabelItemVerticalPaddingVerticalAlignment, | 223 kTrayLabelItemVerticalPaddingVerticalAlignment, |
227 kTrayLabelItemHorizontalPaddingBottomAlignment)); | 224 kTrayLabelItemHorizontalPaddingBottomAlignment)); |
228 } | 225 } |
229 layout_view_->SetLayoutManager( | 226 layout_view_->SetLayoutManager(new views::BoxLayout( |
230 new views::BoxLayout(views::BoxLayout::kVertical, | 227 views::BoxLayout::kVertical, 0, 0, kUserLabelToIconPadding)); |
231 0, 0, kUserLabelToIconPadding)); | |
232 } | 228 } |
233 } | 229 } |
234 | 230 |
235 void TrayUser::OnUserUpdate() { | 231 void TrayUser::OnUserUpdate() { |
236 UpdateAvatarImage( | 232 UpdateAvatarImage( |
237 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); | 233 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); |
238 } | 234 } |
239 | 235 |
240 void TrayUser::OnUserAddedToSession() { | 236 void TrayUser::OnUserAddedToSession() { |
241 SessionStateDelegate* session_state_delegate = | 237 SessionStateDelegate* session_state_delegate = |
(...skipping 26 matching lines...) Expand all Loading... |
268 // Unit tests might come here with no images for some users. | 264 // Unit tests might come here with no images for some users. |
269 if (avatar_->size().IsEmpty()) | 265 if (avatar_->size().IsEmpty()) |
270 avatar_->SetSize(gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); | 266 avatar_->SetSize(gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); |
271 } | 267 } |
272 | 268 |
273 void TrayUser::UpdateLayoutOfItem() { | 269 void TrayUser::UpdateLayoutOfItem() { |
274 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); | 270 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); |
275 } | 271 } |
276 | 272 |
277 } // namespace ash | 273 } // namespace ash |
OLD | NEW |