OLD | NEW |
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/wrench_menu/wrench_menu_button_cell.h" | 5 #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_button_cell.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 @implementation WrenchMenuButtonCell | 10 @implementation WrenchMenuButtonCell |
10 | 11 |
11 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView*)controlView { | 12 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView*)controlView { |
12 [NSGraphicsContext saveGraphicsState]; | 13 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
13 | 14 |
14 // Inset the rect to match the appearance of the layout of interface builder. | 15 // Inset the rect to match the appearance of the layout of interface builder. |
15 // The bounding rect of buttons is actually larger than the display rect shown | 16 // The bounding rect of buttons is actually larger than the display rect shown |
16 // there. | 17 // there. |
17 frame = NSInsetRect(frame, 0.0, 1.0); | 18 frame = NSInsetRect(frame, 0.0, 1.0); |
18 | 19 |
19 // Stroking the rect gives a weak stroke. Filling and insetting gives a | 20 // Stroking the rect gives a weak stroke. Filling and insetting gives a |
20 // strong, un-anti-aliased border. | 21 // strong, un-anti-aliased border. |
21 [[NSColor colorWithDeviceWhite:0.663 alpha:1.0] set]; | 22 [[NSColor colorWithDeviceWhite:0.663 alpha:1.0] set]; |
22 NSRectFill(frame); | 23 NSRectFill(frame); |
23 frame = NSInsetRect(frame, 1.0, 1.0); | 24 frame = NSInsetRect(frame, 1.0, 1.0); |
24 | 25 |
25 // The default state should be a subtle gray gradient. | 26 // The default state should be a subtle gray gradient. |
26 if (![self isHighlighted]) { | 27 if (![self isHighlighted]) { |
27 NSColor* end = [NSColor colorWithDeviceWhite:0.922 alpha:1.0]; | 28 NSColor* end = [NSColor colorWithDeviceWhite:0.922 alpha:1.0]; |
28 scoped_nsobject<NSGradient> gradient( | 29 scoped_nsobject<NSGradient> gradient( |
29 [[NSGradient alloc] initWithStartingColor:[NSColor whiteColor] | 30 [[NSGradient alloc] initWithStartingColor:[NSColor whiteColor] |
30 endingColor:end]); | 31 endingColor:end]); |
31 [gradient drawInRect:frame angle:90.0]; | 32 [gradient drawInRect:frame angle:90.0]; |
32 } else { | 33 } else { |
33 // |+selectedMenuItemColor| appears to be a gradient, so just filling the | 34 // |+selectedMenuItemColor| appears to be a gradient, so just filling the |
34 // rect with that color produces the desired effect. | 35 // rect with that color produces the desired effect. |
35 [[NSColor selectedMenuItemColor] set]; | 36 [[NSColor selectedMenuItemColor] set]; |
36 NSRectFill(frame); | 37 NSRectFill(frame); |
37 } | 38 } |
38 | |
39 [NSGraphicsContext restoreGraphicsState]; | |
40 } | 39 } |
41 | 40 |
42 - (NSBackgroundStyle)interiorBackgroundStyle { | 41 - (NSBackgroundStyle)interiorBackgroundStyle { |
43 if ([self isHighlighted]) | 42 if ([self isHighlighted]) |
44 return NSBackgroundStyleDark; | 43 return NSBackgroundStyleDark; |
45 return [super interiorBackgroundStyle]; | 44 return [super interiorBackgroundStyle]; |
46 } | 45 } |
47 | 46 |
48 @end | 47 @end |
OLD | NEW |