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 "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 5 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
6 | 6 |
7 #import <Carbon/Carbon.h> // kVK_Return. | 7 #import <Carbon/Carbon.h> // kVK_Return. |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include "base/mac/bundle_locations.h" | 10 #include "base/mac/bundle_locations.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 // at the specified |frame_origin| and has a fixed |frame_width|. | 159 // at the specified |frame_origin| and has a fixed |frame_width|. |
160 NSTextView* BuildFixedWidthTextViewWithLink( | 160 NSTextView* BuildFixedWidthTextViewWithLink( |
161 id<NSTextViewDelegate> delegate, | 161 id<NSTextViewDelegate> delegate, |
162 NSString* message, | 162 NSString* message, |
163 NSString* link, | 163 NSString* link, |
164 int link_offset, | 164 int link_offset, |
165 NSPoint frame_origin, | 165 NSPoint frame_origin, |
166 CGFloat frame_width) { | 166 CGFloat frame_width) { |
167 base::scoped_nsobject<HyperlinkTextView> text_view( | 167 base::scoped_nsobject<HyperlinkTextView> text_view( |
168 [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]); | 168 [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]); |
169 NSColor* link_color = gfx::SkColorToCalibratedNSColor( | 169 NSColor* link_color = skia::SkColorToCalibratedNSColor( |
170 chrome_style::GetLinkColor()); | 170 chrome_style::GetLinkColor()); |
171 NSMutableString* finalMessage = | 171 NSMutableString* finalMessage = |
172 [NSMutableString stringWithFormat:@"%@\n", message]; | 172 [NSMutableString stringWithFormat:@"%@\n", message]; |
173 [finalMessage insertString:link atIndex:link_offset]; | 173 [finalMessage insertString:link atIndex:link_offset]; |
174 // Adds a padding row at the bottom, because |boundingRectWithSize| below cuts | 174 // Adds a padding row at the bottom, because |boundingRectWithSize| below cuts |
175 // off the last row sometimes. | 175 // off the last row sometimes. |
176 [text_view setMessage:finalMessage | 176 [text_view setMessage:finalMessage |
177 withFont:[NSFont labelFontOfSize:kTextFontSize] | 177 withFont:[NSFont labelFontOfSize:kTextFontSize] |
178 messageColor:[NSColor blackColor]]; | 178 messageColor:[NSColor blackColor]]; |
179 [text_view addLinkRange:NSMakeRange(link_offset, [link length]) | 179 [text_view addLinkRange:NSMakeRange(link_offset, [link length]) |
(...skipping 12 matching lines...) Expand all Loading... |
192 boundingRectWithSize:NSMakeSize(frame_width, 0) | 192 boundingRectWithSize:NSMakeSize(frame_width, 0) |
193 options:NSStringDrawingUsesLineFragmentOrigin]; | 193 options:NSStringDrawingUsesLineFragmentOrigin]; |
194 frame.origin = frame_origin; | 194 frame.origin = frame_origin; |
195 [text_view setFrame:frame]; | 195 [text_view setFrame:frame]; |
196 [text_view setDelegate:delegate]; | 196 [text_view setDelegate:delegate]; |
197 return text_view.autorelease(); | 197 return text_view.autorelease(); |
198 } | 198 } |
199 | 199 |
200 // Returns the native dialog background color. | 200 // Returns the native dialog background color. |
201 NSColor* GetDialogBackgroundColor() { | 201 NSColor* GetDialogBackgroundColor() { |
202 return gfx::SkColorToCalibratedNSColor( | 202 return skia::SkColorToCalibratedNSColor( |
203 ui::NativeThemeMac::instance()->GetSystemColor( | 203 ui::NativeThemeMac::instance()->GetSystemColor( |
204 ui::NativeTheme::kColorId_DialogBackground)); | 204 ui::NativeTheme::kColorId_DialogBackground)); |
205 } | 205 } |
206 | 206 |
207 // Builds a title card with one back button right aligned and one label center | 207 // Builds a title card with one back button right aligned and one label center |
208 // aligned. | 208 // aligned. |
209 NSView* BuildTitleCard(NSRect frame_rect, | 209 NSView* BuildTitleCard(NSRect frame_rect, |
210 const base::string16& message, | 210 const base::string16& message, |
211 id back_button_target, | 211 id back_button_target, |
212 SEL back_button_action) { | 212 SEL back_button_action) { |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 | 792 |
793 - (id)initWithFrame:(NSRect)frameRect | 793 - (id)initWithFrame:(NSRect)frameRect |
794 imageTitleSpacing:(int)imageTitleSpacing | 794 imageTitleSpacing:(int)imageTitleSpacing |
795 backgroundColor:(NSColor*)backgroundColor { | 795 backgroundColor:(NSColor*)backgroundColor { |
796 if ((self = [super initWithFrame:frameRect])) { | 796 if ((self = [super initWithFrame:frameRect])) { |
797 backgroundColor_.reset([backgroundColor retain]); | 797 backgroundColor_.reset([backgroundColor retain]); |
798 // Use a color from Aura, since this button is not trying to look like a | 798 // Use a color from Aura, since this button is not trying to look like a |
799 // native control. | 799 // native control. |
800 SkColor hoverColor = ui::GetAuraColor( | 800 SkColor hoverColor = ui::GetAuraColor( |
801 ui::NativeTheme::kColorId_ButtonHoverBackgroundColor, nullptr); | 801 ui::NativeTheme::kColorId_ButtonHoverBackgroundColor, nullptr); |
802 hoverColor_.reset([gfx::SkColorToSRGBNSColor(hoverColor) retain]); | 802 hoverColor_.reset([skia::SkColorToSRGBNSColor(hoverColor) retain]); |
803 | 803 |
804 [self setBordered:NO]; | 804 [self setBordered:NO]; |
805 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; | 805 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; |
806 [self setButtonType:NSMomentaryChangeButton]; | 806 [self setButtonType:NSMomentaryChangeButton]; |
807 | 807 |
808 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( | 808 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( |
809 [[CustomPaddingImageButtonCell alloc] | 809 [[CustomPaddingImageButtonCell alloc] |
810 initWithLeftMarginSpacing:kHorizontalSpacing | 810 initWithLeftMarginSpacing:kHorizontalSpacing |
811 imageTitleSpacing:imageTitleSpacing]); | 811 imageTitleSpacing:imageTitleSpacing]); |
812 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; | 812 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 contentMessage:(NSString*)contentMessage | 1558 contentMessage:(NSString*)contentMessage |
1559 linkMessage:(NSString*)linkMessage | 1559 linkMessage:(NSString*)linkMessage |
1560 buttonMessage:(NSString*)buttonMessage | 1560 buttonMessage:(NSString*)buttonMessage |
1561 stackButton:(BOOL)stackButton | 1561 stackButton:(BOOL)stackButton |
1562 hasCloseButton:(BOOL)hasCloseButton | 1562 hasCloseButton:(BOOL)hasCloseButton |
1563 linkAction:(SEL)linkAction | 1563 linkAction:(SEL)linkAction |
1564 buttonAction:(SEL)buttonAction { | 1564 buttonAction:(SEL)buttonAction { |
1565 tutorialMode_ = mode; | 1565 tutorialMode_ = mode; |
1566 | 1566 |
1567 NSColor* tutorialBackgroundColor = | 1567 NSColor* tutorialBackgroundColor = |
1568 gfx::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor); | 1568 skia::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor); |
1569 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] | 1569 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] |
1570 initWithFrame:NSMakeRect(0, 0, kFixedMenuWidth, 0) | 1570 initWithFrame:NSMakeRect(0, 0, kFixedMenuWidth, 0) |
1571 withColor:tutorialBackgroundColor]); | 1571 withColor:tutorialBackgroundColor]); |
1572 CGFloat availableWidth = kFixedMenuWidth - 2 * kHorizontalSpacing; | 1572 CGFloat availableWidth = kFixedMenuWidth - 2 * kHorizontalSpacing; |
1573 CGFloat yOffset = kVerticalSpacing; | 1573 CGFloat yOffset = kVerticalSpacing; |
1574 | 1574 |
1575 // Adds links and buttons at the bottom. | 1575 // Adds links and buttons at the bottom. |
1576 base::scoped_nsobject<NSButton> tutorialOkButton; | 1576 base::scoped_nsobject<NSButton> tutorialOkButton; |
1577 if (buttonMessage) { | 1577 if (buttonMessage) { |
1578 tutorialOkButton.reset([[HoverButton alloc] initWithFrame:NSZeroRect]); | 1578 tutorialOkButton.reset([[HoverButton alloc] initWithFrame:NSZeroRect]); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1635 [container addSubview:learnMoreLink]; | 1635 [container addSubview:learnMoreLink]; |
1636 yOffset = std::max(NSMaxY([learnMoreLink frame]), yOffset); | 1636 yOffset = std::max(NSMaxY([learnMoreLink frame]), yOffset); |
1637 } | 1637 } |
1638 | 1638 |
1639 yOffset += kVerticalSpacing; | 1639 yOffset += kVerticalSpacing; |
1640 | 1640 |
1641 // Adds body content. | 1641 // Adds body content. |
1642 NSTextField* contentLabel = BuildLabel( | 1642 NSTextField* contentLabel = BuildLabel( |
1643 contentMessage, | 1643 contentMessage, |
1644 NSMakePoint(kHorizontalSpacing, yOffset), | 1644 NSMakePoint(kHorizontalSpacing, yOffset), |
1645 gfx::SkColorToSRGBNSColor(profiles::kAvatarTutorialContentTextColor)); | 1645 skia::SkColorToSRGBNSColor(profiles::kAvatarTutorialContentTextColor)); |
1646 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; | 1646 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; |
1647 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; | 1647 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; |
1648 [container addSubview:contentLabel]; | 1648 [container addSubview:contentLabel]; |
1649 yOffset = NSMaxY([contentLabel frame]) + kSmallVerticalSpacing; | 1649 yOffset = NSMaxY([contentLabel frame]) + kSmallVerticalSpacing; |
1650 | 1650 |
1651 // Adds title. | 1651 // Adds title. |
1652 NSTextField* titleLabel = | 1652 NSTextField* titleLabel = |
1653 BuildLabel(titleMessage, | 1653 BuildLabel(titleMessage, |
1654 NSMakePoint(kHorizontalSpacing, yOffset), | 1654 NSMakePoint(kHorizontalSpacing, yOffset), |
1655 [NSColor whiteColor] /* text_color */); | 1655 [NSColor whiteColor] /* text_color */); |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1989 return container.autorelease(); | 1989 return container.autorelease(); |
1990 } | 1990 } |
1991 | 1991 |
1992 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect { | 1992 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect { |
1993 const CGFloat kAccountButtonHeight = 34; | 1993 const CGFloat kAccountButtonHeight = 34; |
1994 | 1994 |
1995 const AvatarMenu::Item& item = | 1995 const AvatarMenu::Item& item = |
1996 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); | 1996 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); |
1997 DCHECK(item.signed_in); | 1997 DCHECK(item.signed_in); |
1998 | 1998 |
1999 NSColor* backgroundColor = gfx::SkColorToCalibratedNSColor( | 1999 NSColor* backgroundColor = skia::SkColorToCalibratedNSColor( |
2000 profiles::kAvatarBubbleAccountsBackgroundColor); | 2000 profiles::kAvatarBubbleAccountsBackgroundColor); |
2001 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] | 2001 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] |
2002 initWithFrame:rect | 2002 initWithFrame:rect |
2003 withColor:backgroundColor]); | 2003 withColor:backgroundColor]); |
2004 | 2004 |
2005 rect.origin.y = 0; | 2005 rect.origin.y = 0; |
2006 if (!browser_->profile()->IsSupervised()) { | 2006 if (!browser_->profile()->IsSupervised()) { |
2007 // Manually elide the button text so the contents fit inside the bubble. | 2007 // Manually elide the button text so the contents fit inside the bubble. |
2008 // This is needed because the BlueLabelButton cell resets the style on | 2008 // This is needed because the BlueLabelButton cell resets the style on |
2009 // every call to -cellSize, which prevents setting a custom lineBreakMode. | 2009 // every call to -cellSize, which prevents setting a custom lineBreakMode. |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2318 return button.autorelease(); | 2318 return button.autorelease(); |
2319 } | 2319 } |
2320 | 2320 |
2321 - (NSButton*)linkButtonWithTitle:(NSString*)title | 2321 - (NSButton*)linkButtonWithTitle:(NSString*)title |
2322 frameOrigin:(NSPoint)frameOrigin | 2322 frameOrigin:(NSPoint)frameOrigin |
2323 action:(SEL)action { | 2323 action:(SEL)action { |
2324 base::scoped_nsobject<NSButton> link( | 2324 base::scoped_nsobject<NSButton> link( |
2325 [[HyperlinkButtonCell buttonWithString:title] retain]); | 2325 [[HyperlinkButtonCell buttonWithString:title] retain]); |
2326 | 2326 |
2327 [[link cell] setShouldUnderline:NO]; | 2327 [[link cell] setShouldUnderline:NO]; |
2328 [[link cell] setTextColor:gfx::SkColorToCalibratedNSColor( | 2328 [[link cell] setTextColor:skia::SkColorToCalibratedNSColor( |
2329 chrome_style::GetLinkColor())]; | 2329 chrome_style::GetLinkColor())]; |
2330 [link setTitle:title]; | 2330 [link setTitle:title]; |
2331 [link setBordered:NO]; | 2331 [link setBordered:NO]; |
2332 [link setFont:[NSFont labelFontOfSize:kTextFontSize]]; | 2332 [link setFont:[NSFont labelFontOfSize:kTextFontSize]]; |
2333 [link setTarget:self]; | 2333 [link setTarget:self]; |
2334 [link setAction:action]; | 2334 [link setAction:action]; |
2335 [link setFrameOrigin:frameOrigin]; | 2335 [link setFrameOrigin:frameOrigin]; |
2336 [link sizeToFit]; | 2336 [link sizeToFit]; |
2337 | 2337 |
2338 return link.autorelease(); | 2338 return link.autorelease(); |
(...skipping 12 matching lines...) Expand all Loading... |
2351 CGFloat deleteImageWidth = [deleteImage size].width; | 2351 CGFloat deleteImageWidth = [deleteImage size].width; |
2352 NSImage* warningImage = reauthRequired ? rb->GetNativeImageNamed( | 2352 NSImage* warningImage = reauthRequired ? rb->GetNativeImageNamed( |
2353 IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToNSImage() : nil; | 2353 IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToNSImage() : nil; |
2354 CGFloat warningImageWidth = [warningImage size].width; | 2354 CGFloat warningImageWidth = [warningImage size].width; |
2355 | 2355 |
2356 CGFloat availableTextWidth = rect.size.width - kHorizontalSpacing - | 2356 CGFloat availableTextWidth = rect.size.width - kHorizontalSpacing - |
2357 warningImageWidth - deleteImageWidth; | 2357 warningImageWidth - deleteImageWidth; |
2358 if (warningImage) | 2358 if (warningImage) |
2359 availableTextWidth -= kHorizontalSpacing; | 2359 availableTextWidth -= kHorizontalSpacing; |
2360 | 2360 |
2361 NSColor* backgroundColor = gfx::SkColorToCalibratedNSColor( | 2361 NSColor* backgroundColor = skia::SkColorToCalibratedNSColor( |
2362 profiles::kAvatarBubbleAccountsBackgroundColor); | 2362 profiles::kAvatarBubbleAccountsBackgroundColor); |
2363 base::scoped_nsobject<BackgroundColorHoverButton> button( | 2363 base::scoped_nsobject<BackgroundColorHoverButton> button( |
2364 [[BackgroundColorHoverButton alloc] initWithFrame:rect | 2364 [[BackgroundColorHoverButton alloc] initWithFrame:rect |
2365 imageTitleSpacing:0 | 2365 imageTitleSpacing:0 |
2366 backgroundColor:backgroundColor]); | 2366 backgroundColor:backgroundColor]); |
2367 [button setTitle:ElideEmail(email, availableTextWidth)]; | 2367 [button setTitle:ElideEmail(email, availableTextWidth)]; |
2368 [button setAlignment:NSLeftTextAlignment]; | 2368 [button setAlignment:NSLeftTextAlignment]; |
2369 [button setBordered:NO]; | 2369 [button setBordered:NO]; |
2370 if (reauthRequired) { | 2370 if (reauthRequired) { |
2371 [button setDefaultImage:warningImage]; | 2371 [button setDefaultImage:warningImage]; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2406 } | 2406 } |
2407 | 2407 |
2408 - (bool)shouldShowGoIncognito { | 2408 - (bool)shouldShowGoIncognito { |
2409 bool incognitoAvailable = | 2409 bool incognitoAvailable = |
2410 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2410 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
2411 IncognitoModePrefs::DISABLED; | 2411 IncognitoModePrefs::DISABLED; |
2412 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2412 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
2413 } | 2413 } |
2414 | 2414 |
2415 @end | 2415 @end |
OLD | NEW |