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

Unified Diff: chrome/browser/ui/cocoa/new_tab_button.mm

Issue 2763093002: cocoa: draw new tab button with heavier stroke in high contrast (Closed)
Patch Set: fix nits :) Created 3 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/new_tab_button.mm
diff --git a/chrome/browser/ui/cocoa/new_tab_button.mm b/chrome/browser/ui/cocoa/new_tab_button.mm
index 3224e675066a5b43bfe63928b6a36589320d1415..50a829b5f553a52ce293fbed4108bc1eb18466da 100644
--- a/chrome/browser/ui/cocoa/new_tab_button.mm
+++ b/chrome/browser/ui/cocoa/new_tab_button.mm
@@ -25,13 +25,7 @@
DARKEN,
};
- const NSSize newTabButtonImageSize = { 34, 18 };
-
-const CGFloat k7PercentAlpha = 0.07;
-const CGFloat k8PercentAlpha = 0.08;
-const CGFloat k10PercentAlpha = 0.1;
-const CGFloat k20PercentAlpha = 0.2;
-const CGFloat k25PercentAlpha = 0.25;
+const NSSize newTabButtonImageSize = {34, 18};
NSImage* GetMaskImageFromCell(NewTabButtonCell* aCell) {
return [aCell imageForState:image_button_cell::kDefaultState view:nil];
@@ -185,8 +179,17 @@ - (NSImage*)imageForState:(image_button_cell::ButtonState)state
// Returns a new tab button image bezier path with the specified line width.
+ (NSBezierPath*)newTabButtonBezierPathWithLineWidth:(CGFloat)lineWidth;
-// NSCustomImageRep custom drawing method that renders the new tab button image.
-+ (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep;
+// Draws the new tab button image to |imageRep|, with either a normal stroke or
+// a heavy stroke for increased visibility.
++ (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep
+ withHeavyStroke:(BOOL)heavyStroke;
+
+// NSCustomImageRep custom drawing method shims for normal and heavy strokes
+// respectively.
++ (void)drawNewTabButtonImageWithNormalStroke:
+ (NewTabButtonCustomImageRep*)imageRep;
++ (void)drawNewTabButtonImageWithHeavyStroke:
+ (NewTabButtonCustomImageRep*)imageRep;
// Returns a new tab button image filled with |fillColor|.
- (NSImage*)imageWithFillColor:(NSColor*)fillColor;
@@ -318,9 +321,13 @@ - (NSImage*)imageForState:(image_button_cell::ButtonState)state
NOTREACHED();
}
+ SEL drawSelector = @selector(drawNewTabButtonImageWithNormalStroke:);
+ if (theme && theme->ShouldIncreaseContrast())
+ drawSelector = @selector(drawNewTabButtonImageWithHeavyStroke:);
+
base::scoped_nsobject<NewTabButtonCustomImageRep> imageRep(
[[NewTabButtonCustomImageRep alloc]
- initWithDrawSelector:@selector(drawNewTabButtonImage:)
+ initWithDrawSelector:drawSelector
delegate:[NewTabButton class]]);
[imageRep setDestView:self];
[imageRep setFillColor:fillColor];
@@ -398,7 +405,8 @@ + (NSBezierPath*)newTabButtonBezierPathWithLineWidth:(CGFloat)lineWidth {
return bezierPath;
}
-+ (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep {
++ (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep
+ withHeavyStroke:(BOOL)heavyStroke {
[[NSGraphicsContext currentContext]
cr_setPatternPhase:[imageRep patternPhasePosition]
forView:[imageRep destView]];
@@ -414,8 +422,9 @@ + (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep {
[bezierPath fill];
}
+ CGFloat alpha = heavyStroke ? 1.0 : 0.25;
static NSColor* strokeColor =
- [[NSColor colorWithCalibratedWhite:0 alpha:k25PercentAlpha] retain];
+ [[NSColor colorWithCalibratedWhite:0 alpha:alpha] retain];
[strokeColor set];
[bezierPath stroke];
@@ -430,7 +439,7 @@ + (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep {
[bottomEdgePath moveToPoint:bottomEdgeStart];
[bottomEdgePath lineToPoint:bottomEdgeEnd];
static NSColor* bottomEdgeColor =
- [[NSColor colorWithCalibratedWhite:0 alpha:k7PercentAlpha] retain];
+ [[NSColor colorWithCalibratedWhite:0 alpha:0.07] retain];
[bottomEdgeColor set];
[bottomEdgePath setLineWidth:lineWidth];
[bottomEdgePath setLineCapStyle:NSRoundLineCapStyle];
@@ -445,9 +454,9 @@ + (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep {
const CGFloat kTopShadowY = kBottomShadowY + 15;
const CGFloat kShadowWidth = 24;
static NSColor* lightOverlayColor =
- [[NSColor colorWithCalibratedWhite:1 alpha:k20PercentAlpha] retain];
+ [[NSColor colorWithCalibratedWhite:1 alpha:0.20] retain];
static NSColor* darkOverlayColor =
- [[NSColor colorWithCalibratedWhite:0 alpha:k8PercentAlpha] retain];
+ [[NSColor colorWithCalibratedWhite:0 alpha:0.08] retain];
switch ([imageRep overlayOption]) {
case OverlayOption::LIGHTEN:
@@ -474,7 +483,7 @@ + (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep {
[shadowPath setLineWidth:lineWidth];
[shadowPath setLineCapStyle:NSRoundLineCapStyle];
static NSColor* shadowColor =
- [[NSColor colorWithCalibratedWhite:0 alpha:k10PercentAlpha] retain];
+ [[NSColor colorWithCalibratedWhite:0 alpha:0.10] retain];
[shadowColor set];
[shadowPath stroke];
}
@@ -485,6 +494,16 @@ + (void)drawNewTabButtonImage:(NewTabButtonCustomImageRep*)imageRep {
}
}
++ (void)drawNewTabButtonImageWithNormalStroke:
+ (NewTabButtonCustomImageRep*)image {
+ [self drawNewTabButtonImage:image withHeavyStroke:NO];
+}
+
++ (void)drawNewTabButtonImageWithHeavyStroke:
+ (NewTabButtonCustomImageRep*)image {
+ [self drawNewTabButtonImage:image withHeavyStroke:YES];
+}
+
- (NSImage*)imageWithFillColor:(NSColor*)fillColor {
NSImage* image =
[[[NSImage alloc] initWithSize:newTabButtonImageSize] autorelease];
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698