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

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

Issue 145033006: views: Make View::set_border() take a scoped_ptr<>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Further renaming Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/tray_user.h" 5 #include "ash/system/user/tray_user.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <climits> 8 #include <climits>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 event->SetHandled(); 466 event->SetHandled();
467 } 467 }
468 } 468 }
469 469
470 PublicAccountUserDetails::PublicAccountUserDetails(SystemTrayItem* owner, 470 PublicAccountUserDetails::PublicAccountUserDetails(SystemTrayItem* owner,
471 int used_width) 471 int used_width)
472 : learn_more_(NULL) { 472 : learn_more_(NULL) {
473 const int inner_padding = 473 const int inner_padding =
474 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; 474 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems;
475 const bool rtl = base::i18n::IsRTL(); 475 const bool rtl = base::i18n::IsRTL();
476 set_border(views::Border::CreateEmptyBorder( 476 SetBorder(views::Border::CreateEmptyBorder(
477 kUserDetailsVerticalPadding, rtl ? 0 : inner_padding, 477 kUserDetailsVerticalPadding, rtl ? 0 : inner_padding,
478 kUserDetailsVerticalPadding, rtl ? inner_padding : 0)); 478 kUserDetailsVerticalPadding, rtl ? inner_padding : 0));
479 479
480 // Retrieve the user's display name and wrap it with markers. 480 // Retrieve the user's display name and wrap it with markers.
481 // Note that since this is a public account it always has to be the primary 481 // Note that since this is a public account it always has to be the primary
482 // user. 482 // user.
483 base::string16 display_name = 483 base::string16 display_name =
484 Shell::GetInstance()->session_state_delegate()->GetUserDisplayName(0); 484 Shell::GetInstance()->session_state_delegate()->GetUserDisplayName(0);
485 base::RemoveChars(display_name, kDisplayNameMark, &display_name); 485 base::RemoveChars(display_name, kDisplayNameMark, &display_name);
486 display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0]; 486 display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0];
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 void UserCard::OnMouseExited(const ui::MouseEvent& event) { 676 void UserCard::OnMouseExited(const ui::MouseEvent& event) {
677 if (is_active_user_) { 677 if (is_active_user_) {
678 button_hovered_ = false; 678 button_hovered_ = false;
679 background()->SetNativeControlColor(kBackgroundColor); 679 background()->SetNativeControlColor(kBackgroundColor);
680 ShowActive(); 680 ShowActive();
681 } 681 }
682 } 682 }
683 683
684 void UserCard::ShowActive() { 684 void UserCard::ShowActive() {
685 int width = button_hovered_ || show_border_ ? 1 : 0; 685 int width = button_hovered_ || show_border_ ? 1 : 0;
686 set_border(views::Border::CreateSolidSidedBorder(width, width, width, 1, 686 SetBorder(views::Border::CreateSolidSidedBorder(width, width, width, 1,
687 kBorderColor)); 687 kBorderColor));
688 SchedulePaint(); 688 SchedulePaint();
689 } 689 }
690 690
691 UserView::UserView(SystemTrayItem* owner, 691 UserView::UserView(SystemTrayItem* owner,
692 user::LoginStatus login, 692 user::LoginStatus login,
693 MultiProfileIndex index) 693 MultiProfileIndex index)
694 : multiprofile_index_(index), 694 : multiprofile_index_(index),
695 user_card_view_(NULL), 695 user_card_view_(NULL),
696 owner_(owner), 696 owner_(owner),
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 } 825 }
826 826
827 void UserView::AddLogoutButton(user::LoginStatus login) { 827 void UserView::AddLogoutButton(user::LoginStatus login) {
828 const base::string16 title = user::GetLocalizedSignOutStringForStatus(login, 828 const base::string16 title = user::GetLocalizedSignOutStringForStatus(login,
829 true); 829 true);
830 TrayPopupLabelButton* logout_button = new TrayPopupLabelButton(this, title); 830 TrayPopupLabelButton* logout_button = new TrayPopupLabelButton(this, title);
831 logout_button->SetAccessibleName(title); 831 logout_button->SetAccessibleName(title);
832 logout_button_ = logout_button; 832 logout_button_ = logout_button;
833 // In public account mode, the logout button border has a custom color. 833 // In public account mode, the logout button border has a custom color.
834 if (login == user::LOGGED_IN_PUBLIC) { 834 if (login == user::LOGGED_IN_PUBLIC) {
835 TrayPopupLabelButtonBorder* border = new TrayPopupLabelButtonBorder(); 835 scoped_ptr<TrayPopupLabelButtonBorder> border(
836 new TrayPopupLabelButtonBorder());
836 border->SetPainter(false, views::Button::STATE_NORMAL, 837 border->SetPainter(false, views::Button::STATE_NORMAL,
837 views::Painter::CreateImageGridPainter( 838 views::Painter::CreateImageGridPainter(
838 kPublicAccountLogoutButtonBorderImagesNormal)); 839 kPublicAccountLogoutButtonBorderImagesNormal));
839 border->SetPainter(false, views::Button::STATE_HOVERED, 840 border->SetPainter(false, views::Button::STATE_HOVERED,
840 views::Painter::CreateImageGridPainter( 841 views::Painter::CreateImageGridPainter(
841 kPublicAccountLogoutButtonBorderImagesHovered)); 842 kPublicAccountLogoutButtonBorderImagesHovered));
842 border->SetPainter(false, views::Button::STATE_PRESSED, 843 border->SetPainter(false, views::Button::STATE_PRESSED,
843 views::Painter::CreateImageGridPainter( 844 views::Painter::CreateImageGridPainter(
844 kPublicAccountLogoutButtonBorderImagesHovered)); 845 kPublicAccountLogoutButtonBorderImagesHovered));
845 logout_button_->set_border(border); 846 logout_button_->SetBorder(border.PassAs<views::Border>());
846 } 847 }
847 AddChildView(logout_button_); 848 AddChildView(logout_button_);
848 } 849 }
849 850
850 void UserView::AddUserCard(SystemTrayItem* owner, user::LoginStatus login) { 851 void UserView::AddUserCard(SystemTrayItem* owner, user::LoginStatus login) {
851 // Add padding around the panel. 852 // Add padding around the panel.
852 set_border(views::Border::CreateEmptyBorder( 853 SetBorder(views::Border::CreateEmptyBorder(
853 kUserCardVerticalPadding, kTrayPopupPaddingHorizontal, 854 kUserCardVerticalPadding, kTrayPopupPaddingHorizontal,
854 kUserCardVerticalPadding, kTrayPopupPaddingHorizontal)); 855 kUserCardVerticalPadding, kTrayPopupPaddingHorizontal));
855 856
856 if (SupportsMultiProfile() && login != user::LOGGED_IN_RETAIL_MODE) { 857 if (SupportsMultiProfile() && login != user::LOGGED_IN_RETAIL_MODE) {
857 user_card_view_ = new UserCard(this, multiprofile_index_ == 0); 858 user_card_view_ = new UserCard(this, multiprofile_index_ == 0);
858 is_user_card_ = true; 859 is_user_card_ = true;
859 } else { 860 } else {
860 user_card_view_ = new views::View(); 861 user_card_view_ = new views::View();
861 is_user_card_ = false; 862 is_user_card_ = false;
862 } 863 }
(...skipping 15 matching lines...) Expand all
878 AddLoggedInPublicModeUserCardContent(owner); 879 AddLoggedInPublicModeUserCardContent(owner);
879 return; 880 return;
880 } 881 }
881 882
882 views::View* icon = CreateIconForUserCard(login); 883 views::View* icon = CreateIconForUserCard(login);
883 user_card_view_->AddChildView(icon); 884 user_card_view_->AddChildView(icon);
884 885
885 // To allow the border to start before the icon, reduce the size before and 886 // To allow the border to start before the icon, reduce the size before and
886 // add an inset to the icon to get the spacing. 887 // add an inset to the icon to get the spacing.
887 if (multiprofile_index_ == 0 && SupportsMultiProfile()) { 888 if (multiprofile_index_ == 0 && SupportsMultiProfile()) {
888 icon->set_border(views::Border::CreateEmptyBorder( 889 icon->SetBorder(views::Border::CreateEmptyBorder(
889 0, kTrayUserTileHoverBorderInset, 0, 0)); 890 0, kTrayUserTileHoverBorderInset, 0, 0));
890 set_border(views::Border::CreateEmptyBorder( 891 SetBorder(views::Border::CreateEmptyBorder(
891 kUserCardVerticalPadding, 892 kUserCardVerticalPadding,
892 kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset, 893 kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset,
893 kUserCardVerticalPadding, 894 kUserCardVerticalPadding,
894 kTrayPopupPaddingHorizontal)); 895 kTrayPopupPaddingHorizontal));
895 } 896 }
896 SessionStateDelegate* delegate = 897 SessionStateDelegate* delegate =
897 Shell::GetInstance()->session_state_delegate(); 898 Shell::GetInstance()->session_state_delegate();
898 views::Label* username = NULL; 899 views::Label* username = NULL;
899 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 900 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
900 if (!multiprofile_index_) { 901 if (!multiprofile_index_) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 gfx::Size(kUserIconSize, kUserIconSize)); 965 gfx::Size(kUserIconSize, kUserIconSize));
965 } 966 }
966 return icon; 967 return icon;
967 } 968 }
968 969
969 void UserView::AddLoggedInRetailModeUserCardContent() { 970 void UserView::AddLoggedInRetailModeUserCardContent() {
970 views::Label* details = new views::Label; 971 views::Label* details = new views::Label;
971 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 972 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
972 details->SetText( 973 details->SetText(
973 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_KIOSK_LABEL)); 974 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_KIOSK_LABEL));
974 details->set_border(views::Border::CreateEmptyBorder(0, 4, 0, 1)); 975 details->SetBorder(views::Border::CreateEmptyBorder(0, 4, 0, 1));
975 details->SetHorizontalAlignment(gfx::ALIGN_LEFT); 976 details->SetHorizontalAlignment(gfx::ALIGN_LEFT);
976 user_card_view_->AddChildView(details); 977 user_card_view_->AddChildView(details);
977 } 978 }
978 979
979 void UserView::AddLoggedInPublicModeUserCardContent(SystemTrayItem* owner) { 980 void UserView::AddLoggedInPublicModeUserCardContent(SystemTrayItem* owner) {
980 user_card_view_->AddChildView(CreateIconForUserCard(user::LOGGED_IN_PUBLIC)); 981 user_card_view_->AddChildView(CreateIconForUserCard(user::LOGGED_IN_PUBLIC));
981 user_card_view_->AddChildView(new PublicAccountUserDetails( 982 user_card_view_->AddChildView(new PublicAccountUserDetails(
982 owner, GetPreferredSize().width() + kTrayPopupPaddingBetweenItems)); 983 owner, GetPreferredSize().width() + kTrayPopupPaddingBetweenItems));
983 } 984 }
984 985
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 1091
1091 const SessionStateDelegate* delegate = 1092 const SessionStateDelegate* delegate =
1092 Shell::GetInstance()->session_state_delegate(); 1093 Shell::GetInstance()->session_state_delegate();
1093 bool enable = delegate->NumberOfLoggedInUsers() < 1094 bool enable = delegate->NumberOfLoggedInUsers() <
1094 delegate->GetMaximumNumberOfLoggedInUsers(); 1095 delegate->GetMaximumNumberOfLoggedInUsers();
1095 1096
1096 SetLayoutManager(new views::FillLayout()); 1097 SetLayoutManager(new views::FillLayout());
1097 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); 1098 set_background(views::Background::CreateSolidBackground(kBackgroundColor));
1098 1099
1099 // Add padding around the panel. 1100 // Add padding around the panel.
1100 set_border(views::Border::CreateSolidBorder(1, kBorderColor)); 1101 SetBorder(views::Border::CreateSolidBorder(1, kBorderColor));
1101 1102
1102 add_user_ = new UserCard(this, enable); 1103 add_user_ = new UserCard(this, enable);
1103 add_user_->set_border(views::Border::CreateEmptyBorder( 1104 add_user_->SetBorder(views::Border::CreateEmptyBorder(
1104 kUserCardVerticalPadding, 1105 kUserCardVerticalPadding,
1105 kTrayPopupPaddingHorizontal- kTrayUserTileHoverBorderInset, 1106 kTrayPopupPaddingHorizontal- kTrayUserTileHoverBorderInset,
1106 kUserCardVerticalPadding, 1107 kUserCardVerticalPadding,
1107 kTrayPopupPaddingHorizontal- kTrayUserTileHoverBorderInset)); 1108 kTrayPopupPaddingHorizontal- kTrayUserTileHoverBorderInset));
1108 1109
1109 add_user_->SetLayoutManager(new views::BoxLayout( 1110 add_user_->SetLayoutManager(new views::BoxLayout(
1110 views::BoxLayout::kHorizontal, 0, 0 , kTrayPopupPaddingBetweenItems)); 1111 views::BoxLayout::kHorizontal, 0, 0 , kTrayPopupPaddingBetweenItems));
1111 AddChildViewAt(add_user_, 0); 1112 AddChildViewAt(add_user_, 0);
1112 1113
1113 // Add the [+] icon which is also the anchor for messages. 1114 // Add the [+] icon which is also the anchor for messages.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 if (status == user::LOGGED_IN_LOCALLY_MANAGED) { 1284 if (status == user::LOGGED_IN_LOCALLY_MANAGED) {
1284 label_->SetText( 1285 label_->SetText(
1285 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL)); 1286 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL));
1286 } else if (status == user::LOGGED_IN_GUEST) { 1287 } else if (status == user::LOGGED_IN_GUEST) {
1287 label_->SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL)); 1288 label_->SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL));
1288 } 1289 }
1289 1290
1290 if (avatar_ && switches::UseAlternateShelfLayout()) { 1291 if (avatar_ && switches::UseAlternateShelfLayout()) {
1291 int corner_radius = GetTrayItemRadius(); 1292 int corner_radius = GetTrayItemRadius();
1292 avatar_->SetCornerRadii(0, corner_radius, corner_radius, 0); 1293 avatar_->SetCornerRadii(0, corner_radius, corner_radius, 0);
1293 avatar_->set_border(NULL); 1294 avatar_->ClearBorder();
1294 } 1295 }
1295 UpdateAvatarImage(status); 1296 UpdateAvatarImage(status);
1296 1297
1297 // Update layout after setting label_ and avatar_ with new login status. 1298 // Update layout after setting label_ and avatar_ with new login status.
1298 UpdateLayoutOfItem(); 1299 UpdateLayoutOfItem();
1299 } 1300 }
1300 1301
1301 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 1302 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
1302 // Inactive users won't have a layout. 1303 // Inactive users won't have a layout.
1303 if (!layout_view_) 1304 if (!layout_view_)
1304 return; 1305 return;
1305 int corner_radius = GetTrayItemRadius(); 1306 int corner_radius = GetTrayItemRadius();
1306 if (alignment == SHELF_ALIGNMENT_BOTTOM || 1307 if (alignment == SHELF_ALIGNMENT_BOTTOM ||
1307 alignment == SHELF_ALIGNMENT_TOP) { 1308 alignment == SHELF_ALIGNMENT_TOP) {
1308 if (avatar_) { 1309 if (avatar_) {
1309 if (switches::UseAlternateShelfLayout()) { 1310 if (switches::UseAlternateShelfLayout()) {
1310 if (multiprofile_index_) { 1311 if (multiprofile_index_) {
1311 avatar_->set_border( 1312 avatar_->SetBorder(
1312 views::Border::CreateEmptyBorder(0, kTrayLabelSpacing, 0, 0)); 1313 views::Border::CreateEmptyBorder(0, kTrayLabelSpacing, 0, 0));
1313 } else { 1314 } else {
1314 avatar_->set_border(NULL); 1315 avatar_->ClearBorder();
1315 } 1316 }
1316 avatar_->SetCornerRadii(0, corner_radius, corner_radius, 0); 1317 avatar_->SetCornerRadii(0, corner_radius, corner_radius, 0);
1317 } else { 1318 } else {
1318 avatar_->set_border(views::Border::CreateEmptyBorder( 1319 avatar_->SetBorder(views::Border::CreateEmptyBorder(
1319 0, kTrayImageItemHorizontalPaddingBottomAlignment + 2, 1320 0, kTrayImageItemHorizontalPaddingBottomAlignment + 2,
1320 0, kTrayImageItemHorizontalPaddingBottomAlignment)); 1321 0, kTrayImageItemHorizontalPaddingBottomAlignment));
1321 } 1322 }
1322 } 1323 }
1323 if (label_) { 1324 if (label_) {
1324 label_->set_border(views::Border::CreateEmptyBorder( 1325 label_->SetBorder(views::Border::CreateEmptyBorder(
1325 0, kTrayLabelItemHorizontalPaddingBottomAlignment, 1326 0, kTrayLabelItemHorizontalPaddingBottomAlignment,
1326 0, kTrayLabelItemHorizontalPaddingBottomAlignment)); 1327 0, kTrayLabelItemHorizontalPaddingBottomAlignment));
1327 } 1328 }
1328 layout_view_->SetLayoutManager( 1329 layout_view_->SetLayoutManager(
1329 new views::BoxLayout(views::BoxLayout::kHorizontal, 1330 new views::BoxLayout(views::BoxLayout::kHorizontal,
1330 0, 0, kUserLabelToIconPadding)); 1331 0, 0, kUserLabelToIconPadding));
1331 } else { 1332 } else {
1332 if (avatar_) { 1333 if (avatar_) {
1333 if (switches::UseAlternateShelfLayout()) { 1334 if (switches::UseAlternateShelfLayout()) {
1334 if (multiprofile_index_) { 1335 if (multiprofile_index_) {
1335 avatar_->set_border( 1336 avatar_->SetBorder(
1336 views::Border::CreateEmptyBorder(kTrayLabelSpacing, 0, 0, 0)); 1337 views::Border::CreateEmptyBorder(kTrayLabelSpacing, 0, 0, 0));
1337 } else { 1338 } else {
1338 avatar_->set_border(NULL); 1339 avatar_->ClearBorder();
1339 } 1340 }
1340 avatar_->SetCornerRadii(0, 0, corner_radius, corner_radius); 1341 avatar_->SetCornerRadii(0, 0, corner_radius, corner_radius);
1341 } else { 1342 } else {
1342 SetTrayImageItemBorder(avatar_, alignment); 1343 SetTrayImageItemBorder(avatar_, alignment);
1343 } 1344 }
1344 } 1345 }
1345 if (label_) { 1346 if (label_) {
1346 label_->set_border(views::Border::CreateEmptyBorder( 1347 label_->SetBorder(views::Border::CreateEmptyBorder(
1347 kTrayLabelItemVerticalPaddingVerticalAlignment, 1348 kTrayLabelItemVerticalPaddingVerticalAlignment,
1348 kTrayLabelItemHorizontalPaddingBottomAlignment, 1349 kTrayLabelItemHorizontalPaddingBottomAlignment,
1349 kTrayLabelItemVerticalPaddingVerticalAlignment, 1350 kTrayLabelItemVerticalPaddingVerticalAlignment,
1350 kTrayLabelItemHorizontalPaddingBottomAlignment)); 1351 kTrayLabelItemHorizontalPaddingBottomAlignment));
1351 } 1352 }
1352 layout_view_->SetLayoutManager( 1353 layout_view_->SetLayoutManager(
1353 new views::BoxLayout(views::BoxLayout::kVertical, 1354 new views::BoxLayout(views::BoxLayout::kVertical,
1354 0, 0, kUserLabelToIconPadding)); 1355 0, 0, kUserLabelToIconPadding));
1355 } 1356 }
1356 } 1357 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 internal::GetRootWindowController( 1419 internal::GetRootWindowController(
1419 system_tray()->GetWidget()->GetNativeWindow()->GetRootWindow()); 1420 system_tray()->GetWidget()->GetNativeWindow()->GetRootWindow());
1420 if (controller && controller->shelf()) { 1421 if (controller && controller->shelf()) {
1421 UpdateAfterShelfAlignmentChange( 1422 UpdateAfterShelfAlignmentChange(
1422 controller->GetShelfLayoutManager()->GetAlignment()); 1423 controller->GetShelfLayoutManager()->GetAlignment());
1423 } 1424 }
1424 } 1425 }
1425 1426
1426 } // namespace internal 1427 } // namespace internal
1427 } // namespace ash 1428 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698