[rAC, OSX] Align bubble arrow based on location.
Ensure that the error bubble never goes outside the dialog, and that one of the bubble edges is aligned with the corresponding edge of the associated field. (Screenshots on bug) BUG=305378 R=isherman@chromium.org Review URL: https://codereview.chromium.org/82593002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236831 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
chrome/browser/ui/cocoa/autofill
@ -21,6 +21,9 @@
|
||||
- (id)initWithParentWindow:(NSWindow*)parentWindow
|
||||
message:(NSString*)message;
|
||||
|
||||
// Maximum width that the bubble will occupy, regardless of message size.
|
||||
- (CGFloat)maxWidth;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
@ -14,6 +14,9 @@ namespace {
|
||||
// Border inset for error label.
|
||||
const CGFloat kLabelInset = 3.0;
|
||||
|
||||
const CGFloat kMaxLabelWidth =
|
||||
2 * autofill::kFieldWidth + autofill::kHorizontalFieldPadding;
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@ -39,14 +42,10 @@ const CGFloat kLabelInset = 3.0;
|
||||
[label_ setBordered:NO];
|
||||
[label_ setDrawsBackground:NO];
|
||||
[label_ setStringValue:message];
|
||||
NSSize labelSize = [[label_ cell] cellSizeForBounds:
|
||||
NSMakeRect(
|
||||
0, 0,
|
||||
2 * autofill::kFieldWidth + autofill::kHorizontalFieldPadding,
|
||||
CGFLOAT_MAX)];
|
||||
[label_ setFrameSize:labelSize];
|
||||
[label_ setFrameOrigin:NSMakePoint(kLabelInset, kLabelInset)];
|
||||
|
||||
NSRect labelFrame = NSMakeRect(kLabelInset, kLabelInset, 0, 0);
|
||||
labelFrame.size = [[label_ cell] cellSizeForBounds:
|
||||
NSMakeRect(0, 0, kMaxLabelWidth, CGFLOAT_MAX)];
|
||||
[label_ setFrame:labelFrame];
|
||||
[[self bubble] addSubview:label_];
|
||||
|
||||
NSRect windowFrame = [[self window] frame];
|
||||
@ -59,4 +58,8 @@ const CGFloat kLabelInset = 3.0;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (CGFloat)maxWidth {
|
||||
return kMaxLabelWidth + 2 * kLabelInset;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
|
||||
#import "chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.h"
|
||||
#import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h"
|
||||
#import "chrome/browser/ui/cocoa/info_bubble_view.h"
|
||||
|
||||
@implementation AutofillDetailsContainer
|
||||
|
||||
@ -157,14 +158,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (NSPoint)anchorPointFromView:(NSView*)view {
|
||||
// All math done in window coordinates, since views might be flipped.
|
||||
NSRect viewRect = [view convertRect:[view bounds] toView:nil];
|
||||
NSPoint anchorPoint =
|
||||
NSMakePoint(NSMidX(viewRect), NSMinY(viewRect));
|
||||
return [[view window] convertBaseToScreen:anchorPoint];
|
||||
}
|
||||
|
||||
- (void)errorBubbleWindowWillClose:(NSNotification*)notification {
|
||||
DCHECK_EQ([notification object], [errorBubbleController_ window]);
|
||||
|
||||
@ -195,7 +188,28 @@
|
||||
|
||||
// Compute anchor point (in window coords - views might be flipped).
|
||||
NSRect viewRect = [field convertRect:[field bounds] toView:nil];
|
||||
NSPoint anchorPoint = NSMakePoint(NSMidX(viewRect), NSMinY(viewRect));
|
||||
|
||||
// If a bubble at maximum size with a left-aligned edge would exceed the
|
||||
// window width, align the right edge of bubble and view. In all other
|
||||
// cases, align the left edge of the bubble and the view.
|
||||
// Alignment is based on maximum width to avoid the arrow changing positions
|
||||
// if the validation bubble stays on the same field but gets a message of
|
||||
// differing length. (E.g. "Field is required"/"Invalid Zip Code. Please
|
||||
// check and try again" if an empty zip field gets changed to a bad zip).
|
||||
NSPoint anchorPoint;
|
||||
if ((NSMinX(viewRect) + [errorBubbleController_ maxWidth]) >
|
||||
NSWidth([parentWindow frame])) {
|
||||
anchorPoint = NSMakePoint(NSMaxX(viewRect), NSMinY(viewRect));
|
||||
[[errorBubbleController_ bubble] setArrowLocation:info_bubble::kTopRight];
|
||||
[[errorBubbleController_ bubble] setAlignment:
|
||||
info_bubble::kAlignRightEdgeToAnchorEdge];
|
||||
|
||||
} else {
|
||||
anchorPoint = NSMakePoint(NSMinX(viewRect), NSMinY(viewRect));
|
||||
[[errorBubbleController_ bubble] setArrowLocation:info_bubble::kTopLeft];
|
||||
[[errorBubbleController_ bubble] setAlignment:
|
||||
info_bubble::kAlignLeftEdgeToAnchorEdge];
|
||||
}
|
||||
[errorBubbleController_ setAnchorPoint:
|
||||
[parentWindow convertBaseToScreen:anchorPoint]];
|
||||
|
||||
|
Reference in New Issue
Block a user