Commit 87cb34ec authored by isherman@chromium.org's avatar isherman@chromium.org

[rAc OSX] Add support for drawing borders around dialog notifications.

BUG=286528
TEST=Top notification in Wallet mode (i.e. when signed in) should have a subtle
     darker gray border.
R=groby@chromium.org

Review URL: https://codereview.chromium.org/55973003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232981 0039d316-1c4b-4281-b951-d872f2087c98
parent 026d4a52
...@@ -22,11 +22,13 @@ ...@@ -22,11 +22,13 @@
NSView* arrowAnchorView_; NSView* arrowAnchorView_;
BOOL hasArrow_; BOOL hasArrow_;
base::scoped_nsobject<NSColor> backgroundColor_; base::scoped_nsobject<NSColor> backgroundColor_;
base::scoped_nsobject<NSColor> borderColor_;
} }
@property (nonatomic, assign) NSView* anchorView; @property (nonatomic, assign) NSView* anchorView;
@property (nonatomic, assign) BOOL hasArrow; @property (nonatomic, assign) BOOL hasArrow;
@property (nonatomic, retain) NSColor* backgroundColor; @property (nonatomic, retain) NSColor* backgroundColor;
@property (nonatomic, retain) NSColor* borderColor;
@end @end
...@@ -38,26 +40,39 @@ ...@@ -38,26 +40,39 @@
- (void)drawRect:(NSRect)dirtyRect { - (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect]; [super drawRect:dirtyRect];
NSRect backgroundRect = [self bounds]; NSBezierPath* path;
if (hasArrow_) { NSRect bounds = [self bounds];
if (!hasArrow_) {
path = [NSBezierPath bezierPathWithRect:bounds];
} else {
// The upper tip of the arrow.
NSPoint anchorPoint = NSMakePoint(NSMidX([arrowAnchorView_ bounds]), 0); NSPoint anchorPoint = NSMakePoint(NSMidX([arrowAnchorView_ bounds]), 0);
anchorPoint = [self convertPoint:anchorPoint fromView:arrowAnchorView_]; anchorPoint = [self convertPoint:anchorPoint fromView:arrowAnchorView_];
anchorPoint.y = NSMaxY([self bounds]); anchorPoint.y = NSMaxY(bounds);
// The minimal rectangle that encloses the arrow.
NSBezierPath* arrow = [NSBezierPath bezierPath]; NSRect arrowRect = NSMakeRect(anchorPoint.x - autofill::kArrowWidth / 2.0,
[arrow moveToPoint:anchorPoint]; anchorPoint.y - autofill::kArrowHeight,
[arrow relativeLineToPoint: autofill::kArrowWidth,
NSMakePoint(-autofill::kArrowWidth / 2.0, -autofill::kArrowHeight)]; autofill::kArrowHeight);
[arrow relativeLineToPoint:NSMakePoint(autofill::kArrowWidth, 0)];
[arrow closePath]; // Include the arrow and the rectangular non-arrow region in the same path,
[backgroundColor_ setFill]; // so that the stroke is easier to draw. Start at the upper-left of the
[arrow fill]; // rectangular region, and proceed clockwise.
backgroundRect.size.height -= autofill::kArrowHeight; path = [NSBezierPath bezierPath];
[path moveToPoint:NSMakePoint(NSMinX(bounds), NSMinY(arrowRect))];
[path lineToPoint:arrowRect.origin];
[path lineToPoint:NSMakePoint(NSMidX(arrowRect), NSMaxY(arrowRect))];
[path lineToPoint:NSMakePoint(NSMaxX(arrowRect), NSMinY(arrowRect))];
[path lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(arrowRect))];
[path lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))];
[path lineToPoint:NSMakePoint(NSMinX(bounds), NSMinY(bounds))];
[path closePath];
} }
dirtyRect = NSIntersectionRect(backgroundRect, dirtyRect);
[backgroundColor_ setFill]; [backgroundColor_ setFill];
NSRectFill(dirtyRect); [path fill];
[borderColor_ setStroke];
[path stroke];
} }
- (NSColor*)backgroundColor { - (NSColor*)backgroundColor {
...@@ -68,6 +83,14 @@ ...@@ -68,6 +83,14 @@
backgroundColor_.reset([backgroundColor retain]); backgroundColor_.reset([backgroundColor retain]);
} }
- (NSColor*)borderColor {
return borderColor_;
}
- (void)setBorderColor:(NSColor*)borderColor {
borderColor_.reset([borderColor retain]);
}
@end @end
@implementation AutofillNotificationController @implementation AutofillNotificationController
...@@ -78,6 +101,8 @@ ...@@ -78,6 +101,8 @@
[[AutofillNotificationView alloc] initWithFrame:NSZeroRect]); [[AutofillNotificationView alloc] initWithFrame:NSZeroRect]);
[view setBackgroundColor: [view setBackgroundColor:
gfx::SkColorToCalibratedNSColor(notification->GetBackgroundColor())]; gfx::SkColorToCalibratedNSColor(notification->GetBackgroundColor())];
[view setBorderColor:
gfx::SkColorToCalibratedNSColor(notification->GetBorderColor())];
[self setView:view]; [self setView:view];
textfield_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); textfield_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment