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

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

Issue 2498293003: CrOS md user row adjustments (Closed)
Patch Set: more stuff Created 4 years, 1 month 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
10 #include "ash/common/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
(...skipping 10 matching lines...) Expand all
21 #include "ash/common/system/user/button_from_view.h" 21 #include "ash/common/system/user/button_from_view.h"
22 #include "ash/common/system/user/login_status.h" 22 #include "ash/common/system/user/login_status.h"
23 #include "ash/common/system/user/rounded_image_view.h" 23 #include "ash/common/system/user/rounded_image_view.h"
24 #include "ash/common/system/user/user_card_view.h" 24 #include "ash/common/system/user/user_card_view.h"
25 #include "ash/common/wm_lookup.h" 25 #include "ash/common/wm_lookup.h"
26 #include "ash/common/wm_root_window_controller.h" 26 #include "ash/common/wm_root_window_controller.h"
27 #include "ash/common/wm_shell.h" 27 #include "ash/common/wm_shell.h"
28 #include "ash/common/wm_window.h" 28 #include "ash/common/wm_window.h"
29 #include "ash/public/cpp/shell_window_ids.h" 29 #include "ash/public/cpp/shell_window_ids.h"
30 #include "ash/resources/vector_icons/vector_icons.h" 30 #include "ash/resources/vector_icons/vector_icons.h"
31 #include "base/optional.h"
31 #include "components/signin/core/account_id/account_id.h" 32 #include "components/signin/core/account_id/account_id.h"
32 #include "components/user_manager/user_info.h" 33 #include "components/user_manager/user_info.h"
33 #include "grit/ash_resources.h" 34 #include "grit/ash_resources.h"
34 #include "grit/ash_strings.h" 35 #include "grit/ash_strings.h"
35 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
36 #include "ui/base/resource/resource_bundle.h" 37 #include "ui/base/resource/resource_bundle.h"
37 #include "ui/gfx/canvas.h" 38 #include "ui/gfx/canvas.h"
38 #include "ui/gfx/geometry/insets.h" 39 #include "ui/gfx/geometry/insets.h"
39 #include "ui/gfx/paint_vector_icon.h" 40 #include "ui/gfx/paint_vector_icon.h"
40 #include "ui/views/controls/button/label_button.h" 41 #include "ui/views/controls/button/label_button.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 MultiProfileUMA::RecordSwitchActiveUser( 96 MultiProfileUMA::RecordSwitchActiveUser(
96 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY); 97 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY);
97 delegate->SwitchActiveUser(delegate->GetUserInfo(user_index)->GetAccountId()); 98 delegate->SwitchActiveUser(delegate->GetUserInfo(user_index)->GetAccountId());
98 } 99 }
99 100
100 bool IsMultiProfileSupportedAndUserActive() { 101 bool IsMultiProfileSupportedAndUserActive() {
101 return WmShell::Get()->delegate()->IsMultiProfilesEnabled() && 102 return WmShell::Get()->delegate()->IsMultiProfilesEnabled() &&
102 !WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked(); 103 !WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked();
103 } 104 }
104 105
106 // Creates the view shown in the user switcher popup ("AddUserMenuOption").
107 views::View* CreateAddUserView(
108 base::Optional<SessionStateDelegate::AddUserError> error) {
109 DCHECK(UseMd());
110 auto view = new views::View;
111 auto layout = new views::BoxLayout(
112 views::BoxLayout::kHorizontal, (kMenuButtonSize - kMenuIconSize) / 2,
113 kMenuSeparatorVerticalPadding, kTrayPopupPaddingBetweenItems);
114 layout->set_minimum_cross_axis_size(
115 error ? 56 : GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT));
tdanderson 2016/11/16 23:08:08 nit: can you derive this 56 from other constants o
Evan Stade 2016/11/17 00:37:50 part 1: I don't think so, it's basically just a ma
tdanderson 2016/11/17 01:40:15 If it is truly just a magic number that cannot be
Evan Stade 2016/11/17 01:54:19 Acknowledged.
116 view->SetLayoutManager(layout);
117 view->set_background(
118 views::Background::CreateSolidBackground(kBackgroundColor));
119
120 if (!error) {
121 auto icon = new views::ImageView();
122 icon->SetImage(
123 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor));
124 view->AddChildView(icon);
125 }
126
127 int message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT;
128 if (error) {
129 switch (*error) {
130 case SessionStateDelegate::ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER:
131 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER;
132 break;
133 case SessionStateDelegate::ADD_USER_ERROR_MAXIMUM_USERS_REACHED:
134 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER;
135 break;
136 case SessionStateDelegate::ADD_USER_ERROR_OUT_OF_USERS:
137 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS;
138 break;
139 }
140 }
141
142 auto command_label = new views::Label(l10n_util::GetStringUTF16(message_id));
143 command_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
144 command_label->SetMultiLine(true);
145 view->AddChildView(command_label);
146 return view;
147 }
148
105 class UserViewMouseWatcherHost : public views::MouseWatcherHost { 149 class UserViewMouseWatcherHost : public views::MouseWatcherHost {
106 public: 150 public:
107 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area) 151 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area)
108 : screen_area_(screen_area) {} 152 : screen_area_(screen_area) {}
109 ~UserViewMouseWatcherHost() override {} 153 ~UserViewMouseWatcherHost() override {}
110 154
111 // Implementation of MouseWatcherHost. 155 // Implementation of MouseWatcherHost.
112 bool Contains(const gfx::Point& screen_point, 156 bool Contains(const gfx::Point& screen_point,
113 views::MouseWatcherHost::MouseEventType type) override { 157 views::MouseWatcherHost::MouseEventType type) override {
114 return screen_area_.Contains(screen_point); 158 return screen_area_.Contains(screen_point);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 ButtonFromView* owner_; 217 ButtonFromView* owner_;
174 218
175 // The anchor view for targetted bubble messages. 219 // The anchor view for targetted bubble messages.
176 views::View* anchor_; 220 views::View* anchor_;
177 221
178 DISALLOW_COPY_AND_ASSIGN(AddUserView); 222 DISALLOW_COPY_AND_ASSIGN(AddUserView);
179 }; 223 };
180 224
181 AddUserView::AddUserView(ButtonFromView* owner) 225 AddUserView::AddUserView(ButtonFromView* owner)
182 : add_user_(nullptr), owner_(owner), anchor_(nullptr) { 226 : add_user_(nullptr), owner_(owner), anchor_(nullptr) {
227 DCHECK(!UseMd());
183 AddContent(); 228 AddContent();
184 owner_->ForceBorderVisible(true); 229 owner_->ForceBorderVisible(true);
185 } 230 }
186 231
187 AddUserView::~AddUserView() { 232 AddUserView::~AddUserView() {
188 owner_->ForceBorderVisible(false); 233 owner_->ForceBorderVisible(false);
189 } 234 }
190 235
191 gfx::Size AddUserView::GetPreferredSize() const { 236 gfx::Size AddUserView::GetPreferredSize() const {
192 return owner_->bounds().size(); 237 return owner_->bounds().size();
193 } 238 }
194 239
195 void AddUserView::AddContent() { 240 void AddUserView::AddContent() {
196 SetLayoutManager(new views::FillLayout()); 241 SetLayoutManager(new views::FillLayout());
197 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 242 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
198 243
199 add_user_ = new views::View; 244 add_user_ = new views::View;
200 add_user_->SetLayoutManager(new views::BoxLayout( 245 add_user_->SetLayoutManager(new views::BoxLayout(
201 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems)); 246 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems));
202 AddChildViewAt(add_user_, 0); 247 AddChildViewAt(add_user_, 0);
203 248
204 // Add the icon which is also the anchor for messages. 249 // Add the icon which is also the anchor for messages.
205 if (UseMd()) { 250 add_user_->SetBorder(
206 views::ImageView* icon = new views::ImageView(); 251 views::CreateEmptyBorder(0, kTrayUserTileHoverBorderInset, 0, 0));
207 icon->SetImage( 252 RoundedImageView* icon = new RoundedImageView(kTrayRoundedBorderRadius, true);
208 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor)); 253 anchor_ = icon;
209 icon->SetBorder(views::CreateEmptyBorder(gfx::Insets( 254 icon->SetImage(*ui::ResourceBundle::GetSharedInstance()
210 (GetTrayConstant(TRAY_POPUP_ITEM_MAIN_IMAGE_CONTAINER_WIDTH) - 255 .GetImageNamed(IDR_AURA_UBER_TRAY_ADD_MULTIPROFILE_USER)
211 icon->GetPreferredSize().width()) / 256 .ToImageSkia(),
212 2))); 257 gfx::Size(kTrayItemSize, kTrayItemSize));
213 anchor_ = icon; 258 add_user_->AddChildView(icon);
214 add_user_->AddChildView(icon);
215 } else {
216 add_user_->SetBorder(
217 views::CreateEmptyBorder(0, kTrayUserTileHoverBorderInset, 0, 0));
218 RoundedImageView* icon =
219 new RoundedImageView(kTrayRoundedBorderRadius, true);
220 anchor_ = icon;
221 icon->SetImage(*ui::ResourceBundle::GetSharedInstance()
222 .GetImageNamed(IDR_AURA_UBER_TRAY_ADD_MULTIPROFILE_USER)
223 .ToImageSkia(),
224 gfx::Size(kTrayItemSize, kTrayItemSize));
225 add_user_->AddChildView(icon);
226 }
227 259
228 // Add the command text. 260 // Add the command text.
229 views::Label* command_label = new views::Label( 261 views::Label* command_label = new views::Label(
230 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); 262 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
231 command_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 263 command_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
232 add_user_->AddChildView(command_label); 264 add_user_->AddChildView(command_label);
233 } 265 }
234 266
267 // This border reserves 4dp above and 8dp below and paints a horizontal
268 // separator 3dp below the host view.
269 class ActiveUserBorder : public views::Border {
270 public:
271 ActiveUserBorder() {}
272 ~ActiveUserBorder() override {}
273
274 // views::Border:
275 void Paint(const views::View& view, gfx::Canvas* canvas) override {
276 canvas->FillRect(
277 gfx::Rect(
278 0, view.height() - kMenuSeparatorVerticalPadding - kSeparatorWidth,
279 view.width(), kSeparatorWidth),
280 kHorizontalSeparatorColor);
281 }
282
283 gfx::Insets GetInsets() const override {
284 return gfx::Insets(kMenuSeparatorVerticalPadding, 0,
285 kMenuSeparatorVerticalPadding * 2, 0);
286 }
287
288 gfx::Size GetMinimumSize() const override { return gfx::Size(); }
289
290 private:
291 DISALLOW_COPY_AND_ASSIGN(ActiveUserBorder);
292 };
293
235 } // namespace 294 } // namespace
236 295
237 UserView::UserView(SystemTrayItem* owner, LoginStatus login, UserIndex index) 296 UserView::UserView(SystemTrayItem* owner, LoginStatus login, UserIndex index)
238 : user_index_(index), 297 : user_index_(index),
239 user_card_view_(nullptr), 298 user_card_view_(nullptr),
240 owner_(owner), 299 owner_(owner),
241 is_user_card_button_(false), 300 is_user_card_button_(false),
242 logout_button_(nullptr), 301 logout_button_(nullptr),
243 add_user_enabled_(true), 302 add_user_enabled_(true),
244 focus_manager_(nullptr) { 303 focus_manager_(nullptr) {
245 CHECK_NE(LoginStatus::NOT_LOGGED_IN, login); 304 CHECK_NE(LoginStatus::NOT_LOGGED_IN, login);
246 if (!UseMd() && !index && login == LoginStatus::PUBLIC) { 305 if (!UseMd() && !index && login == LoginStatus::PUBLIC) {
247 // Public user gets a yellow bg. 306 // Public user gets a yellow bg.
248 set_background(views::Background::CreateSolidBackground( 307 set_background(views::Background::CreateSolidBackground(
249 kPublicAccountBackgroundColor)); 308 kPublicAccountBackgroundColor));
250 } 309 }
251 // The logout button must be added before the user card so that the user card 310 // The logout button must be added before the user card so that the user card
252 // can correctly calculate the remaining available width. 311 // can correctly calculate the remaining available width.
253 // Note that only the current multiprofile user gets a button. 312 // Note that only the current multiprofile user gets a button.
254 if (IsActiveUser()) 313 if (IsActiveUser())
255 AddLogoutButton(login); 314 AddLogoutButton(login);
256 AddUserCard(login); 315 AddUserCard(login);
257 316
258 if (UseMd()) { 317 if (UseMd()) {
259 auto* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); 318 auto* layout = new views::BoxLayout(views::BoxLayout::kHorizontal,
260 if (IsActiveUser()) { 319 kMenuExtraMarginFromLeftEdge, 0, 0);
261 layout->set_inside_border_insets(gfx::Insets(
262 0, kMenuExtraMarginFromLeftEdge, 0, kMenuExtraMarginFromLeftEdge));
263 }
264
265 SetLayoutManager(layout); 320 SetLayoutManager(layout);
266 layout->set_cross_axis_alignment( 321 layout->set_cross_axis_alignment(
267 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 322 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
268 layout->SetFlexForView(user_card_view_, 1); 323 layout->SetFlexForView(user_card_view_, 1);
269 324
270 if (IsActiveUser()) { 325 if (IsActiveUser())
271 SetBorder(views::CreatePaddedBorder( 326 SetBorder(base::MakeUnique<ActiveUserBorder>());
272 views::CreateSolidSidedBorder(0, 0, kSeparatorWidth, 0,
273 kSeparatorColor),
274 gfx::Insets(kMenuSeparatorVerticalPadding, 0,
275 kMenuSeparatorVerticalPadding - kSeparatorWidth, 0)));
276 }
277 } 327 }
278 } 328 }
279 329
280 UserView::~UserView() { 330 UserView::~UserView() {
281 RemoveAddUserMenuOption(); 331 RemoveAddUserMenuOption();
282 } 332 }
283 333
284 void UserView::MouseMovedOutOfHost() { 334 void UserView::MouseMovedOutOfHost() {
285 DCHECK(!UseMd()); 335 DCHECK(!UseMd());
286 RemoveAddUserMenuOption(); 336 RemoveAddUserMenuOption();
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 if (clickable) { 562 if (clickable) {
513 views::View* contents_view = user_card_view_; 563 views::View* contents_view = user_card_view_;
514 auto* button = 564 auto* button =
515 new ButtonFromView(contents_view, this, false, gfx::Insets()); 565 new ButtonFromView(contents_view, this, false, gfx::Insets());
516 if (IsActiveUser()) 566 if (IsActiveUser())
517 button->set_ink_drop_insets(gfx::Insets(kTrayPopupInkDropInset)); 567 button->set_ink_drop_insets(gfx::Insets(kTrayPopupInkDropInset));
518 user_card_view_ = button; 568 user_card_view_ = button;
519 is_user_card_button_ = true; 569 is_user_card_button_ = true;
520 } 570 }
521 AddChildViewAt(user_card_view_, 0); 571 AddChildViewAt(user_card_view_, 0);
522 // Card for supervised user can consume more space than currently
523 // available. In that case we should increase system bubble's width.
524 // TODO(estade,sgabriel): do we need this?
525 if (login == LoginStatus::PUBLIC) {
526 owner_->system_tray()->GetSystemBubble()->bubble_view()->SetWidth(
527 GetPreferredSize().width());
528 }
529 } 572 }
530 573
531 void UserView::ToggleAddUserMenuOption() { 574 void UserView::ToggleAddUserMenuOption() {
532 if (add_menu_option_.get()) { 575 if (add_menu_option_.get()) {
533 RemoveAddUserMenuOption(); 576 RemoveAddUserMenuOption();
534 return; 577 return;
535 } 578 }
536 579
537 // Note: We do not need to install a global event handler to delete this 580 // Note: We do not need to install a global event handler to delete this
538 // item since it will destroyed automatically before the menu / user menu item 581 // item since it will destroyed automatically before the menu / user menu item
(...skipping 14 matching lines...) Expand all
553 ->ConfigureWidgetInitParamsForContainer( 596 ->ConfigureWidgetInitParamsForContainer(
554 add_menu_option_.get(), kShellWindowId_DragImageAndTooltipContainer, 597 add_menu_option_.get(), kShellWindowId_DragImageAndTooltipContainer,
555 &params); 598 &params);
556 add_menu_option_->Init(params); 599 add_menu_option_->Init(params);
557 600
558 const SessionStateDelegate* delegate = 601 const SessionStateDelegate* delegate =
559 WmShell::Get()->GetSessionStateDelegate(); 602 WmShell::Get()->GetSessionStateDelegate();
560 SessionStateDelegate::AddUserError add_user_error; 603 SessionStateDelegate::AddUserError add_user_error;
561 add_user_enabled_ = delegate->CanAddUserToMultiProfile(&add_user_error); 604 add_user_enabled_ = delegate->CanAddUserToMultiProfile(&add_user_error);
562 605
563 AddUserView* add_user_view = 606 if (UseMd()) {
564 new AddUserView(static_cast<ButtonFromView*>(user_card_view_)); 607 base::Optional<SessionStateDelegate::AddUserError> error;
565 ButtonFromView* button = new ButtonFromView( 608 if (!add_user_enabled_)
566 add_user_view, add_user_enabled_ ? this : nullptr, 609 error = add_user_error;
567 !UseMd() && add_user_enabled_, gfx::Insets(UseMd() ? 0 : 1)); 610 ButtonFromView* button = new ButtonFromView(
568 if (UseMd()) 611 CreateAddUserView(error), add_user_enabled_ ? this : nullptr, false,
612 gfx::Insets());
569 button->set_ink_drop_insets(gfx::Insets(kTrayPopupInkDropInset)); 613 button->set_ink_drop_insets(gfx::Insets(kTrayPopupInkDropInset));
570 button->SetAccessibleName( 614 button->SetAccessibleName(
571 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); 615 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
572 button->ForceBorderVisible(true); 616 button->ForceBorderVisible(true);
573 617
574 if (UseMd()) {
575 // Position the widget on top of the user card view (which is still in the 618 // Position the widget on top of the user card view (which is still in the
576 // system menu). The top half of the widget will be transparent to allow 619 // system menu). The top half of the widget will be transparent to allow
577 // the active user to show through. 620 // the active user to show through.
578 gfx::Rect bounds = user_card_view_->GetBoundsInScreen(); 621 gfx::Rect bounds = user_card_view_->GetBoundsInScreen();
579 bounds.set_width(bounds.width() + kSeparatorWidth); 622 bounds.set_width(bounds.width() + kSeparatorWidth);
580 int row_height = bounds.height(); 623 int row_height = bounds.height();
581 bounds.set_height(row_height * 2);
582 add_menu_option_->SetBounds(bounds);
583 624
584 views::View* container = new AddUserWidgetContents( 625 views::View* container = new AddUserWidgetContents(
585 base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this))); 626 base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this)));
586 container->SetBorder(views::CreatePaddedBorder( 627 container->SetBorder(views::CreatePaddedBorder(
587 views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, 628 views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth,
588 kBackgroundColor), 629 kBackgroundColor),
589 gfx::Insets(row_height, 0, 0, 0))); 630 gfx::Insets(row_height, 0, 0, 0)));
590 container->SetLayoutManager(new views::FillLayout()); 631 container->SetLayoutManager(new views::FillLayout());
591 container->AddChildView(button); 632 container->AddChildView(button);
592 add_menu_option_->SetContentsView(container); 633 add_menu_option_->SetContentsView(container);
634
635 bounds.set_height(container->GetPreferredSize().height());
636 add_menu_option_->SetBounds(bounds);
637
638 // Show the content.
639 add_menu_option_->SetAlwaysOnTop(true);
640 add_menu_option_->Show();
641
642 // We activate the entry automatically if invoked with focus.
643 if (add_user_enabled_ && user_card_view_->HasFocus()) {
644 button->GetFocusManager()->SetFocusedView(button);
645 user_card_view_->GetFocusManager()->SetFocusedView(button);
646 }
593 } else { 647 } else {
648 AddUserView* add_user_view =
649 new AddUserView(static_cast<ButtonFromView*>(user_card_view_));
650 ButtonFromView* button =
651 new ButtonFromView(add_user_view, add_user_enabled_ ? this : nullptr,
652 add_user_enabled_, gfx::Insets(1));
653 button->SetAccessibleName(
654 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
655 button->ForceBorderVisible(true);
656
594 add_menu_option_->SetOpacity(1.f); 657 add_menu_option_->SetOpacity(1.f);
595 add_menu_option_->SetContentsView(button); 658 add_menu_option_->SetContentsView(button);
596 // Position it below our user card. 659 // Position it below our user card.
597 gfx::Rect bounds = user_card_view_->GetBoundsInScreen(); 660 gfx::Rect bounds = user_card_view_->GetBoundsInScreen();
598 bounds.set_y(bounds.y() + bounds.height()); 661 bounds.set_y(bounds.y() + bounds.height());
599 add_menu_option_->SetBounds(bounds); 662 add_menu_option_->SetBounds(bounds);
600 }
601 663
602 // Show the content. 664 // Show the content.
603 add_menu_option_->SetAlwaysOnTop(true); 665 add_menu_option_->SetAlwaysOnTop(true);
604 add_menu_option_->Show(); 666 add_menu_option_->Show();
605 667
606 if (add_user_enabled_) { 668 if (add_user_enabled_) {
607 // We activate the entry automatically if invoked with focus. 669 // We activate the entry automatically if invoked with focus.
608 if (user_card_view_->HasFocus()) { 670 if (user_card_view_->HasFocus()) {
609 button->GetFocusManager()->SetFocusedView(button); 671 button->GetFocusManager()->SetFocusedView(button);
610 user_card_view_->GetFocusManager()->SetFocusedView(button); 672 user_card_view_->GetFocusManager()->SetFocusedView(button);
673 }
674 } else {
675 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
676 int message_id = 0;
677 switch (add_user_error) {
678 case SessionStateDelegate::ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER:
679 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER;
680 break;
681 case SessionStateDelegate::ADD_USER_ERROR_MAXIMUM_USERS_REACHED:
682 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER;
683 break;
684 case SessionStateDelegate::ADD_USER_ERROR_OUT_OF_USERS:
685 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS;
686 break;
687 default:
688 NOTREACHED() << "Unknown adding user error " << add_user_error;
689 }
690
691 popup_message_.reset(new PopupMessage(
692 bundle.GetLocalizedString(
693 IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER),
694 bundle.GetLocalizedString(message_id), PopupMessage::ICON_WARNING,
695 add_user_view->anchor(), views::BubbleBorder::TOP_LEFT,
696 gfx::Size(parent()->bounds().width() - kPopupMessageOffset, 0),
697 2 * kPopupMessageOffset));
611 } 698 }
612 } else {
613 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
614 int message_id = 0;
615 switch (add_user_error) {
616 case SessionStateDelegate::ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER:
617 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER;
618 break;
619 case SessionStateDelegate::ADD_USER_ERROR_MAXIMUM_USERS_REACHED:
620 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER;
621 break;
622 case SessionStateDelegate::ADD_USER_ERROR_OUT_OF_USERS:
623 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS;
624 break;
625 default:
626 NOTREACHED() << "Unknown adding user error " << add_user_error;
627 }
628
629 popup_message_.reset(new PopupMessage(
630 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER),
631 bundle.GetLocalizedString(message_id), PopupMessage::ICON_WARNING,
632 add_user_view->anchor(), views::BubbleBorder::TOP_LEFT,
633 gfx::Size(parent()->bounds().width() - kPopupMessageOffset, 0),
634 2 * kPopupMessageOffset));
635 }
636 if (!UseMd()) {
637 // Find the screen area which encloses both elements and sets then a mouse 699 // Find the screen area which encloses both elements and sets then a mouse
638 // watcher which will close the "menu". 700 // watcher which will close the "menu".
639 gfx::Rect area = user_card_view_->GetBoundsInScreen(); 701 gfx::Rect area = user_card_view_->GetBoundsInScreen();
640 area.set_height(2 * area.height()); 702 area.set_height(2 * area.height());
641 mouse_watcher_.reset( 703 mouse_watcher_.reset(
642 new views::MouseWatcher(new UserViewMouseWatcherHost(area), this)); 704 new views::MouseWatcher(new UserViewMouseWatcherHost(area), this));
643 mouse_watcher_->Start(); 705 mouse_watcher_->Start();
644 } 706 }
645 // Install a listener to focus changes so that we can remove the card when 707 // Install a listener to focus changes so that we can remove the card when
646 // the focus gets changed. When called through the destruction of the bubble, 708 // the focus gets changed. When called through the destruction of the bubble,
647 // the FocusManager cannot be determined anymore and we remember it here. 709 // the FocusManager cannot be determined anymore and we remember it here.
648 focus_manager_ = user_card_view_->GetFocusManager(); 710 focus_manager_ = user_card_view_->GetFocusManager();
649 focus_manager_->AddFocusChangeListener(this); 711 focus_manager_->AddFocusChangeListener(this);
650 } 712 }
651 713
652 void UserView::RemoveAddUserMenuOption() { 714 void UserView::RemoveAddUserMenuOption() {
653 if (!add_menu_option_.get()) 715 if (!add_menu_option_.get())
654 return; 716 return;
655 focus_manager_->RemoveFocusChangeListener(this); 717 focus_manager_->RemoveFocusChangeListener(this);
656 focus_manager_ = nullptr; 718 focus_manager_ = nullptr;
657 if (user_card_view_->GetFocusManager()) 719 if (user_card_view_->GetFocusManager())
658 user_card_view_->GetFocusManager()->ClearFocus(); 720 user_card_view_->GetFocusManager()->ClearFocus();
659 popup_message_.reset(); 721 popup_message_.reset();
660 mouse_watcher_.reset(); 722 mouse_watcher_.reset();
661 add_menu_option_.reset(); 723 add_menu_option_.reset();
662 } 724 }
663 725
664 } // namespace tray 726 } // namespace tray
665 } // namespace ash 727 } // 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