Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / browser_action_button.h
blob5819281e272cef350a99cedc4da7b7abef866f40
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.
5 #ifndef CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTION_BUTTON_H_
6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTION_BUTTON_H_
8 #import <Cocoa/Cocoa.h>
10 #import "base/mac/scoped_nsobject.h"
11 #include "base/memory/scoped_ptr.h"
12 #import "chrome/browser/ui/cocoa/image_button_cell.h"
14 class Browser;
15 @class BrowserActionsController;
16 @class MenuController;
17 class ToolbarActionViewController;
18 class ToolbarActionViewDelegateBridge;
20 // Fired on each drag event while the user is moving the button.
21 extern NSString* const kBrowserActionButtonDraggingNotification;
22 // Fired when the user drops the button.
23 extern NSString* const kBrowserActionButtonDragEndNotification;
25 @interface BrowserActionButton : NSButton<NSMenuDelegate> {
26 @private
27 // Used to move the button and query whether a button is currently animating.
28 base::scoped_nsobject<NSViewAnimation> moveAnimation_;
30 // The controller that handles most non-view logic.
31 ToolbarActionViewController* viewController_;
33 // The bridge between the view controller and this object.
34 scoped_ptr<ToolbarActionViewDelegateBridge> viewControllerDelegate_;
36 // The context menu controller.
37 base::scoped_nsobject<MenuController> contextMenuController_;
39 // A substitute context menu to use in testing. We need this because normally
40 // menu code is blocking, making it difficult to test.
41 NSMenu* testContextMenu_;
43 // The controller for the browser actions bar that owns this button. Weak.
44 BrowserActionsController* browserActionsController_;
46 // Whether the button is currently being dragged.
47 BOOL isBeingDragged_;
49 // Drag events could be intercepted by other buttons, so to make sure that
50 // this is the only button moving if it ends up being dragged. This is set to
51 // YES upon |mouseDown:|.
52 BOOL dragCouldStart_;
54 // If a drag is not currently in progress, this is the point where the mouse
55 // down event occurred, and is used to prevent a drag from starting until it
56 // moves at least kMinimumDragDistance. Once a drag begins, this is the point
57 // at which the drag actually started.
58 NSPoint dragStartPoint_;
61 // Init the button with the frame. Does not own either |view_controller| or
62 // |controller|.
63 - (id)initWithFrame:(NSRect)frame
64 viewController:(ToolbarActionViewController*)viewController
65 controller:(BrowserActionsController*)controller;
67 - (void)setFrame:(NSRect)frameRect animate:(BOOL)animate;
69 - (void)updateState;
71 // Called when the button is removed from the toolbar and will soon be deleted.
72 - (void)onRemoved;
74 - (BOOL)isAnimating;
76 // Returns the frame the button will occupy once animation is complete, or its
77 // current frame if it is not animating.
78 - (NSRect)frameAfterAnimation;
80 - (ToolbarActionViewController*)viewController;
82 // Returns a pointer to an autoreleased NSImage with the badge, shadow and
83 // cell image drawn into it.
84 - (NSImage*)compositedImage;
86 @property(readonly, nonatomic) BOOL isBeingDragged;
88 @end
90 @interface BrowserActionButton(TestingAPI)
91 // Sets a context menu to use for testing purposes.
92 - (void)setTestContextMenu:(NSMenu*)testContextMenu;
93 // Returns true if the action wants to run.
94 - (BOOL)wantsToRunForTesting;
95 @end
97 @interface BrowserActionCell : ImageButtonCell {
98 @private
99 // The controller for the browser actions bar that owns the button. Weak.
100 BrowserActionsController* browserActionsController_;
103 @property(assign, nonatomic)
104 BrowserActionsController* browserActionsController;
106 @end
108 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTION_BUTTON_H_