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

Side by Side Diff: ui/base/cocoa/controls/hover_image_menu_button_cell.mm

Issue 15955003: Menu for the OSX app launcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment Created 7 years, 6 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #import "ui/base/cocoa/controls/hover_image_menu_button_cell.h"
6
7 @implementation HoverImageMenuButtonCell
8
9 @synthesize hovered = hovered_;
10
11 - (id)initTextCell:(NSString*)stringValue
12 pullsDown:(BOOL)pullDown {
13 if ((self = [super initTextCell:stringValue
14 pullsDown:pullDown])) {
15 [self setUsesItemFromMenu:NO];
16 }
17 return self;
18 }
19
20 - (void)setHoverImage:(NSImage*)newImage {
21 if ([hoverImage_ isEqual:newImage])
22 return;
23
24 hoverImage_.reset([newImage retain]);
25 if (hovered_)
26 [[self controlView] setNeedsDisplay:YES];
27 }
28
29 - (NSImage*)hoverImage {
30 return hoverImage_;
31 }
32
33 - (void)setHovered:(BOOL)hovered {
34 if (hovered_ == hovered)
35 return;
36
37 hovered_ = hovered;
38 [[self controlView] setNeedsDisplay:YES];
39 }
40
41 - (NSImage*)imageToDraw {
42 if ([self isHighlighted] && [self alternateImage])
43 return [self alternateImage];
44
45 if ([self isHovered] && [self hoverImage])
46 return [self hoverImage];
47
48 // Note that NSPopUpButtonCell updates the cell image when the [self menuItem]
49 // changes.
50 return [self image];
51 }
52
53 - (void)setDefaultImage:(NSImage*)defaultImage {
54 scoped_nsobject<NSMenuItem> buttonMenuItem([[NSMenuItem alloc] init]);
55 [buttonMenuItem setImage:defaultImage];
56 [self setMenuItem:buttonMenuItem];
57 }
58
59 - (void)drawWithFrame:(NSRect)cellFrame
60 inView:(NSView*)controlView {
61 [[self imageToDraw] drawInRect:cellFrame
62 fromRect:NSZeroRect
63 operation:NSCompositeSourceOver
64 fraction:1.0
65 respectFlipped:YES
66 hints:nil];
67 }
68
69 @end
OLDNEW
« no previous file with comments | « ui/base/cocoa/controls/hover_image_menu_button_cell.h ('k') | ui/base/cocoa/controls/hover_image_menu_button_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698