Home | History | Annotate | Download | only in cocoa
      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 #ifndef CHROME_BROWSER_UI_COCOA_IMAGE_BUTTON_CELL_H_
      6 #define CHROME_BROWSER_UI_COCOA_IMAGE_BUTTON_CELL_H_
      7 
      8 #import <Cocoa/Cocoa.h>
      9 
     10 #include "base/mac/scoped_nsobject.h"
     11 
     12 namespace image_button_cell {
     13 
     14 // Possible states
     15 enum ButtonState {
     16   kDefaultState = 0,
     17   kHoverState,
     18   kPressedState,
     19   kDisabledState,
     20   // The same as above, but for non-main, non-key windows.
     21   kDefaultStateBackground,
     22   kHoverStateBackground,
     23   kButtonStateCount
     24 };
     25 
     26 } // namespace ImageButtonCell
     27 
     28 @protocol ImageButton
     29 @optional
     30 // Sent from an ImageButtonCell to its view when the mouse enters or exits the
     31 // cell.
     32 - (void)mouseInsideStateDidChange:(BOOL)isInside;
     33 @end
     34 
     35 // A button cell that can disable a different image for each possible button
     36 // state. Images are specified by image IDs.
     37 @interface ImageButtonCell : NSButtonCell {
     38  @private
     39   struct {
     40     // At most one of these two fields will be non-null.
     41     int imageId;
     42     base::scoped_nsobject<NSImage> image;
     43   } image_[image_button_cell::kButtonStateCount];
     44   BOOL isMouseInside_;
     45 }
     46 
     47 @property(assign, nonatomic) BOOL isMouseInside;
     48 
     49 // Gets the image for the given button state. Will load from a resource pak if
     50 // the image was originally set using an image ID.
     51 - (NSImage*)imageForState:(image_button_cell::ButtonState)state
     52                      view:(NSView*)controlView;
     53 
     54 // Sets the image for the given button state using an image ID.
     55 // The image will be lazy loaded from a resource pak -- important because
     56 // this is in the hot path for startup.
     57 - (void)setImageID:(NSInteger)imageID
     58     forButtonState:(image_button_cell::ButtonState)state;
     59 
     60 // Sets the image for the given button state using an image.
     61 - (void)setImage:(NSImage*)image
     62   forButtonState:(image_button_cell::ButtonState)state;
     63 
     64 // Gets the alpha to use to draw the button for the current window focus state.
     65 - (CGFloat)imageAlphaForWindowState:(NSWindow*)window;
     66 
     67 // If |controlView| is a first responder then draws a blue focus ring.
     68 - (void)drawFocusRingWithFrame:(NSRect)cellFrame inView:(NSView*)controlView;
     69 
     70 @end
     71 
     72 #endif // CHROME_BROWSER_UI_COCOA_IMAGE_BUTTON_CELL_H_
     73