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

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: More implementation 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.
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
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];
37 }
38
39 - (id)initWithController:(autofill::PasswordGenerationPopupController*)controlle r
40 frame:(NSRect)frame {
41 self = [super initWithAutofillPopupViewDelegate:controller frame:frame];
42 if (self)
43 controller_ = controller;
44
45 return self;
46 }
47
48 - (void)controllerDestroyed {
49 // Since the |controller_| either already has been destroyed or is about to
50 // be, about the only thing we can safely do with it is to null it out.
51 controller_ = NULL;
52 }
53
54 #pragma mark -
55 #pragma mark NSView implementation:
56
57 - (void)drawRect:(NSRect)dirtyRect {
58 // If the view is in the process of being destroyed, don't bother drawing.
59 if (!controller_)
60 return;
61
62 [self drawBackgroundAndBorderInRect:dirtyRect];
63
64 NSRect bounds = [self bounds];
65 bounds.origin.y += autofill::kPopupBorderThickness;
66
67 if (controller_->password_selected()) {
68 // Draw a highlight under the suggested password.
69 NSRect highlightBounds =
70 NSRectFromCGRect(controller_->password_bounds().ToCGRect());
71 highlightBounds.origin.y +=
72 PasswordGenerationPopupView::kPasswordVerticalInset;
73 highlightBounds.size.height -=
74 2 * PasswordGenerationPopupView::kPasswordVerticalInset;
75 [[self highlightColor] set];
76 [NSBezierPath fillRect:highlightBounds];
77 }
78
79 NSFont* font = controller_->font_list().GetPrimaryFont().GetNativeFont();
80 NSRect passwordBounds =
81 NSRectFromCGRect(controller_->password_bounds().ToCGRect());
82
83 BOOL isRTL = NO; // FIXME
84 [self drawText:base::SysUTF16ToNSString(controller_->password())
85 withFont:font
86 color:[self nameColor]
87 bounds:passwordBounds
88 alignment:isRTL ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT];
89
90 [self drawText:base::SysUTF16ToNSString(controller_->SuggestedText())
91 withFont:font
92 color:[self subtextColor]
93 bounds:passwordBounds
94 alignment:isRTL ? gfx::ALIGN_LEFT : gfx::ALIGN_RIGHT];
95
96 // Render the background of the help text.
97 NSRect helpBounds =
98 NSRectFromCGRect(controller_->help_bounds().ToCGRect());
99 [[self helpTextBackgroundColor] set];
100 [NSBezierPath fillRect:helpBounds];
101
102 // Render the divider.
103 NSRect helpBorder = helpBounds;
104 helpBorder.size.height = 1;
105 [[self dividerColor] set];
106 [NSBezierPath fillRect:helpBorder];
107
108 // Render the help text.
109 [self drawText:base::SysUTF16ToNSString(controller_->HelpText())
110 withFont:font
111 color:[self helpTextColor]
112 bounds:helpBounds
113 alignment:isRTL ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT];
114 }
115
116 - (void)drawText:(NSString*)text
117 withFont:(NSFont*)font
118 color:(id)color
119 bounds:(NSRect)bounds
120 alignment:(gfx::HorizontalAlignment)alignment {
121 NSDictionary* textAttributes =
122 [NSDictionary dictionaryWithObjectsAndKeys:
123 font, NSFontAttributeName,
124 color, NSForegroundColorAttributeName,
125 nil];
126 // Adjust horizontal padding before measuring.
127 bounds.size.width -= 2 * controller_->kHorizontalPadding;
128 bounds.origin.x += controller_->kHorizontalPadding;
129
130 NSSize textSize =
131 [text boundingRectWithSize:bounds.size
132 options:NSStringDrawingUsesLineFragmentOrigin
133 attributes:textAttributes].size;
134
135 // Center the text vertically within the bounds.
136 bounds.origin.y = bounds.origin.y + (bounds.size.height - textSize.height) / 2 ;
137
138 if (alignment == gfx::ALIGN_RIGHT)
139 bounds.origin.x += bounds.size.width - textSize.width;
140
141 [text drawInRect:bounds withAttributes:textAttributes];
142 }
143
144 - (NSColor*)dividerColor {
145 return gfx::SkColorToCalibratedNSColor(
146 PasswordGenerationPopupView::GetDividerColor());
147 }
148
149 - (NSColor*)helpTextBackgroundColor {
150 return gfx::SkColorToCalibratedNSColor(
151 PasswordGenerationPopupView::GetExplanatoryTextBackgroundColor());
152 }
153
154 - (NSColor*)helpTextColor {
155 return gfx::SkColorToCalibratedNSColor(
156 PasswordGenerationPopupView::GetExplanatoryTextColor());
157 }
158
159 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698