| 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_window.h" | 8 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 9 #include "skia/ext/skia_utils_mac.h" | 9 #include "skia/ext/skia_utils_mac.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // Border inset for error label. | 13 // Border inset for error label. |
| 14 const CGFloat kLabelInset = 3.0; | 14 const CGFloat kLabelInset = 3.0; |
| 15 | 15 |
| 16 const CGFloat kMaxLabelWidth = | 16 const CGFloat kMaxLabelWidth = |
| 17 2 * autofill::kFieldWidth + autofill::kHorizontalFieldPadding; | 17 2 * autofill::kFieldWidth + autofill::kHorizontalFieldPadding; |
| 18 | 18 |
| 19 } // namespace | 19 } // namespace |
| 20 | 20 |
| 21 @interface AutofillBubbleController () |
| 22 |
| 23 // Update the current message, keeping arrow location in place. |
| 24 - (void)updateMessage:(NSString*)message display:(BOOL)display; |
| 25 |
| 26 @end |
| 21 | 27 |
| 22 @implementation AutofillBubbleController | 28 @implementation AutofillBubbleController |
| 23 | 29 |
| 24 - (id)initWithParentWindow:(NSWindow*)parentWindow | 30 - (id)initWithParentWindow:(NSWindow*)parentWindow |
| 25 message:(NSString*)message { | 31 message:(NSString*)message { |
| 26 return [self initWithParentWindow:parentWindow | 32 return [self initWithParentWindow:parentWindow |
| 27 message:message | 33 message:message |
| 28 inset:NSMakeSize(kLabelInset, kLabelInset) | 34 inset:NSMakeSize(kLabelInset, kLabelInset) |
| 29 arrowLocation:info_bubble::kTopCenter]; | 35 arrowLocation:info_bubble::kTopCenter]; |
| 30 } | 36 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 44 anchoredAt:NSZeroPoint])) { | 50 anchoredAt:NSZeroPoint])) { |
| 45 inset_ = inset; | 51 inset_ = inset; |
| 46 [self setShouldOpenAsKeyWindow:NO]; | 52 [self setShouldOpenAsKeyWindow:NO]; |
| 47 [[self bubble] setArrowLocation:arrowLocation]; | 53 [[self bubble] setArrowLocation:arrowLocation]; |
| 48 [[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor]; | 54 [[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor]; |
| 49 | 55 |
| 50 label_.reset([[NSTextField alloc] init]); | 56 label_.reset([[NSTextField alloc] init]); |
| 51 [label_ setEditable:NO]; | 57 [label_ setEditable:NO]; |
| 52 [label_ setBordered:NO]; | 58 [label_ setBordered:NO]; |
| 53 [label_ setDrawsBackground:NO]; | 59 [label_ setDrawsBackground:NO]; |
| 54 [label_ setStringValue:message]; | |
| 55 NSRect labelFrame = NSMakeRect(inset.width, inset.height, 0, 0); | |
| 56 labelFrame.size = [[label_ cell] cellSizeForBounds: | |
| 57 NSMakeRect(0, 0, kMaxLabelWidth, CGFLOAT_MAX)]; | |
| 58 [label_ setFrame:labelFrame]; | |
| 59 [[self bubble] addSubview:label_]; | 60 [[self bubble] addSubview:label_]; |
| 60 | 61 |
| 61 NSRect windowFrame = [[self window] frame]; | 62 [self updateMessage:message display:NO]; |
| 62 windowFrame.size = NSMakeSize( | |
| 63 NSMaxX([label_ frame]), | |
| 64 NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight); | |
| 65 windowFrame = NSInsetRect(windowFrame, -inset.width, -inset.height); | |
| 66 [[self window] setFrame:windowFrame display:NO]; | |
| 67 } | 63 } |
| 68 return self; | 64 return self; |
| 69 } | 65 } |
| 70 | 66 |
| 71 - (CGFloat)maxWidth { | 67 - (CGFloat)maxWidth { |
| 72 return kMaxLabelWidth + 2 * inset_.width; | 68 return kMaxLabelWidth + 2 * inset_.width; |
| 73 } | 69 } |
| 74 | 70 |
| 71 - (void)setMessage:(NSString*)message { |
| 72 if ([[label_ stringValue] isEqualToString:message]) |
| 73 return; |
| 74 [self updateMessage:message display:YES]; |
| 75 } |
| 76 |
| 77 - (void)updateMessage:(NSString*)message display:(BOOL)display { |
| 78 [label_ setStringValue:message]; |
| 79 |
| 80 NSRect labelFrame = NSMakeRect(inset_.width, inset_.height, 0, 0); |
| 81 labelFrame.size = [[label_ cell] cellSizeForBounds: |
| 82 NSMakeRect(0, 0, kMaxLabelWidth, CGFLOAT_MAX)]; |
| 83 [label_ setFrame:labelFrame]; |
| 84 |
| 85 // Update window's size, but ensure the origin is maintained so that the arrow |
| 86 // still points at the same location. |
| 87 NSRect windowFrame = [[self window] frame]; |
| 88 NSPoint origin = windowFrame.origin; |
| 89 origin.y += NSHeight(windowFrame); |
| 90 windowFrame.size = NSMakeSize( |
| 91 NSMaxX([label_ frame]), |
| 92 NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight); |
| 93 windowFrame = NSInsetRect(windowFrame, -inset_.width, -inset_.height); |
| 94 origin.y -= NSHeight(windowFrame); |
| 95 windowFrame.origin = origin; |
| 96 [[self window] setFrame:windowFrame display:display]; |
| 97 } |
| 98 |
| 75 @end | 99 @end |
| OLD | NEW |