OLD | NEW |
| (Empty) |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #import "chrome/browser/ui/cocoa/autofill/autofill_notification_container.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/mac/scoped_nsobject.h" | |
11 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" | |
12 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" | |
13 #import "chrome/browser/ui/cocoa/autofill/autofill_notification_controller.h" | |
14 | |
15 @implementation AutofillNotificationContainer | |
16 | |
17 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate { | |
18 if (self = [super init]) { | |
19 delegate_ = delegate; | |
20 [self setView:[[[NSView alloc] initWithFrame:NSZeroRect] autorelease]]; | |
21 } | |
22 return self; | |
23 } | |
24 | |
25 // Just here to satisfy the protocol - not actually invoked. | |
26 - (NSSize)preferredSize { | |
27 NOTREACHED(); | |
28 return NSZeroSize; | |
29 } | |
30 | |
31 - (NSSize)preferredSizeForWidth:(CGFloat)width { | |
32 NSSize preferredSize = NSMakeSize(width, 0); | |
33 | |
34 if ([notificationControllers_ count] == 0) | |
35 return preferredSize; | |
36 | |
37 // A bit of padding above the arrow. | |
38 preferredSize.height += autofill::kDetailVerticalPadding; | |
39 | |
40 for (AutofillNotificationController* controller in | |
41 notificationControllers_.get()) { | |
42 preferredSize.height += [controller preferredSizeForWidth:width].height; | |
43 } | |
44 | |
45 preferredSize.height += autofill::kDetailVerticalPadding; | |
46 | |
47 return preferredSize; | |
48 } | |
49 | |
50 - (void)performLayout { | |
51 if ([notificationControllers_ count] == 0) | |
52 return; | |
53 | |
54 NSRect remaining = [[self view] bounds]; | |
55 remaining.origin.y += autofill::kDetailVerticalPadding; | |
56 remaining.size.height -= 2 * autofill::kDetailVerticalPadding; | |
57 | |
58 for (AutofillNotificationController* controller in | |
59 notificationControllers_.get()) { | |
60 NSRect viewRect; | |
61 NSSize size = [controller preferredSizeForWidth:NSWidth(remaining)]; | |
62 NSDivideRect(remaining, &viewRect, &remaining, size.height, NSMaxYEdge); | |
63 [[controller view ] setFrame:viewRect]; | |
64 [controller performLayout]; | |
65 } | |
66 DCHECK_EQ(0, NSHeight(remaining)); | |
67 } | |
68 | |
69 - (void)setNotifications:(const autofill::DialogNotifications&)notifications { | |
70 notificationControllers_.reset([[NSMutableArray alloc] init]); | |
71 [[self view] setSubviews:@[]]; | |
72 | |
73 for (size_t i = 0; i < notifications.size(); ++i) { | |
74 // Create basic notification view. | |
75 const autofill::DialogNotification& notification = notifications[i]; | |
76 base::scoped_nsobject<AutofillNotificationController> | |
77 notificationController([[AutofillNotificationController alloc] | |
78 initWithNotification:¬ification | |
79 delegate:delegate_]); | |
80 | |
81 [notificationControllers_ addObject:notificationController]; | |
82 [[self view] addSubview:[notificationController view]]; | |
83 } | |
84 } | |
85 | |
86 @end | |
OLD | NEW |