OLD | NEW |
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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
8 | 8 |
9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 imageResourceId:(int)imageResourceId | 708 imageResourceId:(int)imageResourceId |
709 alternateImageResourceId:(int)alternateImageResourceId | 709 alternateImageResourceId:(int)alternateImageResourceId |
710 action:(SEL)action; | 710 action:(SEL)action; |
711 | 711 |
712 // Creates a generic link button with |title| and an |action| positioned at | 712 // Creates a generic link button with |title| and an |action| positioned at |
713 // |frameOrigin|. | 713 // |frameOrigin|. |
714 - (NSButton*)linkButtonWithTitle:(NSString*)title | 714 - (NSButton*)linkButtonWithTitle:(NSString*)title |
715 frameOrigin:(NSPoint)frameOrigin | 715 frameOrigin:(NSPoint)frameOrigin |
716 action:(SEL)action; | 716 action:(SEL)action; |
717 | 717 |
718 // Creates an email account button with |title| and a remove icon. | 718 // Creates an email account button with |title| and a remove icon. |tag| |
| 719 // indicates which account the button refers to. |
719 - (NSButton*)accountButtonWithRect:(NSRect)rect | 720 - (NSButton*)accountButtonWithRect:(NSRect)rect |
720 title:(const std::string&)title; | 721 title:(const std::string&)title |
| 722 tag:(int)tag; |
721 | 723 |
722 @end | 724 @end |
723 | 725 |
724 @implementation ProfileChooserController | 726 @implementation ProfileChooserController |
725 - (BubbleViewMode) viewMode { | 727 - (BubbleViewMode) viewMode { |
726 return viewMode_; | 728 return viewMode_; |
727 } | 729 } |
728 | 730 |
729 - (IBAction)switchToProfile:(id)sender { | 731 - (IBAction)switchToProfile:(id)sender { |
730 // Check the event flags to see if a new window should be created. | 732 // Check the event flags to see if a new window should be created. |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); | 1332 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); |
1331 DCHECK(!primaryAccount.empty()); | 1333 DCHECK(!primaryAccount.empty()); |
1332 std::vector<std::string>accounts = | 1334 std::vector<std::string>accounts = |
1333 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount); | 1335 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount); |
1334 | 1336 |
1335 rect.origin.y = 0; | 1337 rect.origin.y = 0; |
1336 for (size_t i = 0; i < accounts.size(); ++i) { | 1338 for (size_t i = 0; i < accounts.size(); ++i) { |
1337 // Save the original email address, as the button text could be elided. | 1339 // Save the original email address, as the button text could be elided. |
1338 currentProfileAccounts_[i] = accounts[i]; | 1340 currentProfileAccounts_[i] = accounts[i]; |
1339 NSButton* accountButton = [self accountButtonWithRect:rect | 1341 NSButton* accountButton = [self accountButtonWithRect:rect |
1340 title:accounts[i]]; | 1342 title:accounts[i] |
1341 [accountButton setTag:i]; | 1343 tag:i]; |
1342 [container addSubview:accountButton]; | 1344 [container addSubview:accountButton]; |
1343 rect.origin.y = NSMaxY([accountButton frame]); | 1345 rect.origin.y = NSMaxY([accountButton frame]); |
1344 } | 1346 } |
1345 | 1347 |
1346 // The primary account should always be listed first. | 1348 // The primary account should always be listed first. |
1347 NSButton* accountButton = [self accountButtonWithRect:rect | 1349 NSButton* accountButton = [self accountButtonWithRect:rect |
1348 title:primaryAccount]; | 1350 title:primaryAccount |
| 1351 tag:kPrimaryProfileTag]; |
1349 [container addSubview:accountButton]; | 1352 [container addSubview:accountButton]; |
1350 [container setFrameSize:NSMakeSize(NSWidth([container frame]), | 1353 [container setFrameSize:NSMakeSize(NSWidth([container frame]), |
1351 NSMaxY([accountButton frame]))]; | 1354 NSMaxY([accountButton frame]))]; |
1352 [accountButton setTag:kPrimaryProfileTag]; | |
1353 return container.autorelease(); | 1355 return container.autorelease(); |
1354 } | 1356 } |
1355 | 1357 |
1356 - (NSView*)buildGaiaEmbeddedView { | 1358 - (NSView*)buildGaiaEmbeddedView { |
1357 base::scoped_nsobject<NSView> container( | 1359 base::scoped_nsobject<NSView> container( |
1358 [[NSView alloc] initWithFrame:NSZeroRect]); | 1360 [[NSView alloc] initWithFrame:NSZeroRect]); |
1359 CGFloat yOffset = 0; | 1361 CGFloat yOffset = 0; |
1360 | 1362 |
1361 bool addSecondaryAccount = viewMode_ == BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT; | 1363 bool addSecondaryAccount = viewMode_ == BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT; |
1362 signin::Source source = addSecondaryAccount ? | 1364 signin::Source source = addSecondaryAccount ? |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 [link setFont:[NSFont labelFontOfSize:kTextFontSize]]; | 1517 [link setFont:[NSFont labelFontOfSize:kTextFontSize]]; |
1516 [link setTarget:self]; | 1518 [link setTarget:self]; |
1517 [link setAction:action]; | 1519 [link setAction:action]; |
1518 [link setFrameOrigin:frameOrigin]; | 1520 [link setFrameOrigin:frameOrigin]; |
1519 [link sizeToFit]; | 1521 [link sizeToFit]; |
1520 | 1522 |
1521 return link.autorelease(); | 1523 return link.autorelease(); |
1522 } | 1524 } |
1523 | 1525 |
1524 - (NSButton*)accountButtonWithRect:(NSRect)rect | 1526 - (NSButton*)accountButtonWithRect:(NSRect)rect |
1525 title:(const std::string&)title { | 1527 title:(const std::string&)title |
| 1528 tag:(int)tag { |
1526 NSColor* backgroundColor = gfx::SkColorToCalibratedNSColor( | 1529 NSColor* backgroundColor = gfx::SkColorToCalibratedNSColor( |
1527 profiles::kAvatarBubbleAccountsBackgroundColor); | 1530 profiles::kAvatarBubbleAccountsBackgroundColor); |
1528 base::scoped_nsobject<BackgroundColorHoverButton> button( | 1531 base::scoped_nsobject<BackgroundColorHoverButton> button( |
1529 [[BackgroundColorHoverButton alloc] initWithFrame:rect | 1532 [[BackgroundColorHoverButton alloc] initWithFrame:rect |
1530 imageTitleSpacing:0 | 1533 imageTitleSpacing:0 |
1531 backgroundColor:backgroundColor]); | 1534 backgroundColor:backgroundColor]); |
1532 | 1535 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
1533 [button setTitle:ElideEmail(title, rect.size.width)]; | 1536 NSImage* defaultImage = rb->GetNativeImageNamed(IDR_CLOSE_1).AsNSImage(); |
| 1537 CGFloat kDeleteButtonWidth = [defaultImage size].width; |
| 1538 CGFloat availableWidth = rect.size.width - |
| 1539 kDeleteButtonWidth - kHorizontalSpacing; |
| 1540 [button setTitle:ElideEmail(title, availableWidth)]; |
1534 [button setAlignment:NSLeftTextAlignment]; | 1541 [button setAlignment:NSLeftTextAlignment]; |
1535 [button setBordered:NO]; | 1542 [button setBordered:NO]; |
1536 [button setTarget:self]; | |
1537 [button setAction:@selector(showAccountRemovalView:)]; | |
1538 | 1543 |
| 1544 // Delete button. |
| 1545 rect.origin = NSMakePoint(availableWidth, 0); |
| 1546 rect.size.width = kDeleteButtonWidth; |
| 1547 base::scoped_nsobject<HoverImageButton> deleteButton( |
| 1548 [[HoverImageButton alloc] initWithFrame:rect]); |
| 1549 [deleteButton setBordered:NO]; |
| 1550 [deleteButton setDefaultImage:defaultImage]; |
| 1551 [deleteButton setHoverImage:rb->GetNativeImageNamed( |
| 1552 IDR_CLOSE_1_H).ToNSImage()]; |
| 1553 [deleteButton setPressedImage:rb->GetNativeImageNamed( |
| 1554 IDR_CLOSE_1_P).ToNSImage()]; |
| 1555 [deleteButton setTarget:self]; |
| 1556 [deleteButton setAction:@selector(showAccountRemovalView:)]; |
| 1557 [deleteButton setTag:tag]; |
| 1558 |
| 1559 [button addSubview:deleteButton]; |
1539 return button.autorelease(); | 1560 return button.autorelease(); |
1540 } | 1561 } |
1541 | 1562 |
1542 @end | 1563 @end |
OLD | NEW |