| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/autofill/autofill_main_container.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 - (void)loadView { | 43 - (void)loadView { |
| 44 [self buildWindowButtonsForFrame:NSZeroRect]; | 44 [self buildWindowButtonsForFrame:NSZeroRect]; |
| 45 | 45 |
| 46 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); | 46 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); |
| 47 [view setAutoresizesSubviews:YES]; | 47 [view setAutoresizesSubviews:YES]; |
| 48 [view setSubviews:@[buttonContainer_]]; | 48 [view setSubviews:@[buttonContainer_]]; |
| 49 [self setView:view]; | 49 [self setView:view]; |
| 50 | 50 |
| 51 [self layoutButtons]; | 51 [self layoutButtons]; |
| 52 | 52 |
| 53 // Set up "Save in Chrome" checkbox. |
| 54 saveInChromeCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); |
| 55 [saveInChromeCheckbox_ setButtonType:NSSwitchButton]; |
| 56 [saveInChromeCheckbox_ setTitle: |
| 57 base::SysUTF16ToNSString(controller_->SaveLocallyText())]; |
| 58 [saveInChromeCheckbox_ setState:NSOnState]; |
| 59 [saveInChromeCheckbox_ sizeToFit]; |
| 60 [[self view] addSubview:saveInChromeCheckbox_]; |
| 61 |
| 53 detailsContainer_.reset( | 62 detailsContainer_.reset( |
| 54 [[AutofillDetailsContainer alloc] initWithController:controller_]); | 63 [[AutofillDetailsContainer alloc] initWithController:controller_]); |
| 55 NSSize frameSize = [[detailsContainer_ view] frame].size; | 64 NSSize frameSize = [[detailsContainer_ view] frame].size; |
| 56 [[detailsContainer_ view] setFrameOrigin: | 65 [[detailsContainer_ view] setFrameOrigin: |
| 57 NSMakePoint(0, NSHeight([buttonContainer_ frame]))]; | 66 NSMakePoint(0, NSHeight([buttonContainer_ frame]))]; |
| 58 frameSize.height += NSHeight([buttonContainer_ frame]); | 67 frameSize.height += NSHeight([buttonContainer_ frame]); |
| 59 [[self view] setFrameSize:frameSize]; | 68 [[self view] setFrameSize:frameSize]; |
| 60 [[self view] addSubview:[detailsContainer_ view]]; | 69 [[self view] addSubview:[detailsContainer_ view]]; |
| 61 | 70 |
| 62 legalDocumentsView_.reset( | 71 legalDocumentsView_.reset( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 if (![legalDocumentsView_ isHidden]) { | 124 if (![legalDocumentsView_ isHidden]) { |
| 116 [legalDocumentsView_ setFrameSize: | 125 [legalDocumentsView_ setFrameSize: |
| 117 [self preferredLegalDocumentSizeForWidth:preferredContainerSize.width]]; | 126 [self preferredLegalDocumentSizeForWidth:preferredContainerSize.width]]; |
| 118 currentY = NSMaxY([legalDocumentsView_ frame]) + kVerticalSpacing; | 127 currentY = NSMaxY([legalDocumentsView_ frame]) + kVerticalSpacing; |
| 119 } | 128 } |
| 120 | 129 |
| 121 NSRect buttonFrame = [buttonContainer_ frame]; | 130 NSRect buttonFrame = [buttonContainer_ frame]; |
| 122 buttonFrame.origin.y = currentY; | 131 buttonFrame.origin.y = currentY; |
| 123 [buttonContainer_ setFrameOrigin:buttonFrame.origin]; | 132 [buttonContainer_ setFrameOrigin:buttonFrame.origin]; |
| 124 | 133 |
| 134 NSRect checkboxFrame = [saveInChromeCheckbox_ frame]; |
| 135 checkboxFrame.origin.y = NSMidY(buttonFrame) - NSHeight(checkboxFrame) / 2.0; |
| 136 [saveInChromeCheckbox_ setFrameOrigin:checkboxFrame.origin]; |
| 137 |
| 125 [detailsContainer_ performLayout]; | 138 [detailsContainer_ performLayout]; |
| 126 NSRect containerFrame = [[detailsContainer_ view] frame]; | 139 NSRect containerFrame = [[detailsContainer_ view] frame]; |
| 127 containerFrame.origin.y = NSMaxY(buttonFrame); | 140 containerFrame.origin.y = NSMaxY(buttonFrame); |
| 128 [[detailsContainer_ view] setFrameOrigin:containerFrame.origin]; | 141 [[detailsContainer_ view] setFrameOrigin:containerFrame.origin]; |
| 129 | 142 |
| 130 NSRect notificationFrame; | 143 NSRect notificationFrame; |
| 131 notificationFrame.origin = NSMakePoint(0, NSMaxY(containerFrame)); | 144 notificationFrame.origin = NSMakePoint(0, NSMaxY(containerFrame)); |
| 132 notificationFrame.size = [notificationContainer_ preferredSizeForWidth: | 145 notificationFrame.size = [notificationContainer_ preferredSizeForWidth: |
| 133 preferredContainerSize.width]; | 146 preferredContainerSize.width]; |
| 134 [[notificationContainer_ view] setFrame:notificationFrame]; | 147 [[notificationContainer_ view] setFrame:notificationFrame]; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 legalDocumentsSizeDirty_ = NO; | 214 legalDocumentsSizeDirty_ = NO; |
| 202 legalDocumentsSize_ = newFrame.size; | 215 legalDocumentsSize_ = newFrame.size; |
| 203 return legalDocumentsSize_; | 216 return legalDocumentsSize_; |
| 204 } | 217 } |
| 205 | 218 |
| 206 - (AutofillSectionContainer*)sectionForId:(autofill::DialogSection)section { | 219 - (AutofillSectionContainer*)sectionForId:(autofill::DialogSection)section { |
| 207 return [detailsContainer_ sectionForId:section]; | 220 return [detailsContainer_ sectionForId:section]; |
| 208 } | 221 } |
| 209 | 222 |
| 210 - (void)modelChanged { | 223 - (void)modelChanged { |
| 224 [saveInChromeCheckbox_ setHidden:!controller_->ShouldOfferToSaveInChrome()]; |
| 211 [detailsContainer_ modelChanged]; | 225 [detailsContainer_ modelChanged]; |
| 212 } | 226 } |
| 213 | 227 |
| 228 - (BOOL)saveDetailsLocally { |
| 229 return [saveInChromeCheckbox_ state] == NSOnState; |
| 230 } |
| 231 |
| 214 - (void)updateLegalDocuments { | 232 - (void)updateLegalDocuments { |
| 215 NSString* text = base::SysUTF16ToNSString(controller_->LegalDocumentsText()); | 233 NSString* text = base::SysUTF16ToNSString(controller_->LegalDocumentsText()); |
| 216 | 234 |
| 217 if ([text length]) { | 235 if ([text length]) { |
| 218 NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; | 236 NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; |
| 219 [legalDocumentsView_ setMessage:text | 237 [legalDocumentsView_ setMessage:text |
| 220 withFont:font | 238 withFont:font |
| 221 messageColor:[NSColor blackColor]]; | 239 messageColor:[NSColor blackColor]]; |
| 222 | 240 |
| 223 const std::vector<ui::Range>& link_ranges = | 241 const std::vector<ui::Range>& link_ranges = |
| (...skipping 23 matching lines...) Expand all Loading... |
| 247 | 265 |
| 248 - (void)setAnchorView:(NSView*)anchorView { | 266 - (void)setAnchorView:(NSView*)anchorView { |
| 249 [notificationContainer_ setAnchorView:anchorView]; | 267 [notificationContainer_ setAnchorView:anchorView]; |
| 250 } | 268 } |
| 251 | 269 |
| 252 - (BOOL)validate { | 270 - (BOOL)validate { |
| 253 return [detailsContainer_ validate]; | 271 return [detailsContainer_ validate]; |
| 254 } | 272 } |
| 255 | 273 |
| 256 @end | 274 @end |
| 275 |
| 276 |
| 277 @implementation AutofillMainContainer (Testing) |
| 278 |
| 279 - (NSButton*)saveInChromeCheckboxForTesting { |
| 280 return saveInChromeCheckbox_.get(); |
| 281 } |
| 282 |
| 283 @end |
| OLD | NEW |