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 "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h" | 5 #include "chrome/browser/ui/views/profiles/avatar_menu_bubble_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 AvatarMenuBubbleView::AvatarMenuBubbleView( | 519 AvatarMenuBubbleView::AvatarMenuBubbleView( |
520 views::View* anchor_view, | 520 views::View* anchor_view, |
521 views::BubbleBorder::Arrow arrow, | 521 views::BubbleBorder::Arrow arrow, |
522 const gfx::Rect& anchor_rect, | 522 const gfx::Rect& anchor_rect, |
523 Browser* browser) | 523 Browser* browser) |
524 : BubbleDelegateView(anchor_view, arrow), | 524 : BubbleDelegateView(anchor_view, arrow), |
525 anchor_rect_(anchor_rect), | 525 anchor_rect_(anchor_rect), |
526 browser_(browser), | 526 browser_(browser), |
527 separator_(NULL), | 527 separator_(NULL), |
528 buttons_view_(NULL), | 528 buttons_view_(NULL), |
529 managed_user_info_(NULL), | 529 supervised_user_info_(NULL), |
530 separator_switch_users_(NULL), | 530 separator_switch_users_(NULL), |
531 expanded_(false) { | 531 expanded_(false) { |
532 avatar_menu_.reset(new AvatarMenu( | 532 avatar_menu_.reset(new AvatarMenu( |
533 &g_browser_process->profile_manager()->GetProfileInfoCache(), | 533 &g_browser_process->profile_manager()->GetProfileInfoCache(), |
534 this, | 534 this, |
535 browser_)); | 535 browser_)); |
536 avatar_menu_->RebuildMenu(); | 536 avatar_menu_->RebuildMenu(); |
537 } | 537 } |
538 | 538 |
539 AvatarMenuBubbleView::~AvatarMenuBubbleView() { | 539 AvatarMenuBubbleView::~AvatarMenuBubbleView() { |
(...skipping 11 matching lines...) Expand all Loading... |
551 if (buttons_view_) { | 551 if (buttons_view_) { |
552 preferred_size.Enlarge( | 552 preferred_size.Enlarge( |
553 0, kSeparatorPaddingY * 2 + separator_->GetPreferredSize().height()); | 553 0, kSeparatorPaddingY * 2 + separator_->GetPreferredSize().height()); |
554 | 554 |
555 gfx::Size buttons_size = buttons_view_->GetPreferredSize(); | 555 gfx::Size buttons_size = buttons_view_->GetPreferredSize(); |
556 preferred_size.Enlarge(0, buttons_size.height()); | 556 preferred_size.Enlarge(0, buttons_size.height()); |
557 preferred_size.SetToMax(buttons_size); | 557 preferred_size.SetToMax(buttons_size); |
558 } | 558 } |
559 | 559 |
560 | 560 |
561 if (managed_user_info_) { | 561 if (supervised_user_info_) { |
562 // First handle the switch profile link because it can still affect the | 562 // First handle the switch profile link because it can still affect the |
563 // preferred width. | 563 // preferred width. |
564 gfx::Size size = switch_profile_link_->GetPreferredSize(); | 564 gfx::Size size = switch_profile_link_->GetPreferredSize(); |
565 preferred_size.Enlarge(0, size.height()); | 565 preferred_size.Enlarge(0, size.height()); |
566 preferred_size.SetToMax(size); | 566 preferred_size.SetToMax(size); |
567 | 567 |
568 // Add the height of the two separators. | 568 // Add the height of the two separators. |
569 preferred_size.Enlarge( | 569 preferred_size.Enlarge( |
570 0, | 570 0, |
571 kSeparatorPaddingY * 4 + separator_->GetPreferredSize().height() * 2); | 571 kSeparatorPaddingY * 4 + separator_->GetPreferredSize().height() * 2); |
572 } | 572 } |
573 | 573 |
574 const int kBubbleViewMaxWidth = 800; | 574 const int kBubbleViewMaxWidth = 800; |
575 preferred_size.SetToMin( | 575 preferred_size.SetToMin( |
576 gfx::Size(kBubbleViewMaxWidth, preferred_size.height())); | 576 gfx::Size(kBubbleViewMaxWidth, preferred_size.height())); |
577 | 577 |
578 // We have to do this after the final width is calculated, since the label | 578 // We have to do this after the final width is calculated, since the label |
579 // will wrap based on the width. | 579 // will wrap based on the width. |
580 if (managed_user_info_) { | 580 if (supervised_user_info_) { |
581 int remaining_width = | 581 int remaining_width = |
582 preferred_size.width() - icon_view_->GetPreferredSize().width() - | 582 preferred_size.width() - icon_view_->GetPreferredSize().width() - |
583 views::kRelatedControlSmallHorizontalSpacing; | 583 views::kRelatedControlSmallHorizontalSpacing; |
584 preferred_size.Enlarge( | 584 preferred_size.Enlarge( |
585 0, | 585 0, |
586 managed_user_info_->GetHeightForWidth(remaining_width) + kItemMarginY); | 586 supervised_user_info_->GetHeightForWidth(remaining_width) + |
| 587 kItemMarginY); |
587 } | 588 } |
588 | 589 |
589 return preferred_size; | 590 return preferred_size; |
590 } | 591 } |
591 | 592 |
592 void AvatarMenuBubbleView::Layout() { | 593 void AvatarMenuBubbleView::Layout() { |
593 int y = 0; | 594 int y = 0; |
594 for (size_t i = 0; i < item_views_.size(); ++i) { | 595 for (size_t i = 0; i < item_views_.size(); ++i) { |
595 views::CustomButton* item_view = item_views_[i]; | 596 views::CustomButton* item_view = item_views_[i]; |
596 int item_height = item_view->GetPreferredSize().height(); | 597 int item_height = item_view->GetPreferredSize().height(); |
597 int item_width = width(); | 598 int item_width = width(); |
598 item_view->SetBounds(0, y, item_width, item_height); | 599 item_view->SetBounds(0, y, item_width, item_height); |
599 y += item_height + kItemMarginY; | 600 y += item_height + kItemMarginY; |
600 } | 601 } |
601 | 602 |
602 int separator_height; | 603 int separator_height; |
603 if (buttons_view_ || managed_user_info_) { | 604 if (buttons_view_ || supervised_user_info_) { |
604 separator_height = separator_->GetPreferredSize().height(); | 605 separator_height = separator_->GetPreferredSize().height(); |
605 y += kSeparatorPaddingY; | 606 y += kSeparatorPaddingY; |
606 separator_->SetBounds(0, y, width(), separator_height); | 607 separator_->SetBounds(0, y, width(), separator_height); |
607 y += kSeparatorPaddingY + separator_height; | 608 y += kSeparatorPaddingY + separator_height; |
608 } | 609 } |
609 | 610 |
610 if (buttons_view_) { | 611 if (buttons_view_) { |
611 buttons_view_->SetBounds(0, y, | 612 buttons_view_->SetBounds(0, y, |
612 width(), buttons_view_->GetPreferredSize().height()); | 613 width(), buttons_view_->GetPreferredSize().height()); |
613 } else if (managed_user_info_) { | 614 } else if (supervised_user_info_) { |
614 gfx::Size icon_size = icon_view_->GetPreferredSize(); | 615 gfx::Size icon_size = icon_view_->GetPreferredSize(); |
615 gfx::Rect icon_bounds(0, y, icon_size.width(), icon_size.height()); | 616 gfx::Rect icon_bounds(0, y, icon_size.width(), icon_size.height()); |
616 icon_view_->SetBoundsRect(icon_bounds); | 617 icon_view_->SetBoundsRect(icon_bounds); |
617 int info_width = width() - icon_bounds.right() - | 618 int info_width = width() - icon_bounds.right() - |
618 views::kRelatedControlSmallHorizontalSpacing; | 619 views::kRelatedControlSmallHorizontalSpacing; |
619 int height = managed_user_info_->GetHeightForWidth(info_width); | 620 int height = supervised_user_info_->GetHeightForWidth(info_width); |
620 managed_user_info_->SetBounds( | 621 supervised_user_info_->SetBounds( |
621 icon_bounds.right() + views::kRelatedControlSmallHorizontalSpacing, | 622 icon_bounds.right() + views::kRelatedControlSmallHorizontalSpacing, |
622 y, info_width, height); | 623 y, info_width, height); |
623 y += height + kItemMarginY + kSeparatorPaddingY; | 624 y += height + kItemMarginY + kSeparatorPaddingY; |
624 separator_switch_users_->SetBounds(0, y, width(), separator_height); | 625 separator_switch_users_->SetBounds(0, y, width(), separator_height); |
625 y += separator_height + kSeparatorPaddingY; | 626 y += separator_height + kSeparatorPaddingY; |
626 int link_height = switch_profile_link_->GetPreferredSize().height(); | 627 int link_height = switch_profile_link_->GetPreferredSize().height(); |
627 switch_profile_link_->SetBounds(0, y, width(), link_height); | 628 switch_profile_link_->SetBounds(0, y, width(), link_height); |
628 } | 629 } |
629 } | 630 } |
630 | 631 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 add_profile_link->set_listener(this); | 739 add_profile_link->set_listener(this); |
739 add_profile_link->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 740 add_profile_link->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
740 add_profile_link->SetBackgroundColor(color()); | 741 add_profile_link->SetBackgroundColor(color()); |
741 separator_ = new views::Separator(views::Separator::HORIZONTAL); | 742 separator_ = new views::Separator(views::Separator::HORIZONTAL); |
742 AddChildView(separator_); | 743 AddChildView(separator_); |
743 buttons_view_ = add_profile_link; | 744 buttons_view_ = add_profile_link; |
744 AddChildView(buttons_view_); | 745 AddChildView(buttons_view_); |
745 } | 746 } |
746 } | 747 } |
747 | 748 |
748 void AvatarMenuBubbleView::InitManagedUserContents( | 749 void AvatarMenuBubbleView::InitSupervisedUserContents( |
749 AvatarMenu* avatar_menu) { | 750 AvatarMenu* avatar_menu) { |
750 // Show the profile of the managed user. | 751 // Show the profile of the supervised user. |
751 size_t active_index = avatar_menu->GetActiveProfileIndex(); | 752 size_t active_index = avatar_menu->GetActiveProfileIndex(); |
752 const AvatarMenu::Item& item = | 753 const AvatarMenu::Item& item = |
753 avatar_menu->GetItemAt(active_index); | 754 avatar_menu->GetItemAt(active_index); |
754 ProfileItemView* item_view = new ProfileItemView(item, | 755 ProfileItemView* item_view = new ProfileItemView(item, |
755 this, | 756 this, |
756 avatar_menu_.get()); | 757 avatar_menu_.get()); |
757 item_view->SetAccessibleName(l10n_util::GetStringFUTF16( | 758 item_view->SetAccessibleName(l10n_util::GetStringFUTF16( |
758 IDS_PROFILES_SWITCH_TO_PROFILE_ACCESSIBLE_NAME, item.name)); | 759 IDS_PROFILES_SWITCH_TO_PROFILE_ACCESSIBLE_NAME, item.name)); |
759 item_views_.push_back(item_view); | 760 item_views_.push_back(item_view); |
760 AddChildView(item_view); | 761 AddChildView(item_view); |
761 separator_ = new views::Separator(views::Separator::HORIZONTAL); | 762 separator_ = new views::Separator(views::Separator::HORIZONTAL); |
762 AddChildView(separator_); | 763 AddChildView(separator_); |
763 | 764 |
764 // Add information about managed users. | 765 // Add information about supervised users. |
765 managed_user_info_ = | 766 supervised_user_info_ = |
766 new views::Label(avatar_menu_->GetManagedUserInformation(), | 767 new views::Label(avatar_menu_->GetSupervisedUserInformation(), |
767 ui::ResourceBundle::GetSharedInstance().GetFontList( | 768 ui::ResourceBundle::GetSharedInstance().GetFontList( |
768 ui::ResourceBundle::SmallFont)); | 769 ui::ResourceBundle::SmallFont)); |
769 managed_user_info_->SetMultiLine(true); | 770 supervised_user_info_->SetMultiLine(true); |
770 managed_user_info_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 771 supervised_user_info_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
771 managed_user_info_->SetBackgroundColor(color()); | 772 supervised_user_info_->SetBackgroundColor(color()); |
772 AddChildView(managed_user_info_); | 773 AddChildView(supervised_user_info_); |
773 | 774 |
774 // Add the managed user icon. | 775 // Add the supervised user icon. |
775 icon_view_ = new views::ImageView(); | 776 icon_view_ = new views::ImageView(); |
776 icon_view_->SetImage(avatar_menu_->GetManagedUserIcon().ToImageSkia()); | 777 icon_view_->SetImage(avatar_menu_->GetSupervisedUserIcon().ToImageSkia()); |
777 AddChildView(icon_view_); | 778 AddChildView(icon_view_); |
778 | 779 |
779 // Add a link for switching profiles. | 780 // Add a link for switching profiles. |
780 separator_switch_users_ = new views::Separator(views::Separator::HORIZONTAL); | 781 separator_switch_users_ = new views::Separator(views::Separator::HORIZONTAL); |
781 AddChildView(separator_switch_users_); | 782 AddChildView(separator_switch_users_); |
782 switch_profile_link_ = new views::Link( | 783 switch_profile_link_ = new views::Link( |
783 l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_PROFILE_LINK)); | 784 l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_PROFILE_LINK)); |
784 switch_profile_link_->set_listener(this); | 785 switch_profile_link_->set_listener(this); |
785 switch_profile_link_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 786 switch_profile_link_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
786 switch_profile_link_->SetBackgroundColor(color()); | 787 switch_profile_link_->SetBackgroundColor(color()); |
787 AddChildView(switch_profile_link_); | 788 AddChildView(switch_profile_link_); |
788 } | 789 } |
789 | 790 |
790 void AvatarMenuBubbleView::OnAvatarMenuChanged( | 791 void AvatarMenuBubbleView::OnAvatarMenuChanged( |
791 AvatarMenu* avatar_menu) { | 792 AvatarMenu* avatar_menu) { |
792 // Unset all our child view references and call RemoveAllChildViews() which | 793 // Unset all our child view references and call RemoveAllChildViews() which |
793 // will actually delete them. | 794 // will actually delete them. |
794 buttons_view_ = NULL; | 795 buttons_view_ = NULL; |
795 managed_user_info_ = NULL; | 796 supervised_user_info_ = NULL; |
796 item_views_.clear(); | 797 item_views_.clear(); |
797 RemoveAllChildViews(true); | 798 RemoveAllChildViews(true); |
798 | 799 |
799 if (avatar_menu_->GetManagedUserInformation().empty() || expanded_) | 800 if (avatar_menu_->GetSupervisedUserInformation().empty() || expanded_) |
800 InitMenuContents(avatar_menu); | 801 InitMenuContents(avatar_menu); |
801 else | 802 else |
802 InitManagedUserContents(avatar_menu); | 803 InitSupervisedUserContents(avatar_menu); |
803 | 804 |
804 // If the bubble has already been shown then resize and reposition the bubble. | 805 // If the bubble has already been shown then resize and reposition the bubble. |
805 Layout(); | 806 Layout(); |
806 if (GetBubbleFrameView()) | 807 if (GetBubbleFrameView()) |
807 SizeToContents(); | 808 SizeToContents(); |
808 } | 809 } |
809 | 810 |
810 void AvatarMenuBubbleView::SetBackgroundColors() { | 811 void AvatarMenuBubbleView::SetBackgroundColors() { |
811 for (size_t i = 0; i < item_views_.size(); ++i) { | 812 for (size_t i = 0; i < item_views_.size(); ++i) { |
812 item_views_[i]->OnHighlightStateChanged(); | 813 item_views_[i]->OnHighlightStateChanged(); |
813 } | 814 } |
814 } | 815 } |
OLD | NEW |