OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/password_generation_popup_view_cocoa.h " | 5 #import "chrome/browser/ui/cocoa/autofill/password_generation_popup_view_cocoa.h " |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 9 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
10 #include "chrome/browser/ui/autofill/autofill_popup_view.h" | 10 #include "chrome/browser/ui/autofill/autofill_popup_view.h" |
11 #include "chrome/browser/ui/autofill/popup_constants.h" | 11 #include "chrome/browser/ui/autofill/popup_constants.h" |
12 #include "chrome/browser/ui/chrome_style.h" | 12 #include "chrome/browser/ui/chrome_style.h" |
13 #include "chrome/browser/ui/cocoa/autofill/password_generation_popup_view_bridge .h" | 13 #include "chrome/browser/ui/cocoa/autofill/password_generation_popup_view_bridge .h" |
14 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" | 14 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h" |
15 #import "chrome/browser/ui/cocoa/l10n_util.h" | 15 #import "chrome/browser/ui/cocoa/l10n_util.h" |
16 #include "components/autofill/core/browser/popup_item_ids.h" | 16 #include "components/autofill/core/browser/popup_item_ids.h" |
17 #include "grit/theme_resources.h" | |
17 #include "skia/ext/skia_utils_mac.h" | 18 #include "skia/ext/skia_utils_mac.h" |
18 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/gfx/font_list.h" | 20 #include "ui/gfx/font_list.h" |
20 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
21 #include "ui/gfx/point.h" | 22 #include "ui/gfx/point.h" |
22 #include "ui/gfx/range/range.h" | 23 #include "ui/gfx/range/range.h" |
23 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
24 #include "ui/gfx/text_constants.h" | 25 #include "ui/gfx/text_constants.h" |
25 | 26 |
26 using autofill::AutofillPopupView; | 27 using autofill::AutofillPopupView; |
28 using autofill::PasswordGenerationPopupController; | |
27 using autofill::PasswordGenerationPopupView; | 29 using autofill::PasswordGenerationPopupView; |
28 using base::scoped_nsobject; | 30 using base::scoped_nsobject; |
29 | 31 |
30 namespace { | 32 namespace { |
31 | 33 |
34 const CGFloat kDividerWidth = 1; | |
35 const CGFloat kPasswordSectionVerticalSeparation = 5; | |
Ilya Sherman
2014/08/19 22:32:17
nit: Please document these, including units.
dconnelly
2014/08/20 17:07:06
Done.
| |
36 | |
37 CGFloat MidY(NSRect frame) { | |
38 return (NSMaxY(frame) + NSMinY(frame)) / 2.0; | |
Ilya Sherman
2014/08/19 22:32:17
Any particular reason not to just use NSMidY?
dconnelly
2014/08/20 17:07:06
Amusingly, I googled for it and only found crap, b
| |
39 } | |
40 | |
32 NSColor* DividerColor() { | 41 NSColor* DividerColor() { |
33 return gfx::SkColorToCalibratedNSColor( | 42 return gfx::SkColorToCalibratedNSColor( |
34 PasswordGenerationPopupView::kDividerColor); | 43 PasswordGenerationPopupView::kDividerColor); |
35 } | 44 } |
36 | 45 |
37 NSColor* HelpTextBackgroundColor() { | 46 NSColor* HelpTextBackgroundColor() { |
38 return gfx::SkColorToCalibratedNSColor( | 47 return gfx::SkColorToCalibratedNSColor( |
39 PasswordGenerationPopupView::kExplanatoryTextBackgroundColor); | 48 PasswordGenerationPopupView::kExplanatoryTextBackgroundColor); |
40 } | 49 } |
41 | 50 |
(...skipping 18 matching lines...) Expand all Loading... | |
60 } | 69 } |
61 | 70 |
62 - (id)initWithController: | 71 - (id)initWithController: |
63 (autofill::PasswordGenerationPopupController*)controller | 72 (autofill::PasswordGenerationPopupController*)controller |
64 frame:(NSRect)frame { | 73 frame:(NSRect)frame { |
65 if (self = [super initWithDelegate:controller frame:frame]) { | 74 if (self = [super initWithDelegate:controller frame:frame]) { |
66 controller_ = controller; | 75 controller_ = controller; |
67 | 76 |
68 passwordField_ = [self textFieldWithText:controller_->password() | 77 passwordField_ = [self textFieldWithText:controller_->password() |
69 color:[self nameColor] | 78 color:[self nameColor] |
79 font:[self textFont] | |
70 alignment:NSLeftTextAlignment]; | 80 alignment:NSLeftTextAlignment]; |
71 [self addSubview:passwordField_]; | 81 [self addSubview:passwordField_]; |
72 | 82 |
73 passwordSubtextField_ = [self textFieldWithText:controller_->SuggestedText() | 83 passwordTitleField_ = [self textFieldWithText:controller_->SuggestedText() |
74 color:[self subtextColor] | 84 color:[self nameColor] |
75 alignment:NSRightTextAlignment]; | 85 font:[self boldFont] |
76 [self addSubview:passwordSubtextField_]; | 86 alignment:NSLeftTextAlignment]; |
87 [self addSubview:passwordTitleField_]; | |
88 | |
89 keyIcon_ = ResourceBundle::GetSharedInstance() | |
groby-ooo-7-16
2014/08/19 23:32:18
There's nothing retaining keyIcon_ - it can (and w
dconnelly
2014/08/20 17:07:05
Done.
| |
90 .GetImageNamed(IDR_GENERATE_PASSWORD_KEY) | |
91 .ToNSImage(); | |
77 | 92 |
78 scoped_nsobject<HyperlinkTextView> helpTextView( | 93 scoped_nsobject<HyperlinkTextView> helpTextView( |
79 [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]); | 94 [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]); |
80 [helpTextView setMessage:base::SysUTF16ToNSString(controller_->HelpText()) | 95 [helpTextView setMessage:base::SysUTF16ToNSString(controller_->HelpText()) |
81 withFont:[self textFont] | 96 withFont:[self textFont] |
82 messageColor:HelpTextColor()]; | 97 messageColor:HelpTextColor()]; |
83 [helpTextView addLinkRange:controller_->HelpTextLinkRange().ToNSRange() | 98 [helpTextView addLinkRange:controller_->HelpTextLinkRange().ToNSRange() |
84 withName:@"" | 99 withName:@"" |
85 linkColor:HelpLinkColor()]; | 100 linkColor:HelpLinkColor()]; |
86 [helpTextView setDelegate:self]; | 101 [helpTextView setDelegate:self]; |
102 // Remove the underlining. | |
87 [[helpTextView textContainer] setLineFragmentPadding:0.0f]; | 103 [[helpTextView textContainer] setLineFragmentPadding:0.0f]; |
Ilya Sherman
2014/08/19 22:32:17
Is this still needed, in addition to the code you
dconnelly
2014/08/20 17:07:06
Done.
| |
88 [helpTextView setVerticallyResizable:YES]; | 104 [helpTextView setVerticallyResizable:YES]; |
105 [helpTextView setLinkTextAttributes:nil]; | |
groby-ooo-7-16
2014/08/19 23:32:18
setLinkTextAttributes:nil does nothing for Hyperli
dconnelly
2014/08/20 17:07:06
Done.
| |
106 NSTextStorage* text = [helpTextView textStorage]; | |
107 [text addAttribute:NSUnderlineStyleAttributeName | |
108 value:[NSNumber numberWithInt:NSUnderlineStyleNone] | |
109 range:controller_->HelpTextLinkRange().ToNSRange()]; | |
groby-ooo-7-16
2014/08/19 23:32:18
Is this cleared with UI review? HyperlinkTextView
dconnelly
2014/08/20 17:07:06
This came from UI mocks: https://code.google.com/p
| |
89 [self addSubview:helpTextView]; | 110 [self addSubview:helpTextView]; |
90 helpTextView_ = helpTextView.get(); | 111 helpTextView_ = helpTextView.get(); |
groby-ooo-7-16
2014/08/19 23:32:18
Why? Why not make helpTextView_ a scoped_nsobject?
dconnelly
2014/08/20 17:07:06
Agreed. I've now converted all the __weak pointer
| |
91 } | 112 } |
92 | 113 |
93 return self; | 114 return self; |
94 } | 115 } |
95 | 116 |
96 #pragma mark NSView implementation: | 117 #pragma mark NSView implementation: |
97 | 118 |
98 - (void)drawRect:(NSRect)dirtyRect { | 119 - (void)drawRect:(NSRect)dirtyRect { |
groby-ooo-7-16
2014/08/19 23:32:18
This is missing a call to [super drawRect:] - inte
dconnelly
2014/08/20 17:07:06
I don't know; this is inherited code. I can't tell
| |
99 // If the view is in the process of being destroyed, don't bother drawing. | 120 // If the view is in the process of being destroyed, don't bother drawing. |
100 if (!controller_) | 121 if (!controller_) |
101 return; | 122 return; |
102 | 123 |
103 [self drawBackgroundAndBorder]; | 124 [self drawBackgroundAndBorder]; |
104 | 125 |
126 const CGFloat width = | |
127 NSWidth(NSRectFromCGRect(controller_->popup_bounds().ToCGRect())); | |
128 | |
105 if (controller_->password_selected()) { | 129 if (controller_->password_selected()) { |
106 // Draw a highlight under the suggested password. | 130 // Draw a highlight under the suggested password. |
107 NSRect highlightBounds = [self passwordBounds]; | 131 NSRect highlightBounds = [self passwordSectionBoundsForWidth:width]; |
108 [[self highlightColor] set]; | 132 [[self highlightColor] set]; |
109 [NSBezierPath fillRect:highlightBounds]; | 133 [NSBezierPath fillRect:highlightBounds]; |
110 } | 134 } |
111 | 135 |
112 // Render the background of the help text. | 136 // Render the background of the help text. |
113 [HelpTextBackgroundColor() set]; | 137 [HelpTextBackgroundColor() set]; |
114 [NSBezierPath fillRect:[self helpBounds]]; | 138 [NSBezierPath fillRect:[self helpBoundsForWidth:width]]; |
groby-ooo-7-16
2014/08/19 23:32:18
Why not just set a background color on the help te
dconnelly
2014/08/20 17:07:06
Done.
| |
115 | 139 |
116 // Render the divider. | 140 // Render the divider. |
117 [DividerColor() set]; | 141 [DividerColor() set]; |
groby-ooo-7-16
2014/08/19 23:32:17
Usually, you draw dividers by just having an NSBox
dconnelly
2014/08/20 17:07:06
You can't change its color that way. I've replaced
| |
118 [NSBezierPath fillRect:[self dividerBounds]]; | 142 [NSBezierPath fillRect:[self dividerBoundsForWidth:width]]; |
143 | |
144 // Render the key icon. | |
145 [keyIcon_ drawInRect:[self iconBoundsForWidth:width] | |
groby-ooo-7-16
2014/08/19 23:32:18
Can you use an NSImageView instead?
dconnelly
2014/08/20 17:07:05
Done.
| |
146 fromRect:{ NSZeroPoint, [keyIcon_ size] } | |
groby-ooo-7-16
2014/08/19 23:32:18
Passing in NSZeroRect automatically specifies the
dconnelly
2014/08/20 17:07:05
Done.
| |
147 operation:NSCompositeSourceOver | |
148 fraction:1.0 | |
149 respectFlipped:YES | |
150 hints:nil]; | |
119 } | 151 } |
120 | 152 |
121 #pragma mark Public API: | 153 #pragma mark Public API: |
122 | 154 |
155 - (NSSize)preferredSize { | |
156 const CGFloat popupWidth = controller_->GetMinimumWidth(); | |
157 NSRect helpBounds = [self helpBoundsForWidth:popupWidth]; | |
158 CGFloat height = | |
159 (controller_->display_password() | |
160 ? NSHeight([self passwordSectionBoundsForWidth:popupWidth]) | |
161 : 0) + | |
162 NSHeight([self dividerBoundsForWidth:popupWidth]) + NSHeight(helpBounds) + | |
163 2 * autofill::kPopupBorderThickness; | |
164 return NSMakeSize(popupWidth + 2 * autofill::kPopupBorderThickness, height); | |
165 } | |
166 | |
167 - (void)updatePassword { | |
168 [self setText:controller_->password() | |
169 color:[self nameColor] | |
170 font:[self textFont] | |
171 alignment:NSLeftTextAlignment | |
172 forField:passwordField_]; | |
Ilya Sherman
2014/08/19 22:32:17
Is it not possible to update the text without need
dconnelly
2014/08/20 17:07:05
I thought not, but I found a way. Done.
| |
173 } | |
174 | |
123 - (void)updateBoundsAndRedrawPopup { | 175 - (void)updateBoundsAndRedrawPopup { |
124 [self positionView:passwordField_ inRect:[self passwordBounds]]; | 176 const CGFloat width = |
125 [self positionView:passwordSubtextField_ inRect:[self passwordBounds]]; | 177 NSWidth(NSRectFromCGRect(controller_->popup_bounds().ToCGRect())); |
groby-ooo-7-16
2014/08/19 23:32:18
Just width = controller->popup_bounds().width()
N
dconnelly
2014/08/20 17:07:05
Done.
| |
126 [self positionView:helpTextView_ inRect:[self helpBounds]]; | 178 // The password can change while the bubble is shown: if the user has |
Ilya Sherman
2014/08/19 22:32:17
nit: "if" -> "If"
dconnelly
2014/08/20 17:07:06
TIL. Done.
| |
179 // accepted the password and then selects the form again and starts deleting | |
180 // the password, the field will be initially invisible and then become | |
181 // visible. | |
182 [self updatePassword]; | |
Ilya Sherman
2014/08/19 22:32:17
nit: Can this be moved into the if-stmt below?
dconnelly
2014/08/20 17:07:05
Done.
| |
183 if (controller_->display_password()) { | |
184 [self positionView:passwordTitleField_ | |
185 inRect:[self passwordSectionTitleBoundsForWidth:width]]; | |
186 [self positionView:passwordField_ | |
187 inRect:[self passwordBoundsForWidth:width]]; | |
188 } | |
189 [self positionView:helpTextView_ inRect:[self helpBoundsForWidth:width]]; | |
190 [super updateBoundsAndRedrawPopup]; | |
191 } | |
127 | 192 |
128 [super updateBoundsAndRedrawPopup]; | 193 - (BOOL)isPointInPasswordBounds:(CGPoint)point { |
194 const CGFloat width = | |
195 NSWidth(NSRectFromCGRect(controller_->popup_bounds().ToCGRect())); | |
196 return CGRectContainsPoint( | |
197 NSRectToCGRect([self passwordSectionBoundsForWidth:width]), point); | |
Ilya Sherman
2014/08/19 22:32:17
Can you use NSPointInRect instead? (In general, N
dconnelly
2014/08/20 17:07:05
Done.
| |
129 } | 198 } |
130 | 199 |
131 - (void)controllerDestroyed { | 200 - (void)controllerDestroyed { |
132 controller_ = NULL; | 201 controller_ = NULL; |
133 [super delegateDestroyed]; | 202 [super delegateDestroyed]; |
134 } | 203 } |
135 | 204 |
136 #pragma mark NSTextViewDelegate implementation: | 205 #pragma mark NSTextViewDelegate implementation: |
137 | 206 |
138 - (BOOL)textView:(NSTextView*)textView | 207 - (BOOL)textView:(NSTextView*)textView |
139 clickedOnLink:(id)link | 208 clickedOnLink:(id)link |
140 atIndex:(NSUInteger)charIndex { | 209 atIndex:(NSUInteger)charIndex { |
141 controller_->OnSavedPasswordsLinkClicked(); | 210 controller_->OnSavedPasswordsLinkClicked(); |
142 return YES; | 211 return YES; |
143 } | 212 } |
144 | 213 |
145 #pragma mark Private helpers: | 214 #pragma mark Private helpers: |
146 | 215 |
147 - (NSTextField*)textFieldWithText:(const base::string16&)text | 216 - (void)setText:(const base::string16&)text |
148 color:(NSColor*)color | 217 color:(NSColor*)color |
149 alignment:(NSTextAlignment)alignment { | 218 font:(NSFont*)font |
219 alignment:(NSTextAlignment)alignment | |
220 forField:(NSTextField*)field { | |
groby-ooo-7-16
2014/08/19 23:32:17
This seem overkill, but I'm not sure how many diff
dconnelly
2014/08/20 17:07:06
Done.
| |
150 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( | 221 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( |
151 [[NSMutableParagraphStyle alloc] init]); | 222 [[NSMutableParagraphStyle alloc] init]); |
152 [paragraphStyle setAlignment:alignment]; | 223 [paragraphStyle setAlignment:alignment]; |
153 | 224 |
154 NSDictionary* textAttributes = @{ | 225 NSDictionary* textAttributes = @{ |
155 NSFontAttributeName : [self textFont], | 226 NSFontAttributeName : font, |
156 NSForegroundColorAttributeName : color, | 227 NSForegroundColorAttributeName : color, |
157 NSParagraphStyleAttributeName : paragraphStyle | 228 NSParagraphStyleAttributeName : paragraphStyle |
158 }; | 229 }; |
159 | 230 |
160 scoped_nsobject<NSAttributedString> attributedString( | 231 scoped_nsobject<NSAttributedString> attributedString( |
161 [[NSAttributedString alloc] | 232 [[NSAttributedString alloc] |
162 initWithString:base::SysUTF16ToNSString(text) | 233 initWithString:base::SysUTF16ToNSString(text) |
163 attributes:textAttributes]); | 234 attributes:textAttributes]); |
164 | 235 |
236 [field setAttributedStringValue:attributedString]; | |
237 } | |
238 | |
239 - (NSTextField*)textFieldWithText:(const base::string16&)text | |
240 color:(NSColor*)color | |
241 font:(NSFont*)font | |
242 alignment:(NSTextAlignment)alignment { | |
165 NSTextField* textField = | 243 NSTextField* textField = |
166 [[[NSTextField alloc] initWithFrame:NSZeroRect] autorelease]; | 244 [[[NSTextField alloc] initWithFrame:NSZeroRect] autorelease]; |
167 [textField setAttributedStringValue:attributedString]; | 245 [self setText:text |
246 color:color | |
247 font:font | |
248 alignment:alignment | |
249 forField:textField]; | |
168 [textField setEditable:NO]; | 250 [textField setEditable:NO]; |
169 [textField setSelectable:NO]; | 251 [textField setSelectable:NO]; |
170 [textField setDrawsBackground:NO]; | 252 [textField setDrawsBackground:NO]; |
171 [textField setBezeled:NO]; | 253 [textField setBezeled:NO]; |
172 return textField; | 254 return textField; |
173 } | 255 } |
174 | 256 |
175 - (void)positionView:(NSView*)view inRect:(NSRect)bounds { | 257 - (void)positionView:(NSView*)view inRect:(NSRect)bounds { |
176 NSRect frame = NSInsetRect(bounds, controller_->kHorizontalPadding, 0); | 258 NSRect frame = NSInsetRect(bounds, controller_->kHorizontalPadding, 0); |
177 [view setFrame:frame]; | 259 [view setFrame:frame]; |
178 | 260 |
179 // Center the text vertically within the bounds. | 261 // Center the text vertically within the bounds. |
180 NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(view); | 262 NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(view); |
181 [view setFrameOrigin: | 263 [view setFrameOrigin: |
182 NSInsetRect(frame, 0, floor(-delta.height/2)).origin]; | 264 NSInsetRect(frame, 0, floor(-delta.height/2)).origin]; |
183 } | 265 } |
184 | 266 |
185 - (NSRect)passwordBounds { | 267 - (NSRect)passwordSectionBoundsForWidth:(CGFloat)width { |
groby-ooo-7-16
2014/08/19 23:32:18
Using bounds in the name is confusing. Usually, [s
dconnelly
2014/08/20 17:07:06
I think all this is confusing, so I've removed the
| |
186 return NSZeroRect; | 268 if (!controller_->display_password()) |
269 return NSZeroRect; | |
270 return NSMakeRect( | |
271 autofill::kPopupBorderThickness, | |
272 autofill::kPopupBorderThickness, | |
273 width - 2 * autofill::kPopupBorderThickness, | |
274 PasswordGenerationPopupController::kPopupPasswordSectionHeight); | |
187 } | 275 } |
188 | 276 |
189 - (NSRect)helpBounds { | 277 - (NSSize)sizeOfSingleLineString:(const base::string16&)string |
190 return NSZeroRect; | 278 withFont:(NSFont*)font { |
279 NSRect textFrame = [base::SysUTF16ToNSString(string) | |
280 boundingRectWithSize:NSMakeSize(MAXFLOAT, MAXFLOAT) | |
281 options:0 | |
282 attributes:@{ NSFontAttributeName : font }]; | |
283 return textFrame.size; | |
Ilya Sherman
2014/08/19 22:32:17
I feel like this code must already exist somewhere
dconnelly
2014/08/20 17:07:06
Done.
| |
191 } | 284 } |
192 | 285 |
193 - (NSRect)dividerBounds { | 286 - (NSRect)passwordSectionTitleBoundsForWidth:(CGFloat)width { |
194 return NSZeroRect; | 287 if (!controller_->display_password()) |
288 return NSZeroRect; | |
289 NSRect passwordSectionBounds = [self passwordSectionBoundsForWidth:width]; | |
290 NSSize passwordSize = [self sizeOfSingleLineString:controller_->password() | |
291 withFont:[self boldFont]]; | |
292 const CGFloat y = MidY(passwordSectionBounds) - | |
293 (kPasswordSectionVerticalSeparation / 2.0) - | |
groby-ooo-7-16
2014/08/19 23:32:18
Be careful with rounding. Currently, kPasswordSect
dconnelly
2014/08/20 17:07:05
Done.
| |
294 passwordSize.height; | |
groby-ooo-7-16
2014/08/19 23:32:18
You seem to just care about the height of the text
dconnelly
2014/08/20 17:07:06
It's deprecated. I think this should be fine, as t
| |
295 const CGFloat x = NSMaxX([self iconBoundsForWidth:width]); | |
296 return NSMakeRect( | |
297 x, y, NSWidth(passwordSectionBounds) - x, passwordSize.height); | |
298 } | |
299 | |
300 - (NSRect)passwordBoundsForWidth:(CGFloat)width { | |
301 NSRect passwordSectionBounds = [self passwordSectionBoundsForWidth:width]; | |
302 NSSize titleSize = [self sizeOfSingleLineString:controller_->SuggestedText() | |
303 withFont:[self textFont]]; | |
304 const CGFloat y = MidY(passwordSectionBounds) + | |
305 (kPasswordSectionVerticalSeparation / 2.0); | |
306 const CGFloat x = NSMaxX([self iconBoundsForWidth:width]); | |
307 return NSMakeRect(x, y, NSWidth(passwordSectionBounds) - x, titleSize.height); | |
308 } | |
309 | |
310 - (NSRect)dividerBoundsForWidth:(CGFloat)width { | |
311 if (!controller_->display_password()) | |
312 return NSZeroRect; | |
313 return NSMakeRect(autofill::kPopupBorderThickness, | |
314 NSMaxY([self passwordSectionBoundsForWidth:width]), | |
315 width - 2 * autofill::kPopupBorderThickness, | |
316 kDividerWidth); | |
groby-ooo-7-16
2014/08/19 23:32:18
Why is the last param kDividerWidth? Shouldn't tha
dconnelly
2014/08/20 17:07:06
Poor naming. I was thinking of the line as having
| |
317 } | |
318 | |
319 - (NSRect)helpBoundsForWidth:(CGFloat)width { | |
320 NSSize size = | |
321 NSMakeSize(width - 2 * autofill::kPopupBorderThickness, MAXFLOAT); | |
322 NSStringDrawingOptions options = | |
323 NSLineBreakByWordWrapping | NSStringDrawingUsesLineFragmentOrigin; | |
324 NSDictionary* attributes = @{ NSFontAttributeName : [self textFont] }; | |
325 NSRect textFrame = [base::SysUTF16ToNSString(controller_->HelpText()) | |
326 boundingRectWithSize:size | |
327 options:options | |
328 attributes:attributes]; | |
groby-ooo-7-16
2014/08/19 23:32:18
Ideally, you don't want to compute field sizes at
dconnelly
2014/08/20 17:07:05
Done.
| |
329 const int verticalPadding = | |
330 autofill::PasswordGenerationPopupController::kHelpVerticalPadding; | |
331 size.height = NSHeight(textFrame) + 2 * verticalPadding; | |
332 | |
333 // The help section falls immediately above and to the right of the border. | |
334 NSPoint origin = NSMakePoint(autofill::kPopupBorderThickness, | |
335 controller_->display_password() | |
336 ? NSMaxY([self dividerBoundsForWidth:width]) | |
337 : autofill::kPopupBorderThickness); | |
338 | |
339 return { origin, size }; | |
340 } | |
341 | |
342 - (NSRect)iconBoundsForWidth:(CGFloat)width { | |
343 if (!controller_->display_password()) | |
344 return NSZeroRect; | |
345 NSRect passwordSectionBounds = [self passwordSectionBoundsForWidth:width]; | |
346 CGFloat passwordMidY = MidY(passwordSectionBounds); | |
347 NSSize iconSize = [keyIcon_ size]; | |
348 return NSMakeRect(PasswordGenerationPopupController::kHorizontalPadding, | |
349 passwordMidY - (iconSize.height / 2.0), | |
350 iconSize.width, | |
351 iconSize.height); | |
352 } | |
353 | |
354 - (NSFont*)boldFont { | |
355 return ResourceBundle::GetSharedInstance() | |
groby-ooo-7-16
2014/08/19 23:32:18
Fonts grabbed with DeriveWithStyle don't always lo
dconnelly
2014/08/20 17:07:06
Done.
| |
356 .GetFontList(ResourceBundle::SmallFont) | |
357 .DeriveWithStyle(gfx::Font::BOLD) | |
358 .GetPrimaryFont() | |
359 .GetNativeFont(); | |
195 } | 360 } |
196 | 361 |
197 - (NSFont*)textFont { | 362 - (NSFont*)textFont { |
198 return ResourceBundle::GetSharedInstance().GetFontList( | 363 return ResourceBundle::GetSharedInstance().GetFontList( |
199 ResourceBundle::SmallFont).GetPrimaryFont().GetNativeFont(); | 364 ResourceBundle::SmallFont).GetPrimaryFont().GetNativeFont(); |
Ilya Sherman
2014/08/19 22:32:17
nit: Perhaps format this to match the formatting a
dconnelly
2014/08/20 17:07:05
Done.
| |
200 } | 365 } |
201 | 366 |
202 @end | 367 @end |
OLD | NEW |