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.
5 #import "chrome/browser/ui/cocoa/autofill/autofill_header.h"
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"
15 // Height of the account chooser.
16 const CGFloat kAccountChooserHeight = 20.0;
20 @implementation AutofillHeader
22 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate {
23 if (self = [super initWithNibName:nil bundle:nil]) {
26 accountChooser_.reset(
27 [[AutofillAccountChooser alloc] initWithFrame:NSZeroRect
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())];
39 base::scoped_nsobject<NSView> view(
40 [[NSView alloc] initWithFrame:NSZeroRect]);
41 [view setSubviews:@[accountChooser_, title_]];
47 - (NSView*)anchorView {
48 return [[accountChooser_ subviews] objectAtIndex:1];
52 [accountChooser_ update];
54 [title_ setStringValue:base::SysUTF16ToNSString(delegate_->DialogTitle())];
58 - (NSSize)preferredSize {
60 chrome_style::kTitleTopPadding +
61 kAccountChooserHeight +
62 autofill::kDetailVerticalPadding;
64 // The returned width is unused, and there's no simple way to compute the
65 // account chooser's width, so just return 0 for the width.
66 return NSMakeSize(0, height);
69 - (void)performLayout {
70 NSRect bounds = [[self view] bounds];
72 [title_ setFrameOrigin:NSMakePoint(chrome_style::kHorizontalPadding,
73 autofill::kDetailVerticalPadding)];
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];