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

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

Issue 176883022: Shelf Cleanup (- binary files) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 9 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
« no previous file with comments | « ash/system/tray/tray_constants.cc ('k') | ash/system/web_notification/web_notification_tray.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #include "ui/views/layout/fill_layout.h" 65 #include "ui/views/layout/fill_layout.h"
66 #include "ui/views/mouse_watcher.h" 66 #include "ui/views/mouse_watcher.h"
67 #include "ui/views/painter.h" 67 #include "ui/views/painter.h"
68 #include "ui/views/view.h" 68 #include "ui/views/view.h"
69 #include "ui/views/widget/widget.h" 69 #include "ui/views/widget/widget.h"
70 70
71 namespace { 71 namespace {
72 72
73 const int kUserDetailsVerticalPadding = 5; 73 const int kUserDetailsVerticalPadding = 5;
74 const int kUserCardVerticalPadding = 10; 74 const int kUserCardVerticalPadding = 10;
75 const int kProfileRoundedCornerRadius = 2; 75 const int kUserIconSize = 32;
76 const int kUserIconSize = 27; 76 const int kUserIconCornerRadius = 2;
77 const int kUserIconLargeSize = 32;
78 const int kUserIconLargeCornerRadius = 2;
79 const int kUserLabelToIconPadding = 5; 77 const int kUserLabelToIconPadding = 5;
80 78
81 // When a hover border is used, it is starting this many pixels before the icon 79 // When a hover border is used, it is starting this many pixels before the icon
82 // position. 80 // position.
83 const int kTrayUserTileHoverBorderInset = 10; 81 const int kTrayUserTileHoverBorderInset = 10;
84 82
85 // The border color of the user button. 83 // The border color of the user button.
86 const SkColor kBorderColor = 0xffdcdcdc; 84 const SkColor kBorderColor = 0xffdcdcdc;
87 85
88 // The invisible word joiner character, used as a marker to indicate the start 86 // The invisible word joiner character, used as a marker to indicate the start
(...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 user_card_view_->AddChildView(details); 904 user_card_view_->AddChildView(details);
907 } else { 905 } else {
908 if (username) 906 if (username)
909 user_card_view_->AddChildView(username); 907 user_card_view_->AddChildView(username);
910 if (additional) 908 if (additional)
911 user_card_view_->AddChildView(additional); 909 user_card_view_->AddChildView(additional);
912 } 910 }
913 } 911 }
914 912
915 views::View* UserView::CreateIconForUserCard(user::LoginStatus login) { 913 views::View* UserView::CreateIconForUserCard(user::LoginStatus login) {
916 RoundedImageView* icon = new RoundedImageView(kProfileRoundedCornerRadius, 914 RoundedImageView* icon = new RoundedImageView(kUserIconCornerRadius,
917 multiprofile_index_ == 0); 915 multiprofile_index_ == 0);
918 icon->SetEnabled(false); 916 icon->SetEnabled(false);
919 if (login == user::LOGGED_IN_GUEST) { 917 if (login == user::LOGGED_IN_GUEST) {
920 icon->SetImage(*ui::ResourceBundle::GetSharedInstance(). 918 icon->SetImage(*ui::ResourceBundle::GetSharedInstance().
921 GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON).ToImageSkia(), 919 GetImageNamed(IDR_AURA_UBER_TRAY_GUEST_ICON).ToImageSkia(),
922 gfx::Size(kUserIconSize, kUserIconSize)); 920 gfx::Size(kUserIconSize, kUserIconSize));
923 } else { 921 } else {
924 icon->SetImage( 922 icon->SetImage(
925 Shell::GetInstance()->session_state_delegate()-> 923 Shell::GetInstance()->session_state_delegate()->
926 GetUserImage(multiprofile_index_), 924 GetUserImage(multiprofile_index_),
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset, 1066 kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset,
1069 kUserCardVerticalPadding, 1067 kUserCardVerticalPadding,
1070 kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset)); 1068 kTrayPopupPaddingHorizontal - kTrayUserTileHoverBorderInset));
1071 1069
1072 add_user_->SetLayoutManager(new views::BoxLayout( 1070 add_user_->SetLayoutManager(new views::BoxLayout(
1073 views::BoxLayout::kHorizontal, 0, 0 , kTrayPopupPaddingBetweenItems)); 1071 views::BoxLayout::kHorizontal, 0, 0 , kTrayPopupPaddingBetweenItems));
1074 AddChildViewAt(add_user_, 0); 1072 AddChildViewAt(add_user_, 0);
1075 1073
1076 // Add the [+] icon which is also the anchor for messages. 1074 // Add the [+] icon which is also the anchor for messages.
1077 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 1075 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
1078 RoundedImageView* icon = new RoundedImageView(kProfileRoundedCornerRadius, 1076 RoundedImageView* icon = new RoundedImageView(kUserIconCornerRadius,
1079 true); 1077 true);
1080 anchor_ = icon; 1078 anchor_ = icon;
1081 icon->SetImage(*ui::ResourceBundle::GetSharedInstance(). 1079 icon->SetImage(*ui::ResourceBundle::GetSharedInstance().
1082 GetImageNamed(IDR_AURA_UBER_TRAY_ADD_MULTIPROFILE_USER).ToImageSkia(), 1080 GetImageNamed(IDR_AURA_UBER_TRAY_ADD_MULTIPROFILE_USER).ToImageSkia(),
1083 gfx::Size(kUserIconSize, kUserIconSize)); 1081 gfx::Size(kUserIconSize, kUserIconSize));
1084 add_user_->AddChildView(icon); 1082 add_user_->AddChildView(icon);
1085 1083
1086 // Add the command text. 1084 // Add the command text.
1087 views::Label* command_label = new views::Label( 1085 views::Label* command_label = new views::Label(
1088 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); 1086 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT));
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 (need_label != (label_ != NULL))) { 1197 (need_label != (label_ != NULL))) {
1200 layout_view_->RemoveAllChildViews(true); 1198 layout_view_->RemoveAllChildViews(true);
1201 if (need_label) { 1199 if (need_label) {
1202 label_ = new views::Label; 1200 label_ = new views::Label;
1203 SetupLabelForTray(label_); 1201 SetupLabelForTray(label_);
1204 layout_view_->AddChildView(label_); 1202 layout_view_->AddChildView(label_);
1205 } else { 1203 } else {
1206 label_ = NULL; 1204 label_ = NULL;
1207 } 1205 }
1208 if (need_avatar) { 1206 if (need_avatar) {
1209 avatar_ = new tray::RoundedImageView(kProfileRoundedCornerRadius, true); 1207 avatar_ = new tray::RoundedImageView(kUserIconCornerRadius, true);
1210 layout_view_->AddChildView(avatar_); 1208 layout_view_->AddChildView(avatar_);
1211 } else { 1209 } else {
1212 avatar_ = NULL; 1210 avatar_ = NULL;
1213 } 1211 }
1214 } 1212 }
1215 1213
1216 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 1214 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
1217 if (status == user::LOGGED_IN_LOCALLY_MANAGED) { 1215 if (status == user::LOGGED_IN_LOCALLY_MANAGED) {
1218 label_->SetText( 1216 label_->SetText(
1219 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL)); 1217 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL));
1220 } else if (status == user::LOGGED_IN_GUEST) { 1218 } else if (status == user::LOGGED_IN_GUEST) {
1221 label_->SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL)); 1219 label_->SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL));
1222 } 1220 }
1223 1221
1224 if (avatar_ && switches::UseAlternateShelfLayout()) { 1222 if (avatar_) {
1225 avatar_->SetCornerRadii( 1223 avatar_->SetCornerRadii(
1226 0, kUserIconLargeCornerRadius, kUserIconLargeCornerRadius, 0); 1224 0, kUserIconCornerRadius, kUserIconCornerRadius, 0);
1227 avatar_->SetBorder(views::Border::NullBorder()); 1225 avatar_->SetBorder(views::Border::NullBorder());
1228 } 1226 }
1229 UpdateAvatarImage(status); 1227 UpdateAvatarImage(status);
1230 1228
1231 // Update layout after setting label_ and avatar_ with new login status. 1229 // Update layout after setting label_ and avatar_ with new login status.
1232 UpdateLayoutOfItem(); 1230 UpdateLayoutOfItem();
1233 } 1231 }
1234 1232
1235 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 1233 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
1236 // Inactive users won't have a layout. 1234 // Inactive users won't have a layout.
1237 if (!layout_view_) 1235 if (!layout_view_)
1238 return; 1236 return;
1239 if (alignment == SHELF_ALIGNMENT_BOTTOM || 1237 if (alignment == SHELF_ALIGNMENT_BOTTOM ||
1240 alignment == SHELF_ALIGNMENT_TOP) { 1238 alignment == SHELF_ALIGNMENT_TOP) {
1241 if (avatar_) { 1239 if (avatar_) {
1242 if (switches::UseAlternateShelfLayout()) { 1240 avatar_->SetBorder(views::Border::NullBorder());
1243 avatar_->SetBorder(views::Border::NullBorder()); 1241 avatar_->SetCornerRadii(
1244 avatar_->SetCornerRadii( 1242 0, kUserIconCornerRadius, kUserIconCornerRadius, 0);
1245 0, kUserIconLargeCornerRadius, kUserIconLargeCornerRadius, 0);
1246 } else {
1247 avatar_->SetBorder(views::Border::CreateEmptyBorder(
1248 0,
1249 kTrayImageItemHorizontalPaddingBottomAlignment + 2,
1250 0,
1251 kTrayImageItemHorizontalPaddingBottomAlignment));
1252 }
1253 } 1243 }
1254 if (label_) { 1244 if (label_) {
1255 label_->SetBorder(views::Border::CreateEmptyBorder( 1245 label_->SetBorder(views::Border::CreateEmptyBorder(
1256 0, 1246 0,
1257 kTrayLabelItemHorizontalPaddingBottomAlignment, 1247 kTrayLabelItemHorizontalPaddingBottomAlignment,
1258 0, 1248 0,
1259 kTrayLabelItemHorizontalPaddingBottomAlignment)); 1249 kTrayLabelItemHorizontalPaddingBottomAlignment));
1260 } 1250 }
1261 layout_view_->SetLayoutManager( 1251 layout_view_->SetLayoutManager(
1262 new views::BoxLayout(views::BoxLayout::kHorizontal, 1252 new views::BoxLayout(views::BoxLayout::kHorizontal,
1263 0, 0, kUserLabelToIconPadding)); 1253 0, 0, kUserLabelToIconPadding));
1264 } else { 1254 } else {
1265 if (avatar_) { 1255 if (avatar_) {
1266 if (switches::UseAlternateShelfLayout()) { 1256 avatar_->SetBorder(views::Border::NullBorder());
1267 avatar_->SetBorder(views::Border::NullBorder()); 1257 avatar_->SetCornerRadii(
1268 avatar_->SetCornerRadii( 1258 0, 0, kUserIconCornerRadius, kUserIconCornerRadius);
1269 0, 0, kUserIconLargeCornerRadius, kUserIconLargeCornerRadius);
1270 } else {
1271 SetTrayImageItemBorder(avatar_, alignment);
1272 }
1273 } 1259 }
1274 if (label_) { 1260 if (label_) {
1275 label_->SetBorder(views::Border::CreateEmptyBorder( 1261 label_->SetBorder(views::Border::CreateEmptyBorder(
1276 kTrayLabelItemVerticalPaddingVerticalAlignment, 1262 kTrayLabelItemVerticalPaddingVerticalAlignment,
1277 kTrayLabelItemHorizontalPaddingBottomAlignment, 1263 kTrayLabelItemHorizontalPaddingBottomAlignment,
1278 kTrayLabelItemVerticalPaddingVerticalAlignment, 1264 kTrayLabelItemVerticalPaddingVerticalAlignment,
1279 kTrayLabelItemHorizontalPaddingBottomAlignment)); 1265 kTrayLabelItemHorizontalPaddingBottomAlignment));
1280 } 1266 }
1281 layout_view_->SetLayoutManager( 1267 layout_view_->SetLayoutManager(
1282 new views::BoxLayout(views::BoxLayout::kVertical, 1268 new views::BoxLayout(views::BoxLayout::kVertical,
(...skipping 21 matching lines...) Expand all
1304 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()); 1290 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus());
1305 } 1291 }
1306 1292
1307 void TrayUser::UpdateAvatarImage(user::LoginStatus status) { 1293 void TrayUser::UpdateAvatarImage(user::LoginStatus status) {
1308 SessionStateDelegate* session_state_delegate = 1294 SessionStateDelegate* session_state_delegate =
1309 Shell::GetInstance()->session_state_delegate(); 1295 Shell::GetInstance()->session_state_delegate();
1310 if (!avatar_ || 1296 if (!avatar_ ||
1311 GetTrayIndex() >= session_state_delegate->NumberOfLoggedInUsers()) 1297 GetTrayIndex() >= session_state_delegate->NumberOfLoggedInUsers())
1312 return; 1298 return;
1313 1299
1314 int icon_size = switches::UseAlternateShelfLayout() ?
1315 kUserIconLargeSize : kUserIconSize;
1316
1317 avatar_->SetImage( 1300 avatar_->SetImage(
1318 Shell::GetInstance()->session_state_delegate()->GetUserImage( 1301 Shell::GetInstance()->session_state_delegate()->GetUserImage(
1319 GetTrayIndex()), 1302 GetTrayIndex()),
1320 gfx::Size(icon_size, icon_size)); 1303 gfx::Size(kUserIconSize, kUserIconSize));
1321 1304
1322 // Unit tests might come here with no images for some users. 1305 // Unit tests might come here with no images for some users.
1323 if (avatar_->size().IsEmpty()) 1306 if (avatar_->size().IsEmpty())
1324 avatar_->SetSize(gfx::Size(icon_size, icon_size)); 1307 avatar_->SetSize(gfx::Size(kUserIconSize, kUserIconSize));
1325 } 1308 }
1326 1309
1327 MultiProfileIndex TrayUser::GetTrayIndex() { 1310 MultiProfileIndex TrayUser::GetTrayIndex() {
1328 Shell* shell = Shell::GetInstance(); 1311 Shell* shell = Shell::GetInstance();
1329 // If multi profile is not enabled we can use the normal index. 1312 // If multi profile is not enabled we can use the normal index.
1330 if (!shell->delegate()->IsMultiProfilesEnabled()) 1313 if (!shell->delegate()->IsMultiProfilesEnabled())
1331 return multiprofile_index_; 1314 return multiprofile_index_;
1332 // In case of multi profile we need to mirror the indices since the system 1315 // In case of multi profile we need to mirror the indices since the system
1333 // tray items are in the reverse order then the menu items. 1316 // tray items are in the reverse order then the menu items.
1334 return shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers() - 1317 return shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers() -
1335 1 - multiprofile_index_; 1318 1 - multiprofile_index_;
1336 } 1319 }
1337 1320
1338 void TrayUser::UpdateLayoutOfItem() { 1321 void TrayUser::UpdateLayoutOfItem() {
1339 internal::RootWindowController* controller = 1322 internal::RootWindowController* controller =
1340 internal::GetRootWindowController( 1323 internal::GetRootWindowController(
1341 system_tray()->GetWidget()->GetNativeWindow()->GetRootWindow()); 1324 system_tray()->GetWidget()->GetNativeWindow()->GetRootWindow());
1342 if (controller && controller->shelf()) { 1325 if (controller && controller->shelf()) {
1343 UpdateAfterShelfAlignmentChange( 1326 UpdateAfterShelfAlignmentChange(
1344 controller->GetShelfLayoutManager()->GetAlignment()); 1327 controller->GetShelfLayoutManager()->GetAlignment());
1345 } 1328 }
1346 } 1329 }
1347 1330
1348 } // namespace internal 1331 } // namespace internal
1349 } // namespace ash 1332 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/tray_constants.cc ('k') | ash/system/web_notification/web_notification_tray.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698