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 3 // found in the LICENSE file. 4 5 #import "chrome/browser/ui/cocoa/hover_image_button.h" 6 7 #include "base/memory/scoped_nsobject.h" 8 #include "grit/generated_resources.h" 9 #include "ui/base/l10n/l10n_util.h" 10 11 @implementation HoverImageButton 12 13 - (void)drawRect:(NSRect)rect { 14 if (hoverState_ == kHoverStateMouseDown && pressedImage_) { 15 [super setImage:pressedImage_.get()]; 16 [super setAlphaValue:pressedOpacity_]; 17 } else if (hoverState_ == kHoverStateMouseOver && hoverImage_) { 18 [super setImage:hoverImage_.get()]; 19 [super setAlphaValue:hoverOpacity_]; 20 } else { 21 [super setImage:defaultImage_.get()]; 22 [super setAlphaValue:defaultOpacity_]; 23 } 24 25 [super drawRect:rect]; 26 } 27 28 - (void)setDefaultImage:(NSImage*)image { 29 defaultImage_.reset([image retain]); 30 } 31 32 - (void)setDefaultOpacity:(float)opacity { 33 defaultOpacity_ = opacity; 34 } 35 36 - (void)setHoverImage:(NSImage*)image { 37 hoverImage_.reset([image retain]); 38 } 39 40 - (void)setHoverOpacity:(float)opacity { 41 hoverOpacity_ = opacity; 42 } 43 44 - (void)setPressedImage:(NSImage*)image { 45 pressedImage_.reset([image retain]); 46 } 47 48 - (void)setPressedOpacity:(float)opacity { 49 pressedOpacity_ = opacity; 50 } 51 52 @end 53