OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.h" |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" | 7 #import "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" |
| 8 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
8 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 9 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
9 #include "skia/ext/skia_utils_mac.h" | 10 #include "skia/ext/skia_utils_mac.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 // Border inset for error label. | 14 // Border inset for error label. |
14 const CGFloat kLabelInset = 3.0; | 15 const CGFloat kLabelInset = 3.0; |
15 | 16 |
16 const CGFloat kMaxLabelWidth = | 17 const CGFloat kMaxLabelWidth = |
17 2 * autofill::kFieldWidth + autofill::kHorizontalFieldPadding; | 18 2 * autofill::kFieldWidth + autofill::kHorizontalFieldPadding; |
18 | 19 |
19 } // namespace | 20 } // namespace |
20 | 21 |
21 | 22 |
22 @implementation AutofillBubbleController | 23 @implementation AutofillBubbleController |
23 | 24 |
24 - (id)initWithParentWindow:(NSWindow*)parentWindow | 25 - (id)initWithParentWindow:(NSWindow*)parentWindow |
25 message:(NSString*)message { | 26 message:(NSString*)message { |
26 return [self initWithParentWindow:parentWindow | 27 return [self initWithParentWindow:parentWindow |
27 message:message | 28 message:message |
28 inset:NSMakeSize(kLabelInset, kLabelInset) | 29 inset:NSMakeSize(kLabelInset, kLabelInset)]; |
29 arrowLocation:info_bubble::kTopCenter]; | |
30 } | 30 } |
31 | 31 |
32 - (id)initWithParentWindow:(NSWindow*)parentWindow | 32 - (id)initWithParentWindow:(NSWindow*)parentWindow |
33 message:(NSString*)message | 33 message:(NSString*)message |
34 inset:(NSSize)inset | 34 inset:(NSSize)inset { |
35 arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation { | |
36 base::scoped_nsobject<InfoBubbleWindow> window( | 35 base::scoped_nsobject<InfoBubbleWindow> window( |
37 [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 100) | 36 [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 100) |
38 styleMask:NSBorderlessWindowMask | 37 styleMask:NSBorderlessWindowMask |
39 backing:NSBackingStoreBuffered | 38 backing:NSBackingStoreBuffered |
40 defer:NO]); | 39 defer:NO]); |
41 [window setAllowedAnimations:info_bubble::kAnimateNone]; | 40 [window setAllowedAnimations:info_bubble::kAnimateNone]; |
42 if ((self = [super initWithWindow:window | 41 if ((self = [super initWithWindow:window |
43 parentWindow:parentWindow | 42 parentWindow:parentWindow |
44 anchoredAt:NSZeroPoint])) { | 43 anchoredAt:NSZeroPoint])) { |
45 inset_ = inset; | 44 inset_ = inset; |
46 [self setShouldOpenAsKeyWindow:NO]; | 45 [self setShouldOpenAsKeyWindow:NO]; |
47 [[self bubble] setArrowLocation:arrowLocation]; | 46 [[self bubble] setArrowLocation:info_bubble::kTopCenter]; |
48 [[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor]; | 47 [[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor]; |
49 | 48 |
50 label_.reset([[NSTextField alloc] init]); | 49 label_.reset([[NSTextField alloc] init]); |
51 [label_ setEditable:NO]; | 50 [label_ setEditable:NO]; |
52 [label_ setBordered:NO]; | 51 [label_ setBordered:NO]; |
53 [label_ setDrawsBackground:NO]; | 52 [label_ setDrawsBackground:NO]; |
54 [label_ setStringValue:message]; | 53 [label_ setStringValue:message]; |
55 NSRect labelFrame = NSMakeRect(inset.width, inset.height, 0, 0); | 54 NSRect labelFrame = NSMakeRect(inset.width, inset.height, 0, 0); |
56 labelFrame.size = [[label_ cell] cellSizeForBounds: | 55 labelFrame.size = [[label_ cell] cellSizeForBounds: |
57 NSMakeRect(0, 0, kMaxLabelWidth, CGFLOAT_MAX)]; | 56 NSMakeRect(0, 0, kMaxLabelWidth, CGFLOAT_MAX)]; |
58 [label_ setFrame:labelFrame]; | 57 [label_ setFrame:labelFrame]; |
59 [[self bubble] addSubview:label_]; | 58 [[self bubble] addSubview:label_]; |
60 | 59 |
61 NSRect windowFrame = [[self window] frame]; | 60 NSRect windowFrame = [[self window] frame]; |
62 windowFrame.size = NSMakeSize( | 61 windowFrame.size = NSMakeSize( |
63 NSMaxX([label_ frame]), | 62 NSMaxX([label_ frame]), |
64 NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight); | 63 NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight); |
65 windowFrame = NSInsetRect(windowFrame, -inset.width, -inset.height); | 64 windowFrame = NSInsetRect(windowFrame, -inset.width, -inset.height); |
66 [[self window] setFrame:windowFrame display:NO]; | 65 [[self window] setFrame:windowFrame display:NO]; |
67 } | 66 } |
68 return self; | 67 return self; |
69 } | 68 } |
70 | 69 |
71 - (CGFloat)maxWidth { | 70 - (CGFloat)maxWidth { |
72 return kMaxLabelWidth + 2 * inset_.width; | 71 return kMaxLabelWidth + 2 * inset_.width; |
73 } | 72 } |
74 | 73 |
75 @end | 74 @end |
OLD | NEW |