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_header.h" | |
6 | |
7 #import "chrome/browser/ui/cocoa/autofill/autofill_account_chooser.h" | |
8 #include "base/strings/sys_string_conversions.h" | |
9 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" | |
10 #include "chrome/browser/ui/chrome_style.h" | |
11 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" | |
12 | |
13 namespace { | |
14 | |
15 // Height of the account chooser. | |
16 const CGFloat kAccountChooserHeight = 20.0; | |
17 | |
18 } // namespace | |
19 | |
20 @implementation AutofillHeader | |
21 | |
22 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate { | |
23 if (self = [super initWithNibName:nil bundle:nil]) { | |
24 delegate_ = delegate; | |
25 | |
26 accountChooser_.reset( | |
27 [[AutofillAccountChooser alloc] initWithFrame:NSZeroRect | |
28 delegate:delegate]); | |
29 | |
30 // Set dialog title. | |
31 title_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); | |
32 [title_ setEditable:NO]; | |
33 [title_ setBordered:NO]; | |
34 [title_ setDrawsBackground:NO]; | |
35 [title_ setFont:[NSFont systemFontOfSize:15.0]]; | |
36 [title_ setStringValue:base::SysUTF16ToNSString(delegate_->DialogTitle())]; | |
37 [title_ sizeToFit]; | |
38 | |
39 base::scoped_nsobject<NSView> view( | |
40 [[NSView alloc] initWithFrame:NSZeroRect]); | |
41 [view setSubviews:@[accountChooser_, title_]]; | |
42 [self setView:view]; | |
43 } | |
44 return self; | |
45 } | |
46 | |
47 - (NSView*)anchorView { | |
48 return [[accountChooser_ subviews] objectAtIndex:1]; | |
49 } | |
50 | |
51 - (void)update { | |
52 [accountChooser_ update]; | |
53 | |
54 [title_ setStringValue:base::SysUTF16ToNSString(delegate_->DialogTitle())]; | |
55 [title_ sizeToFit]; | |
56 } | |
57 | |
58 - (CGFloat)heightForWidth:(int)width { | |
59 return chrome_style::kTitleTopPadding + | |
60 kAccountChooserHeight + | |
61 autofill::kDetailVerticalPadding; | |
62 } | |
63 | |
64 - (NSSize)preferredSize { | |
65 NOTREACHED(); // Only implemented as part of AutofillLayout protocol. | |
66 return NSZeroSize; | |
67 } | |
68 | |
69 - (void)performLayout { | |
70 NSRect bounds = [[self view] bounds]; | |
71 | |
72 [title_ setFrameOrigin:NSMakePoint(chrome_style::kHorizontalPadding, | |
73 autofill::kDetailVerticalPadding)]; | |
Ilya Sherman
2013/11/23 00:27:13
I got rid of the layout_manager stuff because this
groby-ooo-7-16
2013/11/23 02:07:19
I'm not sure how that would align the baselines -
| |
74 | |
75 CGFloat accountChooserLeftX = | |
76 NSMaxX([title_ frame]) + chrome_style::kHorizontalPadding; | |
77 CGFloat accountChooserWidth = | |
78 NSMaxX(bounds) - chrome_style::kHorizontalPadding - accountChooserLeftX; | |
79 NSRect accountChooserFrame = | |
80 NSMakeRect(accountChooserLeftX, autofill::kDetailVerticalPadding, | |
81 accountChooserWidth, kAccountChooserHeight); | |
82 [accountChooser_ setFrame:accountChooserFrame]; | |
83 [accountChooser_ performLayout]; | |
84 } | |
85 | |
86 @end | |
OLD | NEW |