| OLD | NEW |
| 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/autofill_popup_layout_model.h" | 10 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 index:(size_t)index | 52 index:(size_t)index |
| 53 rightAlign:(BOOL)rightAlign | 53 rightAlign:(BOOL)rightAlign |
| 54 bounds:(NSRect)bounds | 54 bounds:(NSRect)bounds |
| 55 textYOffset:(CGFloat)textYOffset; | 55 textYOffset:(CGFloat)textYOffset; |
| 56 - (CGFloat)drawIconAtIndex:(size_t)index | 56 - (CGFloat)drawIconAtIndex:(size_t)index |
| 57 atX:(CGFloat)x | 57 atX:(CGFloat)x |
| 58 rightAlign:(BOOL)rightAlign | 58 rightAlign:(BOOL)rightAlign |
| 59 bounds:(NSRect)bounds; | 59 bounds:(NSRect)bounds; |
| 60 - (CGFloat)drawSubtext:(NSString*)subtext | 60 - (CGFloat)drawSubtext:(NSString*)subtext |
| 61 atX:(CGFloat)x | 61 atX:(CGFloat)x |
| 62 index:(size_t)index |
| 62 rightAlign:(BOOL)rightAlign | 63 rightAlign:(BOOL)rightAlign |
| 63 bounds:(NSRect)bounds | 64 bounds:(NSRect)bounds |
| 64 textYOffset:(CGFloat)textYOffset; | 65 textYOffset:(CGFloat)textYOffset; |
| 65 | 66 |
| 66 // Returns the icon for the row with the given |index|, or |nil| if there is | 67 // Returns the icon for the row with the given |index|, or |nil| if there is |
| 67 // none. | 68 // none. |
| 68 - (NSImage*)iconAtIndex:(size_t)index; | 69 - (NSImage*)iconAtIndex:(size_t)index; |
| 69 | 70 |
| 70 @end | 71 @end |
| 71 | 72 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 index:index | 178 index:index |
| 178 rightAlign:isRTL | 179 rightAlign:isRTL |
| 179 bounds:bounds | 180 bounds:bounds |
| 180 textYOffset:textYOffset]; | 181 textYOffset:textYOffset]; |
| 181 | 182 |
| 182 // Draw right side if isRTL == NO, left side if isRTL == YES. | 183 // Draw right side if isRTL == NO, left side if isRTL == YES. |
| 183 x = isRTL ? leftX : rightX; | 184 x = isRTL ? leftX : rightX; |
| 184 x = [self drawIconAtIndex:index atX:x rightAlign:!isRTL bounds:bounds]; | 185 x = [self drawIconAtIndex:index atX:x rightAlign:!isRTL bounds:bounds]; |
| 185 [self drawSubtext:subtext | 186 [self drawSubtext:subtext |
| 186 atX:x | 187 atX:x |
| 188 index:index |
| 187 rightAlign:!isRTL | 189 rightAlign:!isRTL |
| 188 bounds:bounds | 190 bounds:bounds |
| 189 textYOffset:textYOffset]; | 191 textYOffset:textYOffset]; |
| 190 } | 192 } |
| 191 | 193 |
| 192 - (CGFloat)drawName:(NSString*)name | 194 - (CGFloat)drawName:(NSString*)name |
| 193 atX:(CGFloat)x | 195 atX:(CGFloat)x |
| 194 index:(size_t)index | 196 index:(size_t)index |
| 195 rightAlign:(BOOL)rightAlign | 197 rightAlign:(BOOL)rightAlign |
| 196 bounds:(NSRect)bounds | 198 bounds:(NSRect)bounds |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 respectFlipped:YES | 237 respectFlipped:YES |
| 236 hints:nil]; | 238 hints:nil]; |
| 237 | 239 |
| 238 x += rightAlign ? -AutofillPopupLayoutModel::kIconPadding | 240 x += rightAlign ? -AutofillPopupLayoutModel::kIconPadding |
| 239 : iconSize.width + AutofillPopupLayoutModel::kIconPadding; | 241 : iconSize.width + AutofillPopupLayoutModel::kIconPadding; |
| 240 return x; | 242 return x; |
| 241 } | 243 } |
| 242 | 244 |
| 243 - (CGFloat)drawSubtext:(NSString*)subtext | 245 - (CGFloat)drawSubtext:(NSString*)subtext |
| 244 atX:(CGFloat)x | 246 atX:(CGFloat)x |
| 247 index:(size_t)index |
| 245 rightAlign:(BOOL)rightAlign | 248 rightAlign:(BOOL)rightAlign |
| 246 bounds:(NSRect)bounds | 249 bounds:(NSRect)bounds |
| 247 textYOffset:(CGFloat)textYOffset { | 250 textYOffset:(CGFloat)textYOffset { |
| 248 NSDictionary* subtextAttributes = [NSDictionary | 251 NSDictionary* subtextAttributes = [NSDictionary |
| 249 dictionaryWithObjectsAndKeys:controller_->layout_model() | 252 dictionaryWithObjectsAndKeys:controller_->layout_model() |
| 250 .GetLabelFontList() | 253 .GetLabelFontListForRow(index) |
| 251 .GetPrimaryFont() | 254 .GetPrimaryFont() |
| 252 .GetNativeFont(), | 255 .GetNativeFont(), |
| 253 NSFontAttributeName, [self subtextColor], | 256 NSFontAttributeName, [self subtextColor], |
| 254 NSForegroundColorAttributeName, nil]; | 257 NSForegroundColorAttributeName, nil]; |
| 255 NSSize subtextSize = [subtext sizeWithAttributes:subtextAttributes]; | 258 NSSize subtextSize = [subtext sizeWithAttributes:subtextAttributes]; |
| 256 x -= rightAlign ? subtextSize.width : 0; | 259 x -= rightAlign ? subtextSize.width : 0; |
| 257 CGFloat y = bounds.origin.y + (bounds.size.height - subtextSize.height) / 2; | 260 CGFloat y = bounds.origin.y + (bounds.size.height - subtextSize.height) / 2; |
| 258 y += textYOffset; | 261 y += textYOffset; |
| 259 | 262 |
| 260 [subtext drawAtPoint:NSMakePoint(x, y) withAttributes:subtextAttributes]; | 263 [subtext drawAtPoint:NSMakePoint(x, y) withAttributes:subtextAttributes]; |
| 261 x += rightAlign ? 0 : subtextSize.width; | 264 x += rightAlign ? 0 : subtextSize.width; |
| 262 return x; | 265 return x; |
| 263 } | 266 } |
| 264 | 267 |
| 265 - (NSImage*)iconAtIndex:(size_t)index { | 268 - (NSImage*)iconAtIndex:(size_t)index { |
| 266 const base::string16& icon = controller_->GetSuggestionAt(index).icon; | 269 const base::string16& icon = controller_->GetSuggestionAt(index).icon; |
| 267 if (icon.empty()) | 270 if (icon.empty()) |
| 268 return nil; | 271 return nil; |
| 269 | 272 |
| 270 int iconId = delegate_->GetIconResourceID(icon); | 273 int iconId = delegate_->GetIconResourceID(icon); |
| 271 DCHECK_NE(-1, iconId); | 274 DCHECK_NE(-1, iconId); |
| 272 | 275 |
| 273 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 276 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 274 return rb.GetNativeImageNamed(iconId).ToNSImage(); | 277 return rb.GetNativeImageNamed(iconId).ToNSImage(); |
| 275 } | 278 } |
| 276 | 279 |
| 277 @end | 280 @end |
| OLD | NEW |