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

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

Issue 184113005: Removal of drag window to user tray icon functionality (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/user/tray_user.h ('k') | ash/system/user/tray_user_unittest.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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 kProfileRoundedCornerRadius = 2;
76 const int kUserIconSize = 27; 76 const int kUserIconSize = 27;
77 const int kUserIconLargeSize = 32; 77 const int kUserIconLargeSize = 32;
78 const int kUserIconLargeCornerRadius = 2; 78 const int kUserIconLargeCornerRadius = 2;
79 const int kUserLabelToIconPadding = 5; 79 const int kUserLabelToIconPadding = 5;
80 // When using multi login, this spacing is added between user icons.
81 const int kTrayLabelSpacing = 1;
82 80
83 // When a hover border is used, it is starting this many pixels before the icon 81 // When a hover border is used, it is starting this many pixels before the icon
84 // position. 82 // position.
85 const int kTrayUserTileHoverBorderInset = 10; 83 const int kTrayUserTileHoverBorderInset = 10;
86 84
87 // The border color of the user button. 85 // The border color of the user button.
88 const SkColor kBorderColor = 0xffdcdcdc; 86 const SkColor kBorderColor = 0xffdcdcdc;
89 87
90 // The invisible word joiner character, used as a marker to indicate the start 88 // The invisible word joiner character, used as a marker to indicate the start
91 // and end of the user's display name in the public account user card's text. 89 // and end of the user's display name in the public account user card's text.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 gfx::Size image_size_; 167 gfx::Size image_size_;
170 int corner_radius_[4]; 168 int corner_radius_[4];
171 169
172 // True if the given user is the active user and the icon should get 170 // True if the given user is the active user and the icon should get
173 // painted as active. 171 // painted as active.
174 bool active_user_; 172 bool active_user_;
175 173
176 DISALLOW_COPY_AND_ASSIGN(RoundedImageView); 174 DISALLOW_COPY_AND_ASSIGN(RoundedImageView);
177 }; 175 };
178 176
179 // An inactive user view which can be clicked to make active. Note that this
180 // "button" does not show as a button any click or hover changes.
181 class UserSwitcherView : public RoundedImageView {
182 public:
183 UserSwitcherView(int corner_radius, MultiProfileIndex user_index);
184 virtual ~UserSwitcherView() {}
185
186 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
187 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
188
189 private:
190 // The user index to activate when the item was clicked. Note that this
191 // index refers to the LRU list of logged in users.
192 MultiProfileIndex user_index_;
193
194 DISALLOW_COPY_AND_ASSIGN(UserSwitcherView);
195 };
196
197 // The user details shown in public account mode. This is essentially a label 177 // The user details shown in public account mode. This is essentially a label
198 // but with custom painting code as the text is styled with multiple colors and 178 // but with custom painting code as the text is styled with multiple colors and
199 // contains a link. 179 // contains a link.
200 class PublicAccountUserDetails : public views::View, 180 class PublicAccountUserDetails : public views::View,
201 public views::LinkListener { 181 public views::LinkListener {
202 public: 182 public:
203 PublicAccountUserDetails(SystemTrayItem* owner, int used_width); 183 PublicAccountUserDetails(SystemTrayItem* owner, int used_width);
204 virtual ~PublicAccountUserDetails(); 184 virtual ~PublicAccountUserDetails();
205 185
206 private: 186 private:
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 SkPath path; 419 SkPath path;
440 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius); 420 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius);
441 SkPaint paint; 421 SkPaint paint;
442 paint.setAntiAlias(true); 422 paint.setAntiAlias(true);
443 paint.setXfermodeMode(active_user_ ? SkXfermode::kSrcOver_Mode : 423 paint.setXfermodeMode(active_user_ ? SkXfermode::kSrcOver_Mode :
444 SkXfermode::kLuminosity_Mode); 424 SkXfermode::kLuminosity_Mode);
445 canvas->DrawImageInPath(resized_, image_bounds.x(), image_bounds.y(), 425 canvas->DrawImageInPath(resized_, image_bounds.x(), image_bounds.y(),
446 path, paint); 426 path, paint);
447 } 427 }
448 428
449 UserSwitcherView::UserSwitcherView(int corner_radius,
450 MultiProfileIndex user_index)
451 : RoundedImageView(corner_radius, false),
452 user_index_(user_index) {
453 SetEnabled(true);
454 }
455
456 void UserSwitcherView::OnMouseEvent(ui::MouseEvent* event) {
457 if (event->type() == ui::ET_MOUSE_PRESSED) {
458 SwitchUser(user_index_);
459 event->SetHandled();
460 }
461 }
462
463 void UserSwitcherView::OnTouchEvent(ui::TouchEvent* event) {
464 if (event->type() == ui::ET_TOUCH_PRESSED) {
465 SwitchUser(user_index_);
466 event->SetHandled();
467 }
468 }
469
470 PublicAccountUserDetails::PublicAccountUserDetails(SystemTrayItem* owner, 429 PublicAccountUserDetails::PublicAccountUserDetails(SystemTrayItem* owner,
471 int used_width) 430 int used_width)
472 : learn_more_(NULL) { 431 : learn_more_(NULL) {
473 const int inner_padding = 432 const int inner_padding =
474 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; 433 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems;
475 const bool rtl = base::i18n::IsRTL(); 434 const bool rtl = base::i18n::IsRTL();
476 SetBorder(views::Border::CreateEmptyBorder(kUserDetailsVerticalPadding, 435 SetBorder(views::Border::CreateEmptyBorder(kUserDetailsVerticalPadding,
477 rtl ? 0 : inner_padding, 436 rtl ? 0 : inner_padding,
478 kUserDetailsVerticalPadding, 437 kUserDetailsVerticalPadding,
479 rtl ? inner_padding : 0)); 438 rtl ? inner_padding : 0));
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 TrayUser::~TrayUser() { 1105 TrayUser::~TrayUser() {
1147 Shell::GetInstance()->system_tray_notifier()->RemoveUserObserver(this); 1106 Shell::GetInstance()->system_tray_notifier()->RemoveUserObserver(this);
1148 } 1107 }
1149 1108
1150 TrayUser::TestState TrayUser::GetStateForTest() const { 1109 TrayUser::TestState TrayUser::GetStateForTest() const {
1151 if (!user_) 1110 if (!user_)
1152 return HIDDEN; 1111 return HIDDEN;
1153 return user_->GetStateForTest(); 1112 return user_->GetStateForTest();
1154 } 1113 }
1155 1114
1156 bool TrayUser::CanDropWindowHereToTransferToUser(
1157 const gfx::Point& point_in_screen) {
1158 // Check that this item is shown in the system tray (which means it must have
1159 // a view there) and that the user it represents is not the current user (in
1160 // which case |GetTrayIndex()| would return NULL).
1161 if (!layout_view_ || !GetTrayIndex())
1162 return false;
1163 return layout_view_->GetBoundsInScreen().Contains(point_in_screen);
1164 }
1165
1166 bool TrayUser::TransferWindowToUser(aura::Window* window) {
1167 SessionStateDelegate* session_state_delegate =
1168 ash::Shell::GetInstance()->session_state_delegate();
1169 return session_state_delegate->TransferWindowToDesktopOfUser(window,
1170 GetTrayIndex());
1171 }
1172
1173 gfx::Rect TrayUser::GetUserPanelBoundsInScreenForTest() const { 1115 gfx::Rect TrayUser::GetUserPanelBoundsInScreenForTest() const {
1174 DCHECK(user_); 1116 DCHECK(user_);
1175 return user_->GetBoundsInScreenOfUserButtonForTest(); 1117 return user_->GetBoundsInScreenOfUserButtonForTest();
1176 } 1118 }
1177 1119
1178 views::View* TrayUser::CreateTrayView(user::LoginStatus status) { 1120 views::View* TrayUser::CreateTrayView(user::LoginStatus status) {
1179 CHECK(layout_view_ == NULL); 1121 CHECK(layout_view_ == NULL);
1180 1122
1181 layout_view_ = new views::View(); 1123 layout_view_ = new views::View();
1182 layout_view_->SetLayoutManager( 1124 layout_view_->SetLayoutManager(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 user_ = NULL; 1164 user_ = NULL;
1223 } 1165 }
1224 1166
1225 void TrayUser::DestroyDetailedView() { 1167 void TrayUser::DestroyDetailedView() {
1226 } 1168 }
1227 1169
1228 void TrayUser::UpdateAfterLoginStatusChange(user::LoginStatus status) { 1170 void TrayUser::UpdateAfterLoginStatusChange(user::LoginStatus status) {
1229 // Only the active user is represented in the tray. 1171 // Only the active user is represented in the tray.
1230 if (!layout_view_) 1172 if (!layout_view_)
1231 return; 1173 return;
1232 if (GetTrayIndex() > 0 && !ash::switches::UseMultiUserTray()) 1174 if (GetTrayIndex() > 0)
1233 return; 1175 return;
1234 bool need_label = false; 1176 bool need_label = false;
1235 bool need_avatar = false; 1177 bool need_avatar = false;
1236 switch (status) { 1178 switch (status) {
1237 case user::LOGGED_IN_LOCKED: 1179 case user::LOGGED_IN_LOCKED:
1238 case user::LOGGED_IN_USER: 1180 case user::LOGGED_IN_USER:
1239 case user::LOGGED_IN_OWNER: 1181 case user::LOGGED_IN_OWNER:
1240 case user::LOGGED_IN_PUBLIC: 1182 case user::LOGGED_IN_PUBLIC:
1241 need_avatar = true; 1183 need_avatar = true;
1242 break; 1184 break;
(...skipping 14 matching lines...) Expand all
1257 (need_label != (label_ != NULL))) { 1199 (need_label != (label_ != NULL))) {
1258 layout_view_->RemoveAllChildViews(true); 1200 layout_view_->RemoveAllChildViews(true);
1259 if (need_label) { 1201 if (need_label) {
1260 label_ = new views::Label; 1202 label_ = new views::Label;
1261 SetupLabelForTray(label_); 1203 SetupLabelForTray(label_);
1262 layout_view_->AddChildView(label_); 1204 layout_view_->AddChildView(label_);
1263 } else { 1205 } else {
1264 label_ = NULL; 1206 label_ = NULL;
1265 } 1207 }
1266 if (need_avatar) { 1208 if (need_avatar) {
1267 MultiProfileIndex tray_index = GetTrayIndex(); 1209 avatar_ = new tray::RoundedImageView(kProfileRoundedCornerRadius, true);
1268 if (!tray_index) {
1269 // The active user (index #0) will always be the first.
1270 avatar_ = new tray::RoundedImageView(kProfileRoundedCornerRadius, true);
1271 } else {
1272 // All other users will be inactive users.
1273 avatar_ = new tray::UserSwitcherView(kProfileRoundedCornerRadius,
1274 tray_index);
1275 }
1276 layout_view_->AddChildView(avatar_); 1210 layout_view_->AddChildView(avatar_);
1277 } else { 1211 } else {
1278 avatar_ = NULL; 1212 avatar_ = NULL;
1279 } 1213 }
1280 } 1214 }
1281 1215
1282 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 1216 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
1283 if (status == user::LOGGED_IN_LOCALLY_MANAGED) { 1217 if (status == user::LOGGED_IN_LOCALLY_MANAGED) {
1284 label_->SetText( 1218 label_->SetText(
1285 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL)); 1219 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL));
1286 } else if (status == user::LOGGED_IN_GUEST) { 1220 } else if (status == user::LOGGED_IN_GUEST) {
1287 label_->SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL)); 1221 label_->SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL));
1288 } 1222 }
1289 1223
1290 if (avatar_ && switches::UseAlternateShelfLayout()) { 1224 if (avatar_ && switches::UseAlternateShelfLayout()) {
1291 int corner_radius = GetTrayItemRadius(); 1225 avatar_->SetCornerRadii(
1292 avatar_->SetCornerRadii(0, corner_radius, corner_radius, 0); 1226 0, kUserIconLargeCornerRadius, kUserIconLargeCornerRadius, 0);
1293 avatar_->SetBorder(views::Border::NullBorder()); 1227 avatar_->SetBorder(views::Border::NullBorder());
1294 } 1228 }
1295 UpdateAvatarImage(status); 1229 UpdateAvatarImage(status);
1296 1230
1297 // Update layout after setting label_ and avatar_ with new login status. 1231 // Update layout after setting label_ and avatar_ with new login status.
1298 UpdateLayoutOfItem(); 1232 UpdateLayoutOfItem();
1299 } 1233 }
1300 1234
1301 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 1235 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
1302 // Inactive users won't have a layout. 1236 // Inactive users won't have a layout.
1303 if (!layout_view_) 1237 if (!layout_view_)
1304 return; 1238 return;
1305 int corner_radius = GetTrayItemRadius();
1306 if (alignment == SHELF_ALIGNMENT_BOTTOM || 1239 if (alignment == SHELF_ALIGNMENT_BOTTOM ||
1307 alignment == SHELF_ALIGNMENT_TOP) { 1240 alignment == SHELF_ALIGNMENT_TOP) {
1308 if (avatar_) { 1241 if (avatar_) {
1309 if (switches::UseAlternateShelfLayout()) { 1242 if (switches::UseAlternateShelfLayout()) {
1310 if (multiprofile_index_) { 1243 avatar_->SetBorder(views::Border::NullBorder());
1311 avatar_->SetBorder( 1244 avatar_->SetCornerRadii(
1312 views::Border::CreateEmptyBorder(0, kTrayLabelSpacing, 0, 0)); 1245 0, kUserIconLargeCornerRadius, kUserIconLargeCornerRadius, 0);
1313 } else {
1314 avatar_->SetBorder(views::Border::NullBorder());
1315 }
1316 avatar_->SetCornerRadii(0, corner_radius, corner_radius, 0);
1317 } else { 1246 } else {
1318 avatar_->SetBorder(views::Border::CreateEmptyBorder( 1247 avatar_->SetBorder(views::Border::CreateEmptyBorder(
1319 0, 1248 0,
1320 kTrayImageItemHorizontalPaddingBottomAlignment + 2, 1249 kTrayImageItemHorizontalPaddingBottomAlignment + 2,
1321 0, 1250 0,
1322 kTrayImageItemHorizontalPaddingBottomAlignment)); 1251 kTrayImageItemHorizontalPaddingBottomAlignment));
1323 } 1252 }
1324 } 1253 }
1325 if (label_) { 1254 if (label_) {
1326 label_->SetBorder(views::Border::CreateEmptyBorder( 1255 label_->SetBorder(views::Border::CreateEmptyBorder(
1327 0, 1256 0,
1328 kTrayLabelItemHorizontalPaddingBottomAlignment, 1257 kTrayLabelItemHorizontalPaddingBottomAlignment,
1329 0, 1258 0,
1330 kTrayLabelItemHorizontalPaddingBottomAlignment)); 1259 kTrayLabelItemHorizontalPaddingBottomAlignment));
1331 } 1260 }
1332 layout_view_->SetLayoutManager( 1261 layout_view_->SetLayoutManager(
1333 new views::BoxLayout(views::BoxLayout::kHorizontal, 1262 new views::BoxLayout(views::BoxLayout::kHorizontal,
1334 0, 0, kUserLabelToIconPadding)); 1263 0, 0, kUserLabelToIconPadding));
1335 } else { 1264 } else {
1336 if (avatar_) { 1265 if (avatar_) {
1337 if (switches::UseAlternateShelfLayout()) { 1266 if (switches::UseAlternateShelfLayout()) {
1338 if (multiprofile_index_) { 1267 avatar_->SetBorder(views::Border::NullBorder());
1339 avatar_->SetBorder( 1268 avatar_->SetCornerRadii(
1340 views::Border::CreateEmptyBorder(kTrayLabelSpacing, 0, 0, 0)); 1269 0, 0, kUserIconLargeCornerRadius, kUserIconLargeCornerRadius);
1341 } else {
1342 avatar_->SetBorder(views::Border::NullBorder());
1343 }
1344 avatar_->SetCornerRadii(0, 0, corner_radius, corner_radius);
1345 } else { 1270 } else {
1346 SetTrayImageItemBorder(avatar_, alignment); 1271 SetTrayImageItemBorder(avatar_, alignment);
1347 } 1272 }
1348 } 1273 }
1349 if (label_) { 1274 if (label_) {
1350 label_->SetBorder(views::Border::CreateEmptyBorder( 1275 label_->SetBorder(views::Border::CreateEmptyBorder(
1351 kTrayLabelItemVerticalPaddingVerticalAlignment, 1276 kTrayLabelItemVerticalPaddingVerticalAlignment,
1352 kTrayLabelItemHorizontalPaddingBottomAlignment, 1277 kTrayLabelItemHorizontalPaddingBottomAlignment,
1353 kTrayLabelItemVerticalPaddingVerticalAlignment, 1278 kTrayLabelItemVerticalPaddingVerticalAlignment,
1354 kTrayLabelItemHorizontalPaddingBottomAlignment)); 1279 kTrayLabelItemHorizontalPaddingBottomAlignment));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 Shell* shell = Shell::GetInstance(); 1328 Shell* shell = Shell::GetInstance();
1404 // If multi profile is not enabled we can use the normal index. 1329 // If multi profile is not enabled we can use the normal index.
1405 if (!shell->delegate()->IsMultiProfilesEnabled()) 1330 if (!shell->delegate()->IsMultiProfilesEnabled())
1406 return multiprofile_index_; 1331 return multiprofile_index_;
1407 // In case of multi profile we need to mirror the indices since the system 1332 // In case of multi profile we need to mirror the indices since the system
1408 // tray items are in the reverse order then the menu items. 1333 // tray items are in the reverse order then the menu items.
1409 return shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers() - 1334 return shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers() -
1410 1 - multiprofile_index_; 1335 1 - multiprofile_index_;
1411 } 1336 }
1412 1337
1413 int TrayUser::GetTrayItemRadius() {
1414 SessionStateDelegate* delegate =
1415 Shell::GetInstance()->session_state_delegate();
1416 bool is_last_item = GetTrayIndex() == (delegate->NumberOfLoggedInUsers() - 1);
1417 return is_last_item ? kUserIconLargeCornerRadius : 0;
1418 }
1419
1420 void TrayUser::UpdateLayoutOfItem() { 1338 void TrayUser::UpdateLayoutOfItem() {
1421 internal::RootWindowController* controller = 1339 internal::RootWindowController* controller =
1422 internal::GetRootWindowController( 1340 internal::GetRootWindowController(
1423 system_tray()->GetWidget()->GetNativeWindow()->GetRootWindow()); 1341 system_tray()->GetWidget()->GetNativeWindow()->GetRootWindow());
1424 if (controller && controller->shelf()) { 1342 if (controller && controller->shelf()) {
1425 UpdateAfterShelfAlignmentChange( 1343 UpdateAfterShelfAlignmentChange(
1426 controller->GetShelfLayoutManager()->GetAlignment()); 1344 controller->GetShelfLayoutManager()->GetAlignment());
1427 } 1345 }
1428 } 1346 }
1429 1347
1430 } // namespace internal 1348 } // namespace internal
1431 } // namespace ash 1349 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/user/tray_user.h ('k') | ash/system/user/tray_user_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698