Commit e850da7c authored by dubroy@chromium.org's avatar dubroy@chromium.org

[Mac] Password generation: Make "saved passwords" a hyperlink.

BUG=114092

Review URL: https://codereview.chromium.org/308833002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278017 0039d316-1c4b-4281-b951-d872f2087c98
parent 493e2e84
...@@ -14,15 +14,18 @@ namespace autofill { ...@@ -14,15 +14,18 @@ namespace autofill {
class AutofillPopupController; class AutofillPopupController;
} // namespace autofill } // namespace autofill
@class HyperlinkTextView;
// Draws the native password generation popup view on Mac. // Draws the native password generation popup view on Mac.
@interface PasswordGenerationPopupViewCocoa : AutofillPopupBaseViewCocoa { @interface PasswordGenerationPopupViewCocoa
: AutofillPopupBaseViewCocoa <NSTextViewDelegate> {
@private @private
// The cross-platform controller for this view. // The cross-platform controller for this view.
__weak autofill::PasswordGenerationPopupController* controller_; __weak autofill::PasswordGenerationPopupController* controller_;
__weak NSTextField* passwordField_; __weak NSTextField* passwordField_;
__weak NSTextField* passwordSubtextField_; __weak NSTextField* passwordSubtextField_;
__weak NSTextField* helpTextField_; __weak HyperlinkTextView* helpTextView_;
} }
// Designated initializer. // Designated initializer.
......
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
#include "chrome/browser/ui/autofill/autofill_popup_controller.h" #include "chrome/browser/ui/autofill/autofill_popup_controller.h"
#include "chrome/browser/ui/autofill/autofill_popup_view.h" #include "chrome/browser/ui/autofill/autofill_popup_view.h"
#include "chrome/browser/ui/autofill/popup_constants.h" #include "chrome/browser/ui/autofill/popup_constants.h"
#include "chrome/browser/ui/chrome_style.h"
#include "chrome/browser/ui/cocoa/autofill/password_generation_popup_view_bridge.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" #import "chrome/browser/ui/cocoa/l10n_util.h"
#include "components/autofill/core/browser/popup_item_ids.h" #include "components/autofill/core/browser/popup_item_ids.h"
#include "grit/ui_resources.h" #include "grit/ui_resources.h"
...@@ -18,6 +20,7 @@ ...@@ -18,6 +20,7 @@
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/point.h" #include "ui/gfx/point.h"
#include "ui/gfx/range/range.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#include "ui/gfx/text_constants.h" #include "ui/gfx/text_constants.h"
...@@ -42,6 +45,10 @@ NSColor* HelpTextColor() { ...@@ -42,6 +45,10 @@ NSColor* HelpTextColor() {
PasswordGenerationPopupView::kExplanatoryTextColor); PasswordGenerationPopupView::kExplanatoryTextColor);
} }
NSColor* HelpLinkColor() {
return gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor());
}
} // namespace } // namespace
@implementation PasswordGenerationPopupViewCocoa @implementation PasswordGenerationPopupViewCocoa
...@@ -58,26 +65,30 @@ NSColor* HelpTextColor() { ...@@ -58,26 +65,30 @@ NSColor* HelpTextColor() {
frame:(NSRect)frame { frame:(NSRect)frame {
if (self = [super initWithDelegate:controller frame:frame]) { if (self = [super initWithDelegate:controller frame:frame]) {
controller_ = controller; controller_ = controller;
NSFont* font = controller_->font_list().GetPrimaryFont().GetNativeFont();
passwordField_ = [self textFieldWithText:controller_->password() passwordField_ = [self textFieldWithText:controller_->password()
withFont:font
color:[self nameColor] color:[self nameColor]
alignment:NSLeftTextAlignment]; alignment:NSLeftTextAlignment];
[self addSubview:passwordField_]; [self addSubview:passwordField_];
passwordSubtextField_ = passwordSubtextField_ = [self textFieldWithText:controller_->SuggestedText()
[self textFieldWithText:controller_->SuggestedText() color:[self subtextColor]
withFont:font alignment:NSRightTextAlignment];
color:[self subtextColor]
alignment:NSRightTextAlignment];
[self addSubview:passwordSubtextField_]; [self addSubview:passwordSubtextField_];
helpTextField_ = [self textFieldWithText:controller_->HelpText() scoped_nsobject<HyperlinkTextView> helpTextView(
withFont:font [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]);
color:HelpTextColor() [helpTextView setMessage:base::SysUTF16ToNSString(controller_->HelpText())
alignment:NSLeftTextAlignment]; withFont:[self textFont]
[self addSubview:helpTextField_]; messageColor:HelpTextColor()];
[helpTextView addLinkRange:controller_->HelpTextLinkRange().ToNSRange()
withName:@""
linkColor:HelpLinkColor()];
[helpTextView setDelegate:self];
[[helpTextView textContainer] setLineFragmentPadding:0.0f];
[helpTextView setVerticallyResizable:YES];
[self addSubview:helpTextView];
helpTextView_ = helpTextView.get();
} }
return self; return self;
...@@ -115,9 +126,9 @@ NSColor* HelpTextColor() { ...@@ -115,9 +126,9 @@ NSColor* HelpTextColor() {
#pragma mark Public API: #pragma mark Public API:
- (void)updateBoundsAndRedrawPopup { - (void)updateBoundsAndRedrawPopup {
[self positionTextField:passwordField_ inRect:[self passwordBounds]]; [self positionView:passwordField_ inRect:[self passwordBounds]];
[self positionTextField:passwordSubtextField_ inRect:[self passwordBounds]]; [self positionView:passwordSubtextField_ inRect:[self passwordBounds]];
[self positionTextField:helpTextField_ inRect:[self helpBounds]]; [self positionView:helpTextView_ inRect:[self helpBounds]];
[super updateBoundsAndRedrawPopup]; [super updateBoundsAndRedrawPopup];
} }
...@@ -127,10 +138,18 @@ NSColor* HelpTextColor() { ...@@ -127,10 +138,18 @@ NSColor* HelpTextColor() {
[super delegateDestroyed]; [super delegateDestroyed];
} }
#pragma mark NSTextViewDelegate implementation:
- (BOOL)textView:(NSTextView*)textView
clickedOnLink:(id)link
atIndex:(NSUInteger)charIndex {
controller_->OnSavedPasswordsLinkClicked();
return YES;
}
#pragma mark Private helpers: #pragma mark Private helpers:
- (NSTextField*)textFieldWithText:(const base::string16&)text - (NSTextField*)textFieldWithText:(const base::string16&)text
withFont:(NSFont*)font
color:(NSColor*)color color:(NSColor*)color
alignment:(NSTextAlignment)alignment { alignment:(NSTextAlignment)alignment {
scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
...@@ -138,7 +157,7 @@ NSColor* HelpTextColor() { ...@@ -138,7 +157,7 @@ NSColor* HelpTextColor() {
[paragraphStyle setAlignment:alignment]; [paragraphStyle setAlignment:alignment];
NSDictionary* textAttributes = @{ NSDictionary* textAttributes = @{
NSFontAttributeName : font, NSFontAttributeName : [self textFont],
NSForegroundColorAttributeName : color, NSForegroundColorAttributeName : color,
NSParagraphStyleAttributeName : paragraphStyle NSParagraphStyleAttributeName : paragraphStyle
}; };
...@@ -155,17 +174,16 @@ NSColor* HelpTextColor() { ...@@ -155,17 +174,16 @@ NSColor* HelpTextColor() {
[textField setSelectable:NO]; [textField setSelectable:NO];
[textField setDrawsBackground:NO]; [textField setDrawsBackground:NO];
[textField setBezeled:NO]; [textField setBezeled:NO];
return textField; return textField;
} }
- (void)positionTextField:(NSTextField*)textField inRect:(NSRect)bounds { - (void)positionView:(NSView*)view inRect:(NSRect)bounds {
NSRect frame = NSInsetRect(bounds, controller_->kHorizontalPadding, 0); NSRect frame = NSInsetRect(bounds, controller_->kHorizontalPadding, 0);
[textField setFrame:frame]; [view setFrame:frame];
// Center the text vertically within the bounds. // Center the text vertically within the bounds.
NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(textField); NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(view);
[textField setFrameOrigin: [view setFrameOrigin:
NSInsetRect(frame, 0, floor(-delta.height/2)).origin]; NSInsetRect(frame, 0, floor(-delta.height/2)).origin];
} }
...@@ -181,4 +199,8 @@ NSColor* HelpTextColor() { ...@@ -181,4 +199,8 @@ NSColor* HelpTextColor() {
return NSRectFromCGRect(controller_->divider_bounds().ToCGRect()); return NSRectFromCGRect(controller_->divider_bounds().ToCGRect());
} }
- (NSFont*)textFont {
return controller_->font_list().GetPrimaryFont().GetNativeFont();
}
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment