Chromium Code Reviews| 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 356f79584bb0b76af00e593ea71c498b0ac036d9..86b2257476e9afa96b6a6a7d34a80d1e82bfe972 100644 |
| --- a/chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm |
| +++ b/chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.mm |
| @@ -52,14 +52,61 @@ NSColor* SubtextColor() { |
| } // namespace |
| +@implementation AutofillPopupBaseViewCocoa |
|
Patrick Dubroy
2014/05/06 15:43:52
I will move this into a separate file -- it's just
|
| +- (id)initWithAutofillPopupViewDelegate:(autofill::AutofillPopupViewDelegate*)delegate |
| + frame:(NSRect)frame { |
| + self = [super initWithFrame:frame]; |
| + if (self) |
| + delegate_ = delegate; |
| + |
| + return self; |
| +} |
| + |
| +// Informs the view that its delegate has been (or will imminently be) |
| +// destroyed. |
| +// TODO: What do we need this for? |
| +- (void)delegateDestroyed { |
| + delegate_ = NULL; |
| +} |
| + |
| +- (void)drawSeparatorWithBounds:(NSRect)bounds { |
| + [SeparatorColor() set]; |
| + [NSBezierPath fillRect:bounds]; |
| +} |
| + |
| +// A slight optimization for drawing: |
| +// https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaViewsGuide/Optimizing/Optimizing.html |
| +- (BOOL)isOpaque { |
| + return YES; |
| +} |
| + |
| +- (BOOL)isFlipped { |
| + // Flipped so that it's easier to share controller logic with other OSes. |
| + return YES; |
| +} |
| + |
| +- (void)drawBackgroundAndBorderInRect:(NSRect)dirtyRect { |
| + // The inset is needed since the border is centered on the |path|. |
| + // TODO(isherman): We should consider using asset-based drawing for the |
| + // border, creating simple bitmaps for the view's border and background, and |
| + // drawing them using NSDrawNinePartImage(). |
| + CGFloat inset = autofill::kPopupBorderThickness / 2.0; |
| + NSRect borderRect = NSInsetRect([self bounds], inset, inset); |
| + NSBezierPath* path = [NSBezierPath bezierPathWithRect:borderRect]; |
| + [BackgroundColor() setFill]; |
| + [path fill]; |
| + [path setLineWidth:autofill::kPopupBorderThickness]; |
| + [BorderColor() setStroke]; |
| + [path stroke]; |
| +} |
| + |
| +@end |
| + |
| #pragma mark - |
| #pragma mark Private methods |
| @interface AutofillPopupViewCocoa () |
| -// Draws a thin separator in the popup UI. |
| -- (void)drawSeparatorWithBounds:(NSRect)bounds; |
| - |
| // 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, |
| @@ -98,35 +145,12 @@ NSColor* SubtextColor() { |
| #pragma mark - |
| #pragma mark NSView implementation: |
| -// A slight optimization for drawing: |
| -// https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaViewsGuide/Optimizing/Optimizing.html |
| -- (BOOL)isOpaque { |
| - return YES; |
| -} |
| - |
| -- (BOOL)isFlipped { |
| - // Flipped so that it's easier to share controller logic with other OSes. |
| - return YES; |
| -} |
| - |
| - (void)drawRect:(NSRect)dirtyRect { |
| // If the view is in the process of being destroyed, don't bother drawing. |
| if (!controller_) |
| return; |
| - // Draw the popup's background and border. |
| - // The inset is needed since the border is centered on the |path|. |
| - // TODO(isherman): We should consider using asset-based drawing for the |
| - // border, creating simple bitmaps for the view's border and background, and |
| - // drawing them using NSDrawNinePartImage(). |
| - CGFloat inset = autofill::kPopupBorderThickness / 2.0; |
| - NSRect borderRect = NSInsetRect([self bounds], inset, inset); |
| - NSBezierPath* path = [NSBezierPath bezierPathWithRect:borderRect]; |
| - [BackgroundColor() setFill]; |
| - [path fill]; |
| - [path setLineWidth:autofill::kPopupBorderThickness]; |
| - [BorderColor() setStroke]; |
| - [path stroke]; |
| + [self drawBackgroundAndBorderInRect:dirtyRect]; |
| for (size_t i = 0; i < controller_->names().size(); ++i) { |
| // Skip rows outside of the dirty rect. |
| @@ -199,11 +223,6 @@ NSColor* SubtextColor() { |
| #pragma mark - |
| #pragma mark Private API: |
| -- (void)drawSeparatorWithBounds:(NSRect)bounds { |
| - [SeparatorColor() set]; |
| - [NSBezierPath fillRect:bounds]; |
| -} |
| - |
| - (void)drawSuggestionWithName:(NSString*)name |
| subtext:(NSString*)subtext |
| index:(size_t)index |