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

Unified Diff: chrome/browser/cocoa/autocomplete_text_field_cell.mm

Issue 199072: Add SSL icons on Mac OS X (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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/cocoa/autocomplete_text_field_cell.mm
===================================================================
--- chrome/browser/cocoa/autocomplete_text_field_cell.mm (revision 25790)
+++ chrome/browser/cocoa/autocomplete_text_field_cell.mm (working copy)
@@ -39,6 +39,9 @@
// use that.
const NSInteger kBaselineOffset = 4;
+// The amount of padding on either side reserved for drawing the hint icon
+const NSInteger kHintIconHorizontalPad = 5;
+
} // namespace
@implementation AutocompleteTextFieldCell
@@ -156,6 +159,15 @@
}
}
+- (void)setHintIcon:(NSImage*)icon {
+ if (icon != hintIcon_) {
+ hintIcon_.reset([icon retain]);
+ if (!keywordString_ && !hintString_) {
+ fieldEditorNeedsReset_ = YES;
+ }
+ }
+}
+
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
DCHECK([controlView isFlipped]);
[[NSColor colorWithCalibratedWhite:1.0 alpha:0.25] set];
@@ -219,6 +231,12 @@
textFrame.origin.x += keywordWidth;
textFrame.size.width = NSMaxX(cellFrame) - NSMinX(textFrame);
}
+ } else if (hintIcon_) {
+ CGFloat width = [hintIcon_ size].width;
+ width += kHintIconHorizontalPad * 2;
+ if (width < NSWidth(cellFrame)) {
+ textFrame.size.width -= width;
+ }
}
return textFrame;
@@ -265,11 +283,38 @@
[keywordString_.get() drawInRect:infoFrame];
}
+- (void)drawHintIconWithFrame:(NSRect)cellFrame
+ inView:(NSView*)controlView {
+ // We'll draw the entire image
+ NSRect imageRect = NSZeroRect;
+ imageRect.size = [hintIcon_ size];
+
+ // Move the rect that we're drawing into to the far right
+ cellFrame.origin.x += cellFrame.size.width - imageRect.size.width;
+ // Add back the padding
+ cellFrame.origin.x -= kHintIconHorizontalPad;
+
+ // Center the image vertically in the frame
+ cellFrame.origin.y +=
+ floor((cellFrame.size.height - imageRect.size.height) / 2);
+
+ // Set the drawing size to the image size
+ cellFrame.size = imageRect.size;
+
+ [hintIcon_ setFlipped:[controlView isFlipped]];
+ [hintIcon_ drawInRect:cellFrame
+ fromRect:imageRect
+ operation:NSCompositeSourceOver
+ fraction:1.0];
+}
+
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
if (hintString_) {
[self drawHintWithFrame:cellFrame inView:controlView];
} else if (keywordString_) {
[self drawKeywordWithFrame:cellFrame inView:controlView];
+ } else {
Scott Hess - ex-Googler 2009/09/15 18:16:52 else if (hintIcon_), like the other two cases.
hawk 2009/09/15 21:49:17 Done.
+ [self drawHintIconWithFrame:cellFrame inView:controlView];
}
[super drawInteriorWithFrame:[self textFrameForFrame:cellFrame]
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field_cell.h ('k') | chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698