| 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_.reset([errorMessage retain]); |
| 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 // This is usually called after a click handler has initiated sync |
| 61 // and has reset the callback. However, in the case that we are closing |
| 62 // the window and nothing else has initiated the sync, we must do so here |
| 63 if (isSyncDialog_ && !startSyncCallback_.is_null()) { |
| 54 base::ResetAndReturn(&startSyncCallback_).Run( | 64 base::ResetAndReturn(&startSyncCallback_).Run( |
| 55 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | 65 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); |
| 56 } | 66 } |
| 57 } | 67 } |
| 58 | 68 |
| 59 - (IBAction)ok:(id)sender { | 69 - (IBAction)ok:(id)sender { |
| 60 base::ResetAndReturn(&startSyncCallback_).Run( | 70 if (isSyncDialog_) { |
| 71 base::ResetAndReturn(&startSyncCallback_).Run( |
| 61 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | 72 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); |
| 73 } |
| 62 [self close]; | 74 [self close]; |
| 63 } | 75 } |
| 64 | 76 |
| 65 - (IBAction)onClickUndo:(id)sender { | 77 - (IBAction)onClickUndo:(id)sender { |
| 66 base::ResetAndReturn(&startSyncCallback_).Run( | 78 if (isSyncDialog_) { |
| 67 OneClickSigninSyncStarter::UNDO_SYNC); | 79 base::ResetAndReturn(&startSyncCallback_).Run( |
| 80 OneClickSigninSyncStarter::UNDO_SYNC); |
| 81 } |
| 68 [self close]; | 82 [self close]; |
| 69 } | 83 } |
| 70 | 84 |
| 71 - (IBAction)onClickAdvancedLink:(id)sender { | 85 - (IBAction)onClickAdvancedLink:(id)sender { |
| 72 base::ResetAndReturn(&startSyncCallback_).Run( | 86 if (isSyncDialog_) { |
| 73 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 87 base::ResetAndReturn(&startSyncCallback_).Run( |
| 88 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
| 89 } else { |
| 90 content::OpenURLParams params(GURL(chrome::kChromeUISettingsURL), |
| 91 content::Referrer(), CURRENT_TAB, |
| 92 content::PAGE_TRANSITION_LINK, false); |
| 93 webContents_->OpenURL(params); |
| 94 } |
| 74 [self close]; | 95 [self close]; |
| 75 } | 96 } |
| 76 | 97 |
| 77 - (void)awakeFromNib { | 98 - (void)awakeFromNib { |
| 78 // Lay out the text controls from the bottom up. | 99 // Lay out the text controls from the bottom up. |
| 79 CGFloat totalYOffset = 0.0; | 100 CGFloat totalYOffset = 0.0; |
| 80 | 101 |
| 81 totalYOffset += | 102 totalYOffset += |
| 82 [GTMUILocalizerAndLayoutTweaker sizeToFitView:advancedLink_].height; | 103 [GTMUILocalizerAndLayoutTweaker sizeToFitView:advancedLink_].height; |
| 83 [[advancedLink_ cell] setTextColor: | 104 [[advancedLink_ cell] setTextColor: |
| 84 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor())]; | 105 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor())]; |
| 85 | 106 |
| 86 if (informativePlaceholderTextField_) { | 107 if (informativePlaceholderTextField_) { |
| 87 ShiftOriginY(informativePlaceholderTextField_, totalYOffset); | 108 ShiftOriginY(informativePlaceholderTextField_, totalYOffset); |
| 88 totalYOffset += [self initializeInformativeTextView]; | 109 totalYOffset += [self initializeInformativeTextView]; |
| 89 } | 110 } |
| 90 | 111 |
| 91 ShiftOriginY(messageTextField_, totalYOffset); | 112 ShiftOriginY(messageTextField_, totalYOffset); |
| 92 totalYOffset += | 113 totalYOffset += |
| 93 [GTMUILocalizerAndLayoutTweaker | 114 [GTMUILocalizerAndLayoutTweaker |
| 94 sizeToFitFixedWidthTextField:messageTextField_]; | 115 sizeToFitFixedWidthTextField:messageTextField_]; |
| 95 | 116 |
| 96 if (closeButton_) | 117 if (closeButton_) |
| 97 ShiftOriginY(closeButton_, totalYOffset); | 118 ShiftOriginY(closeButton_, totalYOffset); |
| 98 | 119 |
| 99 NSSize delta = NSMakeSize(0.0, totalYOffset); | 120 NSSize delta = NSMakeSize(0.0, totalYOffset); |
| 100 | 121 |
| 122 if (!isSyncDialog_ && [errorMessage_ length] != 0) |
| 123 [messageTextField_ setStringValue:errorMessage_]; |
| 124 |
| 101 // Resize bubble and window to hold the controls. | 125 // Resize bubble and window to hold the controls. |
| 102 [GTMUILocalizerAndLayoutTweaker | 126 [GTMUILocalizerAndLayoutTweaker |
| 103 resizeViewWithoutAutoResizingSubViews:[self view] | 127 resizeViewWithoutAutoResizingSubViews:[self view] |
| 104 delta:delta]; | 128 delta:delta]; |
| 105 } | 129 } |
| 106 | 130 |
| 107 - (CGFloat)initializeInformativeTextView { | 131 - (CGFloat)initializeInformativeTextView { |
| 108 NSRect oldFrame = [informativePlaceholderTextField_ frame]; | 132 NSRect oldFrame = [informativePlaceholderTextField_ frame]; |
| 109 | 133 |
| 110 // Replace the placeholder NSTextField with the real label NSTextView. The | 134 // 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 | 135 // 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 | 136 // a xib without a containing scroll view, so create the NSTextView |
| 113 // programmatically. | 137 // programmatically. |
| 114 informativeTextView_.reset( | 138 informativeTextView_.reset( |
| 115 [[HyperlinkTextView alloc] initWithFrame:oldFrame]); | 139 [[HyperlinkTextView alloc] initWithFrame:oldFrame]); |
| 116 [informativeTextView_.get() setAutoresizingMask: | 140 [informativeTextView_.get() setAutoresizingMask: |
| 117 [informativePlaceholderTextField_ autoresizingMask]]; | 141 [informativePlaceholderTextField_ autoresizingMask]]; |
| 118 [informativeTextView_.get() setDelegate:self]; | 142 [informativeTextView_.get() setDelegate:self]; |
| 119 | 143 |
| 120 // Set the text. | 144 // Set the text. |
| 121 NSString* learnMoreText = l10n_util::GetNSStringWithFixup(IDS_LEARN_MORE); | 145 NSString* learnMoreText = l10n_util::GetNSStringWithFixup(IDS_LEARN_MORE); |
| 122 NSString* messageText = | 146 NSString* messageText; |
| 123 l10n_util::GetNSStringWithFixup(IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE); | 147 |
| 124 messageText = [messageText stringByAppendingString:@" "]; | 148 ui::ResourceBundle::FontStyle fontStyle = isSyncDialog_ ? |
| 149 chrome_style::kTextFontStyle : ui::ResourceBundle::SmallFont; |
| 125 NSFont* font = ui::ResourceBundle::GetSharedInstance().GetFont( | 150 NSFont* font = ui::ResourceBundle::GetSharedInstance().GetFont( |
| 126 chrome_style::kTextFontStyle).GetNativeFont(); | 151 fontStyle).GetNativeFont(); |
| 152 |
| 153 // The non-modal bubble already has a text content and only needs the |
| 154 // Learn More link (in a smaller font). |
| 155 if (isSyncDialog_) { |
| 156 messageText = l10n_util::GetNSStringWithFixup( |
| 157 IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE); |
| 158 messageText = [messageText stringByAppendingString:@" "]; |
| 159 } else { |
| 160 messageText = @""; |
| 161 } |
| 162 |
| 127 NSColor* linkColor = | 163 NSColor* linkColor = |
| 128 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor()); | 164 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor()); |
| 129 [informativeTextView_ setMessageAndLink:messageText | 165 [informativeTextView_ setMessageAndLink:messageText |
| 130 withLink:learnMoreText | 166 withLink:learnMoreText |
| 131 atOffset:[messageText length] | 167 atOffset:[messageText length] |
| 132 font:font | 168 font:font |
| 133 messageColor:[NSColor blackColor] | 169 messageColor:[NSColor blackColor] |
| 134 linkColor:linkColor]; | 170 linkColor:linkColor]; |
| 135 | 171 |
| 136 // Size to fit. | 172 // Size to fit. |
| 137 [[informativePlaceholderTextField_ cell] setAttributedStringValue: | 173 [[informativePlaceholderTextField_ cell] setAttributedStringValue: |
| 138 [informativeTextView_ attributedString]]; | 174 [informativeTextView_ attributedString]]; |
| 139 [GTMUILocalizerAndLayoutTweaker | 175 [GTMUILocalizerAndLayoutTweaker |
| 140 sizeToFitFixedWidthTextField:informativePlaceholderTextField_]; | 176 sizeToFitFixedWidthTextField:informativePlaceholderTextField_]; |
| 141 NSRect newFrame = [informativePlaceholderTextField_ frame]; | 177 NSRect newFrame = [informativePlaceholderTextField_ frame]; |
| 142 [informativeTextView_ setFrame:newFrame]; | 178 [informativeTextView_ setFrame:newFrame]; |
| 143 | 179 |
| 144 // Swap placeholder. | 180 // Swap placeholder. |
| 145 [[informativePlaceholderTextField_ superview] | 181 [[informativePlaceholderTextField_ superview] |
| 146 replaceSubview:informativePlaceholderTextField_ | 182 replaceSubview:informativePlaceholderTextField_ |
| 147 with:informativeTextView_.get()]; | 183 with:informativeTextView_.get()]; |
| 148 informativePlaceholderTextField_ = nil; // Now released. | 184 informativePlaceholderTextField_ = nil; // Now released. |
| 149 | 185 |
| 150 return NSHeight(newFrame) - NSHeight(oldFrame); | 186 return NSHeight(newFrame) - NSHeight(oldFrame); |
| 151 } | 187 } |
| 152 | 188 |
| 153 - (BOOL)textView:(NSTextView*)textView | 189 - (BOOL)textView:(NSTextView*)textView |
| 154 clickedOnLink:(id)link | 190 clickedOnLink:(id)link |
| 155 atIndex:(NSUInteger)charIndex { | 191 atIndex:(NSUInteger)charIndex { |
| 192 WindowOpenDisposition location = isSyncDialog_ ? |
| 193 NEW_WINDOW : NEW_FOREGROUND_TAB; |
| 194 |
| 156 content::OpenURLParams params(GURL(chrome::kChromeSyncLearnMoreURL), | 195 content::OpenURLParams params(GURL(chrome::kChromeSyncLearnMoreURL), |
| 157 content::Referrer(), NEW_WINDOW, | 196 content::Referrer(), location, |
| 158 content::PAGE_TRANSITION_LINK, false); | 197 content::PAGE_TRANSITION_LINK, false); |
| 159 webContents_->OpenURL(params); | 198 webContents_->OpenURL(params); |
| 160 return YES; | 199 return YES; |
| 161 } | 200 } |
| 162 | 201 |
| 163 - (void)close { | 202 - (void)close { |
| 164 base::ResetAndReturn(&closeCallback_).Run(); | 203 base::ResetAndReturn(&closeCallback_).Run(); |
| 165 } | 204 } |
| 166 | 205 |
| 167 @end | 206 @end |
| OLD | NEW |