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