| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_state_delegate.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // When a hover border is used, it is starting this many pixels before the icon | 65 // When a hover border is used, it is starting this many pixels before the icon |
| 66 // position. | 66 // position. |
| 67 const int kTrayUserTileHoverBorderInset = 10; | 67 const int kTrayUserTileHoverBorderInset = 10; |
| 68 | 68 |
| 69 // Offsetting the popup message relative to the tray menu. | 69 // Offsetting the popup message relative to the tray menu. |
| 70 const int kPopupMessageOffset = 25; | 70 const int kPopupMessageOffset = 25; |
| 71 | 71 |
| 72 // Switch to a user with the given |user_index|. | 72 // Switch to a user with the given |user_index|. |
| 73 void SwitchUser(ash::UserIndex user_index) { | 73 void SwitchUser(UserIndex user_index) { |
| 74 // Do not switch users when the log screen is presented. | 74 // Do not switch users when the log screen is presented. |
| 75 if (ash::Shell::GetInstance() | 75 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate(); |
| 76 ->session_state_delegate() | 76 if (delegate->IsUserSessionBlocked()) |
| 77 ->IsUserSessionBlocked()) | |
| 78 return; | 77 return; |
| 79 | 78 |
| 80 DCHECK(user_index > 0); | 79 DCHECK(user_index > 0); |
| 81 ash::SessionStateDelegate* delegate = | 80 MultiProfileUMA::RecordSwitchActiveUser( |
| 82 ash::Shell::GetInstance()->session_state_delegate(); | 81 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY); |
| 83 ash::MultiProfileUMA::RecordSwitchActiveUser( | |
| 84 ash::MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY); | |
| 85 delegate->SwitchActiveUser(delegate->GetUserInfo(user_index)->GetAccountId()); | 82 delegate->SwitchActiveUser(delegate->GetUserInfo(user_index)->GetAccountId()); |
| 86 } | 83 } |
| 87 | 84 |
| 88 bool IsMultiProfileSupportedAndUserActive() { | 85 bool IsMultiProfileSupportedAndUserActive() { |
| 89 auto* shell = Shell::GetInstance(); | 86 return Shell::GetInstance()->delegate()->IsMultiProfilesEnabled() && |
| 90 return shell->delegate()->IsMultiProfilesEnabled() && | 87 !WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked(); |
| 91 !shell->session_state_delegate()->IsUserSessionBlocked(); | |
| 92 } | 88 } |
| 93 | 89 |
| 94 class UserViewMouseWatcherHost : public views::MouseWatcherHost { | 90 class UserViewMouseWatcherHost : public views::MouseWatcherHost { |
| 95 public: | 91 public: |
| 96 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area) | 92 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area) |
| 97 : screen_area_(screen_area) {} | 93 : screen_area_(screen_area) {} |
| 98 ~UserViewMouseWatcherHost() override {} | 94 ~UserViewMouseWatcherHost() override {} |
| 99 | 95 |
| 100 // Implementation of MouseWatcherHost. | 96 // Implementation of MouseWatcherHost. |
| 101 bool Contains(const gfx::Point& screen_point, | 97 bool Contains(const gfx::Point& screen_point, |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 logout_button_->SetBoundsRect(logout_area); | 285 logout_button_->SetBoundsRect(logout_area); |
| 290 } else if (user_card_view_) { | 286 } else if (user_card_view_) { |
| 291 user_card_view_->SetBoundsRect(contents_area); | 287 user_card_view_->SetBoundsRect(contents_area); |
| 292 } else if (logout_button_) { | 288 } else if (logout_button_) { |
| 293 logout_button_->SetBoundsRect(contents_area); | 289 logout_button_->SetBoundsRect(contents_area); |
| 294 } | 290 } |
| 295 } | 291 } |
| 296 | 292 |
| 297 void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) { | 293 void UserView::ButtonPressed(views::Button* sender, const ui::Event& event) { |
| 298 if (sender == logout_button_) { | 294 if (sender == logout_button_) { |
| 299 Shell::GetInstance()->metrics()->RecordUserMetricsAction( | 295 WmShell::Get()->RecordUserMetricsAction(UMA_STATUS_AREA_SIGN_OUT); |
| 300 ash::UMA_STATUS_AREA_SIGN_OUT); | |
| 301 RemoveAddUserMenuOption(); | 296 RemoveAddUserMenuOption(); |
| 302 WmShell::Get()->system_tray_delegate()->SignOut(); | 297 WmShell::Get()->system_tray_delegate()->SignOut(); |
| 303 } else if (sender == user_card_view_ && | 298 } else if (sender == user_card_view_ && |
| 304 IsMultiProfileSupportedAndUserActive()) { | 299 IsMultiProfileSupportedAndUserActive()) { |
| 305 if (!user_index_) { | 300 if (!user_index_) { |
| 306 ToggleAddUserMenuOption(); | 301 ToggleAddUserMenuOption(); |
| 307 } else { | 302 } else { |
| 308 RemoveAddUserMenuOption(); | 303 RemoveAddUserMenuOption(); |
| 309 SwitchUser(user_index_); | 304 SwitchUser(user_index_); |
| 310 // Since the user list is about to change the system menu should get | 305 // Since the user list is about to change the system menu should get |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 add_menu_option_->SetBounds(bounds); | 445 add_menu_option_->SetBounds(bounds); |
| 451 | 446 |
| 452 // Show the content. | 447 // Show the content. |
| 453 add_menu_option_->SetAlwaysOnTop(true); | 448 add_menu_option_->SetAlwaysOnTop(true); |
| 454 add_menu_option_->Show(); | 449 add_menu_option_->Show(); |
| 455 | 450 |
| 456 AddUserView* add_user_view = | 451 AddUserView* add_user_view = |
| 457 new AddUserView(static_cast<ButtonFromView*>(user_card_view_)); | 452 new AddUserView(static_cast<ButtonFromView*>(user_card_view_)); |
| 458 | 453 |
| 459 const SessionStateDelegate* delegate = | 454 const SessionStateDelegate* delegate = |
| 460 Shell::GetInstance()->session_state_delegate(); | 455 WmShell::Get()->GetSessionStateDelegate(); |
| 461 | 456 |
| 462 SessionStateDelegate::AddUserError add_user_error; | 457 SessionStateDelegate::AddUserError add_user_error; |
| 463 add_user_enabled_ = delegate->CanAddUserToMultiProfile(&add_user_error); | 458 add_user_enabled_ = delegate->CanAddUserToMultiProfile(&add_user_error); |
| 464 | 459 |
| 465 ButtonFromView* button = new ButtonFromView(add_user_view, | 460 ButtonFromView* button = new ButtonFromView(add_user_view, |
| 466 add_user_enabled_ ? this : NULL, | 461 add_user_enabled_ ? this : NULL, |
| 467 add_user_enabled_, | 462 add_user_enabled_, |
| 468 gfx::Insets(1, 1, 1, 1)); | 463 gfx::Insets(1, 1, 1, 1)); |
| 469 button->SetAccessibleName( | 464 button->SetAccessibleName( |
| 470 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); | 465 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 focus_manager_ = NULL; | 519 focus_manager_ = NULL; |
| 525 if (user_card_view_->GetFocusManager()) | 520 if (user_card_view_->GetFocusManager()) |
| 526 user_card_view_->GetFocusManager()->ClearFocus(); | 521 user_card_view_->GetFocusManager()->ClearFocus(); |
| 527 popup_message_.reset(); | 522 popup_message_.reset(); |
| 528 mouse_watcher_.reset(); | 523 mouse_watcher_.reset(); |
| 529 add_menu_option_.reset(); | 524 add_menu_option_.reset(); |
| 530 } | 525 } |
| 531 | 526 |
| 532 } // namespace tray | 527 } // namespace tray |
| 533 } // namespace ash | 528 } // namespace ash |
| OLD | NEW |