OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_COCOA_IMAGE_BUTTON_CELL_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_IMAGE_BUTTON_CELL_H_ |
6 #define CHROME_BROWSER_UI_COCOA_IMAGE_BUTTON_CELL_H_ | 6 #define CHROME_BROWSER_UI_COCOA_IMAGE_BUTTON_CELL_H_ |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include "base/memory/scoped_nsobject.h" | 10 #include "base/memory/scoped_nsobject.h" |
11 | 11 |
12 namespace image_button_cell { | 12 namespace image_button_cell { |
13 | 13 |
14 // Possible states | 14 // Possible states |
15 enum ButtonState { | 15 enum ButtonState { |
16 kDefaultState = 0, | 16 kDefaultState = 0, |
17 kHoverState, | 17 kHoverState, |
18 kPressedState, | 18 kPressedState, |
19 kDisabledState, | 19 kDisabledState, |
20 // The same as above, but for non-main, non-key windows. | 20 // The same as above, but for non-main, non-key windows. |
21 kDefaultStateBackground, | 21 kDefaultStateBackground, |
22 kHoverStateBackground, | 22 kHoverStateBackground, |
23 kButtonStateCount | 23 kButtonStateCount |
24 }; | 24 }; |
25 | 25 |
26 enum ImageType { | |
sail
2013/01/04 05:27:24
It doesn't seem like you actually need this.
imag
Nico
2013/01/04 05:52:55
Thanks, this makes things slightly better. Done.
| |
27 kImageId, | |
28 kImage, | |
29 }; | |
30 | |
26 } // namespace ImageButtonCell | 31 } // namespace ImageButtonCell |
27 | 32 |
28 @protocol ImageButton | 33 @protocol ImageButton |
29 @optional | 34 @optional |
30 // Sent from an ImageButtonCell to its view when the mouse enters or exits the | 35 // Sent from an ImageButtonCell to its view when the mouse enters or exits the |
31 // cell. | 36 // cell. |
32 - (void)mouseInsideStateDidChange:(BOOL)isInside; | 37 - (void)mouseInsideStateDidChange:(BOOL)isInside; |
33 @end | 38 @end |
34 | 39 |
35 // A button cell that can disable a different image for each possible button | 40 // A button cell that can disable a different image for each possible button |
36 // state. Images are specified by image IDs. | 41 // state. Images are specified by image IDs. |
37 @interface ImageButtonCell : NSButtonCell { | 42 @interface ImageButtonCell : NSButtonCell { |
38 @private | 43 @private |
39 scoped_nsobject<NSImage> image_[image_button_cell::kButtonStateCount]; | 44 struct { |
45 image_button_cell::ImageType type; | |
46 int imageId; | |
47 scoped_nsobject<NSImage> image; | |
48 } image_[image_button_cell::kButtonStateCount]; | |
40 NSInteger overlayImageID_; | 49 NSInteger overlayImageID_; |
41 BOOL isMouseInside_; | 50 BOOL isMouseInside_; |
42 } | 51 } |
43 | 52 |
44 @property(assign, nonatomic) NSInteger overlayImageID; | 53 @property(assign, nonatomic) NSInteger overlayImageID; |
45 @property(assign, nonatomic) BOOL isMouseInside; | 54 @property(assign, nonatomic) BOOL isMouseInside; |
46 | 55 |
47 // Sets the image for the given button state using an image ID. | 56 // Sets the image for the given button state using an image ID. |
48 // The image will be loaded from a resource pak. | 57 // The image will be lazy loaded from a resource pak -- important because |
58 // this is in the hot path for startup. | |
49 - (void)setImageID:(NSInteger)imageID | 59 - (void)setImageID:(NSInteger)imageID |
50 forButtonState:(image_button_cell::ButtonState)state; | 60 forButtonState:(image_button_cell::ButtonState)state; |
51 | 61 |
52 // Sets the image for the given button state using an image. | 62 // Sets the image for the given button state using an image. |
53 - (void)setImage:(NSImage*)image | 63 - (void)setImage:(NSImage*)image |
54 forButtonState:(image_button_cell::ButtonState)state; | 64 forButtonState:(image_button_cell::ButtonState)state; |
55 | 65 |
56 @end | 66 @end |
57 | 67 |
58 #endif // CHROME_BROWSER_UI_COCOA_IMAGE_BUTTON_CELL_H_ | 68 #endif // CHROME_BROWSER_UI_COCOA_IMAGE_BUTTON_CELL_H_ |
OLD | NEW |