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; |
18 | 20 class ToolbarActionViewDelegateBridge; |
19 namespace extensions { | |
20 class Extension; | |
21 } | |
22 | 21 |
23 // Fired on each drag event while the user is moving the button. | 22 // Fired on each drag event while the user is moving the button. |
24 extern NSString* const kBrowserActionButtonDraggingNotification; | 23 extern NSString* const kBrowserActionButtonDraggingNotification; |
25 // Fired when the user drops the button. | 24 // Fired when the user drops the button. |
26 extern NSString* const kBrowserActionButtonDragEndNotification; | 25 extern NSString* const kBrowserActionButtonDragEndNotification; |
27 | 26 |
28 @interface BrowserActionButton : NSButton<NSMenuDelegate> { | 27 @interface BrowserActionButton : NSButton<NSMenuDelegate> { |
29 @private | 28 @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. | 29 // Used to move the button and query whether a button is currently animating. |
35 base::scoped_nsobject<NSViewAnimation> moveAnimation_; | 30 base::scoped_nsobject<NSViewAnimation> moveAnimation_; |
36 | 31 |
37 // The extension for this button. Weak. | 32 // The bridge between the view controller and this object. |
38 const extensions::Extension* extension_; | 33 scoped_ptr<ToolbarActionViewDelegateBridge> viewControllerDelegate_; |
39 | 34 |
40 // The ID of the active tab. | 35 // The controller that handles most non-view logic. |
41 int tabId_; | 36 scoped_ptr<ToolbarActionViewController> viewController_; |
37 | |
38 // The controller for the browser actions bar that owns this button. Weak. | |
39 BrowserActionsController* browserActionsController_; | |
42 | 40 |
43 // Whether the button is currently being dragged. | 41 // Whether the button is currently being dragged. |
44 BOOL isBeingDragged_; | 42 BOOL isBeingDragged_; |
45 | 43 |
46 // Drag events could be intercepted by other buttons, so to make sure that | 44 // 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 | 45 // this is the only button moving if it ends up being dragged. This is set to |
48 // YES upon |mouseDown:|. | 46 // YES upon |mouseDown:|. |
49 BOOL dragCouldStart_; | 47 BOOL dragCouldStart_; |
50 | 48 |
51 // The point where the mouse down event occurred. Used to prevent a drag from | 49 // The point where the mouse down event occurred. Used to prevent a drag from |
52 // starting until it moves at least kMinimumDragDistance. | 50 // starting until it moves at least kMinimumDragDistance. |
53 NSPoint dragStartPoint_; | 51 NSPoint dragStartPoint_; |
54 | 52 |
55 base::scoped_nsobject< | 53 base::scoped_nsobject< |
56 ExtensionActionContextMenuController> contextMenuController_; | 54 ExtensionActionContextMenuController> contextMenuController_; |
57 } | 55 } |
58 | 56 |
59 - (id)initWithFrame:(NSRect)frame | 57 - (id)initWithFrame:(NSRect)frame |
60 extension:(const extensions::Extension*)extension | 58 viewController:(scoped_ptr<ToolbarActionViewController>)viewController |
61 browser:(Browser*)browser | 59 controller:(BrowserActionsController*)controller |
62 tabId:(int)tabId; | 60 menuController:(ExtensionActionContextMenuController*)menuController; |
Avi (use Gerrit)
2014/10/30 23:21:25
What are the ownership semantics of the items bein
Devlin
2014/10/31 17:50:43
Ah, good point (related: just to confirm, there is
| |
63 | 61 |
64 - (void)setFrame:(NSRect)frameRect animate:(BOOL)animate; | 62 - (void)setFrame:(NSRect)frameRect animate:(BOOL)animate; |
65 | 63 |
66 - (void)updateState; | 64 - (void)updateState; |
67 | 65 |
68 - (BOOL)isAnimating; | 66 - (BOOL)isAnimating; |
69 | 67 |
68 - (ToolbarActionViewController*)viewController; | |
69 | |
70 // Returns a pointer to an autoreleased NSImage with the badge, shadow and | 70 // Returns a pointer to an autoreleased NSImage with the badge, shadow and |
71 // cell image drawn into it. | 71 // cell image drawn into it. |
72 - (NSImage*)compositedImage; | 72 - (NSImage*)compositedImage; |
73 | 73 |
74 @property(readonly, nonatomic) BOOL isBeingDragged; | 74 @property(readonly, nonatomic) BOOL isBeingDragged; |
75 @property(readonly, nonatomic) const extensions::Extension* extension; | |
76 @property(readwrite, nonatomic) int tabId; | |
77 | 75 |
78 @end | 76 @end |
79 | 77 |
80 @interface BrowserActionCell : ImageButtonCell { | 78 @interface BrowserActionCell : ImageButtonCell { |
81 @private | 79 @private |
82 // The current tab ID used when drawing the cell. | 80 // The controller for the browser actions bar that owns the button. Weak. |
83 int tabId_; | 81 BrowserActionsController* browserActionsController_; |
84 | 82 |
85 // The action we're drawing the cell for. Weak. | 83 // The view controller for the parent button. Weak. |
86 ExtensionAction* extensionAction_; | 84 ToolbarActionViewController* viewController_; |
87 } | 85 } |
88 | 86 |
89 @property(readwrite, nonatomic) int tabId; | 87 @property(assign, nonatomic) |
90 @property(readwrite, nonatomic) ExtensionAction* extensionAction; | 88 BrowserActionsController* browserActionsController; |
89 @property(readwrite, nonatomic) ToolbarActionViewController* viewController; | |
91 | 90 |
92 @end | 91 @end |
93 | 92 |
94 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTION_BUTTON_H_ | 93 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTION_BUTTON_H_ |
OLD | NEW |