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_EXTENSIONS_BROWSER_ACTION_BUTTON_H_ 6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTION_BUTTON_H_ 7 #pragma once 8 9 #import <Cocoa/Cocoa.h> 10 11 #import "base/memory/scoped_nsobject.h" 12 #include "base/memory/scoped_ptr.h" 13 #import "chrome/browser/ui/cocoa/gradient_button_cell.h" 14 15 class Extension; 16 class ExtensionAction; 17 class ExtensionImageTrackerBridge; 18 class Profile; 19 20 // Fired when the Browser Action's state has changed. Usually the image needs to 21 // be updated. 22 extern NSString* const kBrowserActionButtonUpdatedNotification; 23 24 // Fired on each drag event while the user is moving the button. 25 extern NSString* const kBrowserActionButtonDraggingNotification; 26 // Fired when the user drops the button. 27 extern NSString* const kBrowserActionButtonDragEndNotification; 28 29 @interface BrowserActionButton : NSButton { 30 @private 31 // Bridge to proxy Chrome notifications to the Obj-C class as well as load the 32 // extension's icon. 33 scoped_ptr<ExtensionImageTrackerBridge> imageLoadingBridge_; 34 35 // The default icon of the Button. 36 scoped_nsobject<NSImage> defaultIcon_; 37 38 // The icon specific to the active tab. 39 scoped_nsobject<NSImage> tabSpecificIcon_; 40 41 // Used to move the button and query whether a button is currently animating. 42 scoped_nsobject<NSViewAnimation> moveAnimation_; 43 44 // The extension for this button. Weak. 45 const Extension* extension_; 46 47 // The ID of the active tab. 48 int tabId_; 49 50 // Whether the button is currently being dragged. 51 BOOL isBeingDragged_; 52 53 // Drag events could be intercepted by other buttons, so to make sure that 54 // this is the only button moving if it ends up being dragged. This is set to 55 // YES upon |mouseDown:|. 56 BOOL dragCouldStart_; 57 } 58 59 - (id)initWithFrame:(NSRect)frame 60 extension:(const Extension*)extension 61 profile:(Profile*)profile 62 tabId:(int)tabId; 63 64 - (void)setFrame:(NSRect)frameRect animate:(BOOL)animate; 65 66 - (void)setDefaultIcon:(NSImage*)image; 67 68 - (void)setTabSpecificIcon:(NSImage*)image; 69 70 - (void)updateState; 71 72 - (BOOL)isAnimating; 73 74 // Returns a pointer to an autoreleased NSImage with the badge, shadow and 75 // cell image drawn into it. 76 - (NSImage*)compositedImage; 77 78 @property(readonly, nonatomic) BOOL isBeingDragged; 79 @property(readonly, nonatomic) const Extension* extension; 80 @property(readwrite, nonatomic) int tabId; 81 82 @end 83 84 @interface BrowserActionCell : GradientButtonCell { 85 @private 86 // The current tab ID used when drawing the cell. 87 int tabId_; 88 89 // The action we're drawing the cell for. Weak. 90 ExtensionAction* extensionAction_; 91 } 92 93 @property(readwrite, nonatomic) int tabId; 94 @property(readwrite, nonatomic) ExtensionAction* extensionAction; 95 96 @end 97 98 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTION_BUTTON_H_ 99