• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ExtensionActionContextMenuController;
17 class ExtensionActionIconFactoryBridge;
18 
19 namespace extensions {
20 class Extension;
21 }
22 
23 // Fired on each drag event while the user is moving the button.
24 extern NSString* const kBrowserActionButtonDraggingNotification;
25 // Fired when the user drops the button.
26 extern NSString* const kBrowserActionButtonDragEndNotification;
27 
28 @interface BrowserActionButton : NSButton<NSMenuDelegate> {
29  @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.
35   base::scoped_nsobject<NSViewAnimation> moveAnimation_;
36 
37   // The extension for this button. Weak.
38   const extensions::Extension* extension_;
39 
40   // The ID of the active tab.
41   int tabId_;
42 
43   // Whether the button is currently being dragged.
44   BOOL isBeingDragged_;
45 
46   // 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
48   // YES upon |mouseDown:|.
49   BOOL dragCouldStart_;
50 
51   // The point where the mouse down event occurred. Used to prevent a drag from
52   // starting until it moves at least kMinimumDragDistance.
53   NSPoint dragStartPoint_;
54 
55   base::scoped_nsobject<
56       ExtensionActionContextMenuController> contextMenuController_;
57 }
58 
59 - (id)initWithFrame:(NSRect)frame
60           extension:(const extensions::Extension*)extension
61             browser:(Browser*)browser
62               tabId:(int)tabId;
63 
64 - (void)setFrame:(NSRect)frameRect animate:(BOOL)animate;
65 
66 - (void)updateState;
67 
68 - (BOOL)isAnimating;
69 
70 // Returns a pointer to an autoreleased NSImage with the badge, shadow and
71 // cell image drawn into it.
72 - (NSImage*)compositedImage;
73 
74 @property(readonly, nonatomic) BOOL isBeingDragged;
75 @property(readonly, nonatomic) const extensions::Extension* extension;
76 @property(readwrite, nonatomic) int tabId;
77 
78 @end
79 
80 @interface BrowserActionCell : ImageButtonCell {
81  @private
82   // The current tab ID used when drawing the cell.
83   int tabId_;
84 
85   // The action we're drawing the cell for. Weak.
86   ExtensionAction* extensionAction_;
87 }
88 
89 @property(readwrite, nonatomic) int tabId;
90 @property(readwrite, nonatomic) ExtensionAction* extensionAction;
91 
92 @end
93 
94 #endif  // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTION_BUTTON_H_
95