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

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

Issue 84343002: [rAC, OSX] Use a bubble for tooltips. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review 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 = 17 const CGFloat kMaxLabelWidth =
18 2 * autofill::kFieldWidth + autofill::kHorizontalFieldPadding; 18 2 * autofill::kFieldWidth + autofill::kHorizontalFieldPadding;
19 19
20 } // namespace 20 } // namespace
21 21
22 22
23 @implementation AutofillBubbleController 23 @implementation AutofillBubbleController
24 24
25 - (id)initWithParentWindow:(NSWindow*)parentWindow 25 - (id)initWithParentWindow:(NSWindow*)parentWindow
26 message:(NSString*)message { 26 message:(NSString*)message {
27 return [self initWithParentWindow:parentWindow
28 message:message
29 inset:NSMakeSize(kLabelInset, kLabelInset)];
30 }
31
32 - (id)initWithParentWindow:(NSWindow*)parentWindow
33 message:(NSString*)message
34 inset:(NSSize)inset {
27 base::scoped_nsobject<InfoBubbleWindow> window( 35 base::scoped_nsobject<InfoBubbleWindow> window(
28 [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 100) 36 [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 100)
29 styleMask:NSBorderlessWindowMask 37 styleMask:NSBorderlessWindowMask
30 backing:NSBackingStoreBuffered 38 backing:NSBackingStoreBuffered
31 defer:NO]); 39 defer:NO]);
32 [window setAllowedAnimations:info_bubble::kAnimateNone]; 40 [window setAllowedAnimations:info_bubble::kAnimateNone];
33 if ((self = [super initWithWindow:window 41 if ((self = [super initWithWindow:window
34 parentWindow:parentWindow 42 parentWindow:parentWindow
35 anchoredAt:NSZeroPoint])) { 43 anchoredAt:NSZeroPoint])) {
44 inset_ = inset;
36 [self setShouldOpenAsKeyWindow:NO]; 45 [self setShouldOpenAsKeyWindow:NO];
37 [[self bubble] setArrowLocation:info_bubble::kTopCenter]; 46 [[self bubble] setArrowLocation:info_bubble::kTopCenter];
38 [[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor]; 47 [[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor];
39 48
40 label_.reset([[NSTextField alloc] init]); 49 label_.reset([[NSTextField alloc] init]);
41 [label_ setEditable:NO]; 50 [label_ setEditable:NO];
42 [label_ setBordered:NO]; 51 [label_ setBordered:NO];
43 [label_ setDrawsBackground:NO]; 52 [label_ setDrawsBackground:NO];
44 [label_ setStringValue:message]; 53 [label_ setStringValue:message];
45 NSRect labelFrame = NSMakeRect(kLabelInset, kLabelInset, 0, 0); 54 NSRect labelFrame = NSMakeRect(inset.width, inset.height, 0, 0);
46 labelFrame.size = [[label_ cell] cellSizeForBounds: 55 labelFrame.size = [[label_ cell] cellSizeForBounds:
47 NSMakeRect(0, 0, kMaxLabelWidth, CGFLOAT_MAX)]; 56 NSMakeRect(0, 0, kMaxLabelWidth, CGFLOAT_MAX)];
48 [label_ setFrame:labelFrame]; 57 [label_ setFrame:labelFrame];
49 [[self bubble] addSubview:label_]; 58 [[self bubble] addSubview:label_];
50 59
51 NSRect windowFrame = [[self window] frame]; 60 NSRect windowFrame = [[self window] frame];
52 windowFrame.size = NSMakeSize( 61 windowFrame.size = NSMakeSize(
53 NSMaxX([label_ frame]), 62 NSMaxX([label_ frame]),
54 NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight); 63 NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight);
55 windowFrame = NSInsetRect(windowFrame, -kLabelInset, -kLabelInset); 64 windowFrame = NSInsetRect(windowFrame, -inset.width, -inset.height);
56 [[self window] setFrame:windowFrame display:NO]; 65 [[self window] setFrame:windowFrame display:NO];
57 } 66 }
58 return self; 67 return self;
59 } 68 }
60 69
61 - (CGFloat)maxWidth { 70 - (CGFloat)maxWidth {
62 return kMaxLabelWidth + 2 * kLabelInset; 71 return kMaxLabelWidth + 2 * inset_.width;
63 } 72 }
64 73
65 @end 74 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698