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

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

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months 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/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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 148
149 gfx::Size AddUserView::GetPreferredSize() const { 149 gfx::Size AddUserView::GetPreferredSize() const {
150 return owner_->bounds().size(); 150 return owner_->bounds().size();
151 } 151 }
152 152
153 void AddUserView::AddContent() { 153 void AddUserView::AddContent() {
154 SetLayoutManager(new views::FillLayout()); 154 SetLayoutManager(new views::FillLayout());
155 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 155 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
156 156
157 add_user_ = new views::View; 157 add_user_ = new views::View;
158 add_user_->SetBorder(views::Border::CreateEmptyBorder( 158 add_user_->SetBorder(
159 0, kTrayUserTileHoverBorderInset, 0, 0)); 159 views::Border::CreateEmptyBorder(0, kTrayUserTileHoverBorderInset, 0, 0));
160 160
161 add_user_->SetLayoutManager(new views::BoxLayout( 161 add_user_->SetLayoutManager(new views::BoxLayout(
162 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems)); 162 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems));
163 AddChildViewAt(add_user_, 0); 163 AddChildViewAt(add_user_, 0);
164 164
165 // Add the [+] icon which is also the anchor for messages. 165 // Add the [+] icon which is also the anchor for messages.
166 RoundedImageView* icon = new RoundedImageView(kTrayAvatarCornerRadius, true); 166 RoundedImageView* icon = new RoundedImageView(kTrayAvatarCornerRadius, true);
167 anchor_ = icon; 167 anchor_ = icon;
168 icon->SetImage(*ui::ResourceBundle::GetSharedInstance() 168 icon->SetImage(*ui::ResourceBundle::GetSharedInstance()
169 .GetImageNamed(IDR_AURA_UBER_TRAY_ADD_MULTIPROFILE_USER) 169 .GetImageNamed(IDR_AURA_UBER_TRAY_ADD_MULTIPROFILE_USER)
(...skipping 19 matching lines...) Expand all
189 add_user_enabled_(true), 189 add_user_enabled_(true),
190 focus_manager_(NULL) { 190 focus_manager_(NULL) {
191 CHECK_NE(LoginStatus::NOT_LOGGED_IN, login); 191 CHECK_NE(LoginStatus::NOT_LOGGED_IN, login);
192 if (!index) { 192 if (!index) {
193 // Only the logged in user will have a background. All other users will have 193 // Only the logged in user will have a background. All other users will have
194 // to allow the TrayPopupContainer highlighting the menu line. 194 // to allow the TrayPopupContainer highlighting the menu line.
195 set_background(views::Background::CreateSolidBackground( 195 set_background(views::Background::CreateSolidBackground(
196 login == LoginStatus::PUBLIC ? kPublicAccountBackgroundColor 196 login == LoginStatus::PUBLIC ? kPublicAccountBackgroundColor
197 : kBackgroundColor)); 197 : kBackgroundColor));
198 } 198 }
199 SetLayoutManager(new views::BoxLayout( 199 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0,
200 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems)); 200 kTrayPopupPaddingBetweenItems));
201 // The logout button must be added before the user card so that the user card 201 // The logout button must be added before the user card so that the user card
202 // can correctly calculate the remaining available width. 202 // can correctly calculate the remaining available width.
203 // Note that only the current multiprofile user gets a button. 203 // Note that only the current multiprofile user gets a button.
204 if (!user_index_) 204 if (!user_index_)
205 AddLogoutButton(login); 205 AddLogoutButton(login);
206 AddUserCard(login); 206 AddUserCard(login);
207 } 207 }
208 208
209 UserView::~UserView() { 209 UserView::~UserView() {
210 RemoveAddUserMenuOption(); 210 RemoveAddUserMenuOption();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 void UserView::AddLogoutButton(LoginStatus login) { 331 void UserView::AddLogoutButton(LoginStatus login) {
332 const base::string16 title = 332 const base::string16 title =
333 user::GetLocalizedSignOutStringForStatus(login, true); 333 user::GetLocalizedSignOutStringForStatus(login, true);
334 auto* logout_button = new TrayPopupLabelButton(this, title); 334 auto* logout_button = new TrayPopupLabelButton(this, title);
335 logout_button->SetAccessibleName(title); 335 logout_button->SetAccessibleName(title);
336 logout_button_ = logout_button; 336 logout_button_ = logout_button;
337 // In public account mode, the logout button border has a custom color. 337 // In public account mode, the logout button border has a custom color.
338 if (login == LoginStatus::PUBLIC) { 338 if (login == LoginStatus::PUBLIC) {
339 std::unique_ptr<TrayPopupLabelButtonBorder> border( 339 std::unique_ptr<TrayPopupLabelButtonBorder> border(
340 new TrayPopupLabelButtonBorder()); 340 new TrayPopupLabelButtonBorder());
341 border->SetPainter(false, 341 border->SetPainter(false, views::Button::STATE_NORMAL,
342 views::Button::STATE_NORMAL,
343 views::Painter::CreateImageGridPainter( 342 views::Painter::CreateImageGridPainter(
344 kPublicAccountLogoutButtonBorderImagesNormal)); 343 kPublicAccountLogoutButtonBorderImagesNormal));
345 border->SetPainter(false, 344 border->SetPainter(false, views::Button::STATE_HOVERED,
346 views::Button::STATE_HOVERED,
347 views::Painter::CreateImageGridPainter( 345 views::Painter::CreateImageGridPainter(
348 kPublicAccountLogoutButtonBorderImagesHovered)); 346 kPublicAccountLogoutButtonBorderImagesHovered));
349 border->SetPainter(false, 347 border->SetPainter(false, views::Button::STATE_PRESSED,
350 views::Button::STATE_PRESSED,
351 views::Painter::CreateImageGridPainter( 348 views::Painter::CreateImageGridPainter(
352 kPublicAccountLogoutButtonBorderImagesHovered)); 349 kPublicAccountLogoutButtonBorderImagesHovered));
353 logout_button_->SetBorder(std::move(border)); 350 logout_button_->SetBorder(std::move(border));
354 } 351 }
355 AddChildView(logout_button_); 352 AddChildView(logout_button_);
356 } 353 }
357 354
358 void UserView::AddUserCard(LoginStatus login) { 355 void UserView::AddUserCard(LoginStatus login) {
359 // Add padding around the panel. 356 // Add padding around the panel.
360 SetBorder(views::Border::CreateEmptyBorder(kTrayPopupUserCardVerticalPadding, 357 SetBorder(views::Border::CreateEmptyBorder(
361 kTrayPopupPaddingHorizontal, 358 kTrayPopupUserCardVerticalPadding, kTrayPopupPaddingHorizontal,
362 kTrayPopupUserCardVerticalPadding, 359 kTrayPopupUserCardVerticalPadding, kTrayPopupPaddingHorizontal));
363 kTrayPopupPaddingHorizontal));
364 360
365 views::TrayBubbleView* bubble_view = 361 views::TrayBubbleView* bubble_view =
366 owner_->system_tray()->GetSystemBubble()->bubble_view(); 362 owner_->system_tray()->GetSystemBubble()->bubble_view();
367 int max_card_width = 363 int max_card_width =
368 bubble_view->GetMaximumSize().width() - 364 bubble_view->GetMaximumSize().width() -
369 (2 * kTrayPopupPaddingHorizontal + kTrayPopupPaddingBetweenItems); 365 (2 * kTrayPopupPaddingHorizontal + kTrayPopupPaddingBetweenItems);
370 if (logout_button_) 366 if (logout_button_)
371 max_card_width -= logout_button_->GetPreferredSize().width(); 367 max_card_width -= logout_button_->GetPreferredSize().width();
372 user_card_view_ = new UserCardView(login, max_card_width, user_index_); 368 user_card_view_ = new UserCardView(login, max_card_width, user_index_);
373 // The entry is clickable when no system modal dialog is open and the multi 369 // The entry is clickable when no system modal dialog is open and the multi
374 // profile option is active. 370 // profile option is active.
375 bool clickable = !WmShell::Get()->IsSystemModalWindowOpen() && 371 bool clickable = !WmShell::Get()->IsSystemModalWindowOpen() &&
376 IsMultiProfileSupportedAndUserActive(); 372 IsMultiProfileSupportedAndUserActive();
377 if (clickable) { 373 if (clickable) {
378 // To allow the border to start before the icon, reduce the size before and 374 // To allow the border to start before the icon, reduce the size before and
379 // add an inset to the icon to get the spacing. 375 // add an inset to the icon to get the spacing.
380 if (!user_index_) { 376 if (!user_index_) {
381 SetBorder(views::Border::CreateEmptyBorder( 377 SetBorder(views::Border::CreateEmptyBorder(
382 kTrayPopupUserCardVerticalPadding, 378 kTrayPopupUserCardVerticalPadding,
383 kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset, 379 kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset,
384 kTrayPopupUserCardVerticalPadding, 380 kTrayPopupUserCardVerticalPadding, kTrayPopupPaddingHorizontal));
385 kTrayPopupPaddingHorizontal));
386 user_card_view_->SetBorder(views::Border::CreateEmptyBorder( 381 user_card_view_->SetBorder(views::Border::CreateEmptyBorder(
387 0, kTrayUserTileHoverBorderInset, 0, 0)); 382 0, kTrayUserTileHoverBorderInset, 0, 0));
388 } 383 }
389 gfx::Insets insets = gfx::Insets(1, 1, 1, 1); 384 gfx::Insets insets = gfx::Insets(1, 1, 1, 1);
390 views::View* contents_view = user_card_view_; 385 views::View* contents_view = user_card_view_;
391 if (user_index_) { 386 if (user_index_) {
392 // Since the activation border needs to be drawn around the tile, we 387 // Since the activation border needs to be drawn around the tile, we
393 // have to put the tile into another view which fills the menu panel, 388 // have to put the tile into another view which fills the menu panel,
394 // but keeping the offsets of the content. 389 // but keeping the offsets of the content.
395 contents_view = new views::View(); 390 contents_view = new views::View();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 446
452 AddUserView* add_user_view = 447 AddUserView* add_user_view =
453 new AddUserView(static_cast<ButtonFromView*>(user_card_view_)); 448 new AddUserView(static_cast<ButtonFromView*>(user_card_view_));
454 449
455 const SessionStateDelegate* delegate = 450 const SessionStateDelegate* delegate =
456 WmShell::Get()->GetSessionStateDelegate(); 451 WmShell::Get()->GetSessionStateDelegate();
457 452
458 SessionStateDelegate::AddUserError add_user_error; 453 SessionStateDelegate::AddUserError add_user_error;
459 add_user_enabled_ = delegate->CanAddUserToMultiProfile(&add_user_error); 454 add_user_enabled_ = delegate->CanAddUserToMultiProfile(&add_user_error);
460 455
461 ButtonFromView* button = new ButtonFromView(add_user_view, 456 ButtonFromView* button =
462 add_user_enabled_ ? this : NULL, 457 new ButtonFromView(add_user_view, add_user_enabled_ ? this : NULL,
463 add_user_enabled_, 458 add_user_enabled_, gfx::Insets(1, 1, 1, 1));
464 gfx::Insets(1, 1, 1, 1));
465 button->SetAccessibleName( 459 button->SetAccessibleName(
466 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); 460 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
467 button->ForceBorderVisible(true); 461 button->ForceBorderVisible(true);
468 add_menu_option_->SetContentsView(button); 462 add_menu_option_->SetContentsView(button);
469 463
470 if (add_user_enabled_) { 464 if (add_user_enabled_) {
471 // We activate the entry automatically if invoked with focus. 465 // We activate the entry automatically if invoked with focus.
472 if (user_card_view_->HasFocus()) { 466 if (user_card_view_->HasFocus()) {
473 button->GetFocusManager()->SetFocusedView(button); 467 button->GetFocusManager()->SetFocusedView(button);
474 user_card_view_->GetFocusManager()->SetFocusedView(button); 468 user_card_view_->GetFocusManager()->SetFocusedView(button);
(...skipping 10 matching lines...) Expand all
485 break; 479 break;
486 case SessionStateDelegate::ADD_USER_ERROR_OUT_OF_USERS: 480 case SessionStateDelegate::ADD_USER_ERROR_OUT_OF_USERS:
487 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS; 481 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS;
488 break; 482 break;
489 default: 483 default:
490 NOTREACHED() << "Unknown adding user error " << add_user_error; 484 NOTREACHED() << "Unknown adding user error " << add_user_error;
491 } 485 }
492 486
493 popup_message_.reset(new PopupMessage( 487 popup_message_.reset(new PopupMessage(
494 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER), 488 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER),
495 bundle.GetLocalizedString(message_id), 489 bundle.GetLocalizedString(message_id), PopupMessage::ICON_WARNING,
496 PopupMessage::ICON_WARNING, 490 add_user_view->anchor(), views::BubbleBorder::TOP_LEFT,
497 add_user_view->anchor(),
498 views::BubbleBorder::TOP_LEFT,
499 gfx::Size(parent()->bounds().width() - kPopupMessageOffset, 0), 491 gfx::Size(parent()->bounds().width() - kPopupMessageOffset, 0),
500 2 * kPopupMessageOffset)); 492 2 * kPopupMessageOffset));
501 } 493 }
502 // Find the screen area which encloses both elements and sets then a mouse 494 // Find the screen area which encloses both elements and sets then a mouse
503 // watcher which will close the "menu". 495 // watcher which will close the "menu".
504 gfx::Rect area = user_card_view_->GetBoundsInScreen(); 496 gfx::Rect area = user_card_view_->GetBoundsInScreen();
505 area.set_height(2 * area.height()); 497 area.set_height(2 * area.height());
506 mouse_watcher_.reset( 498 mouse_watcher_.reset(
507 new views::MouseWatcher(new UserViewMouseWatcherHost(area), this)); 499 new views::MouseWatcher(new UserViewMouseWatcherHost(area), this));
508 mouse_watcher_->Start(); 500 mouse_watcher_->Start();
(...skipping 11 matching lines...) Expand all
520 focus_manager_ = NULL; 512 focus_manager_ = NULL;
521 if (user_card_view_->GetFocusManager()) 513 if (user_card_view_->GetFocusManager())
522 user_card_view_->GetFocusManager()->ClearFocus(); 514 user_card_view_->GetFocusManager()->ClearFocus();
523 popup_message_.reset(); 515 popup_message_.reset();
524 mouse_watcher_.reset(); 516 mouse_watcher_.reset();
525 add_menu_option_.reset(); 517 add_menu_option_.reset();
526 } 518 }
527 519
528 } // namespace tray 520 } // namespace tray
529 } // namespace ash 521 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/user/user_card_view.cc ('k') | ash/system/web_notification/ash_popup_alignment_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698