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

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

Issue 113763002: [rAc] [OSX] Set tooltip bubble arrow's anchor point based on the icon location. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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"
9 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 8 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
10 #include "skia/ext/skia_utils_mac.h" 9 #include "skia/ext/skia_utils_mac.h"
11 10
12 namespace { 11 namespace {
13 12
14 // Border inset for error label. 13 // Border inset for error label.
15 const CGFloat kLabelInset = 3.0; 14 const CGFloat kLabelInset = 3.0;
16 15
17 const CGFloat kMaxLabelWidth = 16 const CGFloat kMaxLabelWidth =
18 2 * autofill::kFieldWidth + autofill::kHorizontalFieldPadding; 17 2 * autofill::kFieldWidth + autofill::kHorizontalFieldPadding;
19 18
20 } // namespace 19 } // namespace
21 20
22 21
23 @implementation AutofillBubbleController 22 @implementation AutofillBubbleController
24 23
25 - (id)initWithParentWindow:(NSWindow*)parentWindow 24 - (id)initWithParentWindow:(NSWindow*)parentWindow
26 message:(NSString*)message { 25 message:(NSString*)message {
27 return [self initWithParentWindow:parentWindow 26 return [self initWithParentWindow:parentWindow
28 message:message 27 message:message
29 inset:NSMakeSize(kLabelInset, kLabelInset)]; 28 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 {
35 base::scoped_nsobject<InfoBubbleWindow> window( 36 base::scoped_nsobject<InfoBubbleWindow> window(
36 [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 100) 37 [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 100)
37 styleMask:NSBorderlessWindowMask 38 styleMask:NSBorderlessWindowMask
38 backing:NSBackingStoreBuffered 39 backing:NSBackingStoreBuffered
39 defer:NO]); 40 defer:NO]);
40 [window setAllowedAnimations:info_bubble::kAnimateNone]; 41 [window setAllowedAnimations:info_bubble::kAnimateNone];
41 if ((self = [super initWithWindow:window 42 if ((self = [super initWithWindow:window
42 parentWindow:parentWindow 43 parentWindow:parentWindow
43 anchoredAt:NSZeroPoint])) { 44 anchoredAt:NSZeroPoint])) {
44 inset_ = inset; 45 inset_ = inset;
45 [self setShouldOpenAsKeyWindow:NO]; 46 [self setShouldOpenAsKeyWindow:NO];
46 [[self bubble] setArrowLocation:info_bubble::kTopCenter]; 47 [[self bubble] setArrowLocation:arrowLocation];
47 [[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor]; 48 [[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor];
48 49
49 label_.reset([[NSTextField alloc] init]); 50 label_.reset([[NSTextField alloc] init]);
50 [label_ setEditable:NO]; 51 [label_ setEditable:NO];
51 [label_ setBordered:NO]; 52 [label_ setBordered:NO];
52 [label_ setDrawsBackground:NO]; 53 [label_ setDrawsBackground:NO];
53 [label_ setStringValue:message]; 54 [label_ setStringValue:message];
54 NSRect labelFrame = NSMakeRect(inset.width, inset.height, 0, 0); 55 NSRect labelFrame = NSMakeRect(inset.width, inset.height, 0, 0);
55 labelFrame.size = [[label_ cell] cellSizeForBounds: 56 labelFrame.size = [[label_ cell] cellSizeForBounds:
56 NSMakeRect(0, 0, kMaxLabelWidth, CGFLOAT_MAX)]; 57 NSMakeRect(0, 0, kMaxLabelWidth, CGFLOAT_MAX)];
57 [label_ setFrame:labelFrame]; 58 [label_ setFrame:labelFrame];
58 [[self bubble] addSubview:label_]; 59 [[self bubble] addSubview:label_];
59 60
60 NSRect windowFrame = [[self window] frame]; 61 NSRect windowFrame = [[self window] frame];
61 windowFrame.size = NSMakeSize( 62 windowFrame.size = NSMakeSize(
62 NSMaxX([label_ frame]), 63 NSMaxX([label_ frame]),
63 NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight); 64 NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight);
64 windowFrame = NSInsetRect(windowFrame, -inset.width, -inset.height); 65 windowFrame = NSInsetRect(windowFrame, -inset.width, -inset.height);
65 [[self window] setFrame:windowFrame display:NO]; 66 [[self window] setFrame:windowFrame display:NO];
66 } 67 }
67 return self; 68 return self;
68 } 69 }
69 70
70 - (CGFloat)maxWidth { 71 - (CGFloat)maxWidth {
71 return kMaxLabelWidth + 2 * inset_.width; 72 return kMaxLabelWidth + 2 * inset_.width;
72 } 73 }
73 74
74 @end 75 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698