Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: chrome/browser/ui/cocoa/autofill/autofill_bubble_controller.mm

Issue 82593002: [rAC, OSX] Align bubble arrow based on location. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More comment fixes. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_view.h"
9 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 9 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
10 #include "skia/ext/skia_utils_mac.h" 10 #include "skia/ext/skia_utils_mac.h"
11 11
12 namespace { 12 namespace {
13 13
14 // Border inset for error label. 14 // Border inset for error label.
15 const CGFloat kLabelInset = 3.0; 15 const CGFloat kLabelInset = 3.0;
16 16
17 const CGFloat kMaxLabelWidth =
18 2 * autofill::kFieldWidth + autofill::kHorizontalFieldPadding;
19
17 } // namespace 20 } // namespace
18 21
19 22
20 @implementation AutofillBubbleController 23 @implementation AutofillBubbleController
21 24
22 - (id)initWithParentWindow:(NSWindow*)parentWindow 25 - (id)initWithParentWindow:(NSWindow*)parentWindow
23 message:(NSString*)message { 26 message:(NSString*)message {
24 base::scoped_nsobject<InfoBubbleWindow> window( 27 base::scoped_nsobject<InfoBubbleWindow> window(
25 [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 100) 28 [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 100)
26 styleMask:NSBorderlessWindowMask 29 styleMask:NSBorderlessWindowMask
27 backing:NSBackingStoreBuffered 30 backing:NSBackingStoreBuffered
28 defer:NO]); 31 defer:NO]);
29 [window setAllowedAnimations:info_bubble::kAnimateNone]; 32 [window setAllowedAnimations:info_bubble::kAnimateNone];
30 if ((self = [super initWithWindow:window 33 if ((self = [super initWithWindow:window
31 parentWindow:parentWindow 34 parentWindow:parentWindow
32 anchoredAt:NSZeroPoint])) { 35 anchoredAt:NSZeroPoint])) {
33 [self setShouldOpenAsKeyWindow:NO]; 36 [self setShouldOpenAsKeyWindow:NO];
34 [[self bubble] setArrowLocation:info_bubble::kTopCenter]; 37 [[self bubble] setArrowLocation:info_bubble::kTopCenter];
35 [[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor]; 38 [[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor];
36 39
37 label_.reset([[NSTextField alloc] init]); 40 label_.reset([[NSTextField alloc] init]);
38 [label_ setEditable:NO]; 41 [label_ setEditable:NO];
39 [label_ setBordered:NO]; 42 [label_ setBordered:NO];
40 [label_ setDrawsBackground:NO]; 43 [label_ setDrawsBackground:NO];
41 [label_ setStringValue:message]; 44 [label_ setStringValue:message];
42 NSSize labelSize = [[label_ cell] cellSizeForBounds: 45 NSRect labelFrame = NSMakeRect(kLabelInset, kLabelInset, 0, 0);
43 NSMakeRect( 46 labelFrame.size = [[label_ cell] cellSizeForBounds:
44 0, 0, 47 NSMakeRect(0, 0, kMaxLabelWidth, CGFLOAT_MAX)];
45 2 * autofill::kFieldWidth + autofill::kHorizontalFieldPadding, 48 [label_ setFrame:labelFrame];
46 CGFLOAT_MAX)];
47 [label_ setFrameSize:labelSize];
48 [label_ setFrameOrigin:NSMakePoint(kLabelInset, kLabelInset)];
49
50 [[self bubble] addSubview:label_]; 49 [[self bubble] addSubview:label_];
51 50
52 NSRect windowFrame = [[self window] frame]; 51 NSRect windowFrame = [[self window] frame];
53 windowFrame.size = NSMakeSize( 52 windowFrame.size = NSMakeSize(
54 NSMaxX([label_ frame]), 53 NSMaxX([label_ frame]),
55 NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight); 54 NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight);
56 windowFrame = NSInsetRect(windowFrame, -kLabelInset, -kLabelInset); 55 windowFrame = NSInsetRect(windowFrame, -kLabelInset, -kLabelInset);
57 [[self window] setFrame:windowFrame display:NO]; 56 [[self window] setFrame:windowFrame display:NO];
58 } 57 }
59 return self; 58 return self;
60 } 59 }
61 60
61 - (CGFloat)maxWidth {
62 return kMaxLabelWidth + 2 * kLabelInset;
63 }
64
62 @end 65 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698