Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / browser_actions_container_view.h
blobdaaba44d60625bf56205c9bf4b1d102fd69b5d03
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 #include "base/memory/scoped_ptr.h"
12 #import "ui/base/cocoa/tracking_area.h"
14 namespace ui {
15 struct NinePartImageIds;
18 // Sent when a user-initiated drag to resize the container is initiated.
19 extern NSString* const kBrowserActionGrippyDragStartedNotification;
21 // Sent when a user-initiated drag is resizing the container.
22 extern NSString* const kBrowserActionGrippyDraggingNotification;
24 // Sent when a user-initiated drag to resize the container has finished.
25 extern NSString* const kBrowserActionGrippyDragFinishedNotification;
27 // Sent when the Browser Actions container view is about to animate.
28 extern NSString* const kBrowserActionsContainerWillAnimate;
30 // Sent when the mouse enters the browser actions container (if tracking is
31 // enabled).
32 extern NSString* const kBrowserActionsContainerMouseEntered;
34 // Sent when a running animation has ended.
35 extern NSString* const kBrowserActionsContainerAnimationEnded;
37 // Key which is used to notify the translation with delta.
38 extern NSString* const kTranslationWithDelta;
40 // Sent when the container receives a key event that should be processed.
41 // The userInfo contains a single entry with the key event.
42 extern NSString* const kBrowserActionsContainerReceivedKeyEvent;
44 // The key into the userInfo dictionary to retrieve the key event (stored as an
45 // integer).
46 extern NSString* const kBrowserActionsContainerKeyEventKey;
48 // The possible key actions to process.
49 enum BrowserActionsContainerKeyAction {
50 BROWSER_ACTIONS_INCREMENT_FOCUS = 0,
51 BROWSER_ACTIONS_DECREMENT_FOCUS = 1,
52 BROWSER_ACTIONS_EXECUTE_CURRENT = 2,
53 BROWSER_ACTIONS_INVALID_KEY_ACTION = 3,
56 class BrowserActionsContainerViewSizeDelegate {
57 public:
58 virtual CGFloat GetMaxAllowedWidth() = 0;
59 virtual ~BrowserActionsContainerViewSizeDelegate() {}
62 // The view that encompasses the Browser Action buttons in the toolbar and
63 // provides mechanisms for resizing.
64 @interface BrowserActionsContainerView : NSView<NSAnimationDelegate> {
65 @private
66 // The frame encompasing the grippy used for resizing the container.
67 NSRect grippyRect_;
69 // Used to cache the original position within the container that initiated the
70 // drag.
71 NSPoint initialDragPoint_;
73 // The maximum width the container could want; i.e., the width required to
74 // display all the icons.
75 CGFloat maxDesiredWidth_;
77 // Whether the container is currently being resized by the user.
78 BOOL userIsResizing_;
80 // Whether the user can resize the container; this is disabled for overflow
81 // (where it would make no sense) and during highlighting, since this is a
82 // temporary and entirely browser-driven sequence in order to warn the user
83 // about potentially dangerous items.
84 BOOL resizable_;
86 // Whether or not the container is the overflow container, and is shown in the
87 // wrench menu.
88 BOOL isOverflow_;
90 // Whether the user is allowed to drag the grippy to the left. NO if all
91 // extensions are shown or the location bar has hit its minimum width (handled
92 // within toolbar_controller.mm).
93 BOOL canDragLeft_;
95 // Whether the user is allowed to drag the grippy to the right. NO if all
96 // extensions are hidden.
97 BOOL canDragRight_;
99 // When the left grippy is pinned, resizing the window has no effect on its
100 // position. This prevents it from overlapping with other elements as well
101 // as letting the container expand when the window is going from super small
102 // to large.
103 BOOL grippyPinned_;
105 // The nine-grid of the highlight to paint, if any.
106 scoped_ptr<ui::NinePartImageIds> highlight_;
108 // A tracking area to receive mouseEntered events, if tracking is enabled.
109 ui::ScopedCrTrackingArea trackingArea_;
111 // The size delegate, if any.
112 // Weak; delegate is responsible for adding/removing itself.
113 BrowserActionsContainerViewSizeDelegate* sizeDelegate_;
115 base::scoped_nsobject<NSViewAnimation> resizeAnimation_;
118 // Sets whether or not tracking (for mouseEntered events) is enabled.
119 - (void)setTrackingEnabled:(BOOL)enabled;
121 // Sets whether or not the container is the overflow container.
122 - (void)setIsOverflow:(BOOL)isOverflow;
124 // Sets whether or not the container is highlighting.
125 - (void)setHighlight:(scoped_ptr<ui::NinePartImageIds>)highlight;
127 // Resizes the container to the given ideal width, optionally animating.
128 - (void)resizeToWidth:(CGFloat)width animate:(BOOL)animate;
130 // Returns the frame of the container after the running animation has finished.
131 // If no animation is running, returns the container's current frame.
132 - (NSRect)animationEndFrame;
134 // Returns true if the view is animating.
135 - (BOOL)isAnimating;
137 // Stops any animation in progress.
138 - (void)stopAnimation;
140 @property(nonatomic) BOOL canDragLeft;
141 @property(nonatomic) BOOL canDragRight;
142 @property(nonatomic) BOOL grippyPinned;
143 @property(nonatomic) CGFloat maxDesiredWidth;
144 @property(readonly, nonatomic) BOOL userIsResizing;
145 @property(nonatomic) BrowserActionsContainerViewSizeDelegate* delegate;
147 @end
149 #endif // CHROME_BROWSER_UI_COCOA_EXTENSIONS_BROWSER_ACTIONS_CONTAINER_VIEW_