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

Unified Diff: chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm

Issue 329293002: Revert "Revert 3 mac autofill CLs." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm
diff --git a/chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm b/chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm
index 8807dcb3acafc5e3492e51dc92f448ea07ba71be..ab2a029ea5ffe394cbf80a9c550c40b37a3e3bb3 100644
--- a/chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm
+++ b/chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm
@@ -28,12 +28,40 @@ using autofill::AutofillPopupView;
// Draws an Autofill suggestion in the given |bounds|, labeled with the given
// |name| and |subtext| hint. If the suggestion |isSelected|, then it is drawn
// with a highlight. |index| determines the font to use, as well as the icon,
-// if the row requires it -- such as for credit cards.
+// if the row requires it -- such as for credit cards. |imageFirst| indicates
+// whether the image should be drawn before the name, and with the same
+// alignment, or whether it should be drawn afterwards, with the opposite
+// alignment.
- (void)drawSuggestionWithName:(NSString*)name
subtext:(NSString*)subtext
index:(size_t)index
bounds:(NSRect)bounds
- selected:(BOOL)isSelected;
+ selected:(BOOL)isSelected
+ imageFirst:(BOOL)imageFirst
+ textYOffset:(CGFloat)textYOffset;
+
+// This comment block applies to all three draw* methods that follow.
+// If |rightAlign| == YES.
+// Draws the widget with right border aligned to |x|.
+// Returns the x value of left border of the widget.
+// If |rightAlign| == NO.
+// Draws the widget with left border aligned to |x|.
+// Returns the x value of right border of the widget.
+- (CGFloat)drawName:(NSString*)name
+ atX:(CGFloat)x
+ index:(size_t)index
+ rightAlign:(BOOL)rightAlign
+ bounds:(NSRect)bounds
+ textYOffset:(CGFloat)textYOffset;
+- (CGFloat)drawIconAtIndex:(size_t)index
+ atX:(CGFloat)x
+ rightAlign:(BOOL)rightAlign
+ bounds:(NSRect)bounds;
+- (CGFloat)drawSubtext:(NSString*)subtext
+ atX:(CGFloat)x
+ rightAlign:(BOOL)rightAlign
+ bounds:(NSRect)bounds
+ textYOffset:(CGFloat)textYOffset;
// Returns the icon for the row with the given |index|, or |nil| if there is
// none.
@@ -79,16 +107,30 @@ using autofill::AutofillPopupView;
if (controller_->identifiers()[i] == autofill::POPUP_ITEM_ID_SEPARATOR) {
[self drawSeparatorWithBounds:rowBounds];
- } else {
- NSString* name = SysUTF16ToNSString(controller_->names()[i]);
- NSString* subtext = SysUTF16ToNSString(controller_->subtexts()[i]);
- BOOL isSelected = static_cast<int>(i) == controller_->selected_line();
- [self drawSuggestionWithName:name
- subtext:subtext
- index:i
- bounds:rowBounds
- selected:isSelected];
+ continue;
+ }
+
+ // Additional offset applied to the text in the vertical direction.
+ CGFloat textYOffset = 0;
+ BOOL imageFirst = NO;
+ if (controller_->identifiers()[i] ==
+ autofill::POPUP_ITEM_ID_MAC_ACCESS_CONTACTS) {
+ // Due to the weighting of the asset used for this autofill entry, the
+ // text needs to be bumped up by 1 pt to make it look vertically aligned.
+ textYOffset = -1;
+ imageFirst = YES;
}
+
+ NSString* name = SysUTF16ToNSString(controller_->names()[i]);
+ NSString* subtext = SysUTF16ToNSString(controller_->subtexts()[i]);
+ BOOL isSelected = static_cast<int>(i) == controller_->selected_line();
+ [self drawSuggestionWithName:name
+ subtext:subtext
+ index:i
+ bounds:rowBounds
+ selected:isSelected
+ imageFirst:imageFirst
+ textYOffset:textYOffset];
}
}
@@ -115,7 +157,9 @@ using autofill::AutofillPopupView;
subtext:(NSString*)subtext
index:(size_t)index
bounds:(NSRect)bounds
- selected:(BOOL)isSelected {
+ selected:(BOOL)isSelected
+ imageFirst:(BOOL)imageFirst
+ textYOffset:(CGFloat)textYOffset {
// If this row is selected, highlight it.
if (isSelected) {
[[self highlightColor] set];
@@ -124,6 +168,38 @@ using autofill::AutofillPopupView;
BOOL isRTL = controller_->IsRTL();
+ // The X values of the left and right borders of the autofill widget.
+ CGFloat leftX = NSMinX(bounds) + AutofillPopupView::kEndPadding;
+ CGFloat rightX = NSMaxX(bounds) - AutofillPopupView::kEndPadding;
+
+ // Draw left side if isRTL == NO, right side if isRTL == YES.
+ CGFloat x = isRTL ? rightX : leftX;
+ if (imageFirst)
+ x = [self drawIconAtIndex:index atX:x rightAlign:isRTL bounds:bounds];
+ [self drawName:name
+ atX:x
+ index:index
+ rightAlign:isRTL
+ bounds:bounds
+ textYOffset:textYOffset];
+
+ // Draw right side if isRTL == NO, left side if isRTL == YES.
+ x = isRTL ? leftX : rightX;
+ if (!imageFirst)
+ x = [self drawIconAtIndex:index atX:x rightAlign:!isRTL bounds:bounds];
+ [self drawSubtext:subtext
+ atX:x
+ rightAlign:!isRTL
+ bounds:bounds
+ textYOffset:textYOffset];
+}
+
+- (CGFloat)drawName:(NSString*)name
+ atX:(CGFloat)x
+ index:(size_t)index
+ rightAlign:(BOOL)rightAlign
+ bounds:(NSRect)bounds
+ textYOffset:(CGFloat)textYOffset {
NSColor* nameColor =
controller_->IsWarning(index) ? [self warningColor] : [self nameColor];
NSDictionary* nameAttributes =
@@ -133,26 +209,26 @@ using autofill::AutofillPopupView;
NSFontAttributeName, nameColor, NSForegroundColorAttributeName,
nil];
NSSize nameSize = [name sizeWithAttributes:nameAttributes];
- CGFloat x = bounds.origin.x +
- (isRTL ?
- bounds.size.width - AutofillPopupView::kEndPadding - nameSize.width :
- AutofillPopupView::kEndPadding);
+ x -= rightAlign ? nameSize.width : 0;
CGFloat y = bounds.origin.y + (bounds.size.height - nameSize.height) / 2;
+ y += textYOffset;
[name drawAtPoint:NSMakePoint(x, y) withAttributes:nameAttributes];
- // The x-coordinate will be updated as each element is drawn.
- x = bounds.origin.x +
- (isRTL ?
- AutofillPopupView::kEndPadding :
- bounds.size.width - AutofillPopupView::kEndPadding);
+ x += rightAlign ? 0 : nameSize.width;
+ return x;
+}
- // Draw the Autofill icon, if one exists.
+- (CGFloat)drawIconAtIndex:(size_t)index
+ atX:(CGFloat)x
+ rightAlign:(BOOL)rightAlign
+ bounds:(NSRect)bounds {
NSImage* icon = [self iconAtIndex:index];
- if (icon) {
- NSSize iconSize = [icon size];
- x += isRTL ? 0 : -iconSize.width;
- y = bounds.origin.y + (bounds.size.height - iconSize.height) / 2;
+ if (!icon)
+ return x;
+ NSSize iconSize = [icon size];
+ x -= rightAlign ? iconSize.width : 0;
+ CGFloat y = bounds.origin.y + (bounds.size.height - iconSize.height) / 2;
[icon drawInRect:NSMakeRect(x, y, iconSize.width, iconSize.height)
fromRect:NSZeroRect
operation:NSCompositeSourceOver
@@ -160,12 +236,16 @@ using autofill::AutofillPopupView;
respectFlipped:YES
hints:nil];
- x += isRTL ?
- iconSize.width + AutofillPopupView::kIconPadding :
- -AutofillPopupView::kIconPadding;
- }
+ x += rightAlign ? -AutofillPopupView::kIconPadding
+ : iconSize.width + AutofillPopupView::kIconPadding;
+ return x;
+}
- // Draw the subtext.
+- (CGFloat)drawSubtext:(NSString*)subtext
+ atX:(CGFloat)x
+ rightAlign:(BOOL)rightAlign
+ bounds:(NSRect)bounds
+ textYOffset:(CGFloat)textYOffset {
NSDictionary* subtextAttributes =
[NSDictionary dictionaryWithObjectsAndKeys:
controller_->subtext_font_list().GetPrimaryFont().GetNativeFont(),
@@ -174,10 +254,13 @@ using autofill::AutofillPopupView;
NSForegroundColorAttributeName,
nil];
NSSize subtextSize = [subtext sizeWithAttributes:subtextAttributes];
- x += isRTL ? 0 : -subtextSize.width;
- y = bounds.origin.y + (bounds.size.height - subtextSize.height) / 2;
+ x -= rightAlign ? subtextSize.width : 0;
+ CGFloat y = bounds.origin.y + (bounds.size.height - subtextSize.height) / 2;
+ y += textYOffset;
[subtext drawAtPoint:NSMakePoint(x, y) withAttributes:subtextAttributes];
+ x += rightAlign ? 0 : subtextSize.width;
+ return x;
}
- (NSImage*)iconAtIndex:(size_t)index {

Powered by Google App Engine
This is Rietveld 408576698