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