Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / autofill / autofill_header.mm
blob682e2d332f33e1349292ef8375febea22372b870
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"
13 namespace {
15 // Height of the account chooser.
16 const CGFloat kAccountChooserHeight = 20.0;
18 }  // namespace
20 @implementation AutofillHeader
22 - (id)initWithDelegate:(autofill::AutofillDialogViewDelegate*)delegate {
23   if (self = [super initWithNibName:nil bundle:nil]) {
24     delegate_ = delegate;
26     accountChooser_.reset(
27         [[AutofillAccountChooser alloc] initWithFrame:NSZeroRect
28                                              delegate:delegate]);
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];
39     base::scoped_nsobject<NSView> view(
40         [[NSView alloc] initWithFrame:NSZeroRect]);
41     [view setSubviews:@[accountChooser_, title_]];
42     [self setView:view];
43   }
44   return self;
47 - (NSView*)anchorView {
48   return [[accountChooser_ subviews] objectAtIndex:1];
51 - (void)update {
52   [accountChooser_ update];
54   [title_ setStringValue:base::SysUTF16ToNSString(delegate_->DialogTitle())];
55   [title_ sizeToFit];
58 - (NSSize)preferredSize {
59   CGFloat height =
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];
86 @end