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

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

Issue 2703253007: Use (i) icon and the same tooltip for the credit cards dialog and account chooser on Mac. (Closed)
Patch Set: rebase Created 3 years, 9 months 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
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_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 =
17 2 * autofill::kFieldWidth + autofill::kHorizontalFieldPadding;
18
19 } // namespace 16 } // namespace
20 17
21 @interface AutofillBubbleController () 18 @interface AutofillBubbleController () {
19 CGFloat maxLabelWidth_;
20 }
22 21
23 // Update the current message, keeping arrow location in place. 22 // Update the current message, keeping arrow location in place.
24 - (void)updateMessage:(NSString*)message display:(BOOL)display; 23 - (void)updateMessage:(NSString*)message display:(BOOL)display;
25 24
26 @end 25 @end
27 26
28 @implementation AutofillBubbleController 27 @implementation AutofillBubbleController
29 28
30 - (id)initWithParentWindow:(NSWindow*)parentWindow 29 - (id)initWithParentWindow:(NSWindow*)parentWindow
31 message:(NSString*)message { 30 message:(NSString*)message {
32 return [self initWithParentWindow:parentWindow 31 return [self initWithParentWindow:parentWindow
33 message:message 32 message:message
34 inset:NSMakeSize(kLabelInset, kLabelInset) 33 inset:NSMakeSize(kLabelInset, kLabelInset)
34 maxLabelWidth:CGFLOAT_MAX
35 arrowLocation:info_bubble::kTopCenter]; 35 arrowLocation:info_bubble::kTopCenter];
36 } 36 }
37 37
38 - (id)initWithParentWindow:(NSWindow*)parentWindow 38 - (id)initWithParentWindow:(NSWindow*)parentWindow
39 message:(NSString*)message 39 message:(NSString*)message
40 inset:(NSSize)inset 40 inset:(NSSize)inset
41 maxLabelWidth:(CGFloat)maxLabelWidth
41 arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation { 42 arrowLocation:(info_bubble::BubbleArrowLocation)arrowLocation {
42 base::scoped_nsobject<InfoBubbleWindow> window( 43 base::scoped_nsobject<InfoBubbleWindow> window(
43 [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 100) 44 [[InfoBubbleWindow alloc] initWithContentRect:NSMakeRect(0, 0, 200, 100)
44 styleMask:NSBorderlessWindowMask 45 styleMask:NSBorderlessWindowMask
45 backing:NSBackingStoreBuffered 46 backing:NSBackingStoreBuffered
46 defer:NO]); 47 defer:NO]);
47 [window setAllowedAnimations:info_bubble::kAnimateNone]; 48 [window setAllowedAnimations:info_bubble::kAnimateNone];
48 if ((self = [super initWithWindow:window 49 if ((self = [super initWithWindow:window
49 parentWindow:parentWindow 50 parentWindow:parentWindow
50 anchoredAt:NSZeroPoint])) { 51 anchoredAt:NSZeroPoint])) {
51 inset_ = inset; 52 inset_ = inset;
53 maxLabelWidth_ = maxLabelWidth;
52 [self setShouldOpenAsKeyWindow:NO]; 54 [self setShouldOpenAsKeyWindow:NO];
53 [[self bubble] setArrowLocation:arrowLocation]; 55 [[self bubble] setArrowLocation:arrowLocation];
54 [[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor]; 56 [[self bubble] setAlignment:info_bubble::kAlignArrowToAnchor];
55 57
56 label_.reset([[NSTextField alloc] init]); 58 label_.reset([[NSTextField alloc] init]);
57 [label_ setEditable:NO]; 59 [label_ setEditable:NO];
58 [label_ setBordered:NO]; 60 [label_ setBordered:NO];
59 [label_ setDrawsBackground:NO]; 61 [label_ setDrawsBackground:NO];
60 [[self bubble] addSubview:label_]; 62 [[self bubble] addSubview:label_];
61 63
62 [self updateMessage:message display:NO]; 64 [self updateMessage:message display:NO];
63 } 65 }
64 return self; 66 return self;
65 } 67 }
66 68
67 - (CGFloat)maxWidth {
68 return kMaxLabelWidth + 2 * inset_.width;
69 }
70
71 - (void)setMessage:(NSString*)message { 69 - (void)setMessage:(NSString*)message {
72 if ([[label_ stringValue] isEqualToString:message]) 70 if ([[label_ stringValue] isEqualToString:message])
73 return; 71 return;
74 [self updateMessage:message display:YES]; 72 [self updateMessage:message display:YES];
75 } 73 }
76 74
77 - (void)updateMessage:(NSString*)message display:(BOOL)display { 75 - (void)updateMessage:(NSString*)message display:(BOOL)display {
78 [label_ setStringValue:message]; 76 [label_ setStringValue:message];
79 77
80 NSRect labelFrame = NSMakeRect(inset_.width, inset_.height, 0, 0); 78 NSRect labelFrame = NSMakeRect(inset_.width, inset_.height, 0, 0);
81 labelFrame.size = [[label_ cell] cellSizeForBounds: 79 labelFrame.size = [[label_ cell]
82 NSMakeRect(0, 0, kMaxLabelWidth, CGFLOAT_MAX)]; 80 cellSizeForBounds:NSMakeRect(0, 0, maxLabelWidth_, CGFLOAT_MAX)];
83 [label_ setFrame:labelFrame]; 81 [label_ setFrame:labelFrame];
84 82
85 // Update window's size, but ensure the origin is maintained so that the arrow 83 // Update window's size, but ensure the origin is maintained so that the arrow
86 // still points at the same location. 84 // still points at the same location.
87 NSRect windowFrame = [[self window] frame]; 85 NSRect windowFrame = [[self window] frame];
88 NSPoint origin = windowFrame.origin; 86 NSPoint origin = windowFrame.origin;
89 origin.y += NSHeight(windowFrame); 87 origin.y += NSHeight(windowFrame);
90 windowFrame.size = NSMakeSize( 88 windowFrame.size =
91 NSMaxX([label_ frame]), 89 NSMakeSize(NSWidth([label_ frame]),
92 NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight); 90 NSHeight([label_ frame]) + info_bubble::kBubbleArrowHeight);
93 windowFrame = NSInsetRect(windowFrame, -inset_.width, -inset_.height); 91 windowFrame = NSInsetRect(windowFrame, -inset_.width, -inset_.height);
94 origin.y -= NSHeight(windowFrame); 92 origin.y -= NSHeight(windowFrame);
95 windowFrame.origin = origin; 93 windowFrame.origin = origin;
96 [[self window] setFrame:windowFrame display:display]; 94 [[self window] setFrame:windowFrame display:display];
97 } 95 }
98 96
99 @end 97 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698