OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/user_card_view.h" | 5 #include "ash/system/user/user_card_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_state_delegate.h" |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 const int line_height = font_list.GetHeight(); | 325 const int line_height = font_list.GetHeight(); |
326 const int link_extra_height = std::max( | 326 const int link_extra_height = std::max( |
327 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); | 327 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); |
328 preferred_size_ = | 328 preferred_size_ = |
329 gfx::Size(min_width + insets.width(), | 329 gfx::Size(min_width + insets.width(), |
330 line_count * line_height + link_extra_height + insets.height()); | 330 line_count * line_height + link_extra_height + insets.height()); |
331 } | 331 } |
332 | 332 |
333 } // namespace | 333 } // namespace |
334 | 334 |
335 UserCardView::UserCardView(user::LoginStatus login_status, | 335 UserCardView::UserCardView(LoginStatus login_status, |
336 int max_width, | 336 int max_width, |
337 int user_index) { | 337 int user_index) { |
338 SetLayoutManager(new views::BoxLayout( | 338 SetLayoutManager(new views::BoxLayout( |
339 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems)); | 339 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems)); |
340 if (login_status == user::LOGGED_IN_PUBLIC) { | 340 if (login_status == LoginStatus::PUBLIC) { |
341 AddPublicModeUserContent(max_width); | 341 AddPublicModeUserContent(max_width); |
342 } else { | 342 } else { |
343 AddUserContent(login_status, user_index); | 343 AddUserContent(login_status, user_index); |
344 } | 344 } |
345 } | 345 } |
346 | 346 |
347 UserCardView::~UserCardView() {} | 347 UserCardView::~UserCardView() {} |
348 | 348 |
349 void UserCardView::GetAccessibleState(ui::AXViewState* state) { | 349 void UserCardView::GetAccessibleState(ui::AXViewState* state) { |
350 state->role = ui::AX_ROLE_STATIC_TEXT; | 350 state->role = ui::AX_ROLE_STATIC_TEXT; |
351 std::vector<base::string16> labels; | 351 std::vector<base::string16> labels; |
352 for (int i = 0; i < child_count(); ++i) | 352 for (int i = 0; i < child_count(); ++i) |
353 GetAccessibleLabelFromDescendantViews(child_at(i), labels); | 353 GetAccessibleLabelFromDescendantViews(child_at(i), labels); |
354 state->name = base::JoinString(labels, base::ASCIIToUTF16(" ")); | 354 state->name = base::JoinString(labels, base::ASCIIToUTF16(" ")); |
355 } | 355 } |
356 | 356 |
357 void UserCardView::AddPublicModeUserContent(int max_width) { | 357 void UserCardView::AddPublicModeUserContent(int max_width) { |
358 views::View* icon = CreateIcon(user::LOGGED_IN_PUBLIC, 0); | 358 views::View* icon = CreateIcon(LoginStatus::PUBLIC, 0); |
359 AddChildView(icon); | 359 AddChildView(icon); |
360 int details_max_width = max_width - icon->GetPreferredSize().width() - | 360 int details_max_width = max_width - icon->GetPreferredSize().width() - |
361 kTrayPopupPaddingBetweenItems; | 361 kTrayPopupPaddingBetweenItems; |
362 AddChildView(new PublicAccountUserDetails(details_max_width)); | 362 AddChildView(new PublicAccountUserDetails(details_max_width)); |
363 } | 363 } |
364 | 364 |
365 void UserCardView::AddUserContent(user::LoginStatus login_status, | 365 void UserCardView::AddUserContent(LoginStatus login_status, int user_index) { |
366 int user_index) { | |
367 views::View* icon = CreateIcon(login_status, user_index); | 366 views::View* icon = CreateIcon(login_status, user_index); |
368 AddChildView(icon); | 367 AddChildView(icon); |
369 views::Label* user_name = NULL; | 368 views::Label* user_name = NULL; |
370 SessionStateDelegate* delegate = | 369 SessionStateDelegate* delegate = |
371 Shell::GetInstance()->session_state_delegate(); | 370 Shell::GetInstance()->session_state_delegate(); |
372 if (!user_index) { | 371 if (!user_index) { |
373 base::string16 user_name_string = | 372 base::string16 user_name_string = |
374 login_status == user::LOGGED_IN_GUEST | 373 login_status == LoginStatus::GUEST |
375 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL) | 374 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL) |
376 : delegate->GetUserInfo(user_index)->GetDisplayName(); | 375 : delegate->GetUserInfo(user_index)->GetDisplayName(); |
377 if (!user_name_string.empty()) { | 376 if (!user_name_string.empty()) { |
378 user_name = new views::Label(user_name_string); | 377 user_name = new views::Label(user_name_string); |
379 user_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 378 user_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
380 } | 379 } |
381 } | 380 } |
382 | 381 |
383 views::Label* user_email = NULL; | 382 views::Label* user_email = NULL; |
384 if (login_status != user::LOGGED_IN_GUEST) { | 383 if (login_status != LoginStatus::GUEST) { |
385 SystemTrayDelegate* tray_delegate = | 384 SystemTrayDelegate* tray_delegate = |
386 Shell::GetInstance()->system_tray_delegate(); | 385 Shell::GetInstance()->system_tray_delegate(); |
387 base::string16 user_email_string = | 386 base::string16 user_email_string = |
388 tray_delegate->IsUserSupervised() | 387 tray_delegate->IsUserSupervised() |
389 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL) | 388 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL) |
390 : base::UTF8ToUTF16(delegate->GetUserInfo(user_index)->GetEmail()); | 389 : base::UTF8ToUTF16(delegate->GetUserInfo(user_index)->GetEmail()); |
391 if (!user_email_string.empty()) { | 390 if (!user_email_string.empty()) { |
392 user_email = new views::Label(user_email_string); | 391 user_email = new views::Label(user_email_string); |
393 user_email->SetFontList( | 392 user_email->SetFontList( |
394 ui::ResourceBundle::GetSharedInstance().GetFontList( | 393 ui::ResourceBundle::GetSharedInstance().GetFontList( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 details->AddChildView(email_indicator_view); | 433 details->AddChildView(email_indicator_view); |
435 details->AddChildView(media_indicator->GetMessageView()); | 434 details->AddChildView(media_indicator->GetMessageView()); |
436 AddChildView(details); | 435 AddChildView(details); |
437 #else | 436 #else |
438 AddChildView(user_email); | 437 AddChildView(user_email); |
439 #endif | 438 #endif |
440 } | 439 } |
441 } | 440 } |
442 } | 441 } |
443 | 442 |
444 views::View* UserCardView::CreateIcon(user::LoginStatus login_status, | 443 views::View* UserCardView::CreateIcon(LoginStatus login_status, |
445 int user_index) { | 444 int user_index) { |
446 RoundedImageView* icon = | 445 RoundedImageView* icon = |
447 new RoundedImageView(kTrayAvatarCornerRadius, user_index == 0); | 446 new RoundedImageView(kTrayAvatarCornerRadius, user_index == 0); |
448 if (login_status == user::LOGGED_IN_GUEST) { | 447 if (login_status == LoginStatus::GUEST) { |
449 icon->SetImage(*ui::ResourceBundle::GetSharedInstance() | 448 icon->SetImage(*ui::ResourceBundle::GetSharedInstance() |
450 .GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON) | 449 .GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON) |
451 .ToImageSkia(), | 450 .ToImageSkia(), |
452 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); | 451 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); |
453 } else { | 452 } else { |
454 SessionStateDelegate* delegate = | 453 SessionStateDelegate* delegate = |
455 Shell::GetInstance()->session_state_delegate(); | 454 Shell::GetInstance()->session_state_delegate(); |
456 icon->SetImage(delegate->GetUserInfo(user_index)->GetImage(), | 455 icon->SetImage(delegate->GetUserInfo(user_index)->GetImage(), |
457 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); | 456 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); |
458 } | 457 } |
459 return icon; | 458 return icon; |
460 } | 459 } |
461 | 460 |
462 } // namespace tray | 461 } // namespace tray |
463 } // namespace ash | 462 } // namespace ash |
OLD | NEW |