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

Side by Side Diff: chrome/browser/ui/cocoa/dock_icon.mm

Issue 6927058: Merge 83125 - Add and use gfx::ScopedNSGraphicsContextState (ui/gfx/scoped_ns_graphics_context_st... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/742/src/
Patch Set: Created 9 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/scoped_nsobject.h" 7 #include "base/memory/scoped_nsobject.h"
8 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h"
8 9
9 // The fraction of the size of the dock icon that the badge is. 10 // The fraction of the size of the dock icon that the badge is.
10 static const float kBadgeFraction = 0.4f; 11 static const float kBadgeFraction = 0.4f;
11 12
12 // The indentation of the badge. 13 // The indentation of the badge.
13 static const float kBadgeIndent = 5.0f; 14 static const float kBadgeIndent = 5.0f;
14 15
15 // A view that draws our dock tile. 16 // A view that draws our dock tile.
16 @interface DockTileView : NSView { 17 @interface DockTileView : NSView {
17 @private 18 @private
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 green:0.85 71 green:0.85
71 blue:0.85 72 blue:0.85
72 alpha:1.0]; 73 alpha:1.0];
73 NSColor* backgroundHighlight = 74 NSColor* backgroundHighlight =
74 [backgroundColor blendedColorWithFraction:0.85 75 [backgroundColor blendedColorWithFraction:0.85
75 ofColor:[NSColor whiteColor]]; 76 ofColor:[NSColor whiteColor]];
76 scoped_nsobject<NSGradient> backgroundGradient( 77 scoped_nsobject<NSGradient> backgroundGradient(
77 [[NSGradient alloc] initWithStartingColor:backgroundHighlight 78 [[NSGradient alloc] initWithStartingColor:backgroundHighlight
78 endingColor:backgroundColor]); 79 endingColor:backgroundColor]);
79 NSBezierPath* badgeEdge = [NSBezierPath bezierPathWithOvalInRect:badgeRect]; 80 NSBezierPath* badgeEdge = [NSBezierPath bezierPathWithOvalInRect:badgeRect];
80 [NSGraphicsContext saveGraphicsState]; 81 {
81 [badgeEdge addClip]; 82 gfx::ScopedNSGraphicsContextSaveGState scopedGState;
82 [backgroundGradient drawFromCenter:badgeCenter 83 [badgeEdge addClip];
83 radius:0.0 84 [backgroundGradient drawFromCenter:badgeCenter
84 toCenter:badgeCenter 85 radius:0.0
85 radius:badgeRadius 86 toCenter:badgeCenter
86 options:0]; 87 radius:badgeRadius
87 [NSGraphicsContext restoreGraphicsState]; 88 options:0];
89 }
88 90
89 // Slice 91 // Slice
90 if (!indeterminate_) { 92 if (!indeterminate_) {
91 NSColor* sliceColor = [NSColor colorWithCalibratedRed:0.45 93 NSColor* sliceColor = [NSColor colorWithCalibratedRed:0.45
92 green:0.8 94 green:0.8
93 blue:0.25 95 blue:0.25
94 alpha:1.0]; 96 alpha:1.0];
95 NSColor* sliceHighlight = 97 NSColor* sliceHighlight =
96 [sliceColor blendedColorWithFraction:0.4 98 [sliceColor blendedColorWithFraction:0.4
97 ofColor:[NSColor whiteColor]]; 99 ofColor:[NSColor whiteColor]];
98 scoped_nsobject<NSGradient> sliceGradient( 100 scoped_nsobject<NSGradient> sliceGradient(
99 [[NSGradient alloc] initWithStartingColor:sliceHighlight 101 [[NSGradient alloc] initWithStartingColor:sliceHighlight
100 endingColor:sliceColor]); 102 endingColor:sliceColor]);
101 NSBezierPath* progressSlice; 103 NSBezierPath* progressSlice;
102 if (progress_ >= 1.0) { 104 if (progress_ >= 1.0) {
103 progressSlice = [NSBezierPath bezierPathWithOvalInRect:badgeRect]; 105 progressSlice = [NSBezierPath bezierPathWithOvalInRect:badgeRect];
104 } else { 106 } else {
105 CGFloat endAngle = 90.0 - 360.0 * progress_; 107 CGFloat endAngle = 90.0 - 360.0 * progress_;
106 if (endAngle < 0.0) 108 if (endAngle < 0.0)
107 endAngle += 360.0; 109 endAngle += 360.0;
108 progressSlice = [NSBezierPath bezierPath]; 110 progressSlice = [NSBezierPath bezierPath];
109 [progressSlice moveToPoint:badgeCenter]; 111 [progressSlice moveToPoint:badgeCenter];
110 [progressSlice appendBezierPathWithArcWithCenter:badgeCenter 112 [progressSlice appendBezierPathWithArcWithCenter:badgeCenter
111 radius:badgeRadius 113 radius:badgeRadius
112 startAngle:90.0 114 startAngle:90.0
113 endAngle:endAngle 115 endAngle:endAngle
114 clockwise:YES]; 116 clockwise:YES];
115 [progressSlice closePath]; 117 [progressSlice closePath];
116 } 118 }
117 [NSGraphicsContext saveGraphicsState]; 119 gfx::ScopedNSGraphicsContextSaveGState scopedGState;
118 [progressSlice addClip]; 120 [progressSlice addClip];
119 [sliceGradient drawFromCenter:badgeCenter 121 [sliceGradient drawFromCenter:badgeCenter
120 radius:0.0 122 radius:0.0
121 toCenter:badgeCenter 123 toCenter:badgeCenter
122 radius:badgeRadius 124 radius:badgeRadius
123 options:0]; 125 options:0];
124 [NSGraphicsContext restoreGraphicsState];
125 } 126 }
126 127
127 // Edge 128 // Edge
128 [NSGraphicsContext saveGraphicsState]; 129 {
129 [[NSColor whiteColor] set]; 130 gfx::ScopedNSGraphicsContextSaveGState scopedGState;
130 scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); 131 [[NSColor whiteColor] set];
131 [shadow.get() setShadowOffset:NSMakeSize(0, -2)]; 132 scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]);
132 [shadow setShadowBlurRadius:2]; 133 [shadow.get() setShadowOffset:NSMakeSize(0, -2)];
133 [shadow set]; 134 [shadow setShadowBlurRadius:2];
134 [badgeEdge setLineWidth:2]; 135 [shadow set];
135 [badgeEdge stroke]; 136 [badgeEdge setLineWidth:2];
136 [NSGraphicsContext restoreGraphicsState]; 137 [badgeEdge stroke];
138 }
137 139
138 // Download count 140 // Download count
139 scoped_nsobject<NSNumberFormatter> formatter( 141 scoped_nsobject<NSNumberFormatter> formatter(
140 [[NSNumberFormatter alloc] init]); 142 [[NSNumberFormatter alloc] init]);
141 NSString* countString = 143 NSString* countString =
142 [formatter stringFromNumber:[NSNumber numberWithInt:downloads_]]; 144 [formatter stringFromNumber:[NSNumber numberWithInt:downloads_]];
143 145
144 scoped_nsobject<NSShadow> countShadow([[NSShadow alloc] init]); 146 scoped_nsobject<NSShadow> countShadow([[NSShadow alloc] init]);
145 [countShadow setShadowBlurRadius:3.0]; 147 [countShadow setShadowBlurRadius:3.0];
146 [countShadow.get() setShadowColor:[NSColor whiteColor]]; 148 [countShadow.get() setShadowColor:[NSColor whiteColor]];
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 217 }
216 218
217 - (void)setProgress:(float)progress { 219 - (void)setProgress:(float)progress {
218 NSDockTile* dockTile = [[NSApplication sharedApplication] dockTile]; 220 NSDockTile* dockTile = [[NSApplication sharedApplication] dockTile];
219 DockTileView* dockTileView = (DockTileView*)([dockTile contentView]); 221 DockTileView* dockTileView = (DockTileView*)([dockTile contentView]);
220 222
221 [dockTileView setProgress:progress]; 223 [dockTileView setProgress:progress];
222 } 224 }
223 225
224 @end 226 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller.mm ('k') | chrome/browser/ui/cocoa/download/download_item_cell.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698