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 // Key which is used to notify the translation with delta.
30 extern NSString
* const kTranslationWithDelta
;
32 class BrowserActionsContainerViewSizeDelegate
{
34 virtual CGFloat
GetMaxAllowedWidth() = 0;
35 virtual ~BrowserActionsContainerViewSizeDelegate() {}
38 // The view that encompasses the Browser Action buttons in the toolbar and
39 // provides mechanisms for resizing.
40 @interface BrowserActionsContainerView
: NSView
{
42 // The frame encompasing the grippy used for resizing the container.
45 // Used to cache the original position within the container that initiated the
47 NSPoint initialDragPoint_
;
49 // The maximum width the container could want; i.e., the width required to
50 // display all the icons.
51 CGFloat maxDesiredWidth_
;
53 // Whether the container is currently being resized by the user.
56 // Whether the user can resize this at all. Resizing is disabled in incognito
57 // mode since any changes done in incognito mode are not saved anyway, and
58 // also to avoid a crash. http://crbug.com/42848
61 // Whether the user is allowed to drag the grippy to the left. NO if all
62 // extensions are shown or the location bar has hit its minimum width (handled
63 // within toolbar_controller.mm).
66 // Whether the user is allowed to drag the grippy to the right. NO if all
67 // extensions are hidden.
70 // When the left grippy is pinned, resizing the window has no effect on its
71 // position. This prevents it from overlapping with other elements as well
72 // as letting the container expand when the window is going from super small
76 // A tracking area to receive mouseEntered events, if tracking is enabled.
77 ui::ScopedCrTrackingArea trackingArea_
;
79 // The size delegate, if any.
80 // Weak; delegate is responsible for adding/removing itself.
81 BrowserActionsContainerViewSizeDelegate
* sizeDelegate_
;
83 base::scoped_nsobject
<NSViewAnimation
> resizeAnimation_
;
86 // Sets whether or not tracking (for mouseEntered events) is enabled.
87 - (void)setTrackingEnabled
:(BOOL
)enabled
;
89 // Resizes the container to the given ideal width, optionally animating.
90 - (void)resizeToWidth
:(CGFloat
)width animate
:(BOOL
)animate
;
92 // Returns the frame of the container after the running animation has finished.
93 // If no animation is running, returns the container's current frame.
94 - (NSRect
)animationEndFrame
;
96 // Returns true if the view is animating.
99 // Stops any animation in progress.
100 - (void)stopAnimation
;
102 @
property(nonatomic
) BOOL canDragLeft
;
103 @
property(nonatomic
) BOOL canDragRight
;
104 @
property(nonatomic
) BOOL grippyPinned
;
105 @
property(nonatomic
,getter
=isResizable
) BOOL resizable
;
106 @
property(nonatomic
) CGFloat maxDesiredWidth
;
107 @
property(readonly
, nonatomic
) BOOL userIsResizing
;
108 @
property(nonatomic
) BrowserActionsContainerViewSizeDelegate
* delegate
;
112 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTAINER_VIEW_