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

Unified Diff: chrome/browser/ui/cocoa/autofill/password_generation_popup_view_cocoa.mm

Issue 308833002: [Mac] Password generation: Make "saved passwords" a hyperlink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/autofill/password_generation_popup_view_cocoa.mm
diff --git a/chrome/browser/ui/cocoa/autofill/password_generation_popup_view_cocoa.mm b/chrome/browser/ui/cocoa/autofill/password_generation_popup_view_cocoa.mm
index 304bb1a7c0f6d977483f58ea88dc1efb94b79b8c..dea1d21d9299da5170313797e4d86b19bbd790fd 100644
--- a/chrome/browser/ui/cocoa/autofill/password_generation_popup_view_cocoa.mm
+++ b/chrome/browser/ui/cocoa/autofill/password_generation_popup_view_cocoa.mm
@@ -10,6 +10,7 @@
#include "chrome/browser/ui/autofill/autofill_popup_view.h"
#include "chrome/browser/ui/autofill/popup_constants.h"
#include "chrome/browser/ui/cocoa/autofill/password_generation_popup_view_bridge.h"
+#import "chrome/browser/ui/cocoa/hyperlink_text_view.h"
#import "chrome/browser/ui/cocoa/l10n_util.h"
#include "components/autofill/core/browser/popup_item_ids.h"
#include "grit/ui_resources.h"
@@ -18,6 +19,7 @@
#include "ui/gfx/font_list.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/point.h"
+#include "ui/gfx/range/range.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/text_constants.h"
@@ -58,26 +60,29 @@ NSColor* HelpTextColor() {
frame:(NSRect)frame {
if (self = [super initWithDelegate:controller frame:frame]) {
controller_ = controller;
- NSFont* font = controller_->font_list().GetPrimaryFont().GetNativeFont();
-
- passwordField_ = [self textFieldWithText:controller_->password()
- withFont:font
- color:[self nameColor]
- alignment:NSLeftTextAlignment];
- [self addSubview:passwordField_];
-
- passwordSubtextField_ =
- [self textFieldWithText:controller_->SuggestedText()
- withFont:font
- color:[self subtextColor]
- alignment:NSRightTextAlignment];
- [self addSubview:passwordSubtextField_];
-
- helpTextField_ = [self textFieldWithText:controller_->HelpText()
- withFont:font
- color:HelpTextColor()
- alignment:NSLeftTextAlignment];
- [self addSubview:helpTextField_];
+
+ passwordView_ = [self textViewWithText:controller_->password()
groby-ooo-7-16 2014/05/30 18:05:01 I'm not clear why you're switching the password fi
Patrick Dubroy 2014/06/02 07:46:52 It's not really necessary, I just thought NSTextVi
+ color:[self nameColor]
+ alignment:NSLeftTextAlignment];
+ [self addSubview:passwordView_];
+
+ passwordSubtextView_ = [self textViewWithText:controller_->SuggestedText()
+ color:[self subtextColor]
+ alignment:NSRightTextAlignment];
+ [self addSubview:passwordSubtextView_];
+
+ helpTextView_ =
groby-ooo-7-16 2014/05/30 18:05:01 IIRC, we prefer scoped_nsobject over autoreleased
Patrick Dubroy 2014/06/02 07:46:52 Done. Though I'm not sure whether you meant that I
+ [[[HyperlinkTextView alloc] initWithFrame:NSZeroRect] autorelease];
+ [helpTextView_ setMessage:base::SysUTF16ToNSString(controller_->HelpText())
+ withFont:[self textFont]
+ messageColor:HelpTextColor()];
+ [helpTextView_ addLinkRange:controller_->HelpTextLinkRange().ToNSRange()
+ withName:@""
+ linkColor:[NSColor blueColor]];
+ [helpTextView_ setDelegate:self];
+ [[helpTextView_ textContainer] setLineFragmentPadding:0.0f];
+ [helpTextView_ setVerticallyResizable:YES];
+ [self addSubview:helpTextView_];
}
return self;
@@ -115,9 +120,9 @@ NSColor* HelpTextColor() {
#pragma mark Public API:
- (void)updateBoundsAndRedrawPopup {
- [self positionTextField:passwordField_ inRect:[self passwordBounds]];
- [self positionTextField:passwordSubtextField_ inRect:[self passwordBounds]];
- [self positionTextField:helpTextField_ inRect:[self helpBounds]];
+ [self positionTextView:passwordView_ inRect:[self passwordBounds]];
+ [self positionTextView:passwordSubtextView_ inRect:[self passwordBounds]];
+ [self positionTextView:helpTextView_ inRect:[self helpBounds]];
[super updateBoundsAndRedrawPopup];
}
@@ -127,18 +132,26 @@ NSColor* HelpTextColor() {
[super delegateDestroyed];
}
+#pragma mark NSTextViewDelegate implementation:
+
+- (BOOL)textView:(NSTextView *)textView
+ clickedOnLink:(id)link
+ atIndex:(NSUInteger)charIndex {
+ controller_->OnSavedPasswordsLinkClicked();
+ return YES;
+}
+
#pragma mark Private helpers:
-- (NSTextField*)textFieldWithText:(const base::string16&)text
- withFont:(NSFont*)font
- color:(NSColor*)color
- alignment:(NSTextAlignment)alignment {
+- (NSTextView*)textViewWithText:(const base::string16&)text
+ color:(NSColor*)color
+ alignment:(NSTextAlignment)alignment {
scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
[[NSMutableParagraphStyle alloc] init]);
[paragraphStyle setAlignment:alignment];
NSDictionary* textAttributes = @{
- NSFontAttributeName : font,
+ NSFontAttributeName : [self textFont],
NSForegroundColorAttributeName : color,
NSParagraphStyleAttributeName : paragraphStyle
};
@@ -148,24 +161,22 @@ NSColor* HelpTextColor() {
initWithString:base::SysUTF16ToNSString(text)
attributes:textAttributes]);
- NSTextField* textField =
- [[[NSTextField alloc] initWithFrame:NSZeroRect] autorelease];
- [textField setAttributedStringValue:attributedString];
- [textField setEditable:NO];
- [textField setSelectable:NO];
- [textField setDrawsBackground:NO];
- [textField setBezeled:NO];
-
- return textField;
+ NSTextView* textView =
+ [[[NSTextView alloc] initWithFrame:NSZeroRect] autorelease];
+ [[textView textStorage] setAttributedString:attributedString];
+ [[textView textContainer] setLineFragmentPadding:0.0f];
+ [textView setSelectable:NO];
+ [textView setDrawsBackground:NO];
+ return textView;
}
-- (void)positionTextField:(NSTextField*)textField inRect:(NSRect)bounds {
+- (void)positionTextView:(NSTextView*)textView inRect:(NSRect)bounds {
NSRect frame = NSInsetRect(bounds, controller_->kHorizontalPadding, 0);
- [textField setFrame:frame];
+ [textView setFrame:frame];
// Center the text vertically within the bounds.
- NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(textField);
- [textField setFrameOrigin:
+ NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(textView);
+ [textView setFrameOrigin:
NSInsetRect(frame, 0, floor(-delta.height/2)).origin];
}
@@ -181,4 +192,8 @@ NSColor* HelpTextColor() {
return NSRectFromCGRect(controller_->divider_bounds().ToCGRect());
}
+- (NSFont*)textFont {
+ return controller_->font_list().GetPrimaryFont().GetNativeFont();
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698