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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/base/cocoa/controls/hover_image_menu_button_cell.mm
diff --git a/ui/base/cocoa/controls/hover_image_menu_button_cell.mm b/ui/base/cocoa/controls/hover_image_menu_button_cell.mm
new file mode 100644
index 0000000000000000000000000000000000000000..32a9d696c441af2b59bdaaef9560bd91e0322f69
--- /dev/null
+++ b/ui/base/cocoa/controls/hover_image_menu_button_cell.mm
@@ -0,0 +1,69 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ui/base/cocoa/controls/hover_image_menu_button_cell.h"
+
+@implementation HoverImageMenuButtonCell
+
+@synthesize hovered = hovered_;
+
+- (id)initTextCell:(NSString*)stringValue
+ pullsDown:(BOOL)pullDown {
+ if ((self = [super initTextCell:stringValue
+ pullsDown:pullDown])) {
+ [self setUsesItemFromMenu:NO];
+ }
+ return self;
+}
+
+- (void)setHoverImage:(NSImage*)newImage {
+ if ([hoverImage_ isEqual:newImage])
+ return;
+
+ hoverImage_.reset([newImage retain]);
+ if (hovered_)
+ [[self controlView] setNeedsDisplay:YES];
+}
+
+- (NSImage*)hoverImage {
+ return hoverImage_;
+}
+
+- (void)setHovered:(BOOL)hovered {
+ if (hovered_ == hovered)
+ return;
+
+ hovered_ = hovered;
+ [[self controlView] setNeedsDisplay:YES];
+}
+
+- (NSImage*)imageToDraw {
+ if ([self isHighlighted] && [self alternateImage])
+ return [self alternateImage];
+
+ if ([self isHovered] && [self hoverImage])
+ return [self hoverImage];
+
+ // Note that NSPopUpButtonCell updates the cell image when the [self menuItem]
+ // changes.
+ return [self image];
+}
+
+- (void)setDefaultImage:(NSImage*)defaultImage {
+ scoped_nsobject<NSMenuItem> buttonMenuItem([[NSMenuItem alloc] init]);
+ [buttonMenuItem setImage:defaultImage];
+ [self setMenuItem:buttonMenuItem];
+}
+
+- (void)drawWithFrame:(NSRect)cellFrame
+ inView:(NSView*)controlView {
+ [[self imageToDraw] drawInRect:cellFrame
+ fromRect:NSZeroRect
+ operation:NSCompositeSourceOver
+ fraction:1.0
+ respectFlipped:YES
+ hints:nil];
+}
+
+@end
« 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