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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 const CGFloat kHorizontalSpacing = 16.0; | 80 const CGFloat kHorizontalSpacing = 16.0; |
81 const CGFloat kTitleFontSize = 15.0; | 81 const CGFloat kTitleFontSize = 15.0; |
82 const CGFloat kTextFontSize = 12.0; | 82 const CGFloat kTextFontSize = 12.0; |
83 const CGFloat kProfileButtonHeight = 30; | 83 const CGFloat kProfileButtonHeight = 30; |
84 const int kBezelThickness = 3; // Width of the bezel on an NSButton. | 84 const int kBezelThickness = 3; // Width of the bezel on an NSButton. |
85 const int kImageTitleSpacing = 10; | 85 const int kImageTitleSpacing = 10; |
86 const int kBlueButtonHeight = 30; | 86 const int kBlueButtonHeight = 30; |
87 | 87 |
88 // Fixed size for embedded sign in pages as defined in Gaia. | 88 // Fixed size for embedded sign in pages as defined in Gaia. |
89 const CGFloat kFixedGaiaViewWidth = 360; | 89 const CGFloat kFixedGaiaViewWidth = 360; |
90 const CGFloat kFixedGaiaViewHeight = 400; | 90 const CGFloat kFixedGaiaViewHeight = 440; |
91 | 91 |
92 // Fixed size for the account removal view. | 92 // Fixed size for the account removal view. |
93 const CGFloat kFixedAccountRemovalViewWidth = 280; | 93 const CGFloat kFixedAccountRemovalViewWidth = 280; |
94 | 94 |
95 // Fixed size for the switch user view. | 95 // Fixed size for the switch user view. |
96 const int kFixedSwitchUserViewWidth = 280; | 96 const int kFixedSwitchUserViewWidth = 280; |
97 | 97 |
98 // The tag number for the primary account. | 98 // The tag number for the primary account. |
99 const int kPrimaryProfileTag = -1; | 99 const int kPrimaryProfileTag = -1; |
100 | 100 |
(...skipping 10 matching lines...) Expand all Loading... |
111 frame.size = size; | 111 frame.size = size; |
112 [window setFrame:frame display:YES]; | 112 [window setFrame:frame display:YES]; |
113 } | 113 } |
114 | 114 |
115 NSString* ElideEmail(const std::string& email, CGFloat width) { | 115 NSString* ElideEmail(const std::string& email, CGFloat width) { |
116 const base::string16 elidedEmail = gfx::ElideText( | 116 const base::string16 elidedEmail = gfx::ElideText( |
117 base::UTF8ToUTF16(email), gfx::FontList(), width, gfx::ELIDE_EMAIL); | 117 base::UTF8ToUTF16(email), gfx::FontList(), width, gfx::ELIDE_EMAIL); |
118 return base::SysUTF16ToNSString(elidedEmail); | 118 return base::SysUTF16ToNSString(elidedEmail); |
119 } | 119 } |
120 | 120 |
| 121 NSString* ElideMessage(const base::string16& message, CGFloat width) { |
| 122 return base::SysUTF16ToNSString( |
| 123 gfx::ElideText(message, gfx::FontList(), width, gfx::ELIDE_TAIL)); |
| 124 } |
| 125 |
121 // Builds a label with the given |title| anchored at |frame_origin|. Sets the | 126 // Builds a label with the given |title| anchored at |frame_origin|. Sets the |
122 // text color to |text_color| if not null. | 127 // text color to |text_color| if not null. |
123 NSTextField* BuildLabel(NSString* title, | 128 NSTextField* BuildLabel(NSString* title, |
124 NSPoint frame_origin, | 129 NSPoint frame_origin, |
125 NSColor* text_color) { | 130 NSColor* text_color) { |
126 base::scoped_nsobject<NSTextField> label( | 131 base::scoped_nsobject<NSTextField> label( |
127 [[NSTextField alloc] initWithFrame:NSZeroRect]); | 132 [[NSTextField alloc] initWithFrame:NSZeroRect]); |
128 [label setStringValue:title]; | 133 [label setStringValue:title]; |
129 [label setEditable:NO]; | 134 [label setEditable:NO]; |
130 [label setAlignment:NSLeftTextAlignment]; | 135 [label setAlignment:NSLeftTextAlignment]; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 // Returns the native dialog background color. | 188 // Returns the native dialog background color. |
184 NSColor* GetDialogBackgroundColor() { | 189 NSColor* GetDialogBackgroundColor() { |
185 return gfx::SkColorToCalibratedNSColor( | 190 return gfx::SkColorToCalibratedNSColor( |
186 ui::NativeTheme::instance()->GetSystemColor( | 191 ui::NativeTheme::instance()->GetSystemColor( |
187 ui::NativeTheme::kColorId_DialogBackground)); | 192 ui::NativeTheme::kColorId_DialogBackground)); |
188 } | 193 } |
189 | 194 |
190 // Builds a title card with one back button right aligned and one label center | 195 // Builds a title card with one back button right aligned and one label center |
191 // aligned. | 196 // aligned. |
192 NSView* BuildTitleCard(NSRect frame_rect, | 197 NSView* BuildTitleCard(NSRect frame_rect, |
193 NSString* message, | 198 const base::string16& message, |
194 id back_button_target, | 199 id back_button_target, |
195 SEL back_button_action) { | 200 SEL back_button_action) { |
196 base::scoped_nsobject<NSView> container( | 201 base::scoped_nsobject<NSView> container( |
197 [[NSView alloc] initWithFrame:frame_rect]); | 202 [[NSView alloc] initWithFrame:frame_rect]); |
198 | 203 |
199 base::scoped_nsobject<HoverImageButton> button( | 204 base::scoped_nsobject<HoverImageButton> button( |
200 [[HoverImageButton alloc] initWithFrame:frame_rect]); | 205 [[HoverImageButton alloc] initWithFrame:frame_rect]); |
201 [button setBordered:NO]; | 206 [button setBordered:NO]; |
202 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 207 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
203 [button setDefaultImage:rb->GetNativeImageNamed(IDR_BACK).ToNSImage()]; | 208 [button setDefaultImage:rb->GetNativeImageNamed(IDR_BACK).ToNSImage()]; |
204 [button setHoverImage:rb->GetNativeImageNamed(IDR_BACK_H).ToNSImage()]; | 209 [button setHoverImage:rb->GetNativeImageNamed(IDR_BACK_H).ToNSImage()]; |
205 [button setPressedImage:rb->GetNativeImageNamed(IDR_BACK_P).ToNSImage()]; | 210 [button setPressedImage:rb->GetNativeImageNamed(IDR_BACK_P).ToNSImage()]; |
206 [button setTarget:back_button_target]; | 211 [button setTarget:back_button_target]; |
207 [button setAction:back_button_action]; | 212 [button setAction:back_button_action]; |
208 [button setFrameSize:NSMakeSize(kProfileButtonHeight, kProfileButtonHeight)]; | 213 [button setFrameSize:NSMakeSize(kProfileButtonHeight, kProfileButtonHeight)]; |
209 [button setFrameOrigin:NSMakePoint(kHorizontalSpacing, 0)]; | 214 [button setFrameOrigin:NSMakePoint(kHorizontalSpacing, 0)]; |
210 | 215 |
211 NSTextField* title_label = BuildLabel(message, NSZeroPoint, nil); | 216 CGFloat max_label_width = frame_rect.size.width - |
| 217 (kHorizontalSpacing * 2 + kProfileButtonHeight) * 2; |
| 218 NSTextField* title_label = BuildLabel( |
| 219 ElideMessage(message, max_label_width), |
| 220 NSZeroPoint, nil); |
212 [title_label setAlignment:NSCenterTextAlignment]; | 221 [title_label setAlignment:NSCenterTextAlignment]; |
213 [title_label setFont:[NSFont labelFontOfSize:kTitleFontSize]]; | 222 [title_label setFont:[NSFont labelFontOfSize:kTitleFontSize]]; |
214 [title_label sizeToFit]; | 223 [title_label sizeToFit]; |
215 CGFloat x_offset = (frame_rect.size.width - NSWidth([title_label frame])) / 2; | 224 CGFloat x_offset = (frame_rect.size.width - NSWidth([title_label frame])) / 2; |
216 CGFloat y_offset = | 225 CGFloat y_offset = |
217 (NSHeight([button frame]) - NSHeight([title_label frame])) / 2; | 226 (NSHeight([button frame]) - NSHeight([title_label frame])) / 2; |
218 [title_label setFrameOrigin:NSMakePoint(x_offset, y_offset)]; | 227 [title_label setFrameOrigin:NSMakePoint(x_offset, y_offset)]; |
219 | 228 |
220 [container addSubview:button]; | 229 [container addSubview:button]; |
221 [container addSubview:title_label]; | 230 [container addSubview:title_label]; |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 NSRectFill(dirtyRect); | 767 NSRectFill(dirtyRect); |
759 [super drawRect:dirtyRect]; | 768 [super drawRect:dirtyRect]; |
760 } | 769 } |
761 @end | 770 @end |
762 | 771 |
763 @interface ProfileChooserController () | 772 @interface ProfileChooserController () |
764 // Builds the profile chooser view. | 773 // Builds the profile chooser view. |
765 - (NSView*)buildProfileChooserView; | 774 - (NSView*)buildProfileChooserView; |
766 | 775 |
767 // Builds a tutorial card with a title label using |titleMessage|, a content | 776 // Builds a tutorial card with a title label using |titleMessage|, a content |
768 // label using |contentMessage|, and a bottom row with a right-aligned link | 777 // label using |contentMessage|, a link using |linkMessage|, and a button using |
769 // using |linkMessage|, and a left aligned button using |buttonMessage|. | 778 // |buttonMessage|. If |stackButton| is YES, places the button above the link. |
770 // On click, the link would execute |linkAction|, and the button would execute | 779 // Otherwise places both on the same row with the link left aligned and button |
771 // |buttonAction|. It sets |tutorialMode_| to the given |mode|. | 780 // right aligned. On click, the link would execute |linkAction|, and the button |
| 781 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. |
772 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode | 782 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode |
773 titleMessage:(NSString*)titleMessage | 783 titleMessage:(NSString*)titleMessage |
774 contentMessage:(NSString*)contentMessage | 784 contentMessage:(NSString*)contentMessage |
775 linkMessage:(NSString*)linkMessage | 785 linkMessage:(NSString*)linkMessage |
776 buttonMessage:(NSString*)buttonMessage | 786 buttonMessage:(NSString*)buttonMessage |
| 787 stackButton:(BOOL)stackButton |
| 788 hasCloseButton:(BOOL)hasCloseButton |
777 linkAction:(SEL)linkAction | 789 linkAction:(SEL)linkAction |
778 buttonAction:(SEL)buttonAction; | 790 buttonAction:(SEL)buttonAction; |
779 | 791 |
780 // Builds a tutorial card to introduce an upgrade user to the new avatar menu if | 792 // Builds a tutorial card to introduce an upgrade user to the new avatar menu if |
781 // needed. |tutorial_shown| indicates if the tutorial has already been shown in | 793 // needed. |tutorial_shown| indicates if the tutorial has already been shown in |
782 // the previous active view. |avatar_item| refers to the current profile. | 794 // the previous active view. |avatar_item| refers to the current profile. |
783 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded; | 795 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded; |
784 | 796 |
785 // Builds a tutorial card to have the user confirm the last Chrome signin, | 797 // Builds a tutorial card to have the user confirm the last Chrome signin, |
786 // Chrome sync will be delayed until the user either dismisses the tutorial, or | 798 // Chrome sync will be delayed until the user either dismisses the tutorial, or |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 ProfileMetrics::LogProfileNewAvatarMenuNotYou( | 995 ProfileMetrics::LogProfileNewAvatarMenuNotYou( |
984 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_DISCONNECT); | 996 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_DISCONNECT); |
985 } | 997 } |
986 | 998 |
987 - (IBAction)navigateBackFromSwitchUserView:(id)sender { | 999 - (IBAction)navigateBackFromSwitchUserView:(id)sender { |
988 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; | 1000 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; |
989 ProfileMetrics::LogProfileNewAvatarMenuNotYou( | 1001 ProfileMetrics::LogProfileNewAvatarMenuNotYou( |
990 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_BACK); | 1002 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_BACK); |
991 } | 1003 } |
992 | 1004 |
| 1005 - (IBAction)dismissTutorial:(id)sender { |
| 1006 // Never shows the upgrade tutorial again if manually closed. |
| 1007 if (tutorialMode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { |
| 1008 browser_->profile()->GetPrefs()->SetInteger( |
| 1009 prefs::kProfileAvatarTutorialShown, |
| 1010 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); |
| 1011 } |
| 1012 |
| 1013 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; |
| 1014 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; |
| 1015 } |
| 1016 |
993 - (void)windowWillClose:(NSNotification*)notification { | 1017 - (void)windowWillClose:(NSNotification*)notification { |
994 if (tutorialMode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) { | 1018 if (tutorialMode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) { |
995 LoginUIServiceFactory::GetForProfile(browser_->profile())-> | 1019 LoginUIServiceFactory::GetForProfile(browser_->profile())-> |
996 SyncConfirmationUIClosed(false); | 1020 SyncConfirmationUIClosed(false); |
997 } | 1021 } |
998 | 1022 |
999 [super windowWillClose:notification]; | 1023 [super windowWillClose:notification]; |
1000 } | 1024 } |
1001 | 1025 |
1002 - (void)cleanUpEmbeddedViewContents { | 1026 - (void)cleanUpEmbeddedViewContents { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 break; | 1105 break; |
1082 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: | 1106 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: |
1083 subView = [self buildSwitchUserView]; | 1107 subView = [self buildSwitchUserView]; |
1084 break; | 1108 break; |
1085 case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER: | 1109 case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER: |
1086 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT: | 1110 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT: |
1087 subView = [self buildProfileChooserView]; | 1111 subView = [self buildProfileChooserView]; |
1088 break; | 1112 break; |
1089 } | 1113 } |
1090 | 1114 |
| 1115 // Clears tutorial mode for all non-profile-chooser views. |
| 1116 if (viewMode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) |
| 1117 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; |
| 1118 |
1091 [contentView addSubview:subView]; | 1119 [contentView addSubview:subView]; |
1092 SetWindowSize([self window], | 1120 SetWindowSize([self window], |
1093 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame]))); | 1121 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame]))); |
1094 } | 1122 } |
1095 | 1123 |
1096 - (NSView*)buildProfileChooserView { | 1124 - (NSView*)buildProfileChooserView { |
1097 base::scoped_nsobject<NSView> container( | 1125 base::scoped_nsobject<NSView> container( |
1098 [[NSView alloc] initWithFrame:NSZeroRect]); | 1126 [[NSView alloc] initWithFrame:NSZeroRect]); |
1099 | 1127 |
1100 NSView* tutorialView = nil; | 1128 NSView* tutorialView = nil; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_CONTENT_TEXT); | 1251 IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_CONTENT_TEXT); |
1224 NSString* linkMessage = l10n_util::GetNSString( | 1252 NSString* linkMessage = l10n_util::GetNSString( |
1225 IDS_PROFILES_SYNC_SETTINGS_LINK); | 1253 IDS_PROFILES_SYNC_SETTINGS_LINK); |
1226 NSString* buttonMessage = l10n_util::GetNSString( | 1254 NSString* buttonMessage = l10n_util::GetNSString( |
1227 IDS_PROFILES_TUTORIAL_OK_BUTTON); | 1255 IDS_PROFILES_TUTORIAL_OK_BUTTON); |
1228 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_CONFIRM_SIGNIN | 1256 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_CONFIRM_SIGNIN |
1229 titleMessage:titleMessage | 1257 titleMessage:titleMessage |
1230 contentMessage:contentMessage | 1258 contentMessage:contentMessage |
1231 linkMessage:linkMessage | 1259 linkMessage:linkMessage |
1232 buttonMessage:buttonMessage | 1260 buttonMessage:buttonMessage |
| 1261 stackButton:NO |
| 1262 hasCloseButton:NO |
1233 linkAction:@selector(configureSyncSettings:) | 1263 linkAction:@selector(configureSyncSettings:) |
1234 buttonAction:@selector(syncSettingsConfirmed:)]; | 1264 buttonAction:@selector(syncSettingsConfirmed:)]; |
1235 } | 1265 } |
1236 | 1266 |
1237 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded { | 1267 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded { |
1238 Profile* profile = browser_->profile(); | 1268 Profile* profile = browser_->profile(); |
1239 const AvatarMenu::Item& avatarItem = | 1269 const AvatarMenu::Item& avatarItem = |
1240 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); | 1270 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); |
1241 | 1271 |
1242 const int showCount = profile->GetPrefs()->GetInteger( | 1272 const int showCount = profile->GetPrefs()->GetInteger( |
(...skipping 11 matching lines...) Expand all Loading... |
1254 | 1284 |
1255 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( | 1285 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( |
1256 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); | 1286 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); |
1257 | 1287 |
1258 NSString* titleMessage = l10n_util::GetNSString( | 1288 NSString* titleMessage = l10n_util::GetNSString( |
1259 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE); | 1289 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE); |
1260 NSString* contentMessage = l10n_util::GetNSString( | 1290 NSString* contentMessage = l10n_util::GetNSString( |
1261 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT); | 1291 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT); |
1262 // For local profiles, the "Not you" link doesn't make sense. | 1292 // For local profiles, the "Not you" link doesn't make sense. |
1263 NSString* linkMessage = avatarItem.signed_in ? | 1293 NSString* linkMessage = avatarItem.signed_in ? |
1264 l10n_util::GetNSStringF(IDS_PROFILES_NOT_YOU, avatarItem.name) : nil; | 1294 ElideMessage( |
| 1295 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, avatarItem.name), |
| 1296 kFixedMenuWidth - 2 * kHorizontalSpacing) : |
| 1297 nil; |
1265 NSString* buttonMessage = l10n_util::GetNSString( | 1298 NSString* buttonMessage = l10n_util::GetNSString( |
1266 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON); | 1299 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON); |
1267 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE | 1300 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE |
1268 titleMessage:titleMessage | 1301 titleMessage:titleMessage |
1269 contentMessage:contentMessage | 1302 contentMessage:contentMessage |
1270 linkMessage:linkMessage | 1303 linkMessage:linkMessage |
1271 buttonMessage:buttonMessage | 1304 buttonMessage:buttonMessage |
| 1305 stackButton:YES |
| 1306 hasCloseButton:YES |
1272 linkAction:@selector(showSwitchUserView:) | 1307 linkAction:@selector(showSwitchUserView:) |
1273 buttonAction:@selector(seeWhatsNew:)]; | 1308 buttonAction:@selector(seeWhatsNew:)]; |
1274 } | 1309 } |
1275 | 1310 |
1276 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode | 1311 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode |
1277 titleMessage:(NSString*)titleMessage | 1312 titleMessage:(NSString*)titleMessage |
1278 contentMessage:(NSString*)contentMessage | 1313 contentMessage:(NSString*)contentMessage |
1279 linkMessage:(NSString*)linkMessage | 1314 linkMessage:(NSString*)linkMessage |
1280 buttonMessage:(NSString*)buttonMessage | 1315 buttonMessage:(NSString*)buttonMessage |
| 1316 stackButton:(BOOL)stackButton |
| 1317 hasCloseButton:(BOOL)hasCloseButton |
1281 linkAction:(SEL)linkAction | 1318 linkAction:(SEL)linkAction |
1282 buttonAction:(SEL)buttonAction { | 1319 buttonAction:(SEL)buttonAction { |
1283 tutorialMode_ = mode; | 1320 tutorialMode_ = mode; |
1284 | 1321 |
1285 NSColor* tutorialBackgroundColor = | 1322 NSColor* tutorialBackgroundColor = |
1286 gfx::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor); | 1323 gfx::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor); |
1287 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] | 1324 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] |
1288 initWithFrame:NSMakeRect(0, 0, kFixedMenuWidth, 0) | 1325 initWithFrame:NSMakeRect(0, 0, kFixedMenuWidth, 0) |
1289 withColor:tutorialBackgroundColor]); | 1326 withColor:tutorialBackgroundColor]); |
1290 CGFloat availableWidth = kFixedMenuWidth - 2 * kHorizontalSpacing; | 1327 CGFloat availableWidth = kFixedMenuWidth - 2 * kHorizontalSpacing; |
1291 CGFloat yOffset = kSmallVerticalSpacing; | 1328 CGFloat yOffset = kVerticalSpacing; |
1292 | 1329 |
1293 // Adds links and buttons at the bottom. | 1330 // Adds links and buttons at the bottom. |
1294 base::scoped_nsobject<NSButton> tutorialOkButton([[HoverButton alloc] | 1331 base::scoped_nsobject<NSButton> tutorialOkButton([[HoverButton alloc] |
1295 initWithFrame:NSZeroRect]); | 1332 initWithFrame:NSZeroRect]); |
1296 [tutorialOkButton setTitle:buttonMessage]; | 1333 [tutorialOkButton setTitle:buttonMessage]; |
1297 [tutorialOkButton setBezelStyle:NSRoundedBezelStyle]; | 1334 [tutorialOkButton setBezelStyle:NSRoundedBezelStyle]; |
1298 [tutorialOkButton setTarget:self]; | 1335 [tutorialOkButton setTarget:self]; |
1299 [tutorialOkButton setAction:buttonAction]; | 1336 [tutorialOkButton setAction:buttonAction]; |
| 1337 [tutorialOkButton setAlignment:NSCenterTextAlignment]; |
1300 [tutorialOkButton sizeToFit]; | 1338 [tutorialOkButton sizeToFit]; |
1301 NSSize buttonSize = [tutorialOkButton frame].size; | |
1302 const CGFloat kTopBottomTextPadding = 6; | |
1303 const CGFloat kLeftRightTextPadding = 15; | |
1304 buttonSize.width += 2 * kLeftRightTextPadding; | |
1305 buttonSize.height += 2 * kTopBottomTextPadding; | |
1306 [tutorialOkButton setFrameSize:buttonSize]; | |
1307 [tutorialOkButton setAlignment:NSCenterTextAlignment]; | |
1308 | 1339 |
1309 [tutorialOkButton setFrameOrigin:NSMakePoint( | 1340 NSButton* learnMoreLink = nil; |
1310 kFixedMenuWidth - NSWidth([tutorialOkButton frame]) - kHorizontalSpacing, | 1341 if (linkMessage) { |
1311 yOffset)]; | 1342 learnMoreLink = [self linkButtonWithTitle:linkMessage |
| 1343 frameOrigin:NSZeroPoint |
| 1344 action:linkAction]; |
| 1345 [[learnMoreLink cell] setTextColor:[NSColor whiteColor]]; |
| 1346 } |
| 1347 |
| 1348 if (stackButton) { |
| 1349 if (learnMoreLink) { |
| 1350 [learnMoreLink setFrameOrigin:NSMakePoint( |
| 1351 (kFixedMenuWidth - NSWidth([learnMoreLink frame])) / 2, yOffset)]; |
| 1352 } |
| 1353 [tutorialOkButton setFrameSize:NSMakeSize( |
| 1354 availableWidth, NSHeight([tutorialOkButton frame]))]; |
| 1355 [tutorialOkButton setFrameOrigin:NSMakePoint( |
| 1356 kHorizontalSpacing, |
| 1357 yOffset + (learnMoreLink ? NSHeight([learnMoreLink frame]) : 0))]; |
| 1358 } else { |
| 1359 NSSize buttonSize = [tutorialOkButton frame].size; |
| 1360 const CGFloat kTopBottomTextPadding = 6; |
| 1361 const CGFloat kLeftRightTextPadding = 15; |
| 1362 buttonSize.width += 2 * kLeftRightTextPadding; |
| 1363 buttonSize.height += 2 * kTopBottomTextPadding; |
| 1364 [tutorialOkButton setFrameSize:buttonSize]; |
| 1365 CGFloat buttonXOffset = kFixedMenuWidth - |
| 1366 NSWidth([tutorialOkButton frame]) - kHorizontalSpacing; |
| 1367 [tutorialOkButton setFrameOrigin:NSMakePoint(buttonXOffset, yOffset)]; |
| 1368 |
| 1369 if (learnMoreLink) { |
| 1370 CGFloat linkYOffset = yOffset + (NSHeight([tutorialOkButton frame]) - |
| 1371 NSHeight([learnMoreLink frame])) / 2; |
| 1372 [learnMoreLink setFrameOrigin:NSMakePoint( |
| 1373 kHorizontalSpacing, linkYOffset)]; |
| 1374 } |
| 1375 } |
| 1376 |
1312 [container addSubview:tutorialOkButton]; | 1377 [container addSubview:tutorialOkButton]; |
1313 | 1378 if (learnMoreLink) { |
1314 if (linkMessage) { | |
1315 NSButton* learnMoreLink = | |
1316 [self linkButtonWithTitle:linkMessage | |
1317 frameOrigin:NSZeroPoint | |
1318 action:linkAction]; | |
1319 [[learnMoreLink cell] setTextColor:[NSColor whiteColor]]; | |
1320 CGFloat linkYOffset = yOffset + (NSHeight([tutorialOkButton frame]) - | |
1321 NSHeight([learnMoreLink frame])) / 2; | |
1322 [learnMoreLink setFrameOrigin:NSMakePoint(kHorizontalSpacing, linkYOffset)]; | |
1323 [container addSubview:learnMoreLink]; | 1379 [container addSubview:learnMoreLink]; |
1324 yOffset = std::max(NSMaxY([learnMoreLink frame]), | 1380 yOffset = std::max(NSMaxY([learnMoreLink frame]), |
1325 NSMaxY([tutorialOkButton frame])) + kVerticalSpacing; | 1381 NSMaxY([tutorialOkButton frame])) + kVerticalSpacing; |
1326 } else { | 1382 } else { |
1327 yOffset = NSMaxY([tutorialOkButton frame]) + kVerticalSpacing; | 1383 yOffset = NSMaxY([tutorialOkButton frame]) + kVerticalSpacing; |
1328 } | 1384 } |
| 1385 |
1329 // Adds body content. | 1386 // Adds body content. |
1330 NSTextField* contentLabel = BuildLabel( | 1387 NSTextField* contentLabel = BuildLabel( |
1331 contentMessage, | 1388 contentMessage, |
1332 NSMakePoint(kHorizontalSpacing, yOffset), | 1389 NSMakePoint(kHorizontalSpacing, yOffset), |
1333 gfx::SkColorToSRGBNSColor(profiles::kAvatarTutorialContentTextColor)); | 1390 gfx::SkColorToSRGBNSColor(profiles::kAvatarTutorialContentTextColor)); |
1334 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; | 1391 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; |
1335 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; | 1392 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; |
1336 [container addSubview:contentLabel]; | 1393 [container addSubview:contentLabel]; |
1337 yOffset = NSMaxY([contentLabel frame]) + kSmallVerticalSpacing; | 1394 yOffset = NSMaxY([contentLabel frame]) + kSmallVerticalSpacing; |
1338 | 1395 |
1339 // Adds title. | 1396 // Adds title. |
1340 NSTextField* titleLabel = | 1397 NSTextField* titleLabel = |
1341 BuildLabel(titleMessage, | 1398 BuildLabel(titleMessage, |
1342 NSMakePoint(kHorizontalSpacing, yOffset), | 1399 NSMakePoint(kHorizontalSpacing, yOffset), |
1343 [NSColor whiteColor] /* text_color */); | 1400 [NSColor whiteColor] /* text_color */); |
1344 [titleLabel setFont:[NSFont labelFontOfSize:kTitleFontSize]]; | 1401 [titleLabel setFont:[NSFont labelFontOfSize:kTitleFontSize]]; |
1345 [titleLabel setFrameSize:NSMakeSize(availableWidth, 0)]; | 1402 |
| 1403 if (hasCloseButton) { |
| 1404 base::scoped_nsobject<HoverImageButton> closeButton( |
| 1405 [[HoverImageButton alloc] initWithFrame:NSZeroRect]); |
| 1406 [closeButton setBordered:NO]; |
| 1407 |
| 1408 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 1409 NSImage* closeImage = rb->GetNativeImageNamed(IDR_CLOSE_1).ToNSImage(); |
| 1410 CGFloat closeImageWidth = [closeImage size].width; |
| 1411 [closeButton setDefaultImage:closeImage]; |
| 1412 [closeButton setHoverImage: |
| 1413 rb->GetNativeImageNamed(IDR_CLOSE_1_H).ToNSImage()]; |
| 1414 [closeButton setPressedImage: |
| 1415 rb->GetNativeImageNamed(IDR_CLOSE_1_P).ToNSImage()]; |
| 1416 [closeButton setTarget:self]; |
| 1417 [closeButton setAction:@selector(dismissTutorial:)]; |
| 1418 [closeButton setFrameSize:[closeImage size]]; |
| 1419 [closeButton setFrameOrigin:NSMakePoint( |
| 1420 kFixedMenuWidth - kHorizontalSpacing - closeImageWidth, yOffset)]; |
| 1421 [container addSubview:closeButton]; |
| 1422 |
| 1423 [titleLabel setFrameSize:NSMakeSize( |
| 1424 availableWidth - closeImageWidth - kHorizontalSpacing, 0)]; |
| 1425 } else { |
| 1426 [titleLabel setFrameSize:NSMakeSize(availableWidth, 0)]; |
| 1427 } |
| 1428 |
1346 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel]; | 1429 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel]; |
1347 [container addSubview:titleLabel]; | 1430 [container addSubview:titleLabel]; |
1348 yOffset = NSMaxY([titleLabel frame]) + kVerticalSpacing; | 1431 yOffset = NSMaxY([titleLabel frame]) + kVerticalSpacing; |
1349 | 1432 |
1350 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; | 1433 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; |
1351 [container setFrameOrigin:NSZeroPoint]; | 1434 [container setFrameOrigin:NSZeroPoint]; |
1352 return container.autorelease(); | 1435 return container.autorelease(); |
1353 } | 1436 } |
1354 | 1437 |
1355 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item { | 1438 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item { |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1750 yOffset = NSMaxY([webview frame]); | 1833 yOffset = NSMaxY([webview frame]); |
1751 | 1834 |
1752 // Adds the title card. | 1835 // Adds the title card. |
1753 NSBox* separator = [self horizontalSeparatorWithFrame: | 1836 NSBox* separator = [self horizontalSeparatorWithFrame: |
1754 NSMakeRect(0, yOffset, kFixedGaiaViewWidth, 0)]; | 1837 NSMakeRect(0, yOffset, kFixedGaiaViewWidth, 0)]; |
1755 [container addSubview:separator]; | 1838 [container addSubview:separator]; |
1756 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; | 1839 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; |
1757 | 1840 |
1758 NSView* titleView = BuildTitleCard( | 1841 NSView* titleView = BuildTitleCard( |
1759 NSMakeRect(0, yOffset, kFixedGaiaViewWidth, 0), | 1842 NSMakeRect(0, yOffset, kFixedGaiaViewWidth, 0), |
1760 l10n_util::GetNSString(messageId), | 1843 l10n_util::GetStringUTF16(messageId), |
1761 self /* backButtonTarget*/, | 1844 self /* backButtonTarget*/, |
1762 @selector(navigateBackFromSigninPage:) /* backButtonAction */); | 1845 @selector(navigateBackFromSigninPage:) /* backButtonAction */); |
1763 [container addSubview:titleView]; | 1846 [container addSubview:titleView]; |
1764 yOffset = NSMaxY([titleView frame]); | 1847 yOffset = NSMaxY([titleView frame]); |
1765 | 1848 |
1766 [container setFrameSize:NSMakeSize(kFixedGaiaViewWidth, yOffset)]; | 1849 [container setFrameSize:NSMakeSize(kFixedGaiaViewWidth, yOffset)]; |
1767 return container.autorelease(); | 1850 return container.autorelease(); |
1768 } | 1851 } |
1769 | 1852 |
1770 - (NSView*)buildAccountRemovalView { | 1853 - (NSView*)buildAccountRemovalView { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1820 yOffset = NSMaxY([contentView frame]) + kVerticalSpacing; | 1903 yOffset = NSMaxY([contentView frame]) + kVerticalSpacing; |
1821 | 1904 |
1822 // Adds the title card. | 1905 // Adds the title card. |
1823 NSBox* separator = [self horizontalSeparatorWithFrame: | 1906 NSBox* separator = [self horizontalSeparatorWithFrame: |
1824 NSMakeRect(0, yOffset, kFixedAccountRemovalViewWidth, 0)]; | 1907 NSMakeRect(0, yOffset, kFixedAccountRemovalViewWidth, 0)]; |
1825 [container addSubview:separator]; | 1908 [container addSubview:separator]; |
1826 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; | 1909 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; |
1827 | 1910 |
1828 NSView* titleView = BuildTitleCard( | 1911 NSView* titleView = BuildTitleCard( |
1829 NSMakeRect(0, yOffset, kFixedAccountRemovalViewWidth,0), | 1912 NSMakeRect(0, yOffset, kFixedAccountRemovalViewWidth,0), |
1830 l10n_util::GetNSString(IDS_PROFILES_ACCOUNT_REMOVAL_TITLE), | 1913 l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_TITLE), |
1831 self /* backButtonTarget*/, | 1914 self /* backButtonTarget*/, |
1832 @selector(showAccountManagement:) /* backButtonAction */); | 1915 @selector(showAccountManagement:) /* backButtonAction */); |
1833 [container addSubview:titleView]; | 1916 [container addSubview:titleView]; |
1834 yOffset = NSMaxY([titleView frame]); | 1917 yOffset = NSMaxY([titleView frame]); |
1835 | 1918 |
1836 [container setFrameSize:NSMakeSize(kFixedAccountRemovalViewWidth, yOffset)]; | 1919 [container setFrameSize:NSMakeSize(kFixedAccountRemovalViewWidth, yOffset)]; |
1837 return container.autorelease(); | 1920 return container.autorelease(); |
1838 } | 1921 } |
1839 | 1922 |
1840 - (NSView*)buildSwitchUserView { | 1923 - (NSView*)buildSwitchUserView { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1877 action:@selector(showUserManager:)]; | 1960 action:@selector(showUserManager:)]; |
1878 [container addSubview:addPersonButton]; | 1961 [container addSubview:addPersonButton]; |
1879 yOffset = NSMaxY([addPersonButton frame]); | 1962 yOffset = NSMaxY([addPersonButton frame]); |
1880 | 1963 |
1881 separator = [self horizontalSeparatorWithFrame: | 1964 separator = [self horizontalSeparatorWithFrame: |
1882 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; | 1965 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; |
1883 [container addSubview:separator]; | 1966 [container addSubview:separator]; |
1884 yOffset = NSMaxY([separator frame]); | 1967 yOffset = NSMaxY([separator frame]); |
1885 | 1968 |
1886 // Adds the content text. | 1969 // Adds the content text. |
| 1970 base::string16 elidedName(gfx::ElideText( |
| 1971 avatarItem.name, gfx::FontList(), availableWidth, gfx::ELIDE_TAIL)); |
1887 NSTextField* contentLabel = BuildLabel( | 1972 NSTextField* contentLabel = BuildLabel( |
1888 l10n_util::GetNSStringF( | 1973 l10n_util::GetNSStringF(IDS_PROFILES_NOT_YOU_CONTENT_TEXT, elidedName), |
1889 IDS_PROFILES_NOT_YOU_CONTENT_TEXT, avatarItem.name), | |
1890 NSMakePoint(kHorizontalSpacing, yOffset + kVerticalSpacing), | 1974 NSMakePoint(kHorizontalSpacing, yOffset + kVerticalSpacing), |
1891 nil); | 1975 nil); |
1892 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; | 1976 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; |
1893 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; | 1977 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; |
1894 [container addSubview:contentLabel]; | 1978 [container addSubview:contentLabel]; |
1895 yOffset = NSMaxY([contentLabel frame]) + kVerticalSpacing; | 1979 yOffset = NSMaxY([contentLabel frame]) + kVerticalSpacing; |
1896 | 1980 |
1897 // Adds the title card. | 1981 // Adds the title card. |
1898 separator = [self horizontalSeparatorWithFrame: | 1982 separator = [self horizontalSeparatorWithFrame: |
1899 NSMakeRect(0, yOffset, kFixedSwitchUserViewWidth, 0)]; | 1983 NSMakeRect(0, yOffset, kFixedSwitchUserViewWidth, 0)]; |
1900 [container addSubview:separator]; | 1984 [container addSubview:separator]; |
1901 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; | 1985 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; |
1902 | 1986 |
1903 NSView* titleView = BuildTitleCard( | 1987 NSView* titleView = BuildTitleCard( |
1904 NSMakeRect(0, yOffset, kFixedSwitchUserViewWidth,0), | 1988 NSMakeRect(0, yOffset, kFixedSwitchUserViewWidth,0), |
1905 l10n_util::GetNSStringF(IDS_PROFILES_NOT_YOU, avatarItem.name), | 1989 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, avatarItem.name), |
1906 self /* backButtonTarget*/, | 1990 self /* backButtonTarget*/, |
1907 @selector(navigateBackFromSwitchUserView:) /* backButtonAction */); | 1991 @selector(navigateBackFromSwitchUserView:) /* backButtonAction */); |
1908 [container addSubview:titleView]; | 1992 [container addSubview:titleView]; |
1909 yOffset = NSMaxY([titleView frame]); | 1993 yOffset = NSMaxY([titleView frame]); |
1910 | 1994 |
1911 [container setFrameSize:NSMakeSize(kFixedAccountRemovalViewWidth, yOffset)]; | 1995 [container setFrameSize:NSMakeSize(kFixedAccountRemovalViewWidth, yOffset)]; |
1912 return container.autorelease(); | 1996 return container.autorelease(); |
1913 } | 1997 } |
1914 | 1998 |
1915 // Called when clicked on the settings link. | 1999 // Called when clicked on the settings link. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2029 } | 2113 } |
2030 | 2114 |
2031 - (bool)shouldShowGoIncognito { | 2115 - (bool)shouldShowGoIncognito { |
2032 bool incognitoAvailable = | 2116 bool incognitoAvailable = |
2033 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2117 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
2034 IncognitoModePrefs::DISABLED; | 2118 IncognitoModePrefs::DISABLED; |
2035 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2119 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
2036 } | 2120 } |
2037 | 2121 |
2038 @end | 2122 @end |
OLD | NEW |