Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #import "chrome/browser/ui/cocoa/one_click_signin_view_controller.h" | 5 #import "chrome/browser/ui/cocoa/one_click_signin_view_controller.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
| 10 #import "chrome/browser/ui/chrome_style.h" | 10 #import "chrome/browser/ui/chrome_style.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 @interface OneClickSigninViewController () | 31 @interface OneClickSigninViewController () |
| 32 - (CGFloat)initializeInformativeTextView; | 32 - (CGFloat)initializeInformativeTextView; |
| 33 - (void)close; | 33 - (void)close; |
| 34 @end | 34 @end |
| 35 | 35 |
| 36 @implementation OneClickSigninViewController | 36 @implementation OneClickSigninViewController |
| 37 | 37 |
| 38 | |
| 38 - (id)initWithNibName:(NSString*)nibName | 39 - (id)initWithNibName:(NSString*)nibName |
| 39 webContents:(content::WebContents*)webContents | 40 webContents:(content::WebContents*)webContents |
| 40 syncCallback:(const BrowserWindow::StartSyncCallback&)syncCallback | 41 syncCallback:(const BrowserWindow::StartSyncCallback&)syncCallback |
| 41 closeCallback:(const base::Closure&)closeCallback { | 42 closeCallback:(const base::Closure&)closeCallback |
| 43 isSyncDialog:(BOOL)isSyncDialog | |
| 44 errorMessage:(NSString*)errorMessage { | |
| 42 if ((self = [super initWithNibName:nibName | 45 if ((self = [super initWithNibName:nibName |
| 43 bundle:base::mac::FrameworkBundle()])) { | 46 bundle:base::mac::FrameworkBundle()])) { |
| 44 webContents_ = webContents; | 47 webContents_ = webContents; |
| 45 startSyncCallback_ = syncCallback; | 48 startSyncCallback_ = syncCallback; |
| 46 closeCallback_ = closeCallback; | 49 closeCallback_ = closeCallback; |
| 47 DCHECK(!startSyncCallback_.is_null()); | 50 isSyncDialog_ = isSyncDialog; |
| 51 errorMessage_ = errorMessage; | |
| 52 | |
| 53 if (isSyncDialog_) | |
| 54 DCHECK(!startSyncCallback_.is_null()); | |
| 48 } | 55 } |
| 49 return self; | 56 return self; |
| 50 } | 57 } |
| 51 | 58 |
| 52 - (void)viewWillClose { | 59 - (void)viewWillClose { |
| 53 if (!startSyncCallback_.is_null()) { | 60 if (isSyncDialog_ && !startSyncCallback_.is_null()) { |
| 54 base::ResetAndReturn(&startSyncCallback_).Run( | 61 base::ResetAndReturn(&startSyncCallback_).Run( |
| 55 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | 62 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); |
| 56 } | 63 } |
| 57 } | 64 } |
| 58 | 65 |
| 59 - (IBAction)ok:(id)sender { | 66 - (IBAction)ok:(id)sender { |
| 60 base::ResetAndReturn(&startSyncCallback_).Run( | 67 if (isSyncDialog_) { |
| 68 base::ResetAndReturn(&startSyncCallback_).Run( | |
| 61 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | 69 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); |
| 70 } | |
| 62 [self close]; | 71 [self close]; |
| 63 } | 72 } |
| 64 | 73 |
| 65 - (IBAction)onClickUndo:(id)sender { | 74 - (IBAction)onClickUndo:(id)sender { |
| 66 base::ResetAndReturn(&startSyncCallback_).Run( | 75 if (isSyncDialog_) { |
| 67 OneClickSigninSyncStarter::UNDO_SYNC); | 76 base::ResetAndReturn(&startSyncCallback_).Run( |
| 77 OneClickSigninSyncStarter::UNDO_SYNC); | |
| 78 } | |
| 68 [self close]; | 79 [self close]; |
| 69 } | 80 } |
| 70 | 81 |
| 71 - (IBAction)onClickAdvancedLink:(id)sender { | 82 - (IBAction)onClickAdvancedLink:(id)sender { |
| 72 base::ResetAndReturn(&startSyncCallback_).Run( | 83 if (isSyncDialog_) { |
| 73 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 84 base::ResetAndReturn(&startSyncCallback_).Run( |
| 85 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | |
| 86 } else { | |
| 87 content::OpenURLParams params(GURL(chrome::kChromeUISettingsURL), | |
| 88 content::Referrer(), CURRENT_TAB, | |
| 89 content::PAGE_TRANSITION_LINK, false); | |
| 90 webContents_->OpenURL(params); | |
| 91 } | |
| 74 [self close]; | 92 [self close]; |
| 75 } | 93 } |
| 76 | 94 |
| 77 - (void)awakeFromNib { | 95 - (void)awakeFromNib { |
| 78 // Lay out the text controls from the bottom up. | 96 // Lay out the text controls from the bottom up. |
| 79 CGFloat totalYOffset = 0.0; | 97 CGFloat totalYOffset = 0.0; |
| 80 | 98 |
| 81 totalYOffset += | 99 totalYOffset += |
| 82 [GTMUILocalizerAndLayoutTweaker sizeToFitView:advancedLink_].height; | 100 [GTMUILocalizerAndLayoutTweaker sizeToFitView:advancedLink_].height; |
| 83 [[advancedLink_ cell] setTextColor: | 101 [[advancedLink_ cell] setTextColor: |
| 84 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor())]; | 102 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor())]; |
| 85 | 103 |
| 86 if (informativePlaceholderTextField_) { | 104 if (informativePlaceholderTextField_) { |
| 87 ShiftOriginY(informativePlaceholderTextField_, totalYOffset); | 105 ShiftOriginY(informativePlaceholderTextField_, totalYOffset); |
| 88 totalYOffset += [self initializeInformativeTextView]; | 106 totalYOffset += [self initializeInformativeTextView]; |
| 89 } | 107 } |
| 90 | 108 |
| 91 ShiftOriginY(messageTextField_, totalYOffset); | 109 ShiftOriginY(messageTextField_, totalYOffset); |
| 92 totalYOffset += | 110 totalYOffset += |
| 93 [GTMUILocalizerAndLayoutTweaker | 111 [GTMUILocalizerAndLayoutTweaker |
| 94 sizeToFitFixedWidthTextField:messageTextField_]; | 112 sizeToFitFixedWidthTextField:messageTextField_]; |
| 95 | 113 |
| 96 if (closeButton_) | 114 if (closeButton_) |
| 97 ShiftOriginY(closeButton_, totalYOffset); | 115 ShiftOriginY(closeButton_, totalYOffset); |
| 98 | 116 |
| 99 NSSize delta = NSMakeSize(0.0, totalYOffset); | 117 NSSize delta = NSMakeSize(0.0, totalYOffset); |
| 100 | 118 |
| 119 if (!isSyncDialog_ && [errorMessage_ length] != 0) | |
| 120 [messageTextField_ setStringValue:errorMessage_]; | |
| 121 | |
| 101 // Resize bubble and window to hold the controls. | 122 // Resize bubble and window to hold the controls. |
| 102 [GTMUILocalizerAndLayoutTweaker | 123 [GTMUILocalizerAndLayoutTweaker |
| 103 resizeViewWithoutAutoResizingSubViews:[self view] | 124 resizeViewWithoutAutoResizingSubViews:[self view] |
| 104 delta:delta]; | 125 delta:delta]; |
| 105 } | 126 } |
| 106 | 127 |
| 107 - (CGFloat)initializeInformativeTextView { | 128 - (CGFloat)initializeInformativeTextView { |
| 108 NSRect oldFrame = [informativePlaceholderTextField_ frame]; | 129 NSRect oldFrame = [informativePlaceholderTextField_ frame]; |
| 109 | 130 |
| 110 // Replace the placeholder NSTextField with the real label NSTextView. The | 131 // Replace the placeholder NSTextField with the real label NSTextView. The |
| 111 // former doesn't show links in a nice way, but the latter can't be added in | 132 // former doesn't show links in a nice way, but the latter can't be added in |
| 112 // a xib without a containing scroll view, so create the NSTextView | 133 // a xib without a containing scroll view, so create the NSTextView |
| 113 // programmatically. | 134 // programmatically. |
| 114 informativeTextView_.reset( | 135 informativeTextView_.reset( |
| 115 [[HyperlinkTextView alloc] initWithFrame:oldFrame]); | 136 [[HyperlinkTextView alloc] initWithFrame:oldFrame]); |
| 116 [informativeTextView_.get() setAutoresizingMask: | 137 [informativeTextView_.get() setAutoresizingMask: |
| 117 [informativePlaceholderTextField_ autoresizingMask]]; | 138 [informativePlaceholderTextField_ autoresizingMask]]; |
| 118 [informativeTextView_.get() setDelegate:self]; | 139 [informativeTextView_.get() setDelegate:self]; |
| 119 | 140 |
| 120 // Set the text. | 141 // Set the text. |
| 121 NSString* learnMoreText = l10n_util::GetNSStringWithFixup(IDS_LEARN_MORE); | 142 NSString* learnMoreText = l10n_util::GetNSStringWithFixup(IDS_LEARN_MORE); |
| 122 NSString* messageText = | 143 NSString* messageText; |
| 123 l10n_util::GetNSStringWithFixup(IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE); | 144 |
| 124 messageText = [messageText stringByAppendingString:@" "]; | 145 ui::ResourceBundle::FontStyle fontStyle = isSyncDialog_ ? |
| 146 chrome_style::kTextFontStyle : ui::ResourceBundle::SmallFont; | |
| 125 NSFont* font = ui::ResourceBundle::GetSharedInstance().GetFont( | 147 NSFont* font = ui::ResourceBundle::GetSharedInstance().GetFont( |
| 126 chrome_style::kTextFontStyle).GetNativeFont(); | 148 fontStyle).GetNativeFont(); |
| 149 | |
| 150 // The non-modal bubble already has a text content and only needs the | |
| 151 // Learn More link (in a smaller font). | |
| 152 if (isSyncDialog_) { | |
| 153 messageText = l10n_util::GetNSStringWithFixup( | |
| 154 IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE); | |
| 155 messageText = [messageText stringByAppendingString:@" "]; | |
|
Alexei Svitkine (slow)
2013/04/22 18:16:51
What the reason for appending a space here?
noms (inactive)
2013/04/23 18:52:48
In the modal dialog, the Learn More link is append
| |
| 156 } else { | |
| 157 messageText = @""; | |
| 158 } | |
| 159 | |
| 127 NSColor* linkColor = | 160 NSColor* linkColor = |
| 128 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor()); | 161 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor()); |
| 129 [informativeTextView_ setMessageAndLink:messageText | 162 [informativeTextView_ setMessageAndLink:messageText |
| 130 withLink:learnMoreText | 163 withLink:learnMoreText |
| 131 atOffset:[messageText length] | 164 atOffset:[messageText length] |
| 132 font:font | 165 font:font |
| 133 messageColor:[NSColor blackColor] | 166 messageColor:[NSColor blackColor] |
| 134 linkColor:linkColor]; | 167 linkColor:linkColor]; |
| 135 | 168 |
| 136 // Size to fit. | 169 // Size to fit. |
| 137 [[informativePlaceholderTextField_ cell] setAttributedStringValue: | 170 [[informativePlaceholderTextField_ cell] setAttributedStringValue: |
| 138 [informativeTextView_ attributedString]]; | 171 [informativeTextView_ attributedString]]; |
| 139 [GTMUILocalizerAndLayoutTweaker | 172 [GTMUILocalizerAndLayoutTweaker |
| 140 sizeToFitFixedWidthTextField:informativePlaceholderTextField_]; | 173 sizeToFitFixedWidthTextField:informativePlaceholderTextField_]; |
| 141 NSRect newFrame = [informativePlaceholderTextField_ frame]; | 174 NSRect newFrame = [informativePlaceholderTextField_ frame]; |
| 142 [informativeTextView_ setFrame:newFrame]; | 175 [informativeTextView_ setFrame:newFrame]; |
| 143 | 176 |
| 144 // Swap placeholder. | 177 // Swap placeholder. |
| 145 [[informativePlaceholderTextField_ superview] | 178 [[informativePlaceholderTextField_ superview] |
| 146 replaceSubview:informativePlaceholderTextField_ | 179 replaceSubview:informativePlaceholderTextField_ |
| 147 with:informativeTextView_.get()]; | 180 with:informativeTextView_.get()]; |
| 148 informativePlaceholderTextField_ = nil; // Now released. | 181 informativePlaceholderTextField_ = nil; // Now released. |
| 149 | 182 |
| 150 return NSHeight(newFrame) - NSHeight(oldFrame); | 183 return NSHeight(newFrame) - NSHeight(oldFrame); |
| 151 } | 184 } |
| 152 | 185 |
| 153 - (BOOL)textView:(NSTextView*)textView | 186 - (BOOL)textView:(NSTextView*)textView |
| 154 clickedOnLink:(id)link | 187 clickedOnLink:(id)link |
| 155 atIndex:(NSUInteger)charIndex { | 188 atIndex:(NSUInteger)charIndex { |
| 189 WindowOpenDisposition location = isSyncDialog_ ? | |
| 190 NEW_WINDOW : NEW_FOREGROUND_TAB; | |
| 191 | |
| 156 content::OpenURLParams params(GURL(chrome::kChromeSyncLearnMoreURL), | 192 content::OpenURLParams params(GURL(chrome::kChromeSyncLearnMoreURL), |
| 157 content::Referrer(), NEW_WINDOW, | 193 content::Referrer(), location, |
| 158 content::PAGE_TRANSITION_LINK, false); | 194 content::PAGE_TRANSITION_LINK, false); |
| 159 webContents_->OpenURL(params); | 195 webContents_->OpenURL(params); |
| 160 return YES; | 196 return YES; |
| 161 } | 197 } |
| 162 | 198 |
| 163 - (void)close { | 199 - (void)close { |
| 164 base::ResetAndReturn(&closeCallback_).Run(); | 200 base::ResetAndReturn(&closeCallback_).Run(); |
| 165 } | 201 } |
| 166 | 202 |
| 167 @end | 203 @end |
| OLD | NEW |