Commit 13459ae6 authored by Sidney San Martín's avatar Sidney San Martín Committed by Commit Bot

New appearance for the Dock tile download progress indicator.

Not bothering to put it behind the MD downloads flag because this design
change works well on its own.

Bug: 765389
Change-Id: I447cbe35dffaef6790d7ae67ea33d1a121b10b39
Reviewed-on: https://chromium-review.googlesource.com/754581Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516043}
parent 735e145b
...@@ -17,13 +17,20 @@ using content::BrowserThread; ...@@ -17,13 +17,20 @@ using content::BrowserThread;
namespace { namespace {
// The fraction of the size of the dock icon that the badge is. // The fraction of the size of the dock icon that the badge is.
const float kBadgeFraction = 0.4f; constexpr CGFloat kBadgeFraction = 0.375f;
constexpr CGFloat kBadgeMargin = 4;
// The indentation of the badge. constexpr CGFloat kBadgeStrokeWidth = 6;
const float kBadgeIndent = 5.0f;
constexpr struct {
CGFloat offset, radius, opacity;
} kBadgeShadows[] = {
{0, 2, 0.14},
{2, 2, 0.12},
{1, 3, 0.2},
};
// The maximum update rate for the dock icon. 200ms = 5fps. // The maximum update rate for the dock icon. 200ms = 5fps.
const int64_t kUpdateFrequencyMs = 200; constexpr int64_t kUpdateFrequencyMs = 200;
} // namespace } // namespace
...@@ -66,88 +73,57 @@ const int64_t kUpdateFrequencyMs = 200; ...@@ -66,88 +73,57 @@ const int64_t kUpdateFrequencyMs = 200;
if (downloads_ == 0) if (downloads_ == 0)
return; return;
NSRect badgeRect = [self bounds]; const CGFloat badgeSize = NSWidth(self.bounds) * kBadgeFraction;
badgeRect.size.height = (int)(kBadgeFraction * badgeRect.size.height); const NSRect badgeRect =
int newWidth = kBadgeFraction * NSWidth(badgeRect); NSMakeRect(NSMaxX(self.bounds) - badgeSize - kBadgeMargin, kBadgeMargin,
badgeRect.origin.x = NSWidth(badgeRect) - newWidth; badgeSize, badgeSize);
badgeRect.size.width = newWidth; const CGFloat badgeRadius = badgeSize / 2;
const NSPoint badgeCenter = NSMakePoint(NSMidX(badgeRect), NSMidY(badgeRect));
CGFloat badgeRadius = NSMidY(badgeRect);
NSBezierPath* backgroundPath =
badgeRect.origin.x -= kBadgeIndent; [NSBezierPath bezierPathWithOvalInRect:badgeRect];
badgeRect.origin.y += kBadgeIndent; [[NSColor clearColor] setFill];
NSPoint badgeCenter = NSMakePoint(NSMidX(badgeRect), NSMidY(badgeRect)); base::scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]);
shadow.get().shadowColor = [NSColor blackColor];
// Background for (const auto shadowProps : kBadgeShadows) {
NSColor* backgroundColor = [NSColor colorWithCalibratedRed:0.85
green:0.85
blue:0.85
alpha:1.0];
NSColor* backgroundHighlight =
[backgroundColor blendedColorWithFraction:0.85
ofColor:[NSColor whiteColor]];
base::scoped_nsobject<NSGradient> backgroundGradient(
[[NSGradient alloc] initWithStartingColor:backgroundHighlight
endingColor:backgroundColor]);
NSBezierPath* badgeEdge = [NSBezierPath bezierPathWithOvalInRect:badgeRect];
{
gfx::ScopedNSGraphicsContextSaveGState scopedGState; gfx::ScopedNSGraphicsContextSaveGState scopedGState;
[badgeEdge addClip]; shadow.get().shadowOffset = NSMakeSize(0, -shadowProps.offset);
[backgroundGradient drawFromCenter:badgeCenter shadow.get().shadowBlurRadius = shadowProps.radius;
radius:0.0 [[NSColor colorWithCalibratedWhite:0 alpha:shadowProps.opacity] setFill];
toCenter:badgeCenter [shadow set];
radius:badgeRadius [backgroundPath fill];
options:0];
} }
// Slice [[NSColor colorWithCalibratedRed:0xec / 255.0
green:0xf3 / 255.0
blue:0xfe / 255.0
alpha:1] setFill];
[backgroundPath fill];
// Stroke
if (!indeterminate_) { if (!indeterminate_) {
NSColor* sliceColor = [NSColor colorWithCalibratedRed:0.45 NSBezierPath* strokePath;
green:0.8
blue:0.25
alpha:1.0];
NSColor* sliceHighlight =
[sliceColor blendedColorWithFraction:0.4
ofColor:[NSColor whiteColor]];
base::scoped_nsobject<NSGradient> sliceGradient(
[[NSGradient alloc] initWithStartingColor:sliceHighlight
endingColor:sliceColor]);
NSBezierPath* progressSlice;
if (progress_ >= 1.0) { if (progress_ >= 1.0) {
progressSlice = [NSBezierPath bezierPathWithOvalInRect:badgeRect]; strokePath = [NSBezierPath bezierPathWithOvalInRect:badgeRect];
} else { } else {
CGFloat endAngle = 90.0 - 360.0 * progress_; CGFloat endAngle = 90.0 - 360.0 * progress_;
if (endAngle < 0.0) if (endAngle < 0.0)
endAngle += 360.0; endAngle += 360.0;
progressSlice = [NSBezierPath bezierPath]; strokePath = [NSBezierPath bezierPath];
[progressSlice moveToPoint:badgeCenter]; [strokePath
[progressSlice appendBezierPathWithArcWithCenter:badgeCenter appendBezierPathWithArcWithCenter:badgeCenter
radius:badgeRadius radius:badgeRadius - kBadgeStrokeWidth / 2
startAngle:90.0 startAngle:90.0
endAngle:endAngle endAngle:endAngle
clockwise:YES]; clockwise:YES];
[progressSlice closePath];
}
gfx::ScopedNSGraphicsContextSaveGState scopedGState;
[progressSlice addClip];
[sliceGradient drawFromCenter:badgeCenter
radius:0.0
toCenter:badgeCenter
radius:badgeRadius
options:0];
} }
[strokePath setLineWidth:kBadgeStrokeWidth];
// Edge [[NSColor colorWithCalibratedRed:0x42 / 255.0
{ green:0x85 / 255.0
gfx::ScopedNSGraphicsContextSaveGState scopedGState; blue:0xf4 / 255.0
[[NSColor whiteColor] set]; alpha:1] setStroke];
base::scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); [strokePath stroke];
[shadow.get() setShadowOffset:NSMakeSize(0, -2)];
[shadow setShadowBlurRadius:2];
[shadow set];
[badgeEdge setLineWidth:2];
[badgeEdge stroke];
} }
// Download count // Download count
...@@ -156,21 +132,19 @@ const int64_t kUpdateFrequencyMs = 200; ...@@ -156,21 +132,19 @@ const int64_t kUpdateFrequencyMs = 200;
NSString* countString = NSString* countString =
[formatter stringFromNumber:[NSNumber numberWithInt:downloads_]]; [formatter stringFromNumber:[NSNumber numberWithInt:downloads_]];
base::scoped_nsobject<NSShadow> countShadow([[NSShadow alloc] init]); CGFloat countFontSize = 24;
[countShadow setShadowBlurRadius:3.0];
[countShadow.get() setShadowColor:[NSColor whiteColor]];
[countShadow.get() setShadowOffset:NSMakeSize(0.0, 0.0)];
NSMutableDictionary* countAttrsDict =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSColor blackColor], NSForegroundColorAttributeName,
countShadow.get(), NSShadowAttributeName,
nil];
CGFloat countFontSize = badgeRadius;
NSSize countSize = NSZeroSize; NSSize countSize = NSZeroSize;
base::scoped_nsobject<NSAttributedString> countAttrString; base::scoped_nsobject<NSAttributedString> countAttrString;
while (1) { while (1) {
NSFont* countFont = [NSFont fontWithName:@"Helvetica-Bold" NSFont* countFont;
size:countFontSize]; if (@available(macOS 10.11, *)) {
countFont =
[NSFont systemFontOfSize:countFontSize weight:NSFontWeightMedium];
} else {
countFont = [[NSFontManager sharedFontManager]
convertWeight:YES
ofFont:[NSFont systemFontOfSize:countFontSize]];
}
// This will generally be plain Helvetica. // This will generally be plain Helvetica.
if (!countFont) if (!countFont)
...@@ -180,12 +154,15 @@ const int64_t kUpdateFrequencyMs = 200; ...@@ -180,12 +154,15 @@ const int64_t kUpdateFrequencyMs = 200;
if (!countFont) if (!countFont)
break; break;
[countAttrsDict setObject:countFont forKey:NSFontAttributeName]; countAttrString.reset([[NSAttributedString alloc]
countAttrString.reset( initWithString:countString
[[NSAttributedString alloc] initWithString:countString attributes:@{
attributes:countAttrsDict]); NSForegroundColorAttributeName :
[NSColor colorWithCalibratedWhite:0 alpha:0.65],
NSFontAttributeName : countFont,
}]);
countSize = [countAttrString size]; countSize = [countAttrString size];
if (countSize.width > badgeRadius * 1.5) { if (countSize.width > (badgeRadius - kBadgeStrokeWidth) * 1.5) {
countFontSize -= 1.0; countFontSize -= 1.0;
} else { } else {
break; break;
...@@ -194,7 +171,7 @@ const int64_t kUpdateFrequencyMs = 200; ...@@ -194,7 +171,7 @@ const int64_t kUpdateFrequencyMs = 200;
NSPoint countOrigin = badgeCenter; NSPoint countOrigin = badgeCenter;
countOrigin.x -= countSize.width / 2; countOrigin.x -= countSize.width / 2;
countOrigin.y -= countSize.height / 2.2; // tweak; otherwise too low countOrigin.y -= countSize.height / 2;
[countAttrString.get() drawAtPoint:countOrigin]; [countAttrString.get() drawAtPoint:countOrigin];
} }
......
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