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 details_.get()) { |
| 48 NSSize containerSize = [container preferredSize]; |
| 49 size.height += containerSize.height; |
| 50 size.width = std::max(containerSize.width, size.width); |
| 51 } |
| 52 return size; |
| 53 } |
| 54 |
| 55 - (void)performLayout { |
37 NSRect rect = NSZeroRect; | 56 NSRect rect = NSZeroRect; |
38 for (AutofillSectionContainer* container in | 57 for (AutofillSectionContainer* container in |
39 [details_ reverseObjectEnumerator]) { | 58 [details_ reverseObjectEnumerator]) { |
| 59 [container performLayout]; |
40 [[container view] setFrameOrigin:NSMakePoint(0, NSMaxY(rect))]; | 60 [[container view] setFrameOrigin:NSMakePoint(0, NSMaxY(rect))]; |
41 rect = NSUnionRect(rect, [[container view] frame]); | 61 rect = NSUnionRect(rect, [[container view] frame]); |
42 [[self view] addSubview:[container view]]; | |
43 } | 62 } |
44 [[self view] setFrame:rect]; | 63 |
| 64 [[self view] setFrameSize:[self preferredSize]]; |
45 } | 65 } |
46 | 66 |
47 - (AutofillSectionContainer*)sectionForId:(autofill::DialogSection)section { | 67 - (AutofillSectionContainer*)sectionForId:(autofill::DialogSection)section { |
48 for (AutofillSectionContainer* details in details_.get()) { | 68 for (AutofillSectionContainer* details in details_.get()) { |
49 if ([details section] == section) | 69 if ([details section] == section) |
50 return details; | 70 return details; |
51 } | 71 } |
52 return nil; | 72 return nil; |
53 } | 73 } |
54 | 74 |
55 - (void)modelChanged { | 75 - (void)modelChanged { |
56 for (AutofillSectionContainer* details in details_.get()) | 76 for (AutofillSectionContainer* details in details_.get()) |
57 [details modelChanged]; | 77 [details modelChanged]; |
58 } | 78 } |
59 | 79 |
60 @end | 80 @end |
OLD | NEW |