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 initWithFrame:NSZeroRect]) { | |
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 [self setSubviews:@[accountChooser_, title_]]; | |
40 } | |
41 return self; | |
42 } | |
43 | |
44 - (BOOL)isFlipped { | |
45 return YES; | |
46 } | |
groby-ooo-7-16
2013/11/22 14:51:38
Does this really need to be flipped?
Ilya Sherman
2013/11/23 00:23:54
Done.
| |
47 | |
48 - (NSView*)anchorView { | |
49 return [[accountChooser_ subviews] objectAtIndex:1]; | |
50 } | |
51 | |
52 - (void)update { | |
53 [accountChooser_ update]; | |
54 | |
55 [title_ setStringValue:base::SysUTF16ToNSString(delegate_->DialogTitle())]; | |
56 [title_ sizeToFit]; | |
57 } | |
58 | |
59 - (CGFloat)heightForWidth:(int)width { | |
60 return chrome_style::kTitleTopPadding + | |
61 kAccountChooserHeight + | |
62 autofill::kDetailVerticalPadding; | |
63 } | |
64 | |
65 - (NSSize)preferredSize { | |
66 NOTREACHED(); // Only implemented as part of AutofillLayout protocol. | |
67 return NSZeroSize; | |
68 } | |
69 | |
70 - (void)performLayout { | |
71 NSRect bounds = [self bounds]; | |
72 | |
73 // Align baseline of title with bottom of accountChooser. | |
74 base::scoped_nsobject<NSLayoutManager> layout_manager( | |
75 [[NSLayoutManager alloc] init]); | |
76 NSRect titleFrame = [title_ frame]; | |
77 titleFrame.origin.x = chrome_style::kHorizontalPadding; | |
78 titleFrame.origin.y = | |
79 chrome_style::kTitleTopPadding + NSHeight(titleFrame) - | |
80 [layout_manager defaultBaselineOffsetForFont:[title_ font]]; | |
81 [title_ setFrameOrigin:titleFrame.origin]; | |
82 | |
83 CGFloat accountChooserLeftX = | |
84 NSMaxX(titleFrame) + chrome_style::kHorizontalPadding; | |
85 CGFloat accountChooserWidth = | |
86 NSMaxX(bounds) - chrome_style::kHorizontalPadding - accountChooserLeftX; | |
87 NSRect accountChooserFrame = | |
88 NSMakeRect(accountChooserLeftX, chrome_style::kTitleTopPadding, | |
89 accountChooserWidth, kAccountChooserHeight); | |
90 [accountChooser_ setFrame:accountChooserFrame]; | |
91 [accountChooser_ performLayout]; | |
92 } | |
93 | |
94 @end | |
OLD | NEW |