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_view.h" | 5 #include "ash/system/user/user_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/multi_profile_uma.h" | 9 #include "ash/multi_profile_uma.h" |
10 #include "ash/popup_message.h" | 10 #include "ash/popup_message.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 200 |
201 UserView::UserView(SystemTrayItem* owner, | 201 UserView::UserView(SystemTrayItem* owner, |
202 user::LoginStatus login, | 202 user::LoginStatus login, |
203 MultiProfileIndex index, | 203 MultiProfileIndex index, |
204 bool for_detailed_view) | 204 bool for_detailed_view) |
205 : multiprofile_index_(index), | 205 : multiprofile_index_(index), |
206 user_card_view_(NULL), | 206 user_card_view_(NULL), |
207 owner_(owner), | 207 owner_(owner), |
208 is_user_card_button_(false), | 208 is_user_card_button_(false), |
209 logout_button_(NULL), | 209 logout_button_(NULL), |
210 add_user_disabled_(false), | 210 add_user_enabled_(true), |
211 for_detailed_view_(for_detailed_view), | 211 for_detailed_view_(for_detailed_view), |
212 focus_manager_(NULL) { | 212 focus_manager_(NULL) { |
213 CHECK_NE(user::LOGGED_IN_NONE, login); | 213 CHECK_NE(user::LOGGED_IN_NONE, login); |
214 if (!index) { | 214 if (!index) { |
215 // Only the logged in user will have a background. All other users will have | 215 // Only the logged in user will have a background. All other users will have |
216 // to allow the TrayPopupContainer highlighting the menu line. | 216 // to allow the TrayPopupContainer highlighting the menu line. |
217 set_background(views::Background::CreateSolidBackground( | 217 set_background(views::Background::CreateSolidBackground( |
218 login == user::LOGGED_IN_PUBLIC ? kPublicAccountBackgroundColor | 218 login == user::LOGGED_IN_PUBLIC ? kPublicAccountBackgroundColor |
219 : kBackgroundColor)); | 219 : kBackgroundColor)); |
220 } | 220 } |
(...skipping 10 matching lines...) Expand all Loading... |
231 UserView::~UserView() { | 231 UserView::~UserView() { |
232 RemoveAddUserMenuOption(); | 232 RemoveAddUserMenuOption(); |
233 } | 233 } |
234 | 234 |
235 void UserView::MouseMovedOutOfHost() { | 235 void UserView::MouseMovedOutOfHost() { |
236 RemoveAddUserMenuOption(); | 236 RemoveAddUserMenuOption(); |
237 } | 237 } |
238 | 238 |
239 TrayUser::TestState UserView::GetStateForTest() const { | 239 TrayUser::TestState UserView::GetStateForTest() const { |
240 if (add_menu_option_.get()) { | 240 if (add_menu_option_.get()) { |
241 return add_user_disabled_ ? TrayUser::ACTIVE_BUT_DISABLED | 241 return add_user_enabled_ ? TrayUser::ACTIVE : TrayUser::ACTIVE_BUT_DISABLED; |
242 : TrayUser::ACTIVE; | |
243 } | 242 } |
244 | 243 |
245 if (!is_user_card_button_) | 244 if (!is_user_card_button_) |
246 return TrayUser::SHOWN; | 245 return TrayUser::SHOWN; |
247 | 246 |
248 return static_cast<ButtonFromView*>(user_card_view_)->is_hovered_for_test() | 247 return static_cast<ButtonFromView*>(user_card_view_)->is_hovered_for_test() |
249 ? TrayUser::HOVERED | 248 ? TrayUser::HOVERED |
250 : TrayUser::SHOWN; | 249 : TrayUser::SHOWN; |
251 } | 250 } |
252 | 251 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 // Show the content. | 489 // Show the content. |
491 add_menu_option_->SetAlwaysOnTop(true); | 490 add_menu_option_->SetAlwaysOnTop(true); |
492 add_menu_option_->Show(); | 491 add_menu_option_->Show(); |
493 | 492 |
494 AddUserView* add_user_view = | 493 AddUserView* add_user_view = |
495 new AddUserView(static_cast<ButtonFromView*>(user_card_view_)); | 494 new AddUserView(static_cast<ButtonFromView*>(user_card_view_)); |
496 | 495 |
497 const SessionStateDelegate* delegate = | 496 const SessionStateDelegate* delegate = |
498 Shell::GetInstance()->session_state_delegate(); | 497 Shell::GetInstance()->session_state_delegate(); |
499 | 498 |
500 bool multi_profile_allowed = | 499 SessionStateDelegate::MultiProfileAddUserError add_user_error; |
501 delegate->IsMultiProfileAllowedByPrimaryUserPolicy(); | 500 add_user_enabled_ = delegate->CanAddUserToMultiProfile(&add_user_error); |
502 add_user_disabled_ = (delegate->NumberOfLoggedInUsers() >= | |
503 delegate->GetMaximumNumberOfLoggedInUsers()) || | |
504 !multi_profile_allowed; | |
505 | 501 |
506 ButtonFromView* button = new ButtonFromView( | 502 ButtonFromView* button = new ButtonFromView(add_user_view, |
507 add_user_view, | 503 add_user_enabled_ ? this : NULL, |
508 add_user_disabled_ ? NULL : this, | 504 add_user_enabled_, |
509 !add_user_disabled_, | 505 gfx::Insets(1, 1, 1, 1)); |
510 gfx::Insets(1, 1, 1, 1)); | |
511 button->set_request_focus_on_press(false); | 506 button->set_request_focus_on_press(false); |
512 button->SetAccessibleName( | 507 button->SetAccessibleName( |
513 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); | 508 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); |
514 button->ForceBorderVisible(true); | 509 button->ForceBorderVisible(true); |
515 add_menu_option_->SetContentsView(button); | 510 add_menu_option_->SetContentsView(button); |
516 | 511 |
517 if (add_user_disabled_) { | 512 if (add_user_enabled_) { |
| 513 // We activate the entry automatically if invoked with focus. |
| 514 if (user_card_view_->HasFocus()) { |
| 515 button->GetFocusManager()->SetFocusedView(button); |
| 516 user_card_view_->GetFocusManager()->SetFocusedView(button); |
| 517 } |
| 518 } else { |
518 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 519 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
519 int message_id; | 520 int message_id; |
520 if (!multi_profile_allowed) | 521 switch (add_user_error) { |
521 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER; | 522 case SessionStateDelegate:: |
522 else | 523 MULTIPROFILE_ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER: |
523 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER; | 524 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER; |
| 525 break; |
| 526 case SessionStateDelegate:: |
| 527 MULTIPROFILE_ADD_USER_ERROR_MAXIMUM_OF_USERS_REACHED: |
| 528 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER; |
| 529 break; |
| 530 case SessionStateDelegate::MULTIPROFILE_ADD_USER_ERROR_OUT_OF_USERS: |
| 531 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS; |
| 532 break; |
| 533 default: |
| 534 NOTREACHED() << "Unknown adding user error " << add_user_error; |
| 535 } |
524 | 536 |
525 popup_message_.reset(new PopupMessage( | 537 popup_message_.reset(new PopupMessage( |
526 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER), | 538 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER), |
527 bundle.GetLocalizedString(message_id), | 539 bundle.GetLocalizedString(message_id), |
528 PopupMessage::ICON_WARNING, | 540 PopupMessage::ICON_WARNING, |
529 add_user_view->anchor(), | 541 add_user_view->anchor(), |
530 views::BubbleBorder::TOP_LEFT, | 542 views::BubbleBorder::TOP_LEFT, |
531 gfx::Size(parent()->bounds().width() - kPopupMessageOffset, 0), | 543 gfx::Size(parent()->bounds().width() - kPopupMessageOffset, 0), |
532 2 * kPopupMessageOffset)); | 544 2 * kPopupMessageOffset)); |
533 } else { | |
534 // We activate the entry automatically if invoked with focus. | |
535 if (user_card_view_->HasFocus()) { | |
536 button->GetFocusManager()->SetFocusedView(button); | |
537 user_card_view_->GetFocusManager()->SetFocusedView(button); | |
538 } | |
539 } | 545 } |
540 // Find the screen area which encloses both elements and sets then a mouse | 546 // Find the screen area which encloses both elements and sets then a mouse |
541 // watcher which will close the "menu". | 547 // watcher which will close the "menu". |
542 gfx::Rect area = user_card_view_->GetBoundsInScreen(); | 548 gfx::Rect area = user_card_view_->GetBoundsInScreen(); |
543 area.set_height(2 * area.height()); | 549 area.set_height(2 * area.height()); |
544 mouse_watcher_.reset( | 550 mouse_watcher_.reset( |
545 new views::MouseWatcher(new UserViewMouseWatcherHost(area), this)); | 551 new views::MouseWatcher(new UserViewMouseWatcherHost(area), this)); |
546 mouse_watcher_->Start(); | 552 mouse_watcher_->Start(); |
547 // Install a listener to focus changes so that we can remove the card when | 553 // Install a listener to focus changes so that we can remove the card when |
548 // the focus gets changed. When called through the destruction of the bubble, | 554 // the focus gets changed. When called through the destruction of the bubble, |
549 // the FocusManager cannot be determined anymore and we remember it here. | 555 // the FocusManager cannot be determined anymore and we remember it here. |
550 focus_manager_ = user_card_view_->GetFocusManager(); | 556 focus_manager_ = user_card_view_->GetFocusManager(); |
551 focus_manager_->AddFocusChangeListener(this); | 557 focus_manager_->AddFocusChangeListener(this); |
552 } | 558 } |
553 | 559 |
554 void UserView::RemoveAddUserMenuOption() { | 560 void UserView::RemoveAddUserMenuOption() { |
555 if (!add_menu_option_.get()) | 561 if (!add_menu_option_.get()) |
556 return; | 562 return; |
557 focus_manager_->RemoveFocusChangeListener(this); | 563 focus_manager_->RemoveFocusChangeListener(this); |
558 focus_manager_ = NULL; | 564 focus_manager_ = NULL; |
559 if (user_card_view_->GetFocusManager()) | 565 if (user_card_view_->GetFocusManager()) |
560 user_card_view_->GetFocusManager()->ClearFocus(); | 566 user_card_view_->GetFocusManager()->ClearFocus(); |
561 popup_message_.reset(); | 567 popup_message_.reset(); |
562 mouse_watcher_.reset(); | 568 mouse_watcher_.reset(); |
563 add_menu_option_.reset(); | 569 add_menu_option_.reset(); |
564 } | 570 } |
565 | 571 |
566 } // namespace tray | 572 } // namespace tray |
567 } // namespace ash | 573 } // namespace ash |
OLD | NEW |