owner_(owner),
is_user_card_button_(false),
logout_button_(NULL),
- add_user_disabled_(false),
+ add_user_enabled_(true),
for_detailed_view_(for_detailed_view),
focus_manager_(NULL) {
CHECK_NE(user::LOGGED_IN_NONE, login);
TrayUser::TestState UserView::GetStateForTest() const {
if (add_menu_option_.get()) {
- return add_user_disabled_ ? TrayUser::ACTIVE_BUT_DISABLED
- : TrayUser::ACTIVE;
+ return add_user_enabled_ ? TrayUser::ACTIVE : TrayUser::ACTIVE_BUT_DISABLED;
}
if (!is_user_card_button_)
max_card_width -= logout_button_->GetPreferredSize().width();
user_card_view_ =
new UserCardView(login, max_card_width, multiprofile_index_);
- bool clickable = IsMultiProfileSupportedAndUserActive() ||
- IsMultiAccountSupportedAndUserActive();
+ // The entry is clickable when no system modal dialog is open and one of the
+ // multi user options is active.
+ bool clickable = !Shell::GetInstance()->IsSystemModalWindowOpen() &&
+ (IsMultiProfileSupportedAndUserActive() ||
+ IsMultiAccountSupportedAndUserActive());
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.
const SessionStateDelegate* delegate =
Shell::GetInstance()->session_state_delegate();
- bool multi_profile_allowed =
- delegate->IsMultiProfileAllowedByPrimaryUserPolicy();
- add_user_disabled_ = (delegate->NumberOfLoggedInUsers() >=
- delegate->GetMaximumNumberOfLoggedInUsers()) ||
- !multi_profile_allowed;
-
- ButtonFromView* button = new ButtonFromView(
- add_user_view,
- add_user_disabled_ ? NULL : this,
- !add_user_disabled_,
- gfx::Insets(1, 1, 1, 1));
+ SessionStateDelegate::AddUserError add_user_error;
+ add_user_enabled_ = delegate->CanAddUserToMultiProfile(&add_user_error);
+
+ ButtonFromView* button = new ButtonFromView(add_user_view,
+ add_user_enabled_ ? this : NULL,
+ add_user_enabled_,
+ gfx::Insets(1, 1, 1, 1));
button->set_request_focus_on_press(false);
button->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
button->ForceBorderVisible(true);
add_menu_option_->SetContentsView(button);
- if (add_user_disabled_) {
+ if (add_user_enabled_) {
+ // We activate the entry automatically if invoked with focus.
+ if (user_card_view_->HasFocus()) {
+ button->GetFocusManager()->SetFocusedView(button);
+ user_card_view_->GetFocusManager()->SetFocusedView(button);
+ }
+ } else {
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
- int message_id;
- if (!multi_profile_allowed)
- message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER;
- else
- message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER;
+ int message_id = 0;
+ switch (add_user_error) {
+ case SessionStateDelegate::ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER:
+ message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER;
+ break;
+ case SessionStateDelegate::ADD_USER_ERROR_MAXIMUM_USERS_REACHED:
+ message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER;
+ break;
+ case SessionStateDelegate::ADD_USER_ERROR_OUT_OF_USERS:
+ message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS;
+ break;
+ default:
+ NOTREACHED() << "Unknown adding user error " << add_user_error;
+ }
popup_message_.reset(new PopupMessage(
bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER),
views::BubbleBorder::TOP_LEFT,
gfx::Size(parent()->bounds().width() - kPopupMessageOffset, 0),
2 * kPopupMessageOffset));
- } else {
- // We activate the entry automatically if invoked with focus.
- if (user_card_view_->HasFocus()) {
- button->GetFocusManager()->SetFocusedView(button);
- user_card_view_->GetFocusManager()->SetFocusedView(button);
- }
}
// Find the screen area which encloses both elements and sets then a mouse
// watcher which will close the "menu".