1 // Copyright (c) 2010 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_ACTIONS_CONTAINER_VIEW_
6 #define CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTAINER_VIEW_
8 #import <Cocoa/Cocoa.h>
10 #include "base/mac/scoped_nsobject.h"
11 #import "ui/base/cocoa/tracking_area.h"
13 // Sent when a user-initiated drag to resize the container is initiated.
14 extern NSString
* const kBrowserActionGrippyDragStartedNotification
;
16 // Sent when a user-initiated drag is resizing the container.
17 extern NSString
* const kBrowserActionGrippyDraggingNotification
;
19 // Sent when a user-initiated drag to resize the container has finished.
20 extern NSString
* const kBrowserActionGrippyDragFinishedNotification
;
22 // Sent when the Browser Actions container view is about to animate.
23 extern NSString
* const kBrowserActionsContainerWillAnimate
;
25 // Sent when the mouse enters the browser actions container (if tracking is
27 extern NSString
* const kBrowserActionsContainerMouseEntered
;
29 // Sent when a running animation has ended.
30 extern NSString
* const kBrowserActionsContainerAnimationEnded
;
32 // Key which is used to notify the translation with delta.
33 extern NSString
* const kTranslationWithDelta
;
35 class BrowserActionsContainerViewSizeDelegate
{
37 virtual CGFloat
GetMaxAllowedWidth() = 0;
38 virtual ~BrowserActionsContainerViewSizeDelegate() {}
41 // The view that encompasses the Browser Action buttons in the toolbar and
42 // provides mechanisms for resizing.
43 @interface BrowserActionsContainerView
: NSView
<NSAnimationDelegate
> {
45 // The frame encompasing the grippy used for resizing the container.
48 // Used to cache the original position within the container that initiated the
50 NSPoint initialDragPoint_
;
52 // The maximum width the container could want; i.e., the width required to
53 // display all the icons.
54 CGFloat maxDesiredWidth_
;
56 // Whether the container is currently being resized by the user.
59 // Whether the user can resize this at all. Resizing is disabled in incognito
60 // mode since any changes done in incognito mode are not saved anyway, and
61 // also to avoid a crash. http://crbug.com/42848
64 // Whether the user is allowed to drag the grippy to the left. NO if all
65 // extensions are shown or the location bar has hit its minimum width (handled
66 // within toolbar_controller.mm).
69 // Whether the user is allowed to drag the grippy to the right. NO if all
70 // extensions are hidden.
73 // When the left grippy is pinned, resizing the window has no effect on its
74 // position. This prevents it from overlapping with other elements as well
75 // as letting the container expand when the window is going from super small
79 // Whether the toolbar is currently highlighting its actions (in which case it
80 // is drawn with an orange background).
83 // A tracking area to receive mouseEntered events, if tracking is enabled.
84 ui::ScopedCrTrackingArea trackingArea_
;
86 // The size delegate, if any.
87 // Weak; delegate is responsible for adding/removing itself.
88 BrowserActionsContainerViewSizeDelegate
* sizeDelegate_
;
90 base::scoped_nsobject
<NSViewAnimation
> resizeAnimation_
;
93 // Sets whether or not tracking (for mouseEntered events) is enabled.
94 - (void)setTrackingEnabled
:(BOOL
)enabled
;
96 // Sets whether or not the container is highlighting.
97 - (void)setIsHighlighting
:(BOOL
)isHighlighting
;
99 // Resizes the container to the given ideal width, optionally animating.
100 - (void)resizeToWidth
:(CGFloat
)width animate
:(BOOL
)animate
;
102 // Returns the frame of the container after the running animation has finished.
103 // If no animation is running, returns the container's current frame.
104 - (NSRect
)animationEndFrame
;
106 // Returns true if the view is animating.
109 // Stops any animation in progress.
110 - (void)stopAnimation
;
112 @
property(nonatomic
) BOOL canDragLeft
;
113 @
property(nonatomic
) BOOL canDragRight
;
114 @
property(nonatomic
) BOOL grippyPinned
;
115 @
property(nonatomic
,getter
=isResizable
) BOOL resizable
;
116 @
property(nonatomic
) CGFloat maxDesiredWidth
;
117 @
property(readonly
, nonatomic
) BOOL userIsResizing
;
118 @
property(nonatomic
) BrowserActionsContainerViewSizeDelegate
* delegate
;
122 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTAINER_VIEW_