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/common/system/user/user_view.h" | 5 #include "ash/common/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/multi_profile_uma.h" | 10 #include "ash/common/multi_profile_uma.h" |
11 #include "ash/common/session/session_state_delegate.h" | 11 #include "ash/common/session/session_controller.h" |
12 #include "ash/common/shell_delegate.h" | 12 #include "ash/common/shell_delegate.h" |
13 #include "ash/common/system/tray/system_tray.h" | 13 #include "ash/common/system/tray/system_tray.h" |
14 #include "ash/common/system/tray/system_tray_controller.h" | 14 #include "ash/common/system/tray/system_tray_controller.h" |
15 #include "ash/common/system/tray/system_tray_delegate.h" | 15 #include "ash/common/system/tray/system_tray_delegate.h" |
16 #include "ash/common/system/tray/tray_constants.h" | 16 #include "ash/common/system/tray/tray_constants.h" |
17 #include "ash/common/system/tray/tray_popup_item_style.h" | 17 #include "ash/common/system/tray/tray_popup_item_style.h" |
18 #include "ash/common/system/tray/tray_popup_utils.h" | 18 #include "ash/common/system/tray/tray_popup_utils.h" |
19 #include "ash/common/system/user/button_from_view.h" | 19 #include "ash/common/system/user/button_from_view.h" |
20 #include "ash/common/system/user/login_status.h" | 20 #include "ash/common/system/user/login_status.h" |
21 #include "ash/common/system/user/rounded_image_view.h" | 21 #include "ash/common/system/user/rounded_image_view.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
43 #include "ui/views/painter.h" | 43 #include "ui/views/painter.h" |
44 | 44 |
45 namespace ash { | 45 namespace ash { |
46 namespace tray { | 46 namespace tray { |
47 | 47 |
48 namespace { | 48 namespace { |
49 | 49 |
50 // Switch to a user with the given |user_index|. | 50 // Switch to a user with the given |user_index|. |
51 void SwitchUser(UserIndex user_index) { | 51 void SwitchUser(UserIndex user_index) { |
52 // Do not switch users when the log screen is presented. | 52 // Do not switch users when the log screen is presented. |
53 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate(); | 53 SessionController* controller = WmShell::Get()->session_controller(); |
54 if (delegate->IsUserSessionBlocked()) | 54 if (controller->IsUserSessionBlocked()) |
55 return; | 55 return; |
56 | 56 |
57 DCHECK(user_index > 0); | 57 DCHECK(user_index > 0); |
James Cook
2017/03/17 17:14:35
nit: Also DCHECK less than session count
xiyuan
2017/03/17 22:52:02
Done. And added comment of why 0 is excluded.
| |
58 MultiProfileUMA::RecordSwitchActiveUser( | 58 MultiProfileUMA::RecordSwitchActiveUser( |
59 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY); | 59 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY); |
60 delegate->SwitchActiveUser(delegate->GetUserInfo(user_index)->GetAccountId()); | 60 controller->SwitchActiveUser( |
61 controller->GetUserSessions()[user_index]->account_id); | |
61 } | 62 } |
62 | 63 |
63 bool IsMultiProfileSupportedAndUserActive() { | 64 bool IsMultiProfileSupportedAndUserActive() { |
64 return Shell::Get()->shell_delegate()->IsMultiProfilesEnabled() && | 65 return Shell::Get()->shell_delegate()->IsMultiProfilesEnabled() && |
65 !WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked(); | 66 !WmShell::Get()->session_controller()->IsUserSessionBlocked(); |
66 } | 67 } |
67 | 68 |
68 // Creates the view shown in the user switcher popup ("AddUserMenuOption"). | 69 // Creates the view shown in the user switcher popup ("AddUserMenuOption"). |
69 views::View* CreateAddUserView(AddUserSessionPolicy policy, | 70 views::View* CreateAddUserView(AddUserSessionPolicy policy, |
70 views::ButtonListener* listener) { | 71 views::ButtonListener* listener) { |
71 auto* view = new views::View; | 72 auto* view = new views::View; |
72 const int icon_padding = (kMenuButtonSize - kMenuIconSize) / 2; | 73 const int icon_padding = (kMenuButtonSize - kMenuIconSize) / 2; |
73 auto* layout = | 74 auto* layout = |
74 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, | 75 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, |
75 kTrayPopupLabelHorizontalPadding + icon_padding); | 76 kTrayPopupLabelHorizontalPadding + icon_padding); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 339 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
339 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 340 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
340 params.name = "AddUserMenuOption"; | 341 params.name = "AddUserMenuOption"; |
341 WmWindow::Get(GetWidget()->GetNativeWindow()) | 342 WmWindow::Get(GetWidget()->GetNativeWindow()) |
342 ->GetRootWindowController() | 343 ->GetRootWindowController() |
343 ->ConfigureWidgetInitParamsForContainer( | 344 ->ConfigureWidgetInitParamsForContainer( |
344 add_menu_option_.get(), kShellWindowId_DragImageAndTooltipContainer, | 345 add_menu_option_.get(), kShellWindowId_DragImageAndTooltipContainer, |
345 ¶ms); | 346 ¶ms); |
346 add_menu_option_->Init(params); | 347 add_menu_option_->Init(params); |
347 | 348 |
348 const SessionStateDelegate* delegate = | |
349 WmShell::Get()->GetSessionStateDelegate(); | |
350 const AddUserSessionPolicy add_user_policy = | 349 const AddUserSessionPolicy add_user_policy = |
351 delegate->GetAddUserSessionPolicy(); | 350 WmShell::Get()->session_controller()->GetAddUserPolicy(); |
352 add_user_enabled_ = add_user_policy == AddUserSessionPolicy::ALLOWED; | 351 add_user_enabled_ = add_user_policy == AddUserSessionPolicy::ALLOWED; |
353 | 352 |
354 // Position the widget on top of the user card view (which is still in the | 353 // Position the widget on top of the user card view (which is still in the |
355 // system menu). The top half of the widget will be transparent to allow | 354 // system menu). The top half of the widget will be transparent to allow |
356 // the active user to show through. | 355 // the active user to show through. |
357 gfx::Rect bounds = user_card_view_->GetBoundsInScreen(); | 356 gfx::Rect bounds = user_card_view_->GetBoundsInScreen(); |
358 bounds.set_width(bounds.width() + kSeparatorWidth); | 357 bounds.set_width(bounds.width() + kSeparatorWidth); |
359 int row_height = bounds.height(); | 358 int row_height = bounds.height(); |
360 | 359 |
361 views::View* container = new AddUserWidgetContents( | 360 views::View* container = new AddUserWidgetContents( |
(...skipping 30 matching lines...) Expand all Loading... | |
392 return; | 391 return; |
393 focus_manager_->RemoveFocusChangeListener(this); | 392 focus_manager_->RemoveFocusChangeListener(this); |
394 focus_manager_ = nullptr; | 393 focus_manager_ = nullptr; |
395 if (user_card_view_->GetFocusManager()) | 394 if (user_card_view_->GetFocusManager()) |
396 user_card_view_->GetFocusManager()->ClearFocus(); | 395 user_card_view_->GetFocusManager()->ClearFocus(); |
397 add_menu_option_.reset(); | 396 add_menu_option_.reset(); |
398 } | 397 } |
399 | 398 |
400 } // namespace tray | 399 } // namespace tray |
401 } // namespace ash | 400 } // namespace ash |
OLD | NEW |