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

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

Issue 267183002: Password manager: Implement password generation UI for Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove some dead code, add TODO. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
Ilya Sherman 2014/05/09 21:51:28 nit: 2014
Patrick Dubroy 2014/05/12 14:13:39 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/autofill/password_generation_popup_view_cocoa.h "
6
7 #include "base/logging.h"
8 #include "base/strings/sys_string_conversions.h"
9 #include "chrome/browser/ui/autofill/autofill_popup_controller.h"
10 #include "chrome/browser/ui/autofill/autofill_popup_view.h"
11 #include "chrome/browser/ui/autofill/popup_constants.h"
12 #include "chrome/browser/ui/cocoa/autofill/password_generation_popup_view_bridge .h"
13 #include "components/autofill/core/browser/popup_item_ids.h"
14 #include "grit/ui_resources.h"
15 #include "skia/ext/skia_utils_mac.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/font_list.h"
18 #include "ui/gfx/image/image.h"
19 #include "ui/gfx/point.h"
20 #include "ui/gfx/rect.h"
21 #include "ui/gfx/text_constants.h"
22
23 using autofill::AutofillPopupView;
24 using autofill::PasswordGenerationPopupView;
25
26 @interface PasswordGenerationPopupViewCocoa ()
27 @end
Ilya Sherman 2014/05/09 21:51:28 What's this for?
Patrick Dubroy 2014/05/12 14:13:39 Not sure. Removed.
28
29 @implementation PasswordGenerationPopupViewCocoa
30
31 #pragma mark -
32 #pragma mark Initialisers
33
34 - (id)initWithFrame:(NSRect)frame {
35 NOTREACHED();
36 return [self initWithController:NULL frame:frame];
Ilya Sherman 2014/05/09 21:51:28 nit: If the method should not be reachable, just r
Patrick Dubroy 2014/05/12 14:13:39 Done.
37 }
38
39 - (id)initWithController:
40 (autofill::PasswordGenerationPopupController*)controller
41 frame:(NSRect)frame {
42 self = [super initWithAutofillPopupViewDelegate:controller frame:frame];
43 if (self)
44 controller_ = controller;
45
46 return self;
47 }
48
49 - (void)controllerDestroyed {
50 // Since the |controller_| either already has been destroyed or is about to
51 // be, about the only thing we can safely do with it is to null it out.
52 controller_ = NULL;
Ilya Sherman 2014/05/09 21:51:28 Should this call [super controllerDestroyed] as we
Patrick Dubroy 2014/05/12 14:13:39 Actually, I don't think we need this at all. It's
Ilya Sherman 2014/05/12 21:46:10 The view is destroyed asynchronously, though -- th
53 }
54
55 #pragma mark -
56 #pragma mark NSView implementation:
57
58 - (void)drawRect:(NSRect)dirtyRect {
59 // If the view is in the process of being destroyed, don't bother drawing.
60 if (!controller_)
61 return;
62
63 [self drawBackgroundAndBorderInRect:dirtyRect];
64
65 NSRect bounds = [self bounds];
66 bounds.origin.y += autofill::kPopupBorderThickness;
67
68 if (controller_->password_selected()) {
69 // Draw a highlight under the suggested password.
70 NSRect highlightBounds =
71 NSRectFromCGRect(controller_->password_bounds().ToCGRect());
72 highlightBounds.origin.y +=
73 PasswordGenerationPopupView::kPasswordVerticalInset;
74 highlightBounds.size.height -=
75 2 * PasswordGenerationPopupView::kPasswordVerticalInset;
76 [[self highlightColor] set];
77 [NSBezierPath fillRect:highlightBounds];
78 }
79
80 NSFont* font = controller_->font_list().GetPrimaryFont().GetNativeFont();
81 NSRect passwordBounds =
82 NSRectFromCGRect(controller_->password_bounds().ToCGRect());
83
84 BOOL isRTL = NO; // TODO(dubroy): Implement RTL support.
85 [self drawText:base::SysUTF16ToNSString(controller_->password())
86 withFont:font
87 color:[self nameColor]
88 bounds:passwordBounds
89 alignment:isRTL ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT];
90
91 [self drawText:base::SysUTF16ToNSString(controller_->SuggestedText())
92 withFont:font
93 color:[self subtextColor]
94 bounds:passwordBounds
95 alignment:isRTL ? gfx::ALIGN_LEFT : gfx::ALIGN_RIGHT];
96
97 // Render the background of the help text.
98 NSRect helpBounds =
99 NSRectFromCGRect(controller_->help_bounds().ToCGRect());
100 [[self helpTextBackgroundColor] set];
101 [NSBezierPath fillRect:helpBounds];
102
103 // Render the divider.
104 NSRect helpBorder = helpBounds;
105 helpBorder.size.height = 1;
106 [[self dividerColor] set];
107 [NSBezierPath fillRect:helpBorder];
108
109 // Render the help text.
110 [self drawText:base::SysUTF16ToNSString(controller_->HelpText())
111 withFont:font
112 color:[self helpTextColor]
113 bounds:helpBounds
Ilya Sherman 2014/05/09 21:51:28 Hmm, shouldn't this not include the pixel used for
Patrick Dubroy 2014/05/12 14:13:39 Done.
114 alignment:isRTL ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT];
115 }
116
117 - (void)drawText:(NSString*)text
118 withFont:(NSFont*)font
119 color:(id)color
120 bounds:(NSRect)bounds
121 alignment:(gfx::HorizontalAlignment)alignment {
122 NSDictionary* textAttributes =
123 [NSDictionary dictionaryWithObjectsAndKeys:
124 font, NSFontAttributeName,
125 color, NSForegroundColorAttributeName,
126 nil];
127 // Adjust horizontal padding before measuring.
128 bounds.size.width -= 2 * controller_->kHorizontalPadding;
129 bounds.origin.x += controller_->kHorizontalPadding;
130
131 NSSize textSize =
132 [text boundingRectWithSize:bounds.size
133 options:NSStringDrawingUsesLineFragmentOrigin
134 attributes:textAttributes].size;
135
136 // Center the text vertically within the bounds.
137 bounds.origin.y = NSMinY(bounds) + (NSHeight(bounds) - textSize.height) / 2;
138
139 if (alignment == gfx::ALIGN_RIGHT)
140 bounds.origin.x += NSWidth(bounds) - textSize.width;
141
142 [text drawInRect:bounds withAttributes:textAttributes];
143 }
144
145 - (NSColor*)dividerColor {
146 return gfx::SkColorToCalibratedNSColor(
147 PasswordGenerationPopupView::kDividerColor);
148 }
149
150 - (NSColor*)helpTextBackgroundColor {
151 return gfx::SkColorToCalibratedNSColor(
152 PasswordGenerationPopupView::kExplanatoryTextBackgroundColor);
153 }
154
155 - (NSColor*)helpTextColor {
156 return gfx::SkColorToCalibratedNSColor(
157 PasswordGenerationPopupView::kExplanatoryTextColor);
158 }
Ilya Sherman 2014/05/09 21:51:28 These methods don't seem to be declared anywhere.
Patrick Dubroy 2014/05/12 14:13:39 Done.
159
160 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698