| Index: chrome/browser/ui/cocoa/gradient_button_cell.mm
|
| diff --git a/chrome/browser/ui/cocoa/gradient_button_cell.mm b/chrome/browser/ui/cocoa/gradient_button_cell.mm
|
| index 8a4f2487c0055ab726a3c4b50dc7c1e1763d48de..7a846296eedbdcde8888c7d4df10a3d880ddc136 100644
|
| --- a/chrome/browser/ui/cocoa/gradient_button_cell.mm
|
| +++ b/chrome/browser/ui/cocoa/gradient_button_cell.mm
|
| @@ -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_state_mac.h"
|
|
|
| @interface GradientButtonCell (Private)
|
| - (void)sharedInit;
|
| @@ -403,7 +404,7 @@ static const NSTimeInterval kAnimationContinuousCycleDuration = 0.4;
|
|
|
| // Visually indicate unclicked, enabled buttons.
|
| if (!showClickedGradient && [self isEnabled]) {
|
| - [NSGraphicsContext saveGraphicsState];
|
| + gfx::ScopedNSGraphicsContextState scopedGState;
|
| [innerPath addClip];
|
|
|
| // Draw the inner glow.
|
| @@ -423,8 +424,6 @@ static const NSTimeInterval kAnimationContinuousCycleDuration = 0.4;
|
|
|
| // 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 @@ static const NSTimeInterval kAnimationContinuousCycleDuration = 0.4;
|
| if (shouldTheme_) {
|
| BOOL isTemplate = [[self image] isTemplate];
|
|
|
| - [NSGraphicsContext saveGraphicsState];
|
| + gfx::ScopedNSGraphicsContextState scopedGState;
|
|
|
| CGContextRef context =
|
| (CGContextRef)([[NSGraphicsContext currentContext] graphicsPort]);
|
| @@ -611,8 +610,6 @@ static const NSTimeInterval kAnimationContinuousCycleDuration = 0.4;
|
| 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 @@ static const NSTimeInterval kAnimationContinuousCycleDuration = 0.4;
|
|
|
| // 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];
|
| -
|
| - // 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];
|
| -
|
| - // 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];
|
| + NSPoint textOffset = NSZeroPoint;
|
| + {
|
| + gfx::ScopedNSGraphicsContextState 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;
|
| +
|
| + // 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.
|
| + 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::ScopedNSGraphicsContextState scopedGState;
|
| [NSBezierPath clipRect:gradientPart];
|
| CGContextRef context = static_cast<CGContextRef>(
|
| [[NSGraphicsContext currentContext] graphicsPort]);
|
| @@ -703,7 +702,6 @@ static const NSTimeInterval kAnimationContinuousCycleDuration = 0.4;
|
| options:NSGradientDrawsBeforeStartingLocation];
|
| [mask release];
|
| CGContextEndTransparencyLayer(context);
|
| - [[NSGraphicsContext currentContext] restoreGraphicsState];
|
|
|
| return cellFrame;
|
| }
|
|
|