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

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

Issue 772253003: Create an autofill Suggestion class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 6 years 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/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/popup_constants.h" 10 #include "chrome/browser/ui/autofill/popup_constants.h"
11 #include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge.h" 11 #include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge.h"
12 #include "components/autofill/core/browser/popup_item_ids.h" 12 #include "components/autofill/core/browser/popup_item_ids.h"
13 #include "components/autofill/core/browser/suggestion.h"
13 #include "ui/base/cocoa/window_size_constants.h" 14 #include "ui/base/cocoa/window_size_constants.h"
14 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/font_list.h" 16 #include "ui/gfx/font_list.h"
16 #include "ui/gfx/image/image.h" 17 #include "ui/gfx/image/image.h"
17 #include "ui/gfx/point.h" 18 #include "ui/gfx/point.h"
18 #include "ui/gfx/rect.h" 19 #include "ui/gfx/rect.h"
19 20
20 using autofill::AutofillPopupView; 21 using autofill::AutofillPopupView;
21 22
22 @interface AutofillPopupViewCocoa () 23 @interface AutofillPopupViewCocoa ()
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 #pragma mark - 91 #pragma mark -
91 #pragma mark NSView implementation: 92 #pragma mark NSView implementation:
92 93
93 - (void)drawRect:(NSRect)dirtyRect { 94 - (void)drawRect:(NSRect)dirtyRect {
94 // 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.
95 if (!controller_) 96 if (!controller_)
96 return; 97 return;
97 98
98 [self drawBackgroundAndBorder]; 99 [self drawBackgroundAndBorder];
99 100
100 for (size_t i = 0; i < controller_->names().size(); ++i) { 101 for (size_t i = 0; i < controller_->GetLineCount(); ++i) {
101 // Skip rows outside of the dirty rect. 102 // Skip rows outside of the dirty rect.
102 NSRect rowBounds = 103 NSRect rowBounds =
103 NSRectFromCGRect(controller_->GetRowBounds(i).ToCGRect()); 104 NSRectFromCGRect(controller_->GetRowBounds(i).ToCGRect());
104 if (!NSIntersectsRect(rowBounds, dirtyRect)) 105 if (!NSIntersectsRect(rowBounds, dirtyRect))
105 continue; 106 continue;
107 const autofill::Suggestion& suggestion = controller_->GetSuggestionAt(i);
106 108
107 if (controller_->identifiers()[i] == autofill::POPUP_ITEM_ID_SEPARATOR) { 109 if (suggestion.frontend_id == autofill::POPUP_ITEM_ID_SEPARATOR) {
108 [self drawSeparatorWithBounds:rowBounds]; 110 [self drawSeparatorWithBounds:rowBounds];
109 continue; 111 continue;
110 } 112 }
111 113
112 // Additional offset applied to the text in the vertical direction. 114 // Additional offset applied to the text in the vertical direction.
113 CGFloat textYOffset = 0; 115 CGFloat textYOffset = 0;
114 BOOL imageFirst = NO; 116 BOOL imageFirst = NO;
115 if (controller_->identifiers()[i] == 117 if (suggestion.frontend_id == autofill::POPUP_ITEM_ID_MAC_ACCESS_CONTACTS) {
116 autofill::POPUP_ITEM_ID_MAC_ACCESS_CONTACTS) {
117 // Due to the weighting of the asset used for this autofill entry, the 118 // Due to the weighting of the asset used for this autofill entry, the
118 // text needs to be bumped up by 1 pt to make it look vertically aligned. 119 // text needs to be bumped up by 1 pt to make it look vertically aligned.
119 textYOffset = -1; 120 textYOffset = -1;
120 imageFirst = YES; 121 imageFirst = YES;
121 } 122 }
122 123
123 NSString* name = SysUTF16ToNSString(controller_->names()[i]); 124 NSString* value = SysUTF16ToNSString(controller_->GetElidedValueAt(i));
124 NSString* subtext = SysUTF16ToNSString(controller_->subtexts()[i]); 125 NSString* label = SysUTF16ToNSString(controller_->GetElidedLabelAt(i));
125 BOOL isSelected = static_cast<int>(i) == controller_->selected_line(); 126 BOOL isSelected = static_cast<int>(i) == controller_->selected_line();
126 [self drawSuggestionWithName:name 127 [self drawSuggestionWithName:value
127 subtext:subtext 128 subtext:label
128 index:i 129 index:i
129 bounds:rowBounds 130 bounds:rowBounds
130 selected:isSelected 131 selected:isSelected
131 imageFirst:imageFirst 132 imageFirst:imageFirst
132 textYOffset:textYOffset]; 133 textYOffset:textYOffset];
133 } 134 }
134 } 135 }
135 136
136 #pragma mark - 137 #pragma mark -
137 #pragma mark Public API: 138 #pragma mark Public API:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 - (CGFloat)drawName:(NSString*)name 197 - (CGFloat)drawName:(NSString*)name
197 atX:(CGFloat)x 198 atX:(CGFloat)x
198 index:(size_t)index 199 index:(size_t)index
199 rightAlign:(BOOL)rightAlign 200 rightAlign:(BOOL)rightAlign
200 bounds:(NSRect)bounds 201 bounds:(NSRect)bounds
201 textYOffset:(CGFloat)textYOffset { 202 textYOffset:(CGFloat)textYOffset {
202 NSColor* nameColor = 203 NSColor* nameColor =
203 controller_->IsWarning(index) ? [self warningColor] : [self nameColor]; 204 controller_->IsWarning(index) ? [self warningColor] : [self nameColor];
204 NSDictionary* nameAttributes = 205 NSDictionary* nameAttributes =
205 [NSDictionary dictionaryWithObjectsAndKeys: 206 [NSDictionary dictionaryWithObjectsAndKeys:
206 controller_->GetNameFontListForRow(index).GetPrimaryFont(). 207 controller_->GetValueFontListForRow(index).GetPrimaryFont().
207 GetNativeFont(), 208 GetNativeFont(),
208 NSFontAttributeName, nameColor, NSForegroundColorAttributeName, 209 NSFontAttributeName, nameColor, NSForegroundColorAttributeName,
209 nil]; 210 nil];
210 NSSize nameSize = [name sizeWithAttributes:nameAttributes]; 211 NSSize nameSize = [name sizeWithAttributes:nameAttributes];
211 x -= rightAlign ? nameSize.width : 0; 212 x -= rightAlign ? nameSize.width : 0;
212 CGFloat y = bounds.origin.y + (bounds.size.height - nameSize.height) / 2; 213 CGFloat y = bounds.origin.y + (bounds.size.height - nameSize.height) / 2;
213 y += textYOffset; 214 y += textYOffset;
214 215
215 [name drawAtPoint:NSMakePoint(x, y) withAttributes:nameAttributes]; 216 [name drawAtPoint:NSMakePoint(x, y) withAttributes:nameAttributes];
216 217
(...skipping 23 matching lines...) Expand all
240 return x; 241 return x;
241 } 242 }
242 243
243 - (CGFloat)drawSubtext:(NSString*)subtext 244 - (CGFloat)drawSubtext:(NSString*)subtext
244 atX:(CGFloat)x 245 atX:(CGFloat)x
245 rightAlign:(BOOL)rightAlign 246 rightAlign:(BOOL)rightAlign
246 bounds:(NSRect)bounds 247 bounds:(NSRect)bounds
247 textYOffset:(CGFloat)textYOffset { 248 textYOffset:(CGFloat)textYOffset {
248 NSDictionary* subtextAttributes = 249 NSDictionary* subtextAttributes =
249 [NSDictionary dictionaryWithObjectsAndKeys: 250 [NSDictionary dictionaryWithObjectsAndKeys:
250 controller_->subtext_font_list().GetPrimaryFont().GetNativeFont(), 251 controller_->GetLabelFontList().GetPrimaryFont().GetNativeFont(),
251 NSFontAttributeName, 252 NSFontAttributeName,
252 [self subtextColor], 253 [self subtextColor],
253 NSForegroundColorAttributeName, 254 NSForegroundColorAttributeName,
254 nil]; 255 nil];
255 NSSize subtextSize = [subtext sizeWithAttributes:subtextAttributes]; 256 NSSize subtextSize = [subtext sizeWithAttributes:subtextAttributes];
256 x -= rightAlign ? subtextSize.width : 0; 257 x -= rightAlign ? subtextSize.width : 0;
257 CGFloat y = bounds.origin.y + (bounds.size.height - subtextSize.height) / 2; 258 CGFloat y = bounds.origin.y + (bounds.size.height - subtextSize.height) / 2;
258 y += textYOffset; 259 y += textYOffset;
259 260
260 [subtext drawAtPoint:NSMakePoint(x, y) withAttributes:subtextAttributes]; 261 [subtext drawAtPoint:NSMakePoint(x, y) withAttributes:subtextAttributes];
261 x += rightAlign ? 0 : subtextSize.width; 262 x += rightAlign ? 0 : subtextSize.width;
262 return x; 263 return x;
263 } 264 }
264 265
265 - (NSImage*)iconAtIndex:(size_t)index { 266 - (NSImage*)iconAtIndex:(size_t)index {
266 if (controller_->icons()[index].empty()) 267 const base::string16& icon = controller_->GetSuggestionAt(index).icon;
268 if (icon.empty())
267 return nil; 269 return nil;
268 270
269 int iconId = controller_->GetIconResourceID(controller_->icons()[index]); 271 int iconId = controller_->GetIconResourceID(icon);
270 DCHECK_NE(-1, iconId); 272 DCHECK_NE(-1, iconId);
271 273
272 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 274 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
273 return rb.GetNativeImageNamed(iconId).ToNSImage(); 275 return rb.GetNativeImageNamed(iconId).ToNSImage();
274 } 276 }
275 277
276 @end 278 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/chrome_autofill_client.cc ('k') | chrome/browser/ui/views/autofill/autofill_popup_view_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698