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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 | 221 |
222 [container addSubview:button]; | 222 [container addSubview:button]; |
223 [container addSubview:title_label]; | 223 [container addSubview:title_label]; |
224 CGFloat height = std::max(NSMaxY([title_label frame]), | 224 CGFloat height = std::max(NSMaxY([title_label frame]), |
225 NSMaxY([button frame])) + kSmallVerticalSpacing; | 225 NSMaxY([button frame])) + kSmallVerticalSpacing; |
226 [container setFrameSize:NSMakeSize(NSWidth([container frame]), height)]; | 226 [container setFrameSize:NSMakeSize(NSWidth([container frame]), height)]; |
227 | 227 |
228 return container.autorelease(); | 228 return container.autorelease(); |
229 } | 229 } |
230 | 230 |
231 bool HasAuthError(Profile* profile) { | |
232 const SigninErrorController* error = | |
groby-ooo-7-16
2014/06/10 19:28:14
error_controller, please - here and elsewhere.
noms (inactive)
2014/06/17 17:07:33
Done.
| |
233 profiles::GetSigninErrorController(profile); | |
234 return error && error->HasError(); | |
235 } | |
236 | |
231 } // namespace | 237 } // namespace |
232 | 238 |
233 // Class that listens to changes to the OAuth2Tokens for the active profile, | 239 // Class that listens to changes to the OAuth2Tokens for the active profile, |
234 // changes to the avatar menu model or browser close notifications. | 240 // changes to the avatar menu model or browser close notifications. |
235 class ActiveProfileObserverBridge : public AvatarMenuObserver, | 241 class ActiveProfileObserverBridge : public AvatarMenuObserver, |
236 public content::NotificationObserver, | 242 public content::NotificationObserver, |
237 public OAuth2TokenService::Observer { | 243 public OAuth2TokenService::Observer { |
238 public: | 244 public: |
239 ActiveProfileObserverBridge(ProfileChooserController* controller, | 245 ActiveProfileObserverBridge(ProfileChooserController* controller, |
240 Browser* browser) | 246 Browser* browser) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 } | 278 } |
273 | 279 |
274 // OAuth2TokenService::Observer: | 280 // OAuth2TokenService::Observer: |
275 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE { | 281 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE { |
276 // Tokens can only be added by adding an account through the inline flow, | 282 // Tokens can only be added by adding an account through the inline flow, |
277 // which is started from the account management view. Refresh it to show the | 283 // which is started from the account management view. Refresh it to show the |
278 // update. | 284 // update. |
279 profiles::BubbleViewMode viewMode = [controller_ viewMode]; | 285 profiles::BubbleViewMode viewMode = [controller_ viewMode]; |
280 if (viewMode == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT || | 286 if (viewMode == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT || |
281 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN || | 287 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN || |
282 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT) { | 288 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT || |
289 viewMode == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH) { | |
283 [controller_ initMenuContentsWithView: | 290 [controller_ initMenuContentsWithView: |
284 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; | 291 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; |
285 } | 292 } |
286 } | 293 } |
287 | 294 |
288 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE { | 295 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE { |
289 // Tokens can only be removed from the account management view. Refresh it | 296 // Tokens can only be removed from the account management view. Refresh it |
290 // to show the update. | 297 // to show the update. |
291 if ([controller_ viewMode] == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) | 298 if ([controller_ viewMode] == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) |
292 [controller_ initMenuContentsWithView: | 299 [controller_ initMenuContentsWithView: |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
739 imageResourceId:(int)imageResourceId | 746 imageResourceId:(int)imageResourceId |
740 alternateImageResourceId:(int)alternateImageResourceId | 747 alternateImageResourceId:(int)alternateImageResourceId |
741 action:(SEL)action; | 748 action:(SEL)action; |
742 | 749 |
743 // Creates a generic link button with |title| and an |action| positioned at | 750 // Creates a generic link button with |title| and an |action| positioned at |
744 // |frameOrigin|. | 751 // |frameOrigin|. |
745 - (NSButton*)linkButtonWithTitle:(NSString*)title | 752 - (NSButton*)linkButtonWithTitle:(NSString*)title |
746 frameOrigin:(NSPoint)frameOrigin | 753 frameOrigin:(NSPoint)frameOrigin |
747 action:(SEL)action; | 754 action:(SEL)action; |
748 | 755 |
749 // Creates an email account button with |title| and a remove icon. |tag| | 756 // Creates an email account button with |title| and a remove icon. If |
757 // |reauthRequired| is true, the button also displays a warning icon. |tag| | |
750 // indicates which account the button refers to. | 758 // indicates which account the button refers to. |
751 - (NSButton*)accountButtonWithRect:(NSRect)rect | 759 - (NSButton*)accountButtonWithRect:(NSRect)rect |
752 title:(const std::string&)title | 760 title:(const std::string&)title |
753 tag:(int)tag; | 761 tag:(int)tag |
762 reauthRequired:(BOOL)reauthRequired; | |
754 @end | 763 @end |
755 | 764 |
756 @implementation ProfileChooserController | 765 @implementation ProfileChooserController |
757 - (profiles::BubbleViewMode) viewMode { | 766 - (profiles::BubbleViewMode) viewMode { |
758 return viewMode_; | 767 return viewMode_; |
759 } | 768 } |
760 | 769 |
761 - (IBAction)switchToProfile:(id)sender { | 770 - (IBAction)switchToProfile:(id)sender { |
762 // Check the event flags to see if a new window should be created. | 771 // Check the event flags to see if a new window should be created. |
763 bool alwaysCreate = ui::WindowOpenDispositionFromNSEvent( | 772 bool alwaysCreate = ui::WindowOpenDispositionFromNSEvent( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
820 accountIdToRemove_ = SigninManagerFactory::GetForProfile( | 829 accountIdToRemove_ = SigninManagerFactory::GetForProfile( |
821 browser_->profile())->GetAuthenticatedUsername(); | 830 browser_->profile())->GetAuthenticatedUsername(); |
822 } else { | 831 } else { |
823 DCHECK(ContainsKey(currentProfileAccounts_, tag)); | 832 DCHECK(ContainsKey(currentProfileAccounts_, tag)); |
824 accountIdToRemove_ = currentProfileAccounts_[tag]; | 833 accountIdToRemove_ = currentProfileAccounts_[tag]; |
825 } | 834 } |
826 | 835 |
827 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL]; | 836 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL]; |
828 } | 837 } |
829 | 838 |
839 - (IBAction)showAccountReauthView:(id)sender { | |
840 DCHECK(!isGuestSession_); | |
841 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH]; | |
842 } | |
843 | |
830 - (IBAction)removeAccount:(id)sender { | 844 - (IBAction)removeAccount:(id)sender { |
831 DCHECK(!accountIdToRemove_.empty()); | 845 DCHECK(!accountIdToRemove_.empty()); |
832 ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile( | 846 ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile( |
833 browser_->profile())->RevokeCredentials(accountIdToRemove_); | 847 browser_->profile())->RevokeCredentials(accountIdToRemove_); |
834 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_REMOVE_ACCT]; | 848 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_REMOVE_ACCT]; |
835 accountIdToRemove_.clear(); | 849 accountIdToRemove_.clear(); |
836 | 850 |
837 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; | 851 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; |
838 } | 852 } |
839 | 853 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
910 | 924 |
911 avatarMenu_.reset(new AvatarMenu( | 925 avatarMenu_.reset(new AvatarMenu( |
912 &g_browser_process->profile_manager()->GetProfileInfoCache(), | 926 &g_browser_process->profile_manager()->GetProfileInfoCache(), |
913 observer_.get(), | 927 observer_.get(), |
914 browser_)); | 928 browser_)); |
915 avatarMenu_->RebuildMenu(); | 929 avatarMenu_->RebuildMenu(); |
916 | 930 |
917 // Guest profiles do not have a token service. | 931 // Guest profiles do not have a token service. |
918 isGuestSession_ = browser_->profile()->IsGuestSession(); | 932 isGuestSession_ = browser_->profile()->IsGuestSession(); |
919 | 933 |
934 // If view mode is PROFILE_CHOOSER but there is an auth error, force | |
935 // ACCOUNT_MANAGEMENT mode. | |
936 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER && | |
937 HasAuthError(browser_->profile())) { | |
938 viewMode_ = profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT; | |
939 } | |
940 | |
920 [[self bubble] setAlignment:info_bubble::kAlignRightEdgeToAnchorEdge]; | 941 [[self bubble] setAlignment:info_bubble::kAlignRightEdgeToAnchorEdge]; |
921 [[self bubble] setArrowLocation:info_bubble::kNoArrow]; | 942 [[self bubble] setArrowLocation:info_bubble::kNoArrow]; |
922 [[self bubble] setBackgroundColor:GetDialogBackgroundColor()]; | 943 [[self bubble] setBackgroundColor:GetDialogBackgroundColor()]; |
923 [self initMenuContentsWithView:viewMode_]; | 944 [self initMenuContentsWithView:viewMode_]; |
924 } | 945 } |
925 | 946 |
926 return self; | 947 return self; |
927 } | 948 } |
928 | 949 |
929 - (void)initMenuContentsWithView:(profiles::BubbleViewMode)viewToDisplay { | 950 - (void)initMenuContentsWithView:(profiles::BubbleViewMode)viewToDisplay { |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1498 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); | 1519 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); |
1499 currentProfileAccounts_.clear(); | 1520 currentProfileAccounts_.clear(); |
1500 | 1521 |
1501 Profile* profile = browser_->profile(); | 1522 Profile* profile = browser_->profile(); |
1502 std::string primaryAccount = | 1523 std::string primaryAccount = |
1503 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); | 1524 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); |
1504 DCHECK(!primaryAccount.empty()); | 1525 DCHECK(!primaryAccount.empty()); |
1505 std::vector<std::string>accounts = | 1526 std::vector<std::string>accounts = |
1506 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount); | 1527 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount); |
1507 | 1528 |
1529 // If there is an account with an authentication error, it needs to be | |
1530 // badged with a warning icon. | |
groby-ooo-7-16
2014/06/10 19:28:15
Question: Is there ever a chance of multiple accou
noms (inactive)
2014/06/17 17:07:32
Nope. Mike asked the same question on a previous p
| |
1531 const SigninErrorController* error = | |
1532 profiles::GetSigninErrorController(profile); | |
1533 std::string errorAccountId = | |
1534 error ? error->error_account_id() : std::string(); | |
1535 | |
1508 rect.origin.y = 0; | 1536 rect.origin.y = 0; |
1509 for (size_t i = 0; i < accounts.size(); ++i) { | 1537 for (size_t i = 0; i < accounts.size(); ++i) { |
1510 // Save the original email address, as the button text could be elided. | 1538 // Save the original email address, as the button text could be elided. |
1511 currentProfileAccounts_[i] = accounts[i]; | 1539 currentProfileAccounts_[i] = accounts[i]; |
1512 NSButton* accountButton = [self accountButtonWithRect:rect | 1540 NSButton* accountButton = |
1513 title:accounts[i] | 1541 [self accountButtonWithRect:rect |
1514 tag:i]; | 1542 title:accounts[i] |
1543 tag:i | |
1544 reauthRequired:errorAccountId == accounts[i]]; | |
1515 [container addSubview:accountButton]; | 1545 [container addSubview:accountButton]; |
1516 rect.origin.y = NSMaxY([accountButton frame]); | 1546 rect.origin.y = NSMaxY([accountButton frame]); |
1517 } | 1547 } |
1518 | 1548 |
1519 // The primary account should always be listed first. | 1549 // The primary account should always be listed first. |
1520 NSButton* accountButton = [self accountButtonWithRect:rect | 1550 NSButton* accountButton = |
1521 title:primaryAccount | 1551 [self accountButtonWithRect:rect |
1522 tag:kPrimaryProfileTag]; | 1552 title:primaryAccount |
1553 tag:kPrimaryProfileTag | |
1554 reauthRequired:errorAccountId == primaryAccount]; | |
1523 [container addSubview:accountButton]; | 1555 [container addSubview:accountButton]; |
1524 [container setFrameSize:NSMakeSize(NSWidth([container frame]), | 1556 [container setFrameSize:NSMakeSize(NSWidth([container frame]), |
1525 NSMaxY([accountButton frame]))]; | 1557 NSMaxY([accountButton frame]))]; |
1526 return container.autorelease(); | 1558 return container.autorelease(); |
1527 } | 1559 } |
1528 | 1560 |
1529 - (NSView*)buildGaiaEmbeddedView { | 1561 - (NSView*)buildGaiaEmbeddedView { |
1530 base::scoped_nsobject<NSView> container( | 1562 base::scoped_nsobject<NSView> container( |
1531 [[NSView alloc] initWithFrame:NSZeroRect]); | 1563 [[NSView alloc] initWithFrame:NSZeroRect]); |
1532 CGFloat yOffset = 0; | 1564 CGFloat yOffset = 0; |
1533 | 1565 |
1534 bool addSecondaryAccount = | 1566 GURL url; |
1535 viewMode_ == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT; | 1567 int messageId = -1; |
1536 signin::Source source = addSecondaryAccount ? | 1568 SigninErrorController* error = NULL; |
1537 signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT : | 1569 switch (viewMode_) { |
1538 signin::SOURCE_AVATAR_BUBBLE_SIGN_IN; | 1570 case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: |
1571 url = signin::GetPromoURL(signin::SOURCE_AVATAR_BUBBLE_SIGN_IN, | |
1572 false /* auto_close */, | |
1573 true /* is_constrained */); | |
1574 messageId = IDS_PROFILES_GAIA_SIGNIN_TITLE; | |
1575 break; | |
1576 case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: | |
1577 url = signin::GetPromoURL(signin::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT, | |
1578 false /* auto_close */, | |
1579 true /* is_constrained */); | |
1580 messageId = IDS_PROFILES_GAIA_ADD_ACCOUNT_TITLE; | |
1581 break; | |
1582 case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: | |
1583 DCHECK(HasAuthError(browser_->profile())); | |
1584 error = profiles::GetSigninErrorController(browser_->profile()); | |
1585 url = signin::GetReauthURL( | |
1586 browser_->profile(), error ? error->error_username() : std::string()); | |
1587 messageId = IDS_PROFILES_GAIA_REAUTH_TITLE; | |
1588 break; | |
1589 default: | |
1590 NOTREACHED() << "Called with invalid mode=" << viewMode_; | |
1591 return NULL; | |
groby-ooo-7-16
2014/06/10 19:28:14
use break instead of NULL, or kill NOTREACHED. (St
noms (inactive)
2014/06/17 17:07:33
Done.
| |
1592 } | |
1539 | 1593 |
1540 webContents_.reset(content::WebContents::Create( | 1594 webContents_.reset(content::WebContents::Create( |
1541 content::WebContents::CreateParams(browser_->profile()))); | 1595 content::WebContents::CreateParams(browser_->profile()))); |
1542 webContents_->GetController().LoadURL( | 1596 webContents_->GetController().LoadURL(url, |
1543 signin::GetPromoURL( | 1597 content::Referrer(), |
1544 source, false /* auto_close */, true /* is_constrained */), | 1598 content::PAGE_TRANSITION_AUTO_TOPLEVEL, |
1545 content::Referrer(), | 1599 std::string()); |
1546 content::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
1547 std::string()); | |
1548 NSView* webview = webContents_->GetNativeView(); | 1600 NSView* webview = webContents_->GetNativeView(); |
1549 [webview setFrameSize:NSMakeSize(kFixedGaiaViewWidth, kFixedGaiaViewHeight)]; | 1601 [webview setFrameSize:NSMakeSize(kFixedGaiaViewWidth, kFixedGaiaViewHeight)]; |
1550 [container addSubview:webview]; | 1602 [container addSubview:webview]; |
1551 yOffset = NSMaxY([webview frame]); | 1603 yOffset = NSMaxY([webview frame]); |
1552 | 1604 |
1553 // Adds the title card. | 1605 // Adds the title card. |
1554 NSBox* separator = [self separatorWithFrame: | 1606 NSBox* separator = [self separatorWithFrame: |
1555 NSMakeRect(0, yOffset, kFixedGaiaViewWidth, 0)]; | 1607 NSMakeRect(0, yOffset, kFixedGaiaViewWidth, 0)]; |
1556 [container addSubview:separator]; | 1608 [container addSubview:separator]; |
1557 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; | 1609 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; |
1558 | 1610 |
1559 NSView* titleView = BuildTitleCard( | 1611 NSView* titleView = BuildTitleCard( |
1560 NSMakeRect(0, yOffset, kFixedGaiaViewWidth,0), | 1612 NSMakeRect(0, yOffset, kFixedGaiaViewWidth, 0), |
1561 addSecondaryAccount ? IDS_PROFILES_GAIA_ADD_ACCOUNT_TITLE : | 1613 messageId, |
1562 IDS_PROFILES_GAIA_SIGNIN_TITLE, | |
1563 self /* backButtonTarget*/, | 1614 self /* backButtonTarget*/, |
1564 @selector(navigateBackFromSigninPage:) /* backButtonAction */); | 1615 @selector(navigateBackFromSigninPage:) /* backButtonAction */); |
1565 [container addSubview:titleView]; | 1616 [container addSubview:titleView]; |
1566 yOffset = NSMaxY([titleView frame]); | 1617 yOffset = NSMaxY([titleView frame]); |
1567 | 1618 |
1568 [container setFrameSize:NSMakeSize(kFixedGaiaViewWidth, yOffset)]; | 1619 [container setFrameSize:NSMakeSize(kFixedGaiaViewWidth, yOffset)]; |
1569 return container.autorelease(); | 1620 return container.autorelease(); |
1570 } | 1621 } |
1571 | 1622 |
1572 - (NSView*)buildAccountRemovalView { | 1623 - (NSView*)buildAccountRemovalView { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1741 [link setTarget:self]; | 1792 [link setTarget:self]; |
1742 [link setAction:action]; | 1793 [link setAction:action]; |
1743 [link setFrameOrigin:frameOrigin]; | 1794 [link setFrameOrigin:frameOrigin]; |
1744 [link sizeToFit]; | 1795 [link sizeToFit]; |
1745 | 1796 |
1746 return link.autorelease(); | 1797 return link.autorelease(); |
1747 } | 1798 } |
1748 | 1799 |
1749 - (NSButton*)accountButtonWithRect:(NSRect)rect | 1800 - (NSButton*)accountButtonWithRect:(NSRect)rect |
1750 title:(const std::string&)title | 1801 title:(const std::string&)title |
1751 tag:(int)tag { | 1802 tag:(int)tag |
1803 reauthRequired:(BOOL)reauthRequired { | |
1804 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | |
1805 NSImage* deleteImage = rb->GetNativeImageNamed(IDR_CLOSE_1).ToNSImage(); | |
1806 CGFloat deleteImageWidth = [deleteImage size].width; | |
1807 NSImage* warningImage = reauthRequired ? rb->GetNativeImageNamed( | |
1808 IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToNSImage() : nil; | |
1809 CGFloat warningImageWidth = reauthRequired ? [warningImage size].width : 0; | |
groby-ooo-7-16
2014/06/10 19:28:14
Technically, no need to check - just [warningImage
noms (inactive)
2014/06/17 17:07:32
Oh god. Ok. I see. Done.
On 2014/06/10 19:28:14,
| |
1810 | |
1811 CGFloat availableTextWidth = rect.size.width - 2 * kHorizontalSpacing - | |
msw
2014/06/10 17:13:03
nit: should the available text width only include
noms (inactive)
2014/06/17 17:07:32
Done.
| |
1812 warningImageWidth - deleteImageWidth; | |
1813 | |
1752 NSColor* backgroundColor = gfx::SkColorToCalibratedNSColor( | 1814 NSColor* backgroundColor = gfx::SkColorToCalibratedNSColor( |
1753 profiles::kAvatarBubbleAccountsBackgroundColor); | 1815 profiles::kAvatarBubbleAccountsBackgroundColor); |
1754 base::scoped_nsobject<BackgroundColorHoverButton> button( | 1816 base::scoped_nsobject<BackgroundColorHoverButton> button( |
1755 [[BackgroundColorHoverButton alloc] initWithFrame:rect | 1817 [[BackgroundColorHoverButton alloc] initWithFrame:rect |
1756 imageTitleSpacing:0 | 1818 imageTitleSpacing:0 |
1757 backgroundColor:backgroundColor]); | 1819 backgroundColor:backgroundColor]); |
1758 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 1820 [button setTitle:ElideEmail(title, availableTextWidth)]; |
1759 NSImage* defaultImage = rb->GetNativeImageNamed(IDR_CLOSE_1).AsNSImage(); | |
1760 CGFloat kDeleteButtonWidth = [defaultImage size].width; | |
1761 CGFloat availableWidth = rect.size.width - | |
1762 kDeleteButtonWidth - kHorizontalSpacing; | |
1763 [button setTitle:ElideEmail(title, availableWidth)]; | |
1764 [button setAlignment:NSLeftTextAlignment]; | 1821 [button setAlignment:NSLeftTextAlignment]; |
1765 [button setBordered:NO]; | 1822 [button setBordered:NO]; |
1823 if (reauthRequired) { | |
1824 [button setDefaultImage:warningImage]; | |
1825 [button setImagePosition:NSImageLeft]; | |
1826 [button setTarget:self]; | |
1827 [button setAction:@selector(showAccountReauthView:)]; | |
1828 [button setTag:tag]; | |
1829 } | |
1766 | 1830 |
1767 // Delete button. | 1831 // Delete button. |
1768 rect.origin = NSMakePoint(availableWidth, 0); | 1832 rect.origin = NSMakePoint( |
groby-ooo-7-16
2014/06/10 19:28:15
Easier:
NSRect buttonRect;
NSDivideRect(rect, &but
noms (inactive)
2014/06/17 17:07:32
Done.
| |
1769 rect.size.width = kDeleteButtonWidth; | 1833 rect.size.width - kHorizontalSpacing - deleteImageWidth, 0); |
1834 rect.size.width = deleteImageWidth; | |
1770 base::scoped_nsobject<HoverImageButton> deleteButton( | 1835 base::scoped_nsobject<HoverImageButton> deleteButton( |
1771 [[HoverImageButton alloc] initWithFrame:rect]); | 1836 [[HoverImageButton alloc] initWithFrame:rect]); |
1772 [deleteButton setBordered:NO]; | 1837 [deleteButton setBordered:NO]; |
1773 [deleteButton setDefaultImage:defaultImage]; | 1838 [deleteButton setDefaultImage:deleteImage]; |
1774 [deleteButton setHoverImage:rb->GetNativeImageNamed( | 1839 [deleteButton setHoverImage:rb->GetNativeImageNamed( |
1775 IDR_CLOSE_1_H).ToNSImage()]; | 1840 IDR_CLOSE_1_H).ToNSImage()]; |
1776 [deleteButton setPressedImage:rb->GetNativeImageNamed( | 1841 [deleteButton setPressedImage:rb->GetNativeImageNamed( |
1777 IDR_CLOSE_1_P).ToNSImage()]; | 1842 IDR_CLOSE_1_P).ToNSImage()]; |
1778 [deleteButton setTarget:self]; | 1843 [deleteButton setTarget:self]; |
1779 [deleteButton setAction:@selector(showAccountRemovalView:)]; | 1844 [deleteButton setAction:@selector(showAccountRemovalView:)]; |
1780 [deleteButton setTag:tag]; | 1845 [deleteButton setTag:tag]; |
1781 | 1846 |
1782 [button addSubview:deleteButton]; | 1847 [button addSubview:deleteButton]; |
1848 | |
1783 return button.autorelease(); | 1849 return button.autorelease(); |
1784 } | 1850 } |
1785 | 1851 |
1786 - (void)postActionPerformed:(ProfileMetrics::ProfileDesktopMenu)action { | 1852 - (void)postActionPerformed:(ProfileMetrics::ProfileDesktopMenu)action { |
1787 ProfileMetrics::LogProfileDesktopMenu(action, serviceType_); | 1853 ProfileMetrics::LogProfileDesktopMenu(action, serviceType_); |
1788 serviceType_ = signin::GAIA_SERVICE_TYPE_NONE; | 1854 serviceType_ = signin::GAIA_SERVICE_TYPE_NONE; |
1789 } | 1855 } |
1790 | 1856 |
1791 @end | 1857 @end |
OLD | NEW |