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 13namespace { 14 15// Height of the account chooser. 16const 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- (NSSize)preferredSize { 59 CGFloat height = 60 chrome_style::kTitleTopPadding + 61 kAccountChooserHeight + 62 autofill::kDetailVerticalPadding; 63 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); 67} 68 69- (void)performLayout { 70 NSRect bounds = [[self view] bounds]; 71 72 [title_ setFrameOrigin:NSMakePoint(chrome_style::kHorizontalPadding, 73 autofill::kDetailVerticalPadding)]; 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 87