| 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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/session_state_delegate.h" | 9 #include "ash/session_state_delegate.h" |
| 10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "ui/views/border.h" | 26 #include "ui/views/border.h" |
| 27 #include "ui/views/controls/label.h" | 27 #include "ui/views/controls/label.h" |
| 28 #include "ui/views/layout/box_layout.h" | 28 #include "ui/views/layout/box_layout.h" |
| 29 #include "ui/views/view.h" | 29 #include "ui/views/view.h" |
| 30 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 const int kUserLabelToIconPadding = 5; | 34 const int kUserLabelToIconPadding = 5; |
| 35 | 35 |
| 36 const int kTrayAvatarLargeSize = 32; | |
| 37 const int kTrayAvatarLargeCornerRadius = 2; | |
| 38 | |
| 39 } // namespace | 36 } // namespace |
| 40 | 37 |
| 41 namespace ash { | 38 namespace ash { |
| 42 | 39 |
| 43 TrayUser::TrayUser(SystemTray* system_tray, MultiProfileIndex index) | 40 TrayUser::TrayUser(SystemTray* system_tray, MultiProfileIndex index) |
| 44 : SystemTrayItem(system_tray), | 41 : SystemTrayItem(system_tray), |
| 45 multiprofile_index_(index), | 42 multiprofile_index_(index), |
| 46 user_(NULL), | 43 user_(NULL), |
| 47 layout_view_(NULL), | 44 layout_view_(NULL), |
| 48 avatar_(NULL), | 45 avatar_(NULL), |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 } | 170 } |
| 174 } | 171 } |
| 175 | 172 |
| 176 if (status == user::LOGGED_IN_LOCALLY_MANAGED) { | 173 if (status == user::LOGGED_IN_LOCALLY_MANAGED) { |
| 177 label_->SetText( | 174 label_->SetText( |
| 178 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL)); | 175 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL)); |
| 179 } else if (status == user::LOGGED_IN_GUEST) { | 176 } else if (status == user::LOGGED_IN_GUEST) { |
| 180 label_->SetText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)); | 177 label_->SetText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)); |
| 181 } | 178 } |
| 182 | 179 |
| 183 if (avatar_ && switches::UseAlternateShelfLayout()) { | 180 if (avatar_) { |
| 184 avatar_->SetCornerRadii( | 181 avatar_->SetCornerRadii( |
| 185 0, kTrayAvatarLargeCornerRadius, kTrayAvatarLargeCornerRadius, 0); | 182 0, kTrayAvatarCornerRadius, kTrayAvatarCornerRadius, 0); |
| 186 avatar_->SetBorder(views::Border::NullBorder()); | 183 avatar_->SetBorder(views::Border::NullBorder()); |
| 187 } | 184 } |
| 188 UpdateAvatarImage(status); | 185 UpdateAvatarImage(status); |
| 189 | 186 |
| 190 // Update layout after setting label_ and avatar_ with new login status. | 187 // Update layout after setting label_ and avatar_ with new login status. |
| 191 UpdateLayoutOfItem(); | 188 UpdateLayoutOfItem(); |
| 192 } | 189 } |
| 193 | 190 |
| 194 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 191 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 195 // Inactive users won't have a layout. | 192 // Inactive users won't have a layout. |
| 196 if (!layout_view_) | 193 if (!layout_view_) |
| 197 return; | 194 return; |
| 198 if (alignment == SHELF_ALIGNMENT_BOTTOM || | 195 if (alignment == SHELF_ALIGNMENT_BOTTOM || |
| 199 alignment == SHELF_ALIGNMENT_TOP) { | 196 alignment == SHELF_ALIGNMENT_TOP) { |
| 200 if (avatar_) { | 197 if (avatar_) { |
| 201 if (switches::UseAlternateShelfLayout()) { | 198 avatar_->SetBorder(views::Border::NullBorder()); |
| 202 avatar_->SetBorder(views::Border::NullBorder()); | 199 avatar_->SetCornerRadii( |
| 203 avatar_->SetCornerRadii( | 200 0, kTrayAvatarCornerRadius, kTrayAvatarCornerRadius, 0); |
| 204 0, kTrayAvatarLargeCornerRadius, kTrayAvatarLargeCornerRadius, 0); | |
| 205 } else { | |
| 206 avatar_->SetBorder(views::Border::CreateEmptyBorder( | |
| 207 0, | |
| 208 kTrayImageItemHorizontalPaddingBottomAlignment + 2, | |
| 209 0, | |
| 210 kTrayImageItemHorizontalPaddingBottomAlignment)); | |
| 211 } | |
| 212 } | 201 } |
| 213 if (label_) { | 202 if (label_) { |
| 214 // If label_ hasn't figured out its size yet, do that first. | 203 // If label_ hasn't figured out its size yet, do that first. |
| 215 if (label_->GetContentsBounds().height() == 0) | 204 if (label_->GetContentsBounds().height() == 0) |
| 216 label_->SizeToPreferredSize(); | 205 label_->SizeToPreferredSize(); |
| 217 int height = label_->GetContentsBounds().height(); | 206 int height = label_->GetContentsBounds().height(); |
| 218 int vertical_pad = (kTrayItemSize - height) / 2; | 207 int vertical_pad = (kTrayItemSize - height) / 2; |
| 219 int remainder = height % 2; | 208 int remainder = height % 2; |
| 220 label_->SetBorder(views::Border::CreateEmptyBorder( | 209 label_->SetBorder(views::Border::CreateEmptyBorder( |
| 221 vertical_pad + remainder, | 210 vertical_pad + remainder, |
| 222 kTrayLabelItemHorizontalPaddingBottomAlignment, | 211 kTrayLabelItemHorizontalPaddingBottomAlignment, |
| 223 vertical_pad, | 212 vertical_pad, |
| 224 kTrayLabelItemHorizontalPaddingBottomAlignment)); | 213 kTrayLabelItemHorizontalPaddingBottomAlignment)); |
| 225 } | 214 } |
| 226 layout_view_->SetLayoutManager( | 215 layout_view_->SetLayoutManager( |
| 227 new views::BoxLayout(views::BoxLayout::kHorizontal, | 216 new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 228 0, 0, kUserLabelToIconPadding)); | 217 0, 0, kUserLabelToIconPadding)); |
| 229 } else { | 218 } else { |
| 230 if (avatar_) { | 219 if (avatar_) { |
| 231 if (switches::UseAlternateShelfLayout()) { | 220 avatar_->SetBorder(views::Border::NullBorder()); |
| 232 avatar_->SetBorder(views::Border::NullBorder()); | 221 avatar_->SetCornerRadii( |
| 233 avatar_->SetCornerRadii( | 222 0, 0, kTrayAvatarCornerRadius, kTrayAvatarCornerRadius); |
| 234 0, 0, kTrayAvatarLargeCornerRadius, kTrayAvatarLargeCornerRadius); | |
| 235 } else { | |
| 236 SetTrayImageItemBorder(avatar_, alignment); | |
| 237 } | |
| 238 } | 223 } |
| 239 if (label_) { | 224 if (label_) { |
| 240 label_->SetBorder(views::Border::CreateEmptyBorder( | 225 label_->SetBorder(views::Border::CreateEmptyBorder( |
| 241 kTrayLabelItemVerticalPaddingVerticalAlignment, | 226 kTrayLabelItemVerticalPaddingVerticalAlignment, |
| 242 kTrayLabelItemHorizontalPaddingBottomAlignment, | 227 kTrayLabelItemHorizontalPaddingBottomAlignment, |
| 243 kTrayLabelItemVerticalPaddingVerticalAlignment, | 228 kTrayLabelItemVerticalPaddingVerticalAlignment, |
| 244 kTrayLabelItemHorizontalPaddingBottomAlignment)); | 229 kTrayLabelItemHorizontalPaddingBottomAlignment)); |
| 245 } | 230 } |
| 246 layout_view_->SetLayoutManager( | 231 layout_view_->SetLayoutManager( |
| 247 new views::BoxLayout(views::BoxLayout::kVertical, | 232 new views::BoxLayout(views::BoxLayout::kVertical, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 269 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()); | 254 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()); |
| 270 } | 255 } |
| 271 | 256 |
| 272 void TrayUser::UpdateAvatarImage(user::LoginStatus status) { | 257 void TrayUser::UpdateAvatarImage(user::LoginStatus status) { |
| 273 SessionStateDelegate* session_state_delegate = | 258 SessionStateDelegate* session_state_delegate = |
| 274 Shell::GetInstance()->session_state_delegate(); | 259 Shell::GetInstance()->session_state_delegate(); |
| 275 if (!avatar_ || | 260 if (!avatar_ || |
| 276 GetTrayIndex() >= session_state_delegate->NumberOfLoggedInUsers()) | 261 GetTrayIndex() >= session_state_delegate->NumberOfLoggedInUsers()) |
| 277 return; | 262 return; |
| 278 | 263 |
| 279 int icon_size = switches::UseAlternateShelfLayout() ? kTrayAvatarLargeSize | |
| 280 : kTrayAvatarSize; | |
| 281 | |
| 282 content::BrowserContext* context = session_state_delegate-> | 264 content::BrowserContext* context = session_state_delegate-> |
| 283 GetBrowserContextByIndex(GetTrayIndex()); | 265 GetBrowserContextByIndex(GetTrayIndex()); |
| 284 avatar_->SetImage(session_state_delegate->GetUserImage(context), | 266 avatar_->SetImage(session_state_delegate->GetUserImage(context), |
| 285 gfx::Size(icon_size, icon_size)); | 267 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); |
| 286 | 268 |
| 287 // Unit tests might come here with no images for some users. | 269 // Unit tests might come here with no images for some users. |
| 288 if (avatar_->size().IsEmpty()) | 270 if (avatar_->size().IsEmpty()) |
| 289 avatar_->SetSize(gfx::Size(icon_size, icon_size)); | 271 avatar_->SetSize(gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); |
| 290 } | 272 } |
| 291 | 273 |
| 292 MultiProfileIndex TrayUser::GetTrayIndex() { | 274 MultiProfileIndex TrayUser::GetTrayIndex() { |
| 293 Shell* shell = Shell::GetInstance(); | 275 Shell* shell = Shell::GetInstance(); |
| 294 // If multi profile is not enabled we can use the normal index. | 276 // If multi profile is not enabled we can use the normal index. |
| 295 if (!shell->delegate()->IsMultiProfilesEnabled()) | 277 if (!shell->delegate()->IsMultiProfilesEnabled()) |
| 296 return multiprofile_index_; | 278 return multiprofile_index_; |
| 297 // In case of multi profile we need to mirror the indices since the system | 279 // In case of multi profile we need to mirror the indices since the system |
| 298 // tray items are in the reverse order then the menu items. | 280 // tray items are in the reverse order then the menu items. |
| 299 return shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers() - | 281 return shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers() - |
| 300 1 - multiprofile_index_; | 282 1 - multiprofile_index_; |
| 301 } | 283 } |
| 302 | 284 |
| 303 void TrayUser::UpdateLayoutOfItem() { | 285 void TrayUser::UpdateLayoutOfItem() { |
| 304 RootWindowController* controller = GetRootWindowController( | 286 RootWindowController* controller = GetRootWindowController( |
| 305 system_tray()->GetWidget()->GetNativeWindow()->GetRootWindow()); | 287 system_tray()->GetWidget()->GetNativeWindow()->GetRootWindow()); |
| 306 if (controller && controller->shelf()) { | 288 if (controller && controller->shelf()) { |
| 307 UpdateAfterShelfAlignmentChange( | 289 UpdateAfterShelfAlignmentChange( |
| 308 controller->GetShelfLayoutManager()->GetAlignment()); | 290 controller->GetShelfLayoutManager()->GetAlignment()); |
| 309 } | 291 } |
| 310 } | 292 } |
| 311 | 293 |
| 312 } // namespace ash | 294 } // namespace ash |
| OLD | NEW |