1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "ui/base/cocoa/controls/hover_image_menu_button_cell.h"
7 @implementation HoverImageMenuButtonCell
9 @synthesize hovered = hovered_;
11 - (id)initTextCell:(NSString*)stringValue
12 pullsDown:(BOOL)pullDown {
13 if ((self = [super initTextCell:stringValue
14 pullsDown:pullDown])) {
15 [self setUsesItemFromMenu:NO];
20 - (void)setHoverImage:(NSImage*)newImage {
21 if ([hoverImage_ isEqual:newImage])
24 hoverImage_.reset([newImage retain]);
26 [[self controlView] setNeedsDisplay:YES];
29 - (NSImage*)hoverImage {
33 - (void)setHovered:(BOOL)hovered {
34 if (hovered_ == hovered)
38 [[self controlView] setNeedsDisplay:YES];
41 - (NSImage*)imageToDraw {
42 if ([self isHighlighted] && [self alternateImage])
43 return [self alternateImage];
45 if ([self isHovered] && [self hoverImage])
46 return [self hoverImage];
48 // Note that NSPopUpButtonCell updates the cell image when the [self menuItem]
53 - (void)setDefaultImage:(NSImage*)defaultImage {
54 base::scoped_nsobject<NSMenuItem> buttonMenuItem([[NSMenuItem alloc] init]);
55 [buttonMenuItem setImage:defaultImage];
56 [self setMenuItem:buttonMenuItem];
59 - (void)drawWithFrame:(NSRect)cellFrame
60 inView:(NSView*)controlView {
61 [[self imageToDraw] drawInRect:cellFrame
63 operation:NSCompositeSourceOver