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_details_container.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_details_container.h" |
6 | 6 |
7 #include <algorithm> | |
8 | |
7 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" | 9 #include "chrome/browser/ui/autofill/autofill_dialog_controller.h" |
8 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" | 10 #import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h" |
9 | 11 |
10 @implementation AutofillDetailsContainer | 12 @implementation AutofillDetailsContainer |
11 | 13 |
12 - (id)initWithController:(autofill::AutofillDialogController*)controller { | 14 - (id)initWithController:(autofill::AutofillDialogController*)controller { |
13 if (self = [super init]) { | 15 if (self = [super init]) { |
14 controller_ = controller; | 16 controller_ = controller; |
15 } | 17 } |
16 return self; | 18 return self; |
17 } | 19 } |
18 | 20 |
19 - (void)addSection:(autofill::DialogSection)section { | 21 - (void)addSection:(autofill::DialogSection)section { |
20 scoped_nsobject<AutofillSectionContainer> sectionContainer( | 22 scoped_nsobject<AutofillSectionContainer> sectionContainer( |
21 [[AutofillSectionContainer alloc] initWithController:controller_ | 23 [[AutofillSectionContainer alloc] initWithController:controller_ |
22 forSection:section]); | 24 forSection:section]); |
23 [details_ addObject:sectionContainer]; | 25 [details_ addObject:sectionContainer]; |
24 } | 26 } |
25 | 27 |
26 - (void)loadView { | 28 - (void)loadView { |
27 details_.reset([[NSMutableArray alloc] init]); | 29 details_.reset([[NSMutableArray alloc] init]); |
28 | 30 |
29 [self addSection:autofill::SECTION_EMAIL]; | 31 [self addSection:autofill::SECTION_EMAIL]; |
30 [self addSection:autofill::SECTION_CC]; | 32 [self addSection:autofill::SECTION_CC]; |
31 [self addSection:autofill::SECTION_BILLING]; | 33 [self addSection:autofill::SECTION_BILLING]; |
32 // TODO(groby): Add SECTION_CC_BILLING once toggling is enabled. | 34 // TODO(groby): Add SECTION_CC_BILLING once toggling is enabled. |
33 [self addSection:autofill::SECTION_SHIPPING]; | 35 [self addSection:autofill::SECTION_SHIPPING]; |
34 | 36 |
35 [self setView:[[NSView alloc] init]]; | 37 [self setView:[[NSView alloc] init]]; |
38 for (AutofillSectionContainer* container in details_.get()) | |
39 [[self view] addSubview:[container view]]; | |
36 | 40 |
41 [self performLayout]; | |
42 } | |
43 | |
44 - (NSSize)preferredSize { | |
45 NSSize size = NSMakeSize(0, 0); | |
46 | |
47 for (AutofillSectionContainer* container in | |
48 details_.get()) { | |
Robert Sesek
2013/05/24 20:49:23
nit: indent 4 spaces for continuation
groby-ooo-7-16
2013/05/24 23:53:35
Done.
| |
49 NSSize containerSize = [container preferredSize]; | |
50 size.height += containerSize.height; | |
51 size.width = std::max(containerSize.width, size.width); | |
52 } | |
53 return size; | |
54 } | |
55 | |
56 - (void)performLayout { | |
37 NSRect rect = NSZeroRect; | 57 NSRect rect = NSZeroRect; |
38 for (AutofillSectionContainer* container in | 58 for (AutofillSectionContainer* container in |
39 [details_ reverseObjectEnumerator]) { | 59 [details_ reverseObjectEnumerator]) { |
60 [container performLayout]; | |
40 [[container view] setFrameOrigin:NSMakePoint(0, NSMaxY(rect))]; | 61 [[container view] setFrameOrigin:NSMakePoint(0, NSMaxY(rect))]; |
41 rect = NSUnionRect(rect, [[container view] frame]); | 62 rect = NSUnionRect(rect, [[container view] frame]); |
42 [[self view] addSubview:[container view]]; | |
43 } | 63 } |
44 [[self view] setFrame:rect]; | 64 |
65 [[self view] setFrameSize:[self preferredSize]]; | |
45 } | 66 } |
46 | 67 |
47 - (AutofillSectionContainer*)sectionForId:(autofill::DialogSection)section { | 68 - (AutofillSectionContainer*)sectionForId:(autofill::DialogSection)section { |
48 for (AutofillSectionContainer* details in details_.get()) { | 69 for (AutofillSectionContainer* details in details_.get()) { |
49 if ([details section] == section) | 70 if ([details section] == section) |
50 return details; | 71 return details; |
51 } | 72 } |
52 return nil; | 73 return nil; |
53 } | 74 } |
54 | 75 |
55 - (void)modelChanged { | 76 - (void)modelChanged { |
56 for (AutofillSectionContainer* details in details_.get()) | 77 for (AutofillSectionContainer* details in details_.get()) |
57 [details modelChanged]; | 78 [details modelChanged]; |
58 } | 79 } |
59 | 80 |
60 @end | 81 @end |
OLD | NEW |