Index: ash/system/user/tray_user.cc |
diff --git a/ash/system/user/tray_user.cc b/ash/system/user/tray_user.cc |
index adff775effd103e4e3e5fdf7401cb832dc4125d2..42f50090288d3d2a854265ee851ddc94f668d503 100644 |
--- a/ash/system/user/tray_user.cc |
+++ b/ash/system/user/tray_user.cc |
@@ -17,14 +17,20 @@ |
#include "ash/shelf/shelf_layout_manager.h" |
#include "ash/shell.h" |
#include "ash/shell_delegate.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/system_tray_notifier.h" |
#include "ash/system/tray/tray_constants.h" |
+#include "ash/system/tray/tray_details_view.h" |
#include "ash/system/tray/tray_item_view.h" |
+#include "ash/system/tray/tray_popup_header_button.h" |
#include "ash/system/tray/tray_popup_label_button.h" |
#include "ash/system/tray/tray_popup_label_button_border.h" |
#include "ash/system/tray/tray_utils.h" |
+#include "ash/system/tray/view_click_listener.h" |
+#include "ash/system/user/user_accounts_delegate.h" |
#include "base/i18n/rtl.h" |
#include "base/logging.h" |
#include "base/memory/scoped_vector.h" |
@@ -33,6 +39,7 @@ |
#include "base/strings/utf_string_conversions.h" |
#include "grit/ash_resources.h" |
#include "grit/ash_strings.h" |
+#include "grit/ui_resources.h" |
#include "skia/ext/image_operations.h" |
#include "third_party/skia/include/core/SkCanvas.h" |
#include "third_party/skia/include/core/SkPaint.h" |
@@ -56,12 +63,14 @@ |
#include "ui/views/bubble/tray_bubble_view.h" |
#include "ui/views/controls/button/button.h" |
#include "ui/views/controls/button/custom_button.h" |
+#include "ui/views/controls/button/image_button.h" |
#include "ui/views/controls/image_view.h" |
#include "ui/views/controls/label.h" |
#include "ui/views/controls/link.h" |
#include "ui/views/controls/link_listener.h" |
#include "ui/views/layout/box_layout.h" |
#include "ui/views/layout/fill_layout.h" |
+#include "ui/views/layout/grid_layout.h" |
#include "ui/views/mouse_watcher.h" |
#include "ui/views/painter.h" |
#include "ui/views/view.h" |
@@ -138,6 +147,30 @@ namespace internal { |
namespace tray { |
+// Returns true when multi profile is supported. |
+bool IsMultiProfileSupportedAndUserActive() { |
+ // We do not want to see any multi profile additions to a user view when the |
+ // log in screen is shown. |
+ return Shell::GetInstance()->delegate()->IsMultiProfilesEnabled() && |
+ !Shell::GetInstance() |
+ ->session_state_delegate() |
+ ->IsUserSessionBlocked(); |
+} |
+ |
+// Returns true if account management is supported. |
+bool IsAccountManagementSupportedAndUserActive() { |
+ return Shell::GetInstance()->delegate()->IsAccountManagementEnabled() && |
+ !Shell::GetInstance() |
+ ->session_state_delegate() |
+ ->IsUserSessionBlocked(); |
+} |
+ |
+bool IsUserSessionBlocked() { |
Mr4D (OOO till 08-26)
2014/03/30 23:38:26
Please add a comment here as well (e.g. Returns tr
oshima
2014/03/31 23:07:52
Also move this to the 1st place and let other util
dzhioev (left Google)
2014/04/01 17:25:02
Done.
dzhioev (left Google)
2014/04/01 17:25:02
Done.
|
+ return !Shell::GetInstance() |
+ ->session_state_delegate() |
+ ->IsUserSessionBlocked(); |
+} |
+ |
// A custom image view with rounded edges. |
class RoundedImageView : public views::View { |
public: |
@@ -180,7 +213,7 @@ class RoundedImageView : public views::View { |
class PublicAccountUserDetails : public views::View, |
public views::LinkListener { |
public: |
- PublicAccountUserDetails(SystemTrayItem* owner, int used_width); |
+ PublicAccountUserDetails(int max_width); |
virtual ~PublicAccountUserDetails(); |
private: |
@@ -195,7 +228,7 @@ class PublicAccountUserDetails : public views::View, |
// Calculate a preferred size that ensures the label text and the following |
// link do not wrap over more than three lines in total for aesthetic reasons |
// if possible. |
- void CalculatePreferredSize(SystemTrayItem* owner, int used_width); |
+ void CalculatePreferredSize(int max_allowed_width); |
base::string16 text_; |
views::Link* learn_more_; |
@@ -205,11 +238,13 @@ class PublicAccountUserDetails : public views::View, |
DISALLOW_COPY_AND_ASSIGN(PublicAccountUserDetails); |
}; |
-// The button which holds the user card in case of multi profile. |
-class UserCard : public views::CustomButton { |
+// This view is used to wrap it's content and transform it into button. |
+class ButtonFromView : public views::CustomButton { |
public: |
- UserCard(views::ButtonListener* listener, bool active_user); |
- virtual ~UserCard(); |
+ ButtonFromView(views::View* content, |
+ views::ButtonListener* listener, |
+ bool highlight_on_hover); |
+ virtual ~ButtonFromView(); |
// Called when the border should remain even in the non highlighted state. |
void ForceBorderVisible(bool show); |
@@ -225,16 +260,19 @@ class UserCard : public views::CustomButton { |
// Change the hover/active state of the "button" when the status changes. |
void ShowActive(); |
- // True if this is the active user. |
- bool is_active_user_; |
+ // Content of button. |
+ views::View* content_; |
+ |
+ // Whether button should be highligthed on hover. |
+ bool highlight_on_hover_; |
// True if button is hovered. |
bool button_hovered_; |
- // True if the border should be visible. |
+ // True if the border should be always visible. |
bool show_border_; |
- DISALLOW_COPY_AND_ASSIGN(UserCard); |
+ DISALLOW_COPY_AND_ASSIGN(ButtonFromView); |
}; |
class UserViewMouseWatcherHost : public views::MouseWatcherHost { |
@@ -262,7 +300,8 @@ class UserView : public views::View, |
public: |
UserView(SystemTrayItem* owner, |
ash::user::LoginStatus login, |
- MultiProfileIndex index); |
+ MultiProfileIndex index, |
+ bool for_detailed_view); |
virtual ~UserView(); |
// Overridden from MouseWatcherListener: |
@@ -282,24 +321,12 @@ class UserView : public views::View, |
const ui::Event& event) OVERRIDE; |
void AddLogoutButton(user::LoginStatus login); |
- void AddUserCard(SystemTrayItem* owner, user::LoginStatus login); |
- |
- // Create a user icon representation for the user card. |
- views::View* CreateIconForUserCard(user::LoginStatus login); |
- |
- // Create the additional user card content for the retail logged in mode. |
- void AddLoggedInRetailModeUserCardContent(); |
- |
- // Create the additional user card content for the public mode. |
- void AddLoggedInPublicModeUserCardContent(SystemTrayItem* owner); |
+ void AddUserCard(user::LoginStatus login); |
// Create the menu option to add another user. If |disabled| is set the user |
// cannot actively click on the item. |
void ToggleAddUserMenuOption(); |
- // Returns true when multi profile is supported. |
- bool SupportsMultiProfile(); |
- |
MultiProfileIndex multiprofile_index_; |
// The view of the user card. |
views::View* user_card_view_; |
@@ -307,15 +334,19 @@ class UserView : public views::View, |
// This is the owner system tray item of this view. |
SystemTrayItem* owner_; |
- // True if |user_card_view_| is a |UserView| - otherwise it is only a |
- // |views::View|. |
- bool is_user_card_; |
+ // True if |user_card_view_| is a |ButtonFromView| - otherwise it is only |
+ // a |UserCardView|. |
+ bool is_user_card_button_; |
+ |
views::View* logout_button_; |
scoped_ptr<PopupMessage> popup_message_; |
scoped_ptr<views::Widget> add_menu_option_; |
// True when the add user panel is visible but not activatable. |
- bool add_user_visible_but_disabled_; |
+ bool add_user_disabled_; |
+ |
+ // True if this view will be used inside detailed view. |
+ bool for_detailed_view_; |
// The mouse watcher which takes care of out of window hover events. |
scoped_ptr<views::MouseWatcher> mouse_watcher_; |
@@ -325,26 +356,18 @@ class UserView : public views::View, |
// The menu item view which gets shown when the user clicks in multi profile |
// mode onto the user item. |
-class AddUserView : public views::CustomButton, |
- public views::ButtonListener { |
+class AddUserView : public views::View { |
public: |
- // The |owner| is the view for which this view gets created. The |listener| |
- // will get notified when this item gets clicked. |
- AddUserView(UserCard* owner, views::ButtonListener* listener); |
+ // The |owner| is the view for which this view gets created. |
+ AddUserView(ButtonFromView* owner); |
virtual ~AddUserView(); |
// Get the anchor view for a message. |
views::View* anchor() { return anchor_; } |
- // Overridden from views::ButtonListener. |
- virtual void ButtonPressed(views::Button* sender, |
- const ui::Event& event) OVERRIDE; |
- |
private: |
// Overridden from views::View. |
virtual gfx::Size GetPreferredSize() OVERRIDE; |
- virtual int GetHeightForWidth(int width) OVERRIDE; |
- virtual void Layout() OVERRIDE; |
// Create the additional client content for this item. |
void AddContent(); |
@@ -352,11 +375,8 @@ class AddUserView : public views::CustomButton, |
// This is the content we create and show. |
views::View* add_user_; |
- // This listener will get informed when someone clicks on this button. |
- views::ButtonListener* listener_; |
- |
// This is the owner view of this item. |
- UserCard* owner_; |
+ ButtonFromView* owner_; |
// The anchor view for targetted bubble messages. |
views::View* anchor_; |
@@ -364,6 +384,95 @@ class AddUserView : public views::CustomButton, |
DISALLOW_COPY_AND_ASSIGN(AddUserView); |
}; |
+// The view displaying information about the user, such as user's avatar, email |
+// address, name, and more. View has no borders. |
+class UserCardView : public views::View { |
+ public: |
+ // |max_width| takes effect only if |login_status| is LOGGED_IN_PUBLIC. |
+ UserCardView(user::LoginStatus login_status, |
+ int max_width, |
+ int multiprofile_index); |
oshima
2014/03/31 23:07:52
virtual dtor
dzhioev (left Google)
2014/04/01 17:25:02
Done.
|
+ |
+ private: |
+ // Creates the content for the retail logged in mode. |
+ void AddRetailModeUserContent(); |
+ |
+ // Creates the content for the public mode. |
+ void AddPublicModeUserContent(int max_width); |
+ |
+ void AddUserContent(user::LoginStatus login_status, int multiprofile_index); |
+ |
+ // Create a user icon representation. |
+ views::View* CreateIcon(user::LoginStatus login_status, |
+ int multiprofile_index); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(UserCardView); |
+}; |
+ |
+class LogoutButton : public TrayPopupLabelButton { |
+ public: |
+ LogoutButton(views::ButtonListener* listener, |
+ const base::string16& text, |
+ bool placeholder) |
oshima
2014/03/31 23:07:52
this variable name doesn't match the variable name
dzhioev (left Google)
2014/04/01 17:25:02
Done.
|
+ : TrayPopupLabelButton(listener, text), placeholder_(placeholder) { |
+ SetEnabled(!placeholder_); |
+ } |
oshima
2014/03/31 23:07:52
virtual dtor
dzhioev (left Google)
2014/04/01 17:25:02
Done.
|
+ |
+ private: |
+ virtual void Paint(gfx::Canvas* canvas) OVERRIDE { |
+ // Just skip paint if this button used as a placeholder. |
+ if (!placeholder_) |
+ TrayPopupLabelButton::Paint(canvas); |
+ } |
+ |
+ bool placeholder_; |
+ DISALLOW_COPY_AND_ASSIGN(LogoutButton); |
+}; |
+ |
+// This detailed view appears after a click on the primary user's card when the |
+// new account managment is enabled. |
+class AccountsDetailedView : public TrayDetailsView, |
+ public ViewClickListener, |
+ public views::ButtonListener, |
+ public ash::tray::UserAccountsDelegate::Observer { |
+ public: |
+ AccountsDetailedView(TrayUser* owner, user::LoginStatus login_status); |
+ virtual ~AccountsDetailedView(); |
+ |
+ private: |
+ static const int kAccountsViewVerticalPadding = 12; |
+ static const int kPrimaryAccountColumnSetID = 0; |
+ static const int kSecondaryAccountColumnSetID = 1; |
+ static const int kPaddingBetweenAccounts = 20; |
+ |
+ // Overridden from ViewClickListener. |
+ virtual void OnViewClicked(views::View* sender) OVERRIDE; |
+ |
+ // Overridden from views::ButtonListener. |
+ virtual void ButtonPressed(views::Button* sender, |
+ const ui::Event& event) OVERRIDE; |
+ |
+ // Overridden from ash::tray::UserAccountsDelegate::Observer. |
+ virtual void AccountListChanged() OVERRIDE; |
+ |
+ void AddHeader(user::LoginStatus login_status); |
+ void AddAccountList(); |
+ void AddAddAccountButton(); |
+ void AddFooter(); |
+ |
+ void UpdateAccountList(); |
+ |
+ views::View* CreateDeleteButton(); |
+ |
+ ash::tray::UserAccountsDelegate* delegate_; |
+ views::View* account_list_; |
+ views::View* add_account_button_; |
+ views::View* add_user_button_; |
+ std::map<views::View*, std::string> delete_button_to_account_id_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AccountsDetailedView); |
+}; |
+ |
RoundedImageView::RoundedImageView(int corner_radius, bool active_user) |
: active_user_(active_user) { |
for (int i = 0; i < 4; ++i) |
@@ -426,8 +535,7 @@ void RoundedImageView::OnPaint(gfx::Canvas* canvas) { |
path, paint); |
} |
-PublicAccountUserDetails::PublicAccountUserDetails(SystemTrayItem* owner, |
- int used_width) |
+PublicAccountUserDetails::PublicAccountUserDetails(int max_width) |
: learn_more_(NULL) { |
const int inner_padding = |
kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; |
@@ -458,7 +566,7 @@ PublicAccountUserDetails::PublicAccountUserDetails(SystemTrayItem* owner, |
learn_more_->set_listener(this); |
AddChildView(learn_more_); |
- CalculatePreferredSize(owner, used_width); |
+ CalculatePreferredSize(max_width); |
} |
PublicAccountUserDetails::~PublicAccountUserDetails() {} |
@@ -549,21 +657,16 @@ void PublicAccountUserDetails::LinkClicked(views::Link* source, |
Shell::GetInstance()->system_tray_delegate()->ShowPublicAccountInfo(); |
} |
-void PublicAccountUserDetails::CalculatePreferredSize(SystemTrayItem* owner, |
- int used_width) { |
+void PublicAccountUserDetails::CalculatePreferredSize(int max_allowed_width) { |
const gfx::FontList font_list; |
const gfx::Size link_size = learn_more_->GetPreferredSize(); |
const int space_width = |
gfx::GetStringWidth(base::ASCIIToUTF16(" "), font_list); |
const gfx::Insets insets = GetInsets(); |
- views::TrayBubbleView* bubble_view = |
- owner->system_tray()->GetSystemBubble()->bubble_view(); |
- int min_width = std::max( |
- link_size.width(), |
- bubble_view->GetPreferredSize().width() - (used_width + insets.width())); |
+ int min_width = link_size.width(); |
int max_width = std::min( |
gfx::GetStringWidth(text_, font_list) + space_width + link_size.width(), |
- bubble_view->GetMaximumSize().width() - (used_width + insets.width())); |
+ max_allowed_width - insets.width()); |
// Do a binary search for the minimum width that ensures no more than three |
// lines are needed. The lower bound is the minimum of the current bubble |
// width and the width of the link (as no wrapping is permitted inside the |
@@ -602,61 +705,66 @@ void PublicAccountUserDetails::CalculatePreferredSize(SystemTrayItem* owner, |
preferred_size_ = gfx::Size( |
min_width + insets.width(), |
line_count * line_height + link_extra_height + insets.height()); |
- |
- bubble_view->SetWidth(preferred_size_.width() + used_width); |
} |
-UserCard::UserCard(views::ButtonListener* listener, bool active_user) |
+ButtonFromView::ButtonFromView(views::View* content, |
+ views::ButtonListener* listener, |
+ bool highlight_on_hover) |
: CustomButton(listener), |
- is_active_user_(active_user), |
+ content_(content), |
+ highlight_on_hover_(highlight_on_hover), |
button_hovered_(false), |
show_border_(false) { |
- if (is_active_user_) { |
- set_background( |
- views::Background::CreateSolidBackground(kBackgroundColor)); |
- ShowActive(); |
- } |
+ set_notify_enter_exit_on_child(true); |
+ SetLayoutManager( |
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
+ AddChildView(content_); |
+ ShowActive(); |
} |
-UserCard::~UserCard() {} |
+ButtonFromView::~ButtonFromView() {} |
-void UserCard::ForceBorderVisible(bool show) { |
+void ButtonFromView::ForceBorderVisible(bool show) { |
show_border_ = show; |
ShowActive(); |
} |
-void UserCard::OnMouseEntered(const ui::MouseEvent& event) { |
- if (is_active_user_) { |
- button_hovered_ = true; |
- background()->SetNativeControlColor(kHoverBackgroundColor); |
- ShowActive(); |
- } |
+void ButtonFromView::OnMouseEntered(const ui::MouseEvent& event) { |
+ button_hovered_ = true; |
+ ShowActive(); |
} |
-void UserCard::OnMouseExited(const ui::MouseEvent& event) { |
- if (is_active_user_) { |
- button_hovered_ = false; |
- background()->SetNativeControlColor(kBackgroundColor); |
- ShowActive(); |
- } |
+void ButtonFromView::OnMouseExited(const ui::MouseEvent& event) { |
+ button_hovered_ = false; |
+ ShowActive(); |
} |
-void UserCard::ShowActive() { |
- int width = button_hovered_ || show_border_ ? 1 : 0; |
- SetBorder(views::Border::CreateSolidSidedBorder( |
- width, width, width, 1, kBorderColor)); |
+void ButtonFromView::ShowActive() { |
+ bool border_visible = |
+ (button_hovered_ && highlight_on_hover_) || show_border_; |
+ SkColor border_color = border_visible ? kBorderColor : SK_ColorTRANSPARENT; |
+ SetBorder(views::Border::CreateSolidBorder(1, border_color)); |
+ if (highlight_on_hover_) { |
+ SkColor background_color = |
+ button_hovered_ ? kHoverBackgroundColor : kBackgroundColor; |
+ content_->set_background( |
+ views::Background::CreateSolidBackground(background_color)); |
+ set_background(views::Background::CreateSolidBackground(background_color)); |
+ } |
SchedulePaint(); |
} |
UserView::UserView(SystemTrayItem* owner, |
user::LoginStatus login, |
- MultiProfileIndex index) |
+ MultiProfileIndex index, |
+ bool for_detailed_view) |
: multiprofile_index_(index), |
user_card_view_(NULL), |
owner_(owner), |
- is_user_card_(false), |
+ is_user_card_button_(false), |
logout_button_(NULL), |
- add_user_visible_but_disabled_(false) { |
+ add_user_disabled_(false), |
+ for_detailed_view_(for_detailed_view) { |
CHECK_NE(user::LOGGED_IN_NONE, login); |
if (!index) { |
// Only the logged in user will have a background. All other users will have |
@@ -672,7 +780,7 @@ UserView::UserView(SystemTrayItem* owner, |
// Note that only the current multiprofile user gets a button. |
if (!multiprofile_index_) |
AddLogoutButton(login); |
- AddUserCard(owner, login); |
+ AddUserCard(login); |
} |
UserView::~UserView() {} |
@@ -685,15 +793,16 @@ void UserView::MouseMovedOutOfHost() { |
TrayUser::TestState UserView::GetStateForTest() const { |
if (add_menu_option_.get()) { |
- return add_user_visible_but_disabled_ ? TrayUser::ACTIVE_BUT_DISABLED : |
- TrayUser::ACTIVE; |
+ return add_user_disabled_ ? TrayUser::ACTIVE_BUT_DISABLED |
+ : TrayUser::ACTIVE; |
} |
- if (!is_user_card_) |
+ if (!is_user_card_button_) |
return TrayUser::SHOWN; |
- return static_cast<UserCard*>(user_card_view_)->is_hovered_for_test() ? |
- TrayUser::HOVERED : TrayUser::SHOWN; |
+ return static_cast<ButtonFromView*>(user_card_view_)->is_hovered_for_test() |
+ ? TrayUser::HOVERED |
+ : TrayUser::SHOWN; |
} |
gfx::Rect UserView::GetBoundsInScreenOfUserButtonForTest() { |
@@ -726,7 +835,8 @@ void UserView::Layout() { |
// Give the remaining space to the user card. |
gfx::Rect user_card_area = contents_area; |
int remaining_width = contents_area.width() - logout_area.width(); |
- if (SupportsMultiProfile()) { |
+ if (IsMultiProfileSupportedAndUserActive() || |
+ IsAccountManagementSupportedAndUserActive()) { |
// In multiprofile case |user_card_view_| and |logout_button_| have to |
// have the same height. |
int y = std::min(user_card_area.y(), logout_area.y()); |
@@ -765,7 +875,11 @@ void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) { |
Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
ash::UMA_STATUS_AREA_SIGN_OUT); |
Shell::GetInstance()->system_tray_delegate()->SignOut(); |
- } else if (sender == user_card_view_ && SupportsMultiProfile()) { |
+ } else if (sender == user_card_view_ && !multiprofile_index_ && |
+ IsAccountManagementSupportedAndUserActive()) { |
+ owner_->TransitionDetailedView(); |
+ } else if (sender == user_card_view_ && |
+ IsMultiProfileSupportedAndUserActive()) { |
if (!multiprofile_index_) { |
ToggleAddUserMenuOption(); |
} else { |
@@ -788,7 +902,8 @@ void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) { |
void UserView::AddLogoutButton(user::LoginStatus login) { |
const base::string16 title = user::GetLocalizedSignOutStringForStatus(login, |
true); |
- TrayPopupLabelButton* logout_button = new TrayPopupLabelButton(this, title); |
+ TrayPopupLabelButton* logout_button = |
+ new LogoutButton(this, title, for_detailed_view_); |
logout_button->SetAccessibleName(title); |
logout_button_ = logout_button; |
// In public account mode, the logout button border has a custom color. |
@@ -809,142 +924,52 @@ void UserView::AddLogoutButton(user::LoginStatus login) { |
AddChildView(logout_button_); |
} |
-void UserView::AddUserCard(SystemTrayItem* owner, user::LoginStatus login) { |
+void UserView::AddUserCard(user::LoginStatus login) { |
// Add padding around the panel. |
SetBorder(views::Border::CreateEmptyBorder(kUserCardVerticalPadding, |
kTrayPopupPaddingHorizontal, |
kUserCardVerticalPadding, |
kTrayPopupPaddingHorizontal)); |
- if (SupportsMultiProfile() && login != user::LOGGED_IN_RETAIL_MODE) { |
- user_card_view_ = new UserCard(this, multiprofile_index_ == 0); |
- is_user_card_ = true; |
- } else { |
- user_card_view_ = new views::View(); |
- is_user_card_ = false; |
- } |
- |
- user_card_view_->SetLayoutManager(new views::BoxLayout( |
- views::BoxLayout::kHorizontal, 0, 0 , kTrayPopupPaddingBetweenItems)); |
- AddChildViewAt(user_card_view_, 0); |
- |
- if (login == user::LOGGED_IN_RETAIL_MODE) { |
- AddLoggedInRetailModeUserCardContent(); |
- return; |
- } |
- |
- // The entire user card should trigger hover (the inner items get disabled). |
- user_card_view_->SetEnabled(true); |
- user_card_view_->set_notify_enter_exit_on_child(true); |
- |
- if (login == user::LOGGED_IN_PUBLIC) { |
- AddLoggedInPublicModeUserCardContent(owner); |
- return; |
- } |
- |
- views::View* icon = CreateIconForUserCard(login); |
- user_card_view_->AddChildView(icon); |
- |
- // To allow the border to start before the icon, reduce the size before and |
- // add an inset to the icon to get the spacing. |
- if (multiprofile_index_ == 0 && SupportsMultiProfile()) { |
- icon->SetBorder(views::Border::CreateEmptyBorder( |
- 0, kTrayUserTileHoverBorderInset, 0, 0)); |
- SetBorder(views::Border::CreateEmptyBorder( |
- kUserCardVerticalPadding, |
- kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset, |
- kUserCardVerticalPadding, |
- kTrayPopupPaddingHorizontal)); |
- } |
- SessionStateDelegate* delegate = |
- Shell::GetInstance()->session_state_delegate(); |
- views::Label* username = NULL; |
- ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
- if (!multiprofile_index_) { |
- base::string16 user_name_string = |
- login == user::LOGGED_IN_GUEST ? |
- bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL) : |
- delegate->GetUserDisplayName(multiprofile_index_); |
- if (!user_name_string.empty()) { |
- username = new views::Label(user_name_string); |
- username->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
+ views::TrayBubbleView* bubble_view = |
+ owner_->system_tray()->GetSystemBubble()->bubble_view(); |
+ int max_card_width = |
+ bubble_view->GetMaximumSize().width() - |
+ (2 * kTrayPopupPaddingHorizontal + kTrayPopupPaddingBetweenItems); |
+ if (logout_button_) |
+ max_card_width -= logout_button_->GetPreferredSize().width(); |
+ user_card_view_ = |
+ new UserCardView(login, max_card_width, multiprofile_index_); |
+ bool clickable = IsMultiProfileSupportedAndUserActive() || |
+ IsAccountManagementSupportedAndUserActive(); |
+ if (clickable) { |
+ // To allow the border to start before the icon, reduce the size before and |
+ // add an inset to the icon to get the spacing. |
+ if (!multiprofile_index_) { |
+ SetBorder(views::Border::CreateEmptyBorder( |
+ kUserCardVerticalPadding, |
+ kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset, |
+ kUserCardVerticalPadding, |
+ kTrayPopupPaddingHorizontal)); |
+ user_card_view_->SetBorder(views::Border::CreateEmptyBorder( |
+ 0, kTrayUserTileHoverBorderInset, 0, 0)); |
} |
- } |
- |
- views::Label* additional = NULL; |
- if (login != user::LOGGED_IN_GUEST) { |
- base::string16 user_email_string = |
- login == user::LOGGED_IN_LOCALLY_MANAGED ? |
- bundle.GetLocalizedString( |
- IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL) : |
- base::UTF8ToUTF16(delegate->GetUserEmail(multiprofile_index_)); |
- if (!user_email_string.empty()) { |
- additional = new views::Label(user_email_string); |
- additional->SetFontList( |
- bundle.GetFontList(ui::ResourceBundle::SmallFont)); |
- additional->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
+ if (!for_detailed_view_) { |
+ user_card_view_ = |
+ new ButtonFromView(user_card_view_, this, !multiprofile_index_); |
+ } else { |
+ // We want user card for detailed view to have exactly the same look |
+ // as user card for default view. That's why we wrap it in a button |
+ // without click listener and special hover behaviour. |
+ user_card_view_ = new ButtonFromView(user_card_view_, NULL, false); |
} |
+ is_user_card_button_ = true; |
} |
- |
- // Adjust text properties dependent on if it is an active or inactive user. |
- if (multiprofile_index_) { |
- // Fade the text of non active users to 50%. |
- SkColor text_color = additional->enabled_color(); |
- text_color = SkColorSetA(text_color, SkColorGetA(text_color) / 2); |
- if (additional) |
- additional->SetDisabledColor(text_color); |
- if (username) |
- username->SetDisabledColor(text_color); |
- } |
- |
- if (additional && username) { |
- views::View* details = new views::View; |
- details->SetLayoutManager(new views::BoxLayout( |
- views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0)); |
- details->AddChildView(username); |
- details->AddChildView(additional); |
- user_card_view_->AddChildView(details); |
- } else { |
- if (username) |
- user_card_view_->AddChildView(username); |
- if (additional) |
- user_card_view_->AddChildView(additional); |
- } |
-} |
- |
-views::View* UserView::CreateIconForUserCard(user::LoginStatus login) { |
- RoundedImageView* icon = new RoundedImageView(kProfileRoundedCornerRadius, |
- multiprofile_index_ == 0); |
- icon->SetEnabled(false); |
- if (login == user::LOGGED_IN_GUEST) { |
- icon->SetImage(*ui::ResourceBundle::GetSharedInstance(). |
- GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON).ToImageSkia(), |
- gfx::Size(kUserIconSize, kUserIconSize)); |
- } else { |
- SessionStateDelegate* delegate = |
- Shell::GetInstance()->session_state_delegate(); |
- content::BrowserContext* context = delegate->GetBrowserContextByIndex( |
- multiprofile_index_); |
- icon->SetImage(delegate->GetUserImage(context), |
- gfx::Size(kUserIconSize, kUserIconSize)); |
- } |
- return icon; |
-} |
- |
-void UserView::AddLoggedInRetailModeUserCardContent() { |
- views::Label* details = new views::Label; |
- ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
- details->SetText( |
- bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_KIOSK_LABEL)); |
- details->SetBorder(views::Border::CreateEmptyBorder(0, 4, 0, 1)); |
- details->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
- user_card_view_->AddChildView(details); |
-} |
- |
-void UserView::AddLoggedInPublicModeUserCardContent(SystemTrayItem* owner) { |
- user_card_view_->AddChildView(CreateIconForUserCard(user::LOGGED_IN_PUBLIC)); |
- user_card_view_->AddChildView(new PublicAccountUserDetails( |
- owner, GetPreferredSize().width() + kTrayPopupPaddingBetweenItems)); |
+ AddChildViewAt(user_card_view_, 0); |
+ // Card for locally managed user can consume more space than currently |
+ // available. In that case we should increase system bubble's width. |
+ if (login == user::LOGGED_IN_PUBLIC) |
+ bubble_view->SetWidth(GetPreferredSize().width()); |
} |
void UserView::ToggleAddUserMenuOption() { |
@@ -958,11 +983,6 @@ void UserView::ToggleAddUserMenuOption() { |
// Note: We do not need to install a global event handler to delete this |
// item since it will destroyed automatically before the menu / user menu item |
// gets destroyed.. |
- const SessionStateDelegate* session_state_delegate = |
- Shell::GetInstance()->session_state_delegate(); |
- add_user_visible_but_disabled_ = |
- session_state_delegate->NumberOfLoggedInUsers() >= |
- session_state_delegate->GetMaximumNumberOfLoggedInUsers(); |
add_menu_option_.reset(new views::Widget); |
views::Widget::InitParams params; |
params.type = views::Widget::InitParams::TYPE_TOOLTIP; |
@@ -983,12 +1003,23 @@ void UserView::ToggleAddUserMenuOption() { |
add_menu_option_->SetBounds(bounds); |
// Show the content. |
- AddUserView* add_user_view = new AddUserView( |
- static_cast<UserCard*>(user_card_view_), this); |
- add_menu_option_->SetContentsView(add_user_view); |
add_menu_option_->SetAlwaysOnTop(true); |
add_menu_option_->Show(); |
- if (add_user_visible_but_disabled_) { |
+ |
+ AddUserView* add_user_view = |
+ new AddUserView(static_cast<ButtonFromView*>(user_card_view_)); |
+ |
+ const SessionStateDelegate* delegate = |
+ Shell::GetInstance()->session_state_delegate(); |
+ add_user_disabled_ = delegate->NumberOfLoggedInUsers() >= |
+ delegate->GetMaximumNumberOfLoggedInUsers(); |
+ ButtonFromView* button = add_user_disabled_ |
+ ? new ButtonFromView(add_user_view, NULL, false) |
+ : new ButtonFromView(add_user_view, this, true); |
+ button->ForceBorderVisible(true); |
+ add_menu_option_->SetContentsView(button); |
+ |
+ if (add_user_disabled_) { |
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
popup_message_.reset(new PopupMessage( |
bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER), |
@@ -1009,19 +1040,8 @@ void UserView::ToggleAddUserMenuOption() { |
mouse_watcher_->Start(); |
} |
-bool UserView::SupportsMultiProfile() { |
- // We do not want to see any multi profile additions to a user view when the |
- // log in screen is shown. |
- return Shell::GetInstance()->delegate()->IsMultiProfilesEnabled() && |
- !Shell::GetInstance()->session_state_delegate()->IsUserSessionBlocked(); |
-} |
- |
-AddUserView::AddUserView(UserCard* owner, views::ButtonListener* listener) |
- : CustomButton(listener), |
- add_user_(NULL), |
- listener_(listener), |
- owner_(owner), |
- anchor_(NULL) { |
+AddUserView::AddUserView(ButtonFromView* owner) |
+ : add_user_(NULL), owner_(owner), anchor_(NULL) { |
AddContent(); |
owner_->ForceBorderVisible(true); |
} |
@@ -1034,37 +1054,11 @@ gfx::Size AddUserView::GetPreferredSize() { |
return owner_->bounds().size(); |
} |
-int AddUserView::GetHeightForWidth(int width) { |
- return owner_->bounds().size().height(); |
-} |
- |
-void AddUserView::Layout() { |
- gfx::Rect contents_area(GetContentsBounds()); |
- add_user_->SetBoundsRect(contents_area); |
-} |
- |
-void AddUserView::ButtonPressed(views::Button* sender, const ui::Event& event) { |
- if (add_user_ == sender) |
- listener_->ButtonPressed(this, event); |
- else |
- NOTREACHED(); |
-} |
- |
void AddUserView::AddContent() { |
- set_notify_enter_exit_on_child(true); |
- |
- const SessionStateDelegate* delegate = |
- Shell::GetInstance()->session_state_delegate(); |
- bool enable = delegate->NumberOfLoggedInUsers() < |
- delegate->GetMaximumNumberOfLoggedInUsers(); |
- |
SetLayoutManager(new views::FillLayout()); |
set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
- // Add padding around the panel. |
- SetBorder(views::Border::CreateSolidBorder(1, kBorderColor)); |
- |
- add_user_ = new UserCard(this, enable); |
+ add_user_ = new views::View; |
add_user_->SetBorder(views::Border::CreateEmptyBorder( |
kUserCardVerticalPadding, |
kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset, |
@@ -1072,7 +1066,7 @@ void AddUserView::AddContent() { |
kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset)); |
add_user_->SetLayoutManager(new views::BoxLayout( |
- views::BoxLayout::kHorizontal, 0, 0 , kTrayPopupPaddingBetweenItems)); |
+ views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems)); |
AddChildViewAt(add_user_, 0); |
// Add the [+] icon which is also the anchor for messages. |
@@ -1092,6 +1086,312 @@ void AddUserView::AddContent() { |
add_user_->AddChildView(command_label); |
} |
+UserCardView::UserCardView(user::LoginStatus login_status, |
+ int max_width, |
+ int multiprofile_index) { |
+ SetLayoutManager(new views::BoxLayout( |
+ views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems)); |
+ switch (login_status) { |
+ case user::LOGGED_IN_RETAIL_MODE: |
+ AddRetailModeUserContent(); |
+ break; |
+ case user::LOGGED_IN_PUBLIC: |
+ AddPublicModeUserContent(max_width); |
+ break; |
+ default: |
+ AddUserContent(login_status, multiprofile_index); |
+ break; |
+ } |
+} |
+ |
+void UserCardView::AddRetailModeUserContent() { |
+ views::Label* details = new views::Label; |
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
+ details->SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_KIOSK_LABEL)); |
+ details->SetBorder(views::Border::CreateEmptyBorder(0, 4, 0, 1)); |
+ details->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
+ AddChildView(details); |
+} |
+ |
+void UserCardView::AddPublicModeUserContent(int max_width) { |
+ views::View* icon = CreateIcon(user::LOGGED_IN_PUBLIC, 0); |
+ AddChildView(icon); |
+ int details_max_width = max_width - icon->GetPreferredSize().width() - |
+ kTrayPopupPaddingBetweenItems; |
+ AddChildView(new PublicAccountUserDetails(details_max_width)); |
+} |
+ |
+void UserCardView::AddUserContent(user::LoginStatus login_status, |
+ int multiprofile_index) { |
+ views::View* icon = CreateIcon(login_status, multiprofile_index); |
+ AddChildView(icon); |
+ views::Label* username = NULL; |
+ SessionStateDelegate* delegate = |
+ Shell::GetInstance()->session_state_delegate(); |
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
+ if (!multiprofile_index) { |
+ base::string16 user_name_string = |
+ login_status == user::LOGGED_IN_GUEST |
+ ? bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL) |
+ : delegate->GetUserDisplayName(multiprofile_index); |
+ if (user_name_string.empty() && IsAccountManagementSupportedAndUserActive()) |
+ user_name_string = |
+ base::ASCIIToUTF16(delegate->GetUserEmail(multiprofile_index)); |
+ if (!user_name_string.empty()) { |
+ username = new views::Label(user_name_string); |
+ username->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
+ } |
+ } |
+ |
+ views::Label* additional = NULL; |
+ if (login_status != user::LOGGED_IN_GUEST && |
+ (multiprofile_index || !IsAccountManagementSupportedAndUserActive())) { |
+ base::string16 user_email_string = |
+ login_status == user::LOGGED_IN_LOCALLY_MANAGED |
+ ? bundle.GetLocalizedString( |
+ IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL) |
+ : base::UTF8ToUTF16(delegate->GetUserEmail(multiprofile_index)); |
+ if (!user_email_string.empty()) { |
+ additional = new views::Label(user_email_string); |
+ additional->SetFontList( |
+ bundle.GetFontList(ui::ResourceBundle::SmallFont)); |
+ additional->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
+ } |
+ } |
+ |
+ // Adjust text properties dependent on if it is an active or inactive user. |
+ if (multiprofile_index) { |
+ // Fade the text of non active users to 50%. |
+ SkColor text_color = additional->enabled_color(); |
+ text_color = SkColorSetA(text_color, SkColorGetA(text_color) / 2); |
+ if (additional) |
+ additional->SetDisabledColor(text_color); |
+ if (username) |
+ username->SetDisabledColor(text_color); |
+ } |
+ |
+ if (additional && username) { |
+ views::View* details = new views::View; |
+ details->SetLayoutManager(new views::BoxLayout( |
+ views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0)); |
+ details->AddChildView(username); |
+ details->AddChildView(additional); |
+ AddChildView(details); |
+ } else { |
+ if (username) |
+ AddChildView(username); |
+ if (additional) |
+ AddChildView(additional); |
+ } |
+} |
+ |
+views::View* UserCardView::CreateIcon(user::LoginStatus login_status, |
+ int multiprofile_index) { |
+ RoundedImageView* icon = new RoundedImageView(kProfileRoundedCornerRadius, |
+ multiprofile_index == 0); |
+ if (login_status == user::LOGGED_IN_GUEST) { |
+ icon->SetImage(*ui::ResourceBundle::GetSharedInstance() |
+ .GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON) |
+ .ToImageSkia(), |
+ gfx::Size(kUserIconSize, kUserIconSize)); |
+ } else { |
+ SessionStateDelegate* delegate = |
+ Shell::GetInstance()->session_state_delegate(); |
+ content::BrowserContext* context = |
+ delegate->GetBrowserContextByIndex(multiprofile_index); |
+ icon->SetImage(delegate->GetUserImage(context), |
+ gfx::Size(kUserIconSize, kUserIconSize)); |
+ } |
+ return icon; |
+} |
+ |
+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 |
TrayUser::TrayUser(SystemTray* system_tray, MultiProfileIndex index) |
@@ -1134,7 +1434,7 @@ void TrayUser::UpdateAfterLoginStatusChangeForTest(user::LoginStatus status) { |
views::View* TrayUser::CreateTrayView(user::LoginStatus status) { |
CHECK(layout_view_ == NULL); |
- layout_view_ = new views::View(); |
+ layout_view_ = new views::View; |
layout_view_->SetLayoutManager( |
new views::BoxLayout(views::BoxLayout::kHorizontal, |
0, 0, kUserLabelToIconPadding)); |
@@ -1160,12 +1460,12 @@ views::View* TrayUser::CreateDefaultView(user::LoginStatus status) { |
if (multiprofile_index_ >= logged_in_users) |
return NULL; |
- user_ = new tray::UserView(this, status, multiprofile_index_); |
+ user_ = new tray::UserView(this, status, multiprofile_index_, false); |
return user_; |
} |
views::View* TrayUser::CreateDetailedView(user::LoginStatus status) { |
- return NULL; |
+ return new tray::AccountsDetailedView(this, status); |
} |
void TrayUser::DestroyTrayView() { |