Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: ash/common/system/user/user_view.cc

Issue 2535003002: CrOS MD Menu - Some more user row tweaks. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
tdanderson 2016/11/28 20:55:30 Also specified in the bug is "'Sign-out' left and
Evan Stade 2016/11/29 02:30:32 I didn't actually notice that part of the bug ---
10 #include "ash/common/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
11 #include "ash/common/multi_profile_uma.h" 11 #include "ash/common/multi_profile_uma.h"
12 #include "ash/common/popup_message.h" 12 #include "ash/common/popup_message.h"
13 #include "ash/common/session/session_state_delegate.h" 13 #include "ash/common/session/session_state_delegate.h"
14 #include "ash/common/shell_delegate.h" 14 #include "ash/common/shell_delegate.h"
15 #include "ash/common/system/tray/system_tray.h" 15 #include "ash/common/system/tray/system_tray.h"
16 #include "ash/common/system/tray/system_tray_controller.h" 16 #include "ash/common/system/tray/system_tray_controller.h"
17 #include "ash/common/system/tray/system_tray_delegate.h" 17 #include "ash/common/system/tray/system_tray_delegate.h"
18 #include "ash/common/system/tray/tray_constants.h" 18 #include "ash/common/system/tray/tray_constants.h"
19 #include "ash/common/system/tray/tray_popup_item_style.h"
19 #include "ash/common/system/tray/tray_popup_label_button.h" 20 #include "ash/common/system/tray/tray_popup_label_button.h"
20 #include "ash/common/system/tray/tray_popup_label_button_border.h" 21 #include "ash/common/system/tray/tray_popup_label_button_border.h"
21 #include "ash/common/system/tray/tray_popup_utils.h" 22 #include "ash/common/system/tray/tray_popup_utils.h"
22 #include "ash/common/system/user/button_from_view.h" 23 #include "ash/common/system/user/button_from_view.h"
23 #include "ash/common/system/user/login_status.h" 24 #include "ash/common/system/user/login_status.h"
24 #include "ash/common/system/user/rounded_image_view.h" 25 #include "ash/common/system/user/rounded_image_view.h"
25 #include "ash/common/system/user/user_card_view.h" 26 #include "ash/common/system/user/user_card_view.h"
26 #include "ash/common/wm_lookup.h" 27 #include "ash/common/wm_lookup.h"
27 #include "ash/common/wm_root_window_controller.h" 28 #include "ash/common/wm_root_window_controller.h"
28 #include "ash/common/wm_shell.h" 29 #include "ash/common/wm_shell.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY); 98 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY);
98 delegate->SwitchActiveUser(delegate->GetUserInfo(user_index)->GetAccountId()); 99 delegate->SwitchActiveUser(delegate->GetUserInfo(user_index)->GetAccountId());
99 } 100 }
100 101
101 bool IsMultiProfileSupportedAndUserActive() { 102 bool IsMultiProfileSupportedAndUserActive() {
102 return WmShell::Get()->delegate()->IsMultiProfilesEnabled() && 103 return WmShell::Get()->delegate()->IsMultiProfilesEnabled() &&
103 !WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked(); 104 !WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked();
104 } 105 }
105 106
106 // Creates the view shown in the user switcher popup ("AddUserMenuOption"). 107 // Creates the view shown in the user switcher popup ("AddUserMenuOption").
107 views::View* CreateAddUserView(AddUserSessionPolicy policy) { 108 views::View* CreateAddUserView(AddUserSessionPolicy policy,
109 views::ButtonListener* listener) {
108 DCHECK(UseMd()); 110 DCHECK(UseMd());
109 auto view = new views::View; 111 auto view = new views::View;
110 auto layout = new views::BoxLayout( 112 const int icon_padding = (kMenuButtonSize - kMenuIconSize) / 2;
111 views::BoxLayout::kHorizontal, (kMenuButtonSize - kMenuIconSize) / 2, 113 auto layout =
112 kMenuSeparatorVerticalPadding, kTrayPopupPaddingBetweenItems); 114 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0,
115 kTrayPopupLabelHorizontalPadding + icon_padding);
113 layout->set_minimum_cross_axis_size( 116 layout->set_minimum_cross_axis_size(
114 policy == AddUserSessionPolicy::ALLOWED 117 GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT));
115 ? GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT)
116 : 56);
117 view->SetLayoutManager(layout); 118 view->SetLayoutManager(layout);
118 view->set_background( 119 view->set_background(
119 views::Background::CreateSolidBackground(kBackgroundColor)); 120 views::Background::CreateSolidBackground(kBackgroundColor));
120 121
121 int message_id = 0; 122 int message_id = 0;
122 switch (policy) { 123 switch (policy) {
123 case AddUserSessionPolicy::ALLOWED: { 124 case AddUserSessionPolicy::ALLOWED: {
124 message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT; 125 message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT;
125 126
126 auto icon = new views::ImageView(); 127 auto icon = new views::ImageView();
127 icon->SetImage( 128 icon->SetImage(
128 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor)); 129 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor));
129 view->AddChildView(icon); 130 view->AddChildView(icon);
130 break; 131 break;
131 } 132 }
132 case AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER: 133 case AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER:
133 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER; 134 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER;
134 break; 135 break;
135 case AddUserSessionPolicy::ERROR_MAXIMUM_USERS_REACHED: 136 case AddUserSessionPolicy::ERROR_MAXIMUM_USERS_REACHED:
136 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER; 137 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER;
137 break; 138 break;
138 case AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS: 139 case AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS:
139 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS; 140 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS;
140 break; 141 break;
141 } 142 }
142 143
143 auto command_label = new views::Label(l10n_util::GetStringUTF16(message_id)); 144 auto command_label = new views::Label(l10n_util::GetStringUTF16(message_id));
144 command_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 145 command_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
145 command_label->SetMultiLine(true); 146 command_label->SetMultiLine(true);
147
148 TrayPopupItemStyle label_style(
149 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL);
150 int vertical_padding = kMenuSeparatorVerticalPadding;
151 if (policy != AddUserSessionPolicy::ALLOWED) {
152 label_style.set_font_style(TrayPopupItemStyle::FontStyle::CAPTION);
153 label_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE);
154 vertical_padding += kMenuSeparatorVerticalPadding;
tdanderson 2016/11/28 20:55:30 From the bug, Sebastien has specified "the entire
Evan Stade 2016/11/29 02:30:33 I added 4 with add_user_padding (because that 4 is
155 }
156 label_style.SetupLabel(command_label);
146 view->AddChildView(command_label); 157 view->AddChildView(command_label);
158 view->SetBorder(views::CreateEmptyBorder(vertical_padding, icon_padding,
159 vertical_padding,
160 kTrayPopupLabelHorizontalPadding));
161 if (policy == AddUserSessionPolicy::ALLOWED) {
162 auto button =
163 new ButtonFromView(view, listener, TrayPopupInkDropStyle::INSET_BOUNDS,
164 false, gfx::Insets());
165 button->SetAccessibleName(
166 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
167 return button;
tdanderson 2016/11/28 20:55:30 Thanks for making this a button only when it needs
Evan Stade 2016/11/29 02:30:33 Acknowledged.
168 }
169
147 return view; 170 return view;
148 } 171 }
149 172
150 class UserViewMouseWatcherHost : public views::MouseWatcherHost { 173 class UserViewMouseWatcherHost : public views::MouseWatcherHost {
151 public: 174 public:
152 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area) 175 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area)
153 : screen_area_(screen_area) {} 176 : screen_area_(screen_area) {}
154 ~UserViewMouseWatcherHost() override {} 177 ~UserViewMouseWatcherHost() override {}
155 178
156 // Implementation of MouseWatcherHost. 179 // Implementation of MouseWatcherHost.
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 &params); 625 &params);
603 add_menu_option_->Init(params); 626 add_menu_option_->Init(params);
604 627
605 const SessionStateDelegate* delegate = 628 const SessionStateDelegate* delegate =
606 WmShell::Get()->GetSessionStateDelegate(); 629 WmShell::Get()->GetSessionStateDelegate();
607 const AddUserSessionPolicy add_user_policy = 630 const AddUserSessionPolicy add_user_policy =
608 delegate->GetAddUserSessionPolicy(); 631 delegate->GetAddUserSessionPolicy();
609 add_user_enabled_ = add_user_policy == AddUserSessionPolicy::ALLOWED; 632 add_user_enabled_ = add_user_policy == AddUserSessionPolicy::ALLOWED;
610 633
611 if (UseMd()) { 634 if (UseMd()) {
612 ButtonFromView* button = new ButtonFromView(
613 CreateAddUserView(add_user_policy), add_user_enabled_ ? this : nullptr,
614 IsActiveUser() ? TrayPopupInkDropStyle::INSET_BOUNDS
615 : TrayPopupInkDropStyle::FILL_BOUNDS,
616 false, gfx::Insets());
617 button->SetAccessibleName(
618 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
619 button->ForceBorderVisible(true);
620
621 // Position the widget on top of the user card view (which is still in the 635 // Position the widget on top of the user card view (which is still in the
622 // system menu). The top half of the widget will be transparent to allow 636 // system menu). The top half of the widget will be transparent to allow
623 // the active user to show through. 637 // the active user to show through.
624 gfx::Rect bounds = user_card_view_->GetBoundsInScreen(); 638 gfx::Rect bounds = user_card_view_->GetBoundsInScreen();
625 bounds.set_width(bounds.width() + kSeparatorWidth); 639 bounds.set_width(bounds.width() + kSeparatorWidth);
626 int row_height = bounds.height(); 640 int row_height = bounds.height();
627 641
628 views::View* container = new AddUserWidgetContents( 642 views::View* container = new AddUserWidgetContents(
629 base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this))); 643 base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this)));
630 container->SetBorder(views::CreatePaddedBorder( 644 container->SetBorder(views::CreatePaddedBorder(
631 views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, 645 views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth,
632 kBackgroundColor), 646 kBackgroundColor),
633 gfx::Insets(row_height, 0, 0, 0))); 647 gfx::Insets(row_height, 0, 0, 0)));
648 views::View* add_user_padding = new views::View();
649 add_user_padding->SetBorder(views::CreateSolidSidedBorder(
650 kMenuSeparatorVerticalPadding, 0, 0, 0, kBackgroundColor));
651 views::View* add_user_view = CreateAddUserView(add_user_policy, this);
652 add_user_padding->AddChildView(add_user_view);
653 add_user_padding->SetLayoutManager(new views::FillLayout());
654 container->AddChildView(add_user_padding);
634 container->SetLayoutManager(new views::FillLayout()); 655 container->SetLayoutManager(new views::FillLayout());
635 container->AddChildView(button);
636 add_menu_option_->SetContentsView(container); 656 add_menu_option_->SetContentsView(container);
637 657
638 bounds.set_height(container->GetPreferredSize().height()); 658 bounds.set_height(container->GetPreferredSize().height());
639 add_menu_option_->SetBounds(bounds); 659 add_menu_option_->SetBounds(bounds);
640 660
641 // Show the content. 661 // Show the content.
642 add_menu_option_->SetAlwaysOnTop(true); 662 add_menu_option_->SetAlwaysOnTop(true);
643 add_menu_option_->Show(); 663 add_menu_option_->Show();
644 664
645 // We activate the entry automatically if invoked with focus. 665 // We activate the entry automatically if invoked with focus.
646 if (add_user_enabled_ && user_card_view_->HasFocus()) { 666 if (add_user_enabled_ && user_card_view_->HasFocus()) {
647 button->GetFocusManager()->SetFocusedView(button); 667 add_user_view->GetFocusManager()->SetFocusedView(add_user_view);
648 user_card_view_->GetFocusManager()->SetFocusedView(button); 668 user_card_view_->GetFocusManager()->SetFocusedView(add_user_view);
649 } 669 }
650 } else { 670 } else {
651 AddUserView* add_user_view = 671 AddUserView* add_user_view =
652 new AddUserView(static_cast<ButtonFromView*>(user_card_view_)); 672 new AddUserView(static_cast<ButtonFromView*>(user_card_view_));
653 ButtonFromView* button = new ButtonFromView( 673 ButtonFromView* button = new ButtonFromView(
654 add_user_view, add_user_enabled_ ? this : nullptr, 674 add_user_view, add_user_enabled_ ? this : nullptr,
655 // Ignored in non-md. 675 // Ignored in non-md.
656 TrayPopupInkDropStyle::INSET_BOUNDS, add_user_enabled_, gfx::Insets(1)); 676 TrayPopupInkDropStyle::INSET_BOUNDS, add_user_enabled_, gfx::Insets(1));
657 button->SetAccessibleName( 677 button->SetAccessibleName(
658 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); 678 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 focus_manager_ = nullptr; 743 focus_manager_ = nullptr;
724 if (user_card_view_->GetFocusManager()) 744 if (user_card_view_->GetFocusManager())
725 user_card_view_->GetFocusManager()->ClearFocus(); 745 user_card_view_->GetFocusManager()->ClearFocus();
726 popup_message_.reset(); 746 popup_message_.reset();
727 mouse_watcher_.reset(); 747 mouse_watcher_.reset();
728 add_menu_option_.reset(); 748 add_menu_option_.reset();
729 } 749 }
730 750
731 } // namespace tray 751 } // namespace tray
732 } // namespace ash 752 } // namespace ash
OLDNEW
« ash/common/system/user/user_card_view.cc ('K') | « ash/common/system/user/user_card_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698