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

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
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 gfx::Size image_size_; 169 gfx::Size image_size_;
170 int corner_radius_[4]; 170 int corner_radius_[4];
171 171
172 // True if the given user is the active user and the icon should get 172 // True if the given user is the active user and the icon should get
173 // painted as active. 173 // painted as active.
174 bool active_user_; 174 bool active_user_;
175 175
176 DISALLOW_COPY_AND_ASSIGN(RoundedImageView); 176 DISALLOW_COPY_AND_ASSIGN(RoundedImageView);
177 }; 177 };
178 178
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 179 // 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 180 // but with custom painting code as the text is styled with multiple colors and
199 // contains a link. 181 // contains a link.
200 class PublicAccountUserDetails : public views::View, 182 class PublicAccountUserDetails : public views::View,
201 public views::LinkListener { 183 public views::LinkListener {
202 public: 184 public:
203 PublicAccountUserDetails(SystemTrayItem* owner, int used_width); 185 PublicAccountUserDetails(SystemTrayItem* owner, int used_width);
204 virtual ~PublicAccountUserDetails(); 186 virtual ~PublicAccountUserDetails();
205 187
206 private: 188 private:
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 SkPath path; 421 SkPath path;
440 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius); 422 path.addRoundRect(gfx::RectToSkRect(image_bounds), kRadius);
441 SkPaint paint; 423 SkPaint paint;
442 paint.setAntiAlias(true); 424 paint.setAntiAlias(true);
443 paint.setXfermodeMode(active_user_ ? SkXfermode::kSrcOver_Mode : 425 paint.setXfermodeMode(active_user_ ? SkXfermode::kSrcOver_Mode :
444 SkXfermode::kLuminosity_Mode); 426 SkXfermode::kLuminosity_Mode);
445 canvas->DrawImageInPath(resized_, image_bounds.x(), image_bounds.y(), 427 canvas->DrawImageInPath(resized_, image_bounds.x(), image_bounds.y(),
446 path, paint); 428 path, paint);
447 } 429 }
448 430
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, 431 PublicAccountUserDetails::PublicAccountUserDetails(SystemTrayItem* owner,
471 int used_width) 432 int used_width)
472 : learn_more_(NULL) { 433 : learn_more_(NULL) {
473 const int inner_padding = 434 const int inner_padding =
474 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; 435 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems;
475 const bool rtl = base::i18n::IsRTL(); 436 const bool rtl = base::i18n::IsRTL();
476 SetBorder(views::Border::CreateEmptyBorder(kUserDetailsVerticalPadding, 437 SetBorder(views::Border::CreateEmptyBorder(kUserDetailsVerticalPadding,
477 rtl ? 0 : inner_padding, 438 rtl ? 0 : inner_padding,
478 kUserDetailsVerticalPadding, 439 kUserDetailsVerticalPadding,
479 rtl ? inner_padding : 0)); 440 rtl ? inner_padding : 0));
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
1146 TrayUser::~TrayUser() { 1107 TrayUser::~TrayUser() {
1147 Shell::GetInstance()->system_tray_notifier()->RemoveUserObserver(this); 1108 Shell::GetInstance()->system_tray_notifier()->RemoveUserObserver(this);
1148 } 1109 }
1149 1110
1150 TrayUser::TestState TrayUser::GetStateForTest() const { 1111 TrayUser::TestState TrayUser::GetStateForTest() const {
1151 if (!user_) 1112 if (!user_)
1152 return HIDDEN; 1113 return HIDDEN;
1153 return user_->GetStateForTest(); 1114 return user_->GetStateForTest();
1154 } 1115 }
1155 1116
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 { 1117 gfx::Rect TrayUser::GetUserPanelBoundsInScreenForTest() const {
1174 DCHECK(user_); 1118 DCHECK(user_);
1175 return user_->GetBoundsInScreenOfUserButtonForTest(); 1119 return user_->GetBoundsInScreenOfUserButtonForTest();
1176 } 1120 }
1177 1121
1178 views::View* TrayUser::CreateTrayView(user::LoginStatus status) { 1122 views::View* TrayUser::CreateTrayView(user::LoginStatus status) {
1179 CHECK(layout_view_ == NULL); 1123 CHECK(layout_view_ == NULL);
1180 1124
1181 layout_view_ = new views::View(); 1125 layout_view_ = new views::View();
1182 layout_view_->SetLayoutManager( 1126 layout_view_->SetLayoutManager(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 user_ = NULL; 1166 user_ = NULL;
1223 } 1167 }
1224 1168
1225 void TrayUser::DestroyDetailedView() { 1169 void TrayUser::DestroyDetailedView() {
1226 } 1170 }
1227 1171
1228 void TrayUser::UpdateAfterLoginStatusChange(user::LoginStatus status) { 1172 void TrayUser::UpdateAfterLoginStatusChange(user::LoginStatus status) {
1229 // Only the active user is represented in the tray. 1173 // Only the active user is represented in the tray.
1230 if (!layout_view_) 1174 if (!layout_view_)
1231 return; 1175 return;
1232 if (GetTrayIndex() > 0 && !ash::switches::UseMultiUserTray()) 1176 if (GetTrayIndex() > 0)
1233 return; 1177 return;
1234 bool need_label = false; 1178 bool need_label = false;
1235 bool need_avatar = false; 1179 bool need_avatar = false;
1236 switch (status) { 1180 switch (status) {
1237 case user::LOGGED_IN_LOCKED: 1181 case user::LOGGED_IN_LOCKED:
1238 case user::LOGGED_IN_USER: 1182 case user::LOGGED_IN_USER:
1239 case user::LOGGED_IN_OWNER: 1183 case user::LOGGED_IN_OWNER:
1240 case user::LOGGED_IN_PUBLIC: 1184 case user::LOGGED_IN_PUBLIC:
1241 need_avatar = true; 1185 need_avatar = true;
1242 break; 1186 break;
(...skipping 14 matching lines...) Expand all
1257 (need_label != (label_ != NULL))) { 1201 (need_label != (label_ != NULL))) {
1258 layout_view_->RemoveAllChildViews(true); 1202 layout_view_->RemoveAllChildViews(true);
1259 if (need_label) { 1203 if (need_label) {
1260 label_ = new views::Label; 1204 label_ = new views::Label;
1261 SetupLabelForTray(label_); 1205 SetupLabelForTray(label_);
1262 layout_view_->AddChildView(label_); 1206 layout_view_->AddChildView(label_);
1263 } else { 1207 } else {
1264 label_ = NULL; 1208 label_ = NULL;
1265 } 1209 }
1266 if (need_avatar) { 1210 if (need_avatar) {
1267 MultiProfileIndex tray_index = GetTrayIndex(); 1211 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_); 1212 layout_view_->AddChildView(avatar_);
1277 } else { 1213 } else {
1278 avatar_ = NULL; 1214 avatar_ = NULL;
1279 } 1215 }
1280 } 1216 }
1281 1217
1282 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 1218 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
1283 if (status == user::LOGGED_IN_LOCALLY_MANAGED) { 1219 if (status == user::LOGGED_IN_LOCALLY_MANAGED) {
1284 label_->SetText( 1220 label_->SetText(
1285 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL)); 1221 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOCALLY_MANAGED_LABEL));
1286 } else if (status == user::LOGGED_IN_GUEST) { 1222 } else if (status == user::LOGGED_IN_GUEST) {
1287 label_->SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL)); 1223 label_->SetText(bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_GUEST_LABEL));
1288 } 1224 }
1289 1225
1290 if (avatar_ && switches::UseAlternateShelfLayout()) { 1226 if (avatar_ && switches::UseAlternateShelfLayout()) {
1291 int corner_radius = GetTrayItemRadius(); 1227 avatar_->SetCornerRadii(
1292 avatar_->SetCornerRadii(0, corner_radius, corner_radius, 0); 1228 0, kUserIconLargeCornerRadius, kUserIconLargeCornerRadius, 0);
1293 avatar_->SetBorder(views::Border::NullBorder()); 1229 avatar_->SetBorder(views::Border::NullBorder());
1294 } 1230 }
1295 UpdateAvatarImage(status); 1231 UpdateAvatarImage(status);
1296 1232
1297 // Update layout after setting label_ and avatar_ with new login status. 1233 // Update layout after setting label_ and avatar_ with new login status.
1298 UpdateLayoutOfItem(); 1234 UpdateLayoutOfItem();
1299 } 1235 }
1300 1236
1301 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 1237 void TrayUser::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
1302 // Inactive users won't have a layout. 1238 // Inactive users won't have a layout.
1303 if (!layout_view_) 1239 if (!layout_view_)
1304 return; 1240 return;
1305 int corner_radius = GetTrayItemRadius();
1306 if (alignment == SHELF_ALIGNMENT_BOTTOM || 1241 if (alignment == SHELF_ALIGNMENT_BOTTOM ||
1307 alignment == SHELF_ALIGNMENT_TOP) { 1242 alignment == SHELF_ALIGNMENT_TOP) {
1308 if (avatar_) { 1243 if (avatar_) {
1309 if (switches::UseAlternateShelfLayout()) { 1244 if (switches::UseAlternateShelfLayout()) {
1310 if (multiprofile_index_) { 1245 avatar_->SetBorder(views::Border::NullBorder());
1311 avatar_->SetBorder( 1246 avatar_->SetCornerRadii(
1312 views::Border::CreateEmptyBorder(0, kTrayLabelSpacing, 0, 0)); 1247 0, kUserIconLargeCornerRadius, kUserIconLargeCornerRadius, 0);
1313 } else {
1314 avatar_->SetBorder(views::Border::NullBorder());
1315 }
1316 avatar_->SetCornerRadii(0, corner_radius, corner_radius, 0);
1317 } else { 1248 } else {
1318 avatar_->SetBorder(views::Border::CreateEmptyBorder( 1249 avatar_->SetBorder(views::Border::CreateEmptyBorder(
1319 0, 1250 0,
1320 kTrayImageItemHorizontalPaddingBottomAlignment + 2, 1251 kTrayImageItemHorizontalPaddingBottomAlignment + 2,
1321 0, 1252 0,
1322 kTrayImageItemHorizontalPaddingBottomAlignment)); 1253 kTrayImageItemHorizontalPaddingBottomAlignment));
1323 } 1254 }
1324 } 1255 }
1325 if (label_) { 1256 if (label_) {
1326 label_->SetBorder(views::Border::CreateEmptyBorder( 1257 label_->SetBorder(views::Border::CreateEmptyBorder(
1327 0, 1258 0,
1328 kTrayLabelItemHorizontalPaddingBottomAlignment, 1259 kTrayLabelItemHorizontalPaddingBottomAlignment,
1329 0, 1260 0,
1330 kTrayLabelItemHorizontalPaddingBottomAlignment)); 1261 kTrayLabelItemHorizontalPaddingBottomAlignment));
1331 } 1262 }
1332 layout_view_->SetLayoutManager( 1263 layout_view_->SetLayoutManager(
1333 new views::BoxLayout(views::BoxLayout::kHorizontal, 1264 new views::BoxLayout(views::BoxLayout::kHorizontal,
1334 0, 0, kUserLabelToIconPadding)); 1265 0, 0, kUserLabelToIconPadding));
1335 } else { 1266 } else {
1336 if (avatar_) { 1267 if (avatar_) {
1337 if (switches::UseAlternateShelfLayout()) { 1268 if (switches::UseAlternateShelfLayout()) {
1338 if (multiprofile_index_) { 1269 avatar_->SetBorder(views::Border::NullBorder());
1339 avatar_->SetBorder( 1270 avatar_->SetCornerRadii(
1340 views::Border::CreateEmptyBorder(kTrayLabelSpacing, 0, 0, 0)); 1271 0, 0, kUserIconLargeCornerRadius, kUserIconLargeCornerRadius);
1341 } else {
1342 avatar_->SetBorder(views::Border::NullBorder());
1343 }
1344 avatar_->SetCornerRadii(0, 0, corner_radius, corner_radius);
1345 } else { 1272 } else {
1346 SetTrayImageItemBorder(avatar_, alignment); 1273 SetTrayImageItemBorder(avatar_, alignment);
1347 } 1274 }
1348 } 1275 }
1349 if (label_) { 1276 if (label_) {
1350 label_->SetBorder(views::Border::CreateEmptyBorder( 1277 label_->SetBorder(views::Border::CreateEmptyBorder(
1351 kTrayLabelItemVerticalPaddingVerticalAlignment, 1278 kTrayLabelItemVerticalPaddingVerticalAlignment,
1352 kTrayLabelItemHorizontalPaddingBottomAlignment, 1279 kTrayLabelItemHorizontalPaddingBottomAlignment,
1353 kTrayLabelItemVerticalPaddingVerticalAlignment, 1280 kTrayLabelItemVerticalPaddingVerticalAlignment,
1354 kTrayLabelItemHorizontalPaddingBottomAlignment)); 1281 kTrayLabelItemHorizontalPaddingBottomAlignment));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 Shell* shell = Shell::GetInstance(); 1330 Shell* shell = Shell::GetInstance();
1404 // If multi profile is not enabled we can use the normal index. 1331 // If multi profile is not enabled we can use the normal index.
1405 if (!shell->delegate()->IsMultiProfilesEnabled()) 1332 if (!shell->delegate()->IsMultiProfilesEnabled())
1406 return multiprofile_index_; 1333 return multiprofile_index_;
1407 // In case of multi profile we need to mirror the indices since the system 1334 // 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. 1335 // tray items are in the reverse order then the menu items.
1409 return shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers() - 1336 return shell->session_state_delegate()->GetMaximumNumberOfLoggedInUsers() -
1410 1 - multiprofile_index_; 1337 1 - multiprofile_index_;
1411 } 1338 }
1412 1339
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() { 1340 void TrayUser::UpdateLayoutOfItem() {
1421 internal::RootWindowController* controller = 1341 internal::RootWindowController* controller =
1422 internal::GetRootWindowController( 1342 internal::GetRootWindowController(
1423 system_tray()->GetWidget()->GetNativeWindow()->GetRootWindow()); 1343 system_tray()->GetWidget()->GetNativeWindow()->GetRootWindow());
1424 if (controller && controller->shelf()) { 1344 if (controller && controller->shelf()) {
1425 UpdateAfterShelfAlignmentChange( 1345 UpdateAfterShelfAlignmentChange(
1426 controller->GetShelfLayoutManager()->GetAlignment()); 1346 controller->GetShelfLayoutManager()->GetAlignment());
1427 } 1347 }
1428 } 1348 }
1429 1349
1430 } // namespace internal 1350 } // namespace internal
1431 } // namespace ash 1351 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698