Index: chrome/browser/ui/cocoa/gradient_button_cell.mm |
=================================================================== |
--- chrome/browser/ui/cocoa/gradient_button_cell.mm (revision 84308) |
+++ chrome/browser/ui/cocoa/gradient_button_cell.mm (working copy) |
@@ -12,6 +12,7 @@ |
#import "chrome/browser/ui/cocoa/themed_window.h" |
#include "grit/theme_resources.h" |
#import "third_party/GTM/AppKit/GTMNSColor+Luminance.h" |
+#include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
@interface GradientButtonCell (Private) |
- (void)sharedInit; |
@@ -403,7 +404,7 @@ |
// Visually indicate unclicked, enabled buttons. |
if (!showClickedGradient && [self isEnabled]) { |
- [NSGraphicsContext saveGraphicsState]; |
+ gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
[innerPath addClip]; |
// Draw the inner glow. |
@@ -423,8 +424,6 @@ |
// Draw the gradient inside. |
[gradient drawInBezierPath:innerPath angle:90.0]; |
- |
- [NSGraphicsContext restoreGraphicsState]; |
} |
// Don't draw anything else for disabled flat buttons. |
@@ -576,7 +575,7 @@ |
if (shouldTheme_) { |
BOOL isTemplate = [[self image] isTemplate]; |
- [NSGraphicsContext saveGraphicsState]; |
+ gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
CGContextRef context = |
(CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]); |
@@ -611,8 +610,6 @@ |
NSRectFillUsingOperation(cellFrame, NSCompositeSourceAtop); |
} |
CGContextEndTransparencyLayer(context); |
- |
- [NSGraphicsContext restoreGraphicsState]; |
} else { |
// NSCell draws these off-center for some reason, probably because of the |
// positioning of the control in the xib. |
@@ -660,27 +657,29 @@ |
// Draw non-gradient part without transparency layer, as light text on a dark |
// background looks bad with a gradient layer. |
- [[NSGraphicsContext currentContext] saveGraphicsState]; |
- [NSBezierPath clipRect:solidPart]; |
+ NSPoint textOffset = NSZeroPoint; |
+ { |
+ gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
+ [NSBezierPath clipRect:solidPart]; |
- // 11 is the magic number needed to make this match the native NSButtonCell's |
- // label display. |
- CGFloat textLeft = [[self image] size].width + 11; |
+ // 11 is the magic number needed to make this match the native |
+ // NSButtonCell's label display. |
+ CGFloat textLeft = [[self image] size].width + 11; |
- // For some reason, the height of cellFrame as passed in is totally bogus. |
- // For vertical centering purposes, we need the bounds of the containing |
- // view. |
- NSRect buttonFrame = [[self controlView] frame]; |
+ // For some reason, the height of cellFrame as passed in is totally bogus. |
+ // For vertical centering purposes, we need the bounds of the containing |
+ // view. |
+ NSRect buttonFrame = [[self controlView] frame]; |
- // Off-by-one to match native NSButtonCell's version. |
- NSPoint textOffset = NSMakePoint(textLeft, |
- (NSHeight(buttonFrame) - size.height)/2 + 1); |
- [title drawAtPoint:textOffset]; |
- [[NSGraphicsContext currentContext] restoreGraphicsState]; |
+ // Off-by-one to match native NSButtonCell's version. |
+ textOffset = NSMakePoint(textLeft, |
+ (NSHeight(buttonFrame) - size.height)/2 + 1); |
+ [title drawAtPoint:textOffset]; |
+ } |
// Draw the gradient part with a transparency layer. This makes the text look |
// suboptimal, but since it fades out, that's ok. |
- [[NSGraphicsContext currentContext] saveGraphicsState]; |
+ gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
[NSBezierPath clipRect:gradientPart]; |
CGContextRef context = static_cast<CGContextRef>( |
[[NSGraphicsContext currentContext] graphicsPort]); |
@@ -703,7 +702,6 @@ |
options:NSGradientDrawsBeforeStartingLocation]; |
[mask release]; |
CGContextEndTransparencyLayer(context); |
- [[NSGraphicsContext currentContext] restoreGraphicsState]; |
return cellFrame; |
} |