Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: chrome/browser/ui/cocoa/autofill/autofill_main_container.mm

Issue 21692002: Rename AutofillDialogController to AutofillDialogViewDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
12 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" 12 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
13 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" 13 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h"
14 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" 14 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h"
15 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h" 15 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h"
16 #import "chrome/browser/ui/cocoa/autofill/autofill_notification_container.h" 16 #import "chrome/browser/ui/cocoa/autofill/autofill_notification_container.h"
17 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" 17 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h"
18 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h" 18 #import "chrome/browser/ui/cocoa/key_equivalent_constants.h"
19 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
20 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" 20 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
21 #include "ui/base/cocoa/window_size_constants.h" 21 #include "ui/base/cocoa/window_size_constants.h"
22 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/range/range.h" 23 #include "ui/base/range/range.h"
24 24
25 @interface AutofillMainContainer (Private) 25 @interface AutofillMainContainer (Private)
26 - (void)buildWindowButtonsForFrame:(NSRect)frame; 26 - (void)buildWindowButtonsForFrame:(NSRect)frame;
27 - (void)layoutButtons; 27 - (void)layoutButtons;
28 - (NSSize)preferredLegalDocumentSizeForWidth:(CGFloat)width; 28 - (NSSize)preferredLegalDocumentSizeForWidth:(CGFloat)width;
29 @end 29 @end
30 30
31 31
32 @implementation AutofillMainContainer 32 @implementation AutofillMainContainer
33 33
34 @synthesize target = target_; 34 @synthesize target = target_;
35 35
36 - (id)initWithController:(autofill::AutofillDialogController*)controller { 36 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate {
37 if (self = [super init]) { 37 if (self = [super init]) {
38 controller_ = controller; 38 delegate_ = delegate;
39 } 39 }
40 return self; 40 return self;
41 } 41 }
42 42
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. 53 // Set up "Save in Chrome" checkbox.
54 saveInChromeCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); 54 saveInChromeCheckbox_.reset([[NSButton alloc] initWithFrame:NSZeroRect]);
55 [saveInChromeCheckbox_ setButtonType:NSSwitchButton]; 55 [saveInChromeCheckbox_ setButtonType:NSSwitchButton];
56 [saveInChromeCheckbox_ setTitle: 56 [saveInChromeCheckbox_ setTitle:
57 base::SysUTF16ToNSString(controller_->SaveLocallyText())]; 57 base::SysUTF16ToNSString(delegate_->SaveLocallyText())];
58 [saveInChromeCheckbox_ setState:NSOnState]; 58 [saveInChromeCheckbox_ setState:NSOnState];
59 [saveInChromeCheckbox_ sizeToFit]; 59 [saveInChromeCheckbox_ sizeToFit];
60 [[self view] addSubview:saveInChromeCheckbox_]; 60 [[self view] addSubview:saveInChromeCheckbox_];
61 61
62 detailsContainer_.reset( 62 detailsContainer_.reset(
63 [[AutofillDetailsContainer alloc] initWithController:controller_]); 63 [[AutofillDetailsContainer alloc] initWithDelegate:delegate_]);
64 NSSize frameSize = [[detailsContainer_ view] frame].size; 64 NSSize frameSize = [[detailsContainer_ view] frame].size;
65 [[detailsContainer_ view] setFrameOrigin: 65 [[detailsContainer_ view] setFrameOrigin:
66 NSMakePoint(0, NSHeight([buttonContainer_ frame]))]; 66 NSMakePoint(0, NSHeight([buttonContainer_ frame]))];
67 frameSize.height += NSHeight([buttonContainer_ frame]); 67 frameSize.height += NSHeight([buttonContainer_ frame]);
68 [[self view] setFrameSize:frameSize]; 68 [[self view] setFrameSize:frameSize];
69 [[self view] addSubview:[detailsContainer_ view]]; 69 [[self view] addSubview:[detailsContainer_ view]];
70 70
71 legalDocumentsView_.reset( 71 legalDocumentsView_.reset(
72 [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]); 72 [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]);
73 [legalDocumentsView_ setEditable:NO]; 73 [legalDocumentsView_ setEditable:NO];
74 [legalDocumentsView_ setBackgroundColor: 74 [legalDocumentsView_ setBackgroundColor:
75 [NSColor colorWithCalibratedRed:0.96 75 [NSColor colorWithCalibratedRed:0.96
76 green:0.96 76 green:0.96
77 blue:0.96 77 blue:0.96
78 alpha:1.0]]; 78 alpha:1.0]];
79 [legalDocumentsView_ setDrawsBackground:YES]; 79 [legalDocumentsView_ setDrawsBackground:YES];
80 [legalDocumentsView_ setHidden:YES]; 80 [legalDocumentsView_ setHidden:YES];
81 [legalDocumentsView_ setDelegate:self]; 81 [legalDocumentsView_ setDelegate:self];
82 legalDocumentsSizeDirty_ = YES; 82 legalDocumentsSizeDirty_ = YES;
83 [[self view] addSubview:legalDocumentsView_]; 83 [[self view] addSubview:legalDocumentsView_];
84 84
85 notificationContainer_.reset( 85 notificationContainer_.reset(
86 [[AutofillNotificationContainer alloc] initWithController:controller_]); 86 [[AutofillNotificationContainer alloc] initWithDelegate:delegate_]);
87 [[self view] addSubview:[notificationContainer_ view]]; 87 [[self view] addSubview:[notificationContainer_ view]];
88 } 88 }
89 89
90 // Called when embedded links are clicked. 90 // Called when embedded links are clicked.
91 - (BOOL)textView:(NSTextView*)textView 91 - (BOOL)textView:(NSTextView*)textView
92 clickedOnLink:(id)link 92 clickedOnLink:(id)link
93 atIndex:(NSUInteger)charIndex { 93 atIndex:(NSUInteger)charIndex {
94 int index = [base::mac::ObjCCastStrict<NSNumber>(link) intValue]; 94 int index = [base::mac::ObjCCastStrict<NSNumber>(link) intValue];
95 controller_->LegalDocumentLinkClicked( 95 delegate_->LegalDocumentLinkClicked(
96 controller_->LegalDocumentLinks()[index]); 96 delegate_->LegalDocumentLinks()[index]);
97 return YES; 97 return YES;
98 } 98 }
99 99
100 - (NSSize)preferredSize { 100 - (NSSize)preferredSize {
101 // Overall width is determined by |detailsContainer_|. 101 // Overall width is determined by |detailsContainer_|.
102 NSSize buttonSize = [buttonContainer_ frame].size; 102 NSSize buttonSize = [buttonContainer_ frame].size;
103 NSSize detailsSize = [detailsContainer_ preferredSize]; 103 NSSize detailsSize = [detailsContainer_ preferredSize];
104 104
105 NSSize size = NSMakeSize(std::max(buttonSize.width, detailsSize.width), 105 NSSize size = NSMakeSize(std::max(buttonSize.width, detailsSize.width),
106 buttonSize.height + detailsSize.height); 106 buttonSize.height + detailsSize.height);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 legalDocumentsSizeDirty_ = NO; 223 legalDocumentsSizeDirty_ = NO;
224 legalDocumentsSize_ = newFrame.size; 224 legalDocumentsSize_ = newFrame.size;
225 return legalDocumentsSize_; 225 return legalDocumentsSize_;
226 } 226 }
227 227
228 - (AutofillSectionContainer*)sectionForId:(autofill::DialogSection)section { 228 - (AutofillSectionContainer*)sectionForId:(autofill::DialogSection)section {
229 return [detailsContainer_ sectionForId:section]; 229 return [detailsContainer_ sectionForId:section];
230 } 230 }
231 231
232 - (void)modelChanged { 232 - (void)modelChanged {
233 [saveInChromeCheckbox_ setHidden:!controller_->ShouldOfferToSaveInChrome()]; 233 [saveInChromeCheckbox_ setHidden:!delegate_->ShouldOfferToSaveInChrome()];
234 [detailsContainer_ modelChanged]; 234 [detailsContainer_ modelChanged];
235 } 235 }
236 236
237 - (BOOL)saveDetailsLocally { 237 - (BOOL)saveDetailsLocally {
238 return [saveInChromeCheckbox_ state] == NSOnState; 238 return [saveInChromeCheckbox_ state] == NSOnState;
239 } 239 }
240 240
241 - (void)updateLegalDocuments { 241 - (void)updateLegalDocuments {
242 NSString* text = base::SysUTF16ToNSString(controller_->LegalDocumentsText()); 242 NSString* text = base::SysUTF16ToNSString(delegate_->LegalDocumentsText());
243 243
244 if ([text length]) { 244 if ([text length]) {
245 NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]; 245 NSFont* font = [NSFont systemFontOfSize:[NSFont smallSystemFontSize]];
246 [legalDocumentsView_ setMessage:text 246 [legalDocumentsView_ setMessage:text
247 withFont:font 247 withFont:font
248 messageColor:[NSColor blackColor]]; 248 messageColor:[NSColor blackColor]];
249 249
250 const std::vector<ui::Range>& link_ranges = 250 const std::vector<ui::Range>& link_ranges =
251 controller_->LegalDocumentLinks(); 251 delegate_->LegalDocumentLinks();
252 for (size_t i = 0; i < link_ranges.size(); ++i) { 252 for (size_t i = 0; i < link_ranges.size(); ++i) {
253 NSRange range = link_ranges[i].ToNSRange(); 253 NSRange range = link_ranges[i].ToNSRange();
254 [legalDocumentsView_ addLinkRange:range 254 [legalDocumentsView_ addLinkRange:range
255 withName:@(i) 255 withName:@(i)
256 linkColor:[NSColor blueColor]]; 256 linkColor:[NSColor blueColor]];
257 } 257 }
258 legalDocumentsSizeDirty_ = YES; 258 legalDocumentsSizeDirty_ = YES;
259 } 259 }
260 [legalDocumentsView_ setHidden:[text length] == 0]; 260 [legalDocumentsView_ setHidden:[text length] == 0];
261 261
262 // Always request re-layout on state change. 262 // Always request re-layout on state change.
263 id controller = [[[self view] window] windowController]; 263 id delegate = [[[self view] window] windowController];
264 if ([controller respondsToSelector:@selector(requestRelayout)]) 264 if ([delegate respondsToSelector:@selector(requestRelayout)])
265 [controller performSelector:@selector(requestRelayout)]; 265 [delegate performSelector:@selector(requestRelayout)];
266 } 266 }
267 267
268 - (void)updateNotificationArea { 268 - (void)updateNotificationArea {
269 [notificationContainer_ setNotifications:controller_->CurrentNotifications()]; 269 [notificationContainer_ setNotifications:delegate_->CurrentNotifications()];
270 id controller = [[[self view] window] windowController]; 270 id delegate = [[[self view] window] windowController];
271 if ([controller respondsToSelector:@selector(requestRelayout)]) 271 if ([delegate respondsToSelector:@selector(requestRelayout)])
272 [controller performSelector:@selector(requestRelayout)]; 272 [delegate performSelector:@selector(requestRelayout)];
273 } 273 }
274 274
275 - (void)setAnchorView:(NSView*)anchorView { 275 - (void)setAnchorView:(NSView*)anchorView {
276 [notificationContainer_ setAnchorView:anchorView]; 276 [notificationContainer_ setAnchorView:anchorView];
277 } 277 }
278 278
279 - (BOOL)validate { 279 - (BOOL)validate {
280 return [detailsContainer_ validate]; 280 return [detailsContainer_ validate];
281 } 281 }
282 282
283 @end 283 @end
284 284
285 285
286 @implementation AutofillMainContainer (Testing) 286 @implementation AutofillMainContainer (Testing)
287 287
288 - (NSButton*)saveInChromeCheckboxForTesting { 288 - (NSButton*)saveInChromeCheckboxForTesting {
289 return saveInChromeCheckbox_.get(); 289 return saveInChromeCheckbox_.get();
290 } 290 }
291 291
292 @end 292 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698