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

Side by Side Diff: chrome/browser/cocoa/gradient_button_cell.mm

Issue 384115: Mac: Draw download item background like windows does if a theme is installed. (Closed)
Patch Set: Created 11 years, 1 month 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/scoped_nsobject.h" 5 #import "base/scoped_nsobject.h"
6 #include "chrome/browser/cocoa/gradient_button_cell.h" 6 #include "chrome/browser/cocoa/gradient_button_cell.h"
7 #import "third_party/GTM/AppKit/GTMTheme.h" 7 #import "third_party/GTM/AppKit/GTMTheme.h"
8 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" 8 #import "third_party/GTM/AppKit/GTMNSColor+Luminance.h"
9 9
10 @interface GradientButtonCell (Private) 10 @interface GradientButtonCell (Private)
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 } 158 }
159 159
160 - (void)drawBorderAndFillForTheme:(GTMTheme*)theme 160 - (void)drawBorderAndFillForTheme:(GTMTheme*)theme
161 controlView:(NSView*)controlView 161 controlView:(NSView*)controlView
162 outerPath:(NSBezierPath*)outerPath 162 outerPath:(NSBezierPath*)outerPath
163 innerPath:(NSBezierPath*)innerPath 163 innerPath:(NSBezierPath*)innerPath
164 showClickedGradient:(BOOL)showClickedGradient 164 showClickedGradient:(BOOL)showClickedGradient
165 showHighlightGradient:(BOOL)showHighlightGradient 165 showHighlightGradient:(BOOL)showHighlightGradient
166 hoverAlpha:(CGFloat)hoverAlpha 166 hoverAlpha:(CGFloat)hoverAlpha
167 active:(BOOL)active 167 active:(BOOL)active
168 cellFrame:(NSRect)cellFrame { 168 cellFrame:(NSRect)cellFrame
169 defaultGradient:(NSGradient*)defaultGradient {
169 NSImage* backgroundImage = 170 NSImage* backgroundImage =
170 [theme backgroundImageForStyle:GTMThemeStyleToolBarButton state:YES]; 171 [theme backgroundImageForStyle:GTMThemeStyleToolBarButton state:YES];
171 172
173 if (!defaultGradient)
174 defaultGradient = gradient_;
175
172 if (backgroundImage) { 176 if (backgroundImage) {
173 NSColor* patternColor = [NSColor colorWithPatternImage:backgroundImage]; 177 NSColor* patternColor = [NSColor colorWithPatternImage:backgroundImage];
174 [patternColor set]; 178 [patternColor set];
175 // Set the phase to match window. 179 // Set the phase to match window.
176 NSRect trueRect = [controlView convertRectToBase:cellFrame]; 180 NSRect trueRect = [controlView convertRectToBase:cellFrame];
177 [[NSGraphicsContext currentContext] 181 [[NSGraphicsContext currentContext]
178 setPatternPhase:NSMakePoint(NSMinX(trueRect), NSMaxY(trueRect))]; 182 setPatternPhase:NSMakePoint(NSMinX(trueRect), NSMaxY(trueRect))];
179 [innerPath fill]; 183 [innerPath fill];
180 } else { 184 } else {
181 if (showClickedGradient) { 185 if (showClickedGradient) {
(...skipping 20 matching lines...) Expand all
202 // Draw the top inner highlight. 206 // Draw the top inner highlight.
203 NSAffineTransform* highlightTransform = [NSAffineTransform transform]; 207 NSAffineTransform* highlightTransform = [NSAffineTransform transform];
204 [highlightTransform translateXBy:1 yBy:1]; 208 [highlightTransform translateXBy:1 yBy:1];
205 scoped_nsobject<NSBezierPath> highlightPath([innerPath copy]); 209 scoped_nsobject<NSBezierPath> highlightPath([innerPath copy]);
206 [highlightPath transformUsingAffineTransform:highlightTransform]; 210 [highlightPath transformUsingAffineTransform:highlightTransform];
207 [[NSColor colorWithCalibratedWhite:1.0 alpha:0.2] setStroke]; 211 [[NSColor colorWithCalibratedWhite:1.0 alpha:0.2] setStroke];
208 [highlightPath stroke]; 212 [highlightPath stroke];
209 213
210 NSGradient *gradient = nil; 214 NSGradient *gradient = nil;
211 if (hoverAlpha == 0 && !isCustomTheme) { 215 if (hoverAlpha == 0 && !isCustomTheme) {
212 gradient = gradient_; 216 gradient = defaultGradient;
213 } else { 217 } else {
214 gradient = [self gradientForHoverAlpha:hoverAlpha isThemed:isCustomTheme]; 218 gradient = [self gradientForHoverAlpha:hoverAlpha isThemed:isCustomTheme];
215 } 219 }
216 [gradient drawInBezierPath:innerPath angle:90.0]; 220 [gradient drawInBezierPath:innerPath angle:90.0];
217 221
218 [NSGraphicsContext restoreGraphicsState]; 222 [NSGraphicsContext restoreGraphicsState];
219 } 223 }
220 224
221 // Draw the outer stroke 225 // Draw the outer stroke
222 NSColor* stroke = [theme strokeColorForStyle:GTMThemeStyleToolBarButton 226 NSColor* stroke = [theme strokeColorForStyle:GTMThemeStyleToolBarButton
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 [self isMouseInside]) { 281 [self isMouseInside]) {
278 282
279 [self drawBorderAndFillForTheme:theme 283 [self drawBorderAndFillForTheme:theme
280 controlView:controlView 284 controlView:controlView
281 outerPath:outerPath 285 outerPath:outerPath
282 innerPath:innerPath 286 innerPath:innerPath
283 showClickedGradient:pressed 287 showClickedGradient:pressed
284 showHighlightGradient:[self isHighlighted] 288 showHighlightGradient:[self isHighlighted]
285 hoverAlpha:[self hoverAlpha] 289 hoverAlpha:[self hoverAlpha]
286 active:active 290 active:active
287 cellFrame:cellFrame]; 291 cellFrame:cellFrame
292 defaultGradient:nil];
288 } 293 }
289 294
290 // If this is the left side of a segmented button, draw a slight shadow. 295 // If this is the left side of a segmented button, draw a slight shadow.
291 if (type == kLeftButtonWithShadowType) { 296 if (type == kLeftButtonWithShadowType) {
292 NSRect borderRect, contentRect; 297 NSRect borderRect, contentRect;
293 NSDivideRect(cellFrame, &borderRect, &contentRect, 1.0, NSMaxXEdge); 298 NSDivideRect(cellFrame, &borderRect, &contentRect, 1.0, NSMaxXEdge);
294 NSColor* stroke = [theme strokeColorForStyle:GTMThemeStyleToolBarButton 299 NSColor* stroke = [theme strokeColorForStyle:GTMThemeStyleToolBarButton
295 state:active]; 300 state:active];
296 [[stroke colorWithAlphaComponent:0.2] set]; 301 [[stroke colorWithAlphaComponent:0.2] set];
297 NSRectFillUsingOperation(NSInsetRect(borderRect, 0, 2), 302 NSRectFillUsingOperation(NSInsetRect(borderRect, 0, 2),
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 imageRect.size = [underlayImage_ size]; 367 imageRect.size = [underlayImage_ size];
363 [underlayImage_ setFlipped:[controlView isFlipped]]; 368 [underlayImage_ setFlipped:[controlView isFlipped]];
364 [underlayImage_ drawInRect:[self imageRectForBounds:cellFrame] 369 [underlayImage_ drawInRect:[self imageRectForBounds:cellFrame]
365 fromRect:imageRect 370 fromRect:imageRect
366 operation:NSCompositeSourceOver 371 operation:NSCompositeSourceOver
367 fraction:[self isEnabled] ? 1.0 : 0.5]; 372 fraction:[self isEnabled] ? 1.0 : 0.5];
368 } 373 }
369 } 374 }
370 375
371 @end 376 @end
OLDNEW
« chrome/browser/cocoa/download_item_cell.mm ('K') | « chrome/browser/cocoa/gradient_button_cell.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698