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

Side by Side 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: Address comments. Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/cocoa/autofill/password_generation_popup_view_cocoa.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/cocoa/autofill/password_generation_popup_view_bridge .h" 12 #include "chrome/browser/ui/cocoa/autofill/password_generation_popup_view_bridge .h"
13 #import "chrome/browser/ui/cocoa/hyperlink_text_view.h"
13 #import "chrome/browser/ui/cocoa/l10n_util.h" 14 #import "chrome/browser/ui/cocoa/l10n_util.h"
14 #include "components/autofill/core/browser/popup_item_ids.h" 15 #include "components/autofill/core/browser/popup_item_ids.h"
15 #include "grit/ui_resources.h" 16 #include "grit/ui_resources.h"
16 #include "skia/ext/skia_utils_mac.h" 17 #include "skia/ext/skia_utils_mac.h"
17 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/font_list.h" 19 #include "ui/gfx/font_list.h"
19 #include "ui/gfx/image/image.h" 20 #include "ui/gfx/image/image.h"
20 #include "ui/gfx/point.h" 21 #include "ui/gfx/point.h"
22 #include "ui/gfx/range/range.h"
21 #include "ui/gfx/rect.h" 23 #include "ui/gfx/rect.h"
22 #include "ui/gfx/text_constants.h" 24 #include "ui/gfx/text_constants.h"
23 25
24 using autofill::AutofillPopupView; 26 using autofill::AutofillPopupView;
25 using autofill::PasswordGenerationPopupView; 27 using autofill::PasswordGenerationPopupView;
26 using base::scoped_nsobject; 28 using base::scoped_nsobject;
27 29
28 namespace { 30 namespace {
29 31
30 NSColor* DividerColor() { 32 NSColor* DividerColor() {
(...skipping 20 matching lines...) Expand all
51 - (id)initWithFrame:(NSRect)frame { 53 - (id)initWithFrame:(NSRect)frame {
52 NOTREACHED(); 54 NOTREACHED();
53 return nil; 55 return nil;
54 } 56 }
55 57
56 - (id)initWithController: 58 - (id)initWithController:
57 (autofill::PasswordGenerationPopupController*)controller 59 (autofill::PasswordGenerationPopupController*)controller
58 frame:(NSRect)frame { 60 frame:(NSRect)frame {
59 if (self = [super initWithDelegate:controller frame:frame]) { 61 if (self = [super initWithDelegate:controller frame:frame]) {
60 controller_ = controller; 62 controller_ = controller;
61 NSFont* font = controller_->font_list().GetPrimaryFont().GetNativeFont();
62 63
63 passwordField_ = [self textFieldWithText:controller_->password() 64 passwordField_ = [self textFieldWithText:controller_->password()
64 withFont:font
65 color:[self nameColor] 65 color:[self nameColor]
66 alignment:NSLeftTextAlignment]; 66 alignment:NSLeftTextAlignment];
67 [self addSubview:passwordField_]; 67 [self addSubview:passwordField_];
68 68
69 passwordSubtextField_ = 69 passwordSubtextField_ = [self textFieldWithText:controller_->SuggestedText()
70 [self textFieldWithText:controller_->SuggestedText() 70 color:[self subtextColor]
71 withFont:font 71 alignment:NSRightTextAlignment];
72 color:[self subtextColor]
73 alignment:NSRightTextAlignment];
74 [self addSubview:passwordSubtextField_]; 72 [self addSubview:passwordSubtextField_];
75 73
76 helpTextField_ = [self textFieldWithText:controller_->HelpText() 74 scoped_nsobject<HyperlinkTextView> helpTextView(
77 withFont:font 75 [[HyperlinkTextView alloc] initWithFrame:NSZeroRect]);
78 color:HelpTextColor() 76 [helpTextView setMessage:base::SysUTF16ToNSString(controller_->HelpText())
79 alignment:NSLeftTextAlignment]; 77 withFont:[self textFont]
80 [self addSubview:helpTextField_]; 78 messageColor:HelpTextColor()];
79 [helpTextView addLinkRange:controller_->HelpTextLinkRange().ToNSRange()
80 withName:@""
81 linkColor:[NSColor blueColor]];
groby-ooo-7-16 2014/06/04 18:39:56 nit: You might want to get link color via gfx::SkC
Patrick Dubroy 2014/06/17 13:47:21 Done.
82 [helpTextView setDelegate:self];
83 [[helpTextView textContainer] setLineFragmentPadding:0.0f];
84 [helpTextView setVerticallyResizable:YES];
85 [self addSubview:helpTextView];
86 helpTextView_ = helpTextView.get();
81 } 87 }
82 88
83 return self; 89 return self;
84 } 90 }
85 91
86 #pragma mark NSView implementation: 92 #pragma mark NSView implementation:
87 93
88 - (void)drawRect:(NSRect)dirtyRect { 94 - (void)drawRect:(NSRect)dirtyRect {
89 // If the view is in the process of being destroyed, don't bother drawing. 95 // If the view is in the process of being destroyed, don't bother drawing.
90 if (!controller_) 96 if (!controller_)
(...skipping 17 matching lines...) Expand all
108 [NSBezierPath fillRect:[self helpBounds]]; 114 [NSBezierPath fillRect:[self helpBounds]];
109 115
110 // Render the divider. 116 // Render the divider.
111 [DividerColor() set]; 117 [DividerColor() set];
112 [NSBezierPath fillRect:[self dividerBounds]]; 118 [NSBezierPath fillRect:[self dividerBounds]];
113 } 119 }
114 120
115 #pragma mark Public API: 121 #pragma mark Public API:
116 122
117 - (void)updateBoundsAndRedrawPopup { 123 - (void)updateBoundsAndRedrawPopup {
118 [self positionTextField:passwordField_ inRect:[self passwordBounds]]; 124 [self positionView:passwordField_ inRect:[self passwordBounds]];
119 [self positionTextField:passwordSubtextField_ inRect:[self passwordBounds]]; 125 [self positionView:passwordSubtextField_ inRect:[self passwordBounds]];
120 [self positionTextField:helpTextField_ inRect:[self helpBounds]]; 126 [self positionView:helpTextView_ inRect:[self helpBounds]];
121 127
122 [super updateBoundsAndRedrawPopup]; 128 [super updateBoundsAndRedrawPopup];
123 } 129 }
124 130
125 - (void)controllerDestroyed { 131 - (void)controllerDestroyed {
126 controller_ = NULL; 132 controller_ = NULL;
127 [super delegateDestroyed]; 133 [super delegateDestroyed];
128 } 134 }
129 135
136 #pragma mark NSTextViewDelegate implementation:
137
138 - (BOOL)textView:(NSTextView *)textView
groby-ooo-7-16 2014/06/04 18:39:56 NSTextView* - remove space
Patrick Dubroy 2014/06/17 13:47:20 Done.
139 clickedOnLink:(id)link
140 atIndex:(NSUInteger)charIndex {
groby-ooo-7-16 2014/06/04 18:39:56 if (controller_)? I don't _think_ this case can h
Patrick Dubroy 2014/06/17 13:47:21 If it's ok with you, I'd rather not put the check
141 controller_->OnSavedPasswordsLinkClicked();
142 return YES;
143 }
144
130 #pragma mark Private helpers: 145 #pragma mark Private helpers:
131 146
132 - (NSTextField*)textFieldWithText:(const base::string16&)text 147 - (NSTextField*)textFieldWithText:(const base::string16&)text
133 withFont:(NSFont*)font
134 color:(NSColor*)color 148 color:(NSColor*)color
135 alignment:(NSTextAlignment)alignment { 149 alignment:(NSTextAlignment)alignment {
136 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( 150 scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
137 [[NSMutableParagraphStyle alloc] init]); 151 [[NSMutableParagraphStyle alloc] init]);
138 [paragraphStyle setAlignment:alignment]; 152 [paragraphStyle setAlignment:alignment];
139 153
140 NSDictionary* textAttributes = @{ 154 NSDictionary* textAttributes = @{
141 NSFontAttributeName : font, 155 NSFontAttributeName : [self textFont],
142 NSForegroundColorAttributeName : color, 156 NSForegroundColorAttributeName : color,
143 NSParagraphStyleAttributeName : paragraphStyle 157 NSParagraphStyleAttributeName : paragraphStyle
144 }; 158 };
145 159
146 scoped_nsobject<NSAttributedString> attributedString( 160 scoped_nsobject<NSAttributedString> attributedString(
147 [[NSAttributedString alloc] 161 [[NSAttributedString alloc]
148 initWithString:base::SysUTF16ToNSString(text) 162 initWithString:base::SysUTF16ToNSString(text)
149 attributes:textAttributes]); 163 attributes:textAttributes]);
150 164
151 NSTextField* textField = 165 NSTextField* textField =
152 [[[NSTextField alloc] initWithFrame:NSZeroRect] autorelease]; 166 [[[NSTextField alloc] initWithFrame:NSZeroRect] autorelease];
153 [textField setAttributedStringValue:attributedString]; 167 [textField setAttributedStringValue:attributedString];
154 [textField setEditable:NO]; 168 [textField setEditable:NO];
155 [textField setSelectable:NO]; 169 [textField setSelectable:NO];
156 [textField setDrawsBackground:NO]; 170 [textField setDrawsBackground:NO];
157 [textField setBezeled:NO]; 171 [textField setBezeled:NO];
158
159 return textField; 172 return textField;
160 } 173 }
161 174
162 - (void)positionTextField:(NSTextField*)textField inRect:(NSRect)bounds { 175 - (void)positionView:(NSView*)view inRect:(NSRect)bounds {
163 NSRect frame = NSInsetRect(bounds, controller_->kHorizontalPadding, 0); 176 NSRect frame = NSInsetRect(bounds, controller_->kHorizontalPadding, 0);
164 [textField setFrame:frame]; 177 [view setFrame:frame];
165 178
166 // Center the text vertically within the bounds. 179 // Center the text vertically within the bounds.
167 NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(textField); 180 NSSize delta = cocoa_l10n_util::WrapOrSizeToFit(view);
168 [textField setFrameOrigin: 181 [view setFrameOrigin:
169 NSInsetRect(frame, 0, floor(-delta.height/2)).origin]; 182 NSInsetRect(frame, 0, floor(-delta.height/2)).origin];
170 } 183 }
171 184
172 - (NSRect)passwordBounds { 185 - (NSRect)passwordBounds {
173 return NSRectFromCGRect(controller_->password_bounds().ToCGRect()); 186 return NSRectFromCGRect(controller_->password_bounds().ToCGRect());
174 } 187 }
175 188
176 - (NSRect)helpBounds { 189 - (NSRect)helpBounds {
177 return NSRectFromCGRect(controller_->help_bounds().ToCGRect()); 190 return NSRectFromCGRect(controller_->help_bounds().ToCGRect());
178 } 191 }
179 192
180 - (NSRect)dividerBounds { 193 - (NSRect)dividerBounds {
181 return NSRectFromCGRect(controller_->divider_bounds().ToCGRect()); 194 return NSRectFromCGRect(controller_->divider_bounds().ToCGRect());
182 } 195 }
183 196
197 - (NSFont*)textFont {
198 return controller_->font_list().GetPrimaryFont().GetNativeFont();
199 }
200
184 @end 201 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/autofill/password_generation_popup_view_cocoa.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698