| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/dock_icon.h" | 5 #import "chrome/browser/ui/cocoa/dock_icon.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/bundle_locations.h" | 8 #include "base/mac/bundle_locations.h" |
| 9 #include "base/memory/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 11 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 12 | 12 |
| 13 using content::BrowserThread; | 13 using content::BrowserThread; |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // The fraction of the size of the dock icon that the badge is. | 17 // The fraction of the size of the dock icon that the badge is. |
| 18 const float kBadgeFraction = 0.4f; | 18 const float kBadgeFraction = 0.4f; |
| 19 | 19 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 NSPoint badgeCenter = NSMakePoint(NSMidX(badgeRect), NSMidY(badgeRect)); | 78 NSPoint badgeCenter = NSMakePoint(NSMidX(badgeRect), NSMidY(badgeRect)); |
| 79 | 79 |
| 80 // Background | 80 // Background |
| 81 NSColor* backgroundColor = [NSColor colorWithCalibratedRed:0.85 | 81 NSColor* backgroundColor = [NSColor colorWithCalibratedRed:0.85 |
| 82 green:0.85 | 82 green:0.85 |
| 83 blue:0.85 | 83 blue:0.85 |
| 84 alpha:1.0]; | 84 alpha:1.0]; |
| 85 NSColor* backgroundHighlight = | 85 NSColor* backgroundHighlight = |
| 86 [backgroundColor blendedColorWithFraction:0.85 | 86 [backgroundColor blendedColorWithFraction:0.85 |
| 87 ofColor:[NSColor whiteColor]]; | 87 ofColor:[NSColor whiteColor]]; |
| 88 scoped_nsobject<NSGradient> backgroundGradient( | 88 base::scoped_nsobject<NSGradient> backgroundGradient( |
| 89 [[NSGradient alloc] initWithStartingColor:backgroundHighlight | 89 [[NSGradient alloc] initWithStartingColor:backgroundHighlight |
| 90 endingColor:backgroundColor]); | 90 endingColor:backgroundColor]); |
| 91 NSBezierPath* badgeEdge = [NSBezierPath bezierPathWithOvalInRect:badgeRect]; | 91 NSBezierPath* badgeEdge = [NSBezierPath bezierPathWithOvalInRect:badgeRect]; |
| 92 { | 92 { |
| 93 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | 93 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
| 94 [badgeEdge addClip]; | 94 [badgeEdge addClip]; |
| 95 [backgroundGradient drawFromCenter:badgeCenter | 95 [backgroundGradient drawFromCenter:badgeCenter |
| 96 radius:0.0 | 96 radius:0.0 |
| 97 toCenter:badgeCenter | 97 toCenter:badgeCenter |
| 98 radius:badgeRadius | 98 radius:badgeRadius |
| 99 options:0]; | 99 options:0]; |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Slice | 102 // Slice |
| 103 if (!indeterminate_) { | 103 if (!indeterminate_) { |
| 104 NSColor* sliceColor = [NSColor colorWithCalibratedRed:0.45 | 104 NSColor* sliceColor = [NSColor colorWithCalibratedRed:0.45 |
| 105 green:0.8 | 105 green:0.8 |
| 106 blue:0.25 | 106 blue:0.25 |
| 107 alpha:1.0]; | 107 alpha:1.0]; |
| 108 NSColor* sliceHighlight = | 108 NSColor* sliceHighlight = |
| 109 [sliceColor blendedColorWithFraction:0.4 | 109 [sliceColor blendedColorWithFraction:0.4 |
| 110 ofColor:[NSColor whiteColor]]; | 110 ofColor:[NSColor whiteColor]]; |
| 111 scoped_nsobject<NSGradient> sliceGradient( | 111 base::scoped_nsobject<NSGradient> sliceGradient( |
| 112 [[NSGradient alloc] initWithStartingColor:sliceHighlight | 112 [[NSGradient alloc] initWithStartingColor:sliceHighlight |
| 113 endingColor:sliceColor]); | 113 endingColor:sliceColor]); |
| 114 NSBezierPath* progressSlice; | 114 NSBezierPath* progressSlice; |
| 115 if (progress_ >= 1.0) { | 115 if (progress_ >= 1.0) { |
| 116 progressSlice = [NSBezierPath bezierPathWithOvalInRect:badgeRect]; | 116 progressSlice = [NSBezierPath bezierPathWithOvalInRect:badgeRect]; |
| 117 } else { | 117 } else { |
| 118 CGFloat endAngle = 90.0 - 360.0 * progress_; | 118 CGFloat endAngle = 90.0 - 360.0 * progress_; |
| 119 if (endAngle < 0.0) | 119 if (endAngle < 0.0) |
| 120 endAngle += 360.0; | 120 endAngle += 360.0; |
| 121 progressSlice = [NSBezierPath bezierPath]; | 121 progressSlice = [NSBezierPath bezierPath]; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 133 radius:0.0 | 133 radius:0.0 |
| 134 toCenter:badgeCenter | 134 toCenter:badgeCenter |
| 135 radius:badgeRadius | 135 radius:badgeRadius |
| 136 options:0]; | 136 options:0]; |
| 137 } | 137 } |
| 138 | 138 |
| 139 // Edge | 139 // Edge |
| 140 { | 140 { |
| 141 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | 141 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
| 142 [[NSColor whiteColor] set]; | 142 [[NSColor whiteColor] set]; |
| 143 scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); | 143 base::scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); |
| 144 [shadow.get() setShadowOffset:NSMakeSize(0, -2)]; | 144 [shadow.get() setShadowOffset:NSMakeSize(0, -2)]; |
| 145 [shadow setShadowBlurRadius:2]; | 145 [shadow setShadowBlurRadius:2]; |
| 146 [shadow set]; | 146 [shadow set]; |
| 147 [badgeEdge setLineWidth:2]; | 147 [badgeEdge setLineWidth:2]; |
| 148 [badgeEdge stroke]; | 148 [badgeEdge stroke]; |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Download count | 151 // Download count |
| 152 scoped_nsobject<NSNumberFormatter> formatter( | 152 base::scoped_nsobject<NSNumberFormatter> formatter( |
| 153 [[NSNumberFormatter alloc] init]); | 153 [[NSNumberFormatter alloc] init]); |
| 154 NSString* countString = | 154 NSString* countString = |
| 155 [formatter stringFromNumber:[NSNumber numberWithInt:downloads_]]; | 155 [formatter stringFromNumber:[NSNumber numberWithInt:downloads_]]; |
| 156 | 156 |
| 157 scoped_nsobject<NSShadow> countShadow([[NSShadow alloc] init]); | 157 base::scoped_nsobject<NSShadow> countShadow([[NSShadow alloc] init]); |
| 158 [countShadow setShadowBlurRadius:3.0]; | 158 [countShadow setShadowBlurRadius:3.0]; |
| 159 [countShadow.get() setShadowColor:[NSColor whiteColor]]; | 159 [countShadow.get() setShadowColor:[NSColor whiteColor]]; |
| 160 [countShadow.get() setShadowOffset:NSMakeSize(0.0, 0.0)]; | 160 [countShadow.get() setShadowOffset:NSMakeSize(0.0, 0.0)]; |
| 161 NSMutableDictionary* countAttrsDict = | 161 NSMutableDictionary* countAttrsDict = |
| 162 [NSMutableDictionary dictionaryWithObjectsAndKeys: | 162 [NSMutableDictionary dictionaryWithObjectsAndKeys: |
| 163 [NSColor blackColor], NSForegroundColorAttributeName, | 163 [NSColor blackColor], NSForegroundColorAttributeName, |
| 164 countShadow.get(), NSShadowAttributeName, | 164 countShadow.get(), NSShadowAttributeName, |
| 165 nil]; | 165 nil]; |
| 166 CGFloat countFontSize = badgeRadius; | 166 CGFloat countFontSize = badgeRadius; |
| 167 NSSize countSize = NSZeroSize; | 167 NSSize countSize = NSZeroSize; |
| 168 scoped_nsobject<NSAttributedString> countAttrString; | 168 base::scoped_nsobject<NSAttributedString> countAttrString; |
| 169 while (1) { | 169 while (1) { |
| 170 NSFont* countFont = [NSFont fontWithName:@"Helvetica-Bold" | 170 NSFont* countFont = [NSFont fontWithName:@"Helvetica-Bold" |
| 171 size:countFontSize]; | 171 size:countFontSize]; |
| 172 | 172 |
| 173 // This will generally be plain Helvetica. | 173 // This will generally be plain Helvetica. |
| 174 if (!countFont) | 174 if (!countFont) |
| 175 countFont = [NSFont userFontOfSize:countFontSize]; | 175 countFont = [NSFont userFontOfSize:countFontSize]; |
| 176 | 176 |
| 177 // Continued failure would generate an NSException. | 177 // Continued failure would generate an NSException. |
| 178 if (!countFont) | 178 if (!countFont) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 200 @end | 200 @end |
| 201 | 201 |
| 202 | 202 |
| 203 @implementation DockIcon | 203 @implementation DockIcon |
| 204 | 204 |
| 205 + (DockIcon*)sharedDockIcon { | 205 + (DockIcon*)sharedDockIcon { |
| 206 static DockIcon* icon; | 206 static DockIcon* icon; |
| 207 if (!icon) { | 207 if (!icon) { |
| 208 NSDockTile* dockTile = [[NSApplication sharedApplication] dockTile]; | 208 NSDockTile* dockTile = [[NSApplication sharedApplication] dockTile]; |
| 209 | 209 |
| 210 scoped_nsobject<DockTileView> dockTileView([[DockTileView alloc] init]); | 210 base::scoped_nsobject<DockTileView> dockTileView( |
| 211 [[DockTileView alloc] init]); |
| 211 [dockTile setContentView:dockTileView]; | 212 [dockTile setContentView:dockTileView]; |
| 212 | 213 |
| 213 icon = [[DockIcon alloc] init]; | 214 icon = [[DockIcon alloc] init]; |
| 214 } | 215 } |
| 215 | 216 |
| 216 return icon; | 217 return icon; |
| 217 } | 218 } |
| 218 | 219 |
| 219 - (void)updateIcon { | 220 - (void)updateIcon { |
| 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 259 |
| 259 - (void)setProgress:(float)progress { | 260 - (void)setProgress:(float)progress { |
| 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 261 NSDockTile* dockTile = [[NSApplication sharedApplication] dockTile]; | 262 NSDockTile* dockTile = [[NSApplication sharedApplication] dockTile]; |
| 262 DockTileView* dockTileView = (DockTileView*)([dockTile contentView]); | 263 DockTileView* dockTileView = (DockTileView*)([dockTile contentView]); |
| 263 | 264 |
| 264 [dockTileView setProgress:progress]; | 265 [dockTileView setProgress:progress]; |
| 265 } | 266 } |
| 266 | 267 |
| 267 @end | 268 @end |
| OLD | NEW |