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

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

Issue 2727233003: Uses child views in Autofill Popup so we can trigger (Closed)
Patch Set: (int) to NSInteger Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/autofill_popup_view_cocoa.h" 5 #import "chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/mac/mac_util.h" 8 #include "base/mac/mac_util.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 24 matching lines...) Expand all
35 35
36 #pragma mark - 36 #pragma mark -
37 #pragma mark Private methods 37 #pragma mark Private methods
38 38
39 // Draws an Autofill suggestion in the given |bounds|, labeled with the given 39 // Draws an Autofill suggestion in the given |bounds|, labeled with the given
40 // |name| and |subtext| hint. If the suggestion |isSelected|, then it is drawn 40 // |name| and |subtext| hint. If the suggestion |isSelected|, then it is drawn
41 // with a highlight. |index| determines the font to use, as well as the icon, 41 // with a highlight. |index| determines the font to use, as well as the icon,
42 // if the row requires it -- such as for credit cards. 42 // if the row requires it -- such as for credit cards.
43 - (void)drawSuggestionWithName:(NSString*)name 43 - (void)drawSuggestionWithName:(NSString*)name
44 subtext:(NSString*)subtext 44 subtext:(NSString*)subtext
45 index:(size_t)index 45 index:(NSInteger)index
46 bounds:(NSRect)bounds 46 bounds:(NSRect)bounds
47 selected:(BOOL)isSelected 47 selected:(BOOL)isSelected
48 textYOffset:(CGFloat)textYOffset; 48 textYOffset:(CGFloat)textYOffset;
49 49
50 // This comment block applies to all three draw* methods that follow. 50 // This comment block applies to all three draw* methods that follow.
51 // If |rightAlign| == YES. 51 // If |rightAlign| == YES.
52 // Draws the widget with right border aligned to |x|. 52 // Draws the widget with right border aligned to |x|.
53 // Returns the x value of left border of the widget. 53 // Returns the x value of left border of the widget.
54 // If |rightAlign| == NO. 54 // If |rightAlign| == NO.
55 // Draws the widget with left border aligned to |x|. 55 // Draws the widget with left border aligned to |x|.
56 // Returns the x value of right border of the widget. 56 // Returns the x value of right border of the widget.
57 - (CGFloat)drawName:(NSString*)name 57 - (CGFloat)drawName:(NSString*)name
58 atX:(CGFloat)x 58 atX:(CGFloat)x
59 index:(size_t)index 59 index:(NSInteger)index
60 rightAlign:(BOOL)rightAlign 60 rightAlign:(BOOL)rightAlign
61 bounds:(NSRect)bounds 61 bounds:(NSRect)bounds
62 textYOffset:(CGFloat)textYOffset; 62 textYOffset:(CGFloat)textYOffset;
63 - (CGFloat)drawIconAtIndex:(size_t)index 63 - (CGFloat)drawIconAtIndex:(NSInteger)index
64 atX:(CGFloat)x 64 atX:(CGFloat)x
65 rightAlign:(BOOL)rightAlign 65 rightAlign:(BOOL)rightAlign
66 bounds:(NSRect)bounds; 66 bounds:(NSRect)bounds;
67 - (CGFloat)drawSubtext:(NSString*)subtext 67 - (CGFloat)drawSubtext:(NSString*)subtext
68 atX:(CGFloat)x 68 atX:(CGFloat)x
69 index:(size_t)index 69 index:(NSInteger)index
70 rightAlign:(BOOL)rightAlign 70 rightAlign:(BOOL)rightAlign
71 bounds:(NSRect)bounds 71 bounds:(NSRect)bounds
72 textYOffset:(CGFloat)textYOffset; 72 textYOffset:(CGFloat)textYOffset;
73 73
74 // Returns the icon for the row with the given |index|, or |nil| if there is 74 // Returns the icon for the row with the given |index|, or |nil| if there is
75 // none. 75 // none.
76 - (NSImage*)iconAtIndex:(size_t)index; 76 - (NSImage*)iconAtIndex:(NSInteger)index;
77 77
78 @end 78 @end
79 79
80 @implementation AutofillPopupViewCocoa 80 @implementation AutofillPopupViewCocoa
81 81
82 #pragma mark - 82 #pragma mark -
83 #pragma mark Initialisers 83 #pragma mark Initialisers
84 84
85 - (id)initWithFrame:(NSRect)frame { 85 - (id)initWithFrame:(NSRect)frame {
86 NOTREACHED(); 86 NOTREACHED();
(...skipping 15 matching lines...) Expand all
102 #pragma mark - 102 #pragma mark -
103 #pragma mark NSView implementation: 103 #pragma mark NSView implementation:
104 104
105 - (void)drawRect:(NSRect)dirtyRect { 105 - (void)drawRect:(NSRect)dirtyRect {
106 // If the view is in the process of being destroyed, don't bother drawing. 106 // If the view is in the process of being destroyed, don't bother drawing.
107 if (!controller_) 107 if (!controller_)
108 return; 108 return;
109 109
110 [self drawBackgroundAndBorder]; 110 [self drawBackgroundAndBorder];
111 111
112 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { 112 for (int i = 0; i < controller_->GetLineCount(); ++i) {
113 // Skip rows outside of the dirty rect. 113 // Skip rows outside of the dirty rect.
114 NSRect rowBounds = NSRectFromCGRect(delegate_->GetRowBounds(i).ToCGRect()); 114 NSRect rowBounds = NSRectFromCGRect(delegate_->GetRowBounds(i).ToCGRect());
115 if (!NSIntersectsRect(rowBounds, dirtyRect)) 115 if (!NSIntersectsRect(rowBounds, dirtyRect))
116 continue; 116 continue;
117 const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i); 117 const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i);
118 118
119 if (suggestion.frontend_id == autofill::POPUP_ITEM_ID_SEPARATOR) { 119 if (suggestion.frontend_id == autofill::POPUP_ITEM_ID_SEPARATOR) {
120 [self drawSeparatorWithBounds:rowBounds]; 120 [self drawSeparatorWithBounds:rowBounds];
121 continue; 121 continue;
122 } 122 }
123 123
124 // Additional offset applied to the text in the vertical direction. 124 // Additional offset applied to the text in the vertical direction.
125 CGFloat textYOffset = 0; 125 CGFloat textYOffset = 0;
126 126
127 NSString* value = SysUTF16ToNSString(controller_->GetElidedValueAt(i)); 127 NSString* value = SysUTF16ToNSString(controller_->GetElidedValueAt(i));
128 NSString* label = SysUTF16ToNSString(controller_->GetElidedLabelAt(i)); 128 NSString* label = SysUTF16ToNSString(controller_->GetElidedLabelAt(i));
129 BOOL isSelected = static_cast<int>(i) == controller_->selected_line(); 129 BOOL isSelected =
130 controller_->selected_line() && i == *controller_->selected_line();
130 [self drawSuggestionWithName:value 131 [self drawSuggestionWithName:value
131 subtext:label 132 subtext:label
132 index:i 133 index:i
133 bounds:rowBounds 134 bounds:rowBounds
134 selected:isSelected 135 selected:isSelected
135 textYOffset:textYOffset]; 136 textYOffset:textYOffset];
136 } 137 }
137 } 138 }
138 139
139 #pragma mark - 140 #pragma mark -
140 #pragma mark Public API: 141 #pragma mark Public API:
141 142
142 - (void)controllerDestroyed { 143 - (void)controllerDestroyed {
143 // Since the |controller_| either already has been destroyed or is about to 144 // Since the |controller_| either already has been destroyed or is about to
144 // be, about the only thing we can safely do with it is to null it out. 145 // be, about the only thing we can safely do with it is to null it out.
145 controller_ = NULL; 146 controller_ = NULL;
146 [super delegateDestroyed]; 147 [super delegateDestroyed];
147 } 148 }
148 149
149 - (void)invalidateRow:(size_t)row { 150 - (void)invalidateRow:(NSInteger)row {
150 NSRect dirty_rect = NSRectFromCGRect(delegate_->GetRowBounds(row).ToCGRect()); 151 NSRect dirty_rect = NSRectFromCGRect(delegate_->GetRowBounds(row).ToCGRect());
151 [self setNeedsDisplayInRect:dirty_rect]; 152 [self setNeedsDisplayInRect:dirty_rect];
152 } 153 }
153 154
154 #pragma mark - 155 #pragma mark -
155 #pragma mark Private API: 156 #pragma mark Private API:
156 157
157 - (void)drawSuggestionWithName:(NSString*)name 158 - (void)drawSuggestionWithName:(NSString*)name
158 subtext:(NSString*)subtext 159 subtext:(NSString*)subtext
159 index:(size_t)index 160 index:(NSInteger)index
160 bounds:(NSRect)bounds 161 bounds:(NSRect)bounds
161 selected:(BOOL)isSelected 162 selected:(BOOL)isSelected
162 textYOffset:(CGFloat)textYOffset { 163 textYOffset:(CGFloat)textYOffset {
163 BOOL isHTTPWarning = 164 BOOL isHTTPWarning =
164 (controller_->GetSuggestionAt(index).frontend_id == 165 (controller_->GetSuggestionAt(index).frontend_id ==
165 autofill::POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); 166 autofill::POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE);
166 167
167 // If this row is selected, highlight it with this mac system color. 168 // If this row is selected, highlight it with this mac system color.
168 // Otherwise the controller may have a specific background color for this 169 // Otherwise the controller may have a specific background color for this
169 // entry. 170 // entry.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 [self drawSubtext:subtext 205 [self drawSubtext:subtext
205 atX:x 206 atX:x
206 index:index 207 index:index
207 rightAlign:!isRTL 208 rightAlign:!isRTL
208 bounds:bounds 209 bounds:bounds
209 textYOffset:textYOffset]; 210 textYOffset:textYOffset];
210 } 211 }
211 212
212 - (CGFloat)drawName:(NSString*)name 213 - (CGFloat)drawName:(NSString*)name
213 atX:(CGFloat)x 214 atX:(CGFloat)x
214 index:(size_t)index 215 index:(NSInteger)index
215 rightAlign:(BOOL)rightAlign 216 rightAlign:(BOOL)rightAlign
216 bounds:(NSRect)bounds 217 bounds:(NSRect)bounds
217 textYOffset:(CGFloat)textYOffset { 218 textYOffset:(CGFloat)textYOffset {
218 NSColor* nameColor = skia::SkColorToSRGBNSColor( 219 NSColor* nameColor = skia::SkColorToSRGBNSColor(
219 ui::NativeTheme::GetInstanceForNativeUi()->GetSystemColor( 220 ui::NativeTheme::GetInstanceForNativeUi()->GetSystemColor(
220 controller_->layout_model().GetValueFontColorIDForRow(index))); 221 controller_->layout_model().GetValueFontColorIDForRow(index)));
221 NSDictionary* nameAttributes = [NSDictionary 222 NSDictionary* nameAttributes = [NSDictionary
222 dictionaryWithObjectsAndKeys:controller_->layout_model() 223 dictionaryWithObjectsAndKeys:controller_->layout_model()
223 .GetValueFontListForRow(index) 224 .GetValueFontListForRow(index)
224 .GetPrimaryFont() 225 .GetPrimaryFont()
225 .GetNativeFont(), 226 .GetNativeFont(),
226 NSFontAttributeName, nameColor, 227 NSFontAttributeName, nameColor,
227 NSForegroundColorAttributeName, nil]; 228 NSForegroundColorAttributeName, nil];
228 NSSize nameSize = [name sizeWithAttributes:nameAttributes]; 229 NSSize nameSize = [name sizeWithAttributes:nameAttributes];
229 x -= rightAlign ? nameSize.width : 0; 230 x -= rightAlign ? nameSize.width : 0;
230 CGFloat y = bounds.origin.y + (bounds.size.height - nameSize.height) / 2; 231 CGFloat y = bounds.origin.y + (bounds.size.height - nameSize.height) / 2;
231 y += textYOffset; 232 y += textYOffset;
232 233
233 [name drawAtPoint:NSMakePoint(x, y) withAttributes:nameAttributes]; 234 [name drawAtPoint:NSMakePoint(x, y) withAttributes:nameAttributes];
234 235
235 x += rightAlign ? 0 : nameSize.width; 236 x += rightAlign ? 0 : nameSize.width;
236 return x; 237 return x;
237 } 238 }
238 239
239 - (CGFloat)drawIconAtIndex:(size_t)index 240 - (CGFloat)drawIconAtIndex:(NSInteger)index
240 atX:(CGFloat)x 241 atX:(CGFloat)x
241 rightAlign:(BOOL)rightAlign 242 rightAlign:(BOOL)rightAlign
242 bounds:(NSRect)bounds { 243 bounds:(NSRect)bounds {
243 NSImage* icon = [self iconAtIndex:index]; 244 NSImage* icon = [self iconAtIndex:index];
244 if (!icon) 245 if (!icon)
245 return x; 246 return x;
246 NSSize iconSize = [icon size]; 247 NSSize iconSize = [icon size];
247 x -= rightAlign ? iconSize.width : 0; 248 x -= rightAlign ? iconSize.width : 0;
248 CGFloat y = bounds.origin.y + (bounds.size.height - iconSize.height) / 2; 249 CGFloat y = bounds.origin.y + (bounds.size.height - iconSize.height) / 2;
249 [icon drawInRect:NSMakeRect(x, y, iconSize.width, iconSize.height) 250 [icon drawInRect:NSMakeRect(x, y, iconSize.width, iconSize.height)
250 fromRect:NSZeroRect 251 fromRect:NSZeroRect
251 operation:NSCompositeSourceOver 252 operation:NSCompositeSourceOver
252 fraction:1.0 253 fraction:1.0
253 respectFlipped:YES 254 respectFlipped:YES
254 hints:nil]; 255 hints:nil];
255 256
256 x += rightAlign ? -AutofillPopupLayoutModel::kIconPadding 257 x += rightAlign ? -AutofillPopupLayoutModel::kIconPadding
257 : iconSize.width + AutofillPopupLayoutModel::kIconPadding; 258 : iconSize.width + AutofillPopupLayoutModel::kIconPadding;
258 return x; 259 return x;
259 } 260 }
260 261
261 - (CGFloat)drawSubtext:(NSString*)subtext 262 - (CGFloat)drawSubtext:(NSString*)subtext
262 atX:(CGFloat)x 263 atX:(CGFloat)x
263 index:(size_t)index 264 index:(NSInteger)index
264 rightAlign:(BOOL)rightAlign 265 rightAlign:(BOOL)rightAlign
265 bounds:(NSRect)bounds 266 bounds:(NSRect)bounds
266 textYOffset:(CGFloat)textYOffset { 267 textYOffset:(CGFloat)textYOffset {
267 NSDictionary* subtextAttributes = [NSDictionary 268 NSDictionary* subtextAttributes = [NSDictionary
268 dictionaryWithObjectsAndKeys:controller_->layout_model() 269 dictionaryWithObjectsAndKeys:controller_->layout_model()
269 .GetLabelFontListForRow(index) 270 .GetLabelFontListForRow(index)
270 .GetPrimaryFont() 271 .GetPrimaryFont()
271 .GetNativeFont(), 272 .GetNativeFont(),
272 NSFontAttributeName, [self subtextColor], 273 NSFontAttributeName, [self subtextColor],
273 NSForegroundColorAttributeName, nil]; 274 NSForegroundColorAttributeName, nil];
274 NSSize subtextSize = [subtext sizeWithAttributes:subtextAttributes]; 275 NSSize subtextSize = [subtext sizeWithAttributes:subtextAttributes];
275 x -= rightAlign ? subtextSize.width : 0; 276 x -= rightAlign ? subtextSize.width : 0;
276 CGFloat y = bounds.origin.y + (bounds.size.height - subtextSize.height) / 2; 277 CGFloat y = bounds.origin.y + (bounds.size.height - subtextSize.height) / 2;
277 y += textYOffset; 278 y += textYOffset;
278 279
279 [subtext drawAtPoint:NSMakePoint(x, y) withAttributes:subtextAttributes]; 280 [subtext drawAtPoint:NSMakePoint(x, y) withAttributes:subtextAttributes];
280 x += rightAlign ? 0 : subtextSize.width; 281 x += rightAlign ? 0 : subtextSize.width;
281 return x; 282 return x;
282 } 283 }
283 284
284 - (NSImage*)iconAtIndex:(size_t)index { 285 - (NSImage*)iconAtIndex:(NSInteger)index {
285 const int kHttpWarningIconWidth = 16; 286 const int kHttpWarningIconWidth = 16;
286 const base::string16& icon = controller_->GetSuggestionAt(index).icon; 287 const base::string16& icon = controller_->GetSuggestionAt(index).icon;
287 if (icon.empty()) 288 if (icon.empty())
288 return nil; 289 return nil;
289 290
290 // For the Form-Not-Secure warning about password/credit card fields on HTTP 291 // For the Form-Not-Secure warning about password/credit card fields on HTTP
291 // pages, reuse the omnibox vector icons. 292 // pages, reuse the omnibox vector icons.
292 if (icon == base::ASCIIToUTF16("httpWarning")) { 293 if (icon == base::ASCIIToUTF16("httpWarning")) {
293 return NSImageFromImageSkiaWithColorSpace( 294 return NSImageFromImageSkiaWithColorSpace(
294 gfx::CreateVectorIcon(toolbar::kHttpIcon, kHttpWarningIconWidth, 295 gfx::CreateVectorIcon(toolbar::kHttpIcon, kHttpWarningIconWidth,
295 gfx::kChromeIconGrey), 296 gfx::kChromeIconGrey),
296 base::mac::GetSRGBColorSpace()); 297 base::mac::GetSRGBColorSpace());
297 } 298 }
298 299
299 if (icon == base::ASCIIToUTF16("httpsInvalid")) { 300 if (icon == base::ASCIIToUTF16("httpsInvalid")) {
300 return NSImageFromImageSkiaWithColorSpace( 301 return NSImageFromImageSkiaWithColorSpace(
301 gfx::CreateVectorIcon(toolbar::kHttpsInvalidIcon, kHttpWarningIconWidth, 302 gfx::CreateVectorIcon(toolbar::kHttpsInvalidIcon, kHttpWarningIconWidth,
302 gfx::kGoogleRed700), 303 gfx::kGoogleRed700),
303 base::mac::GetSRGBColorSpace()); 304 base::mac::GetSRGBColorSpace());
304 } 305 }
305 306
306 int iconId = delegate_->GetIconResourceID(icon); 307 int iconId = delegate_->GetIconResourceID(icon);
307 DCHECK_NE(-1, iconId); 308 DCHECK_NE(-1, iconId);
308 309
309 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 310 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
310 return rb.GetNativeImageNamed(iconId).ToNSImage(); 311 return rb.GetNativeImageNamed(iconId).ToNSImage();
311 } 312 }
312 313
313 @end 314 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698