Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: chrome/browser/cocoa/bookmark_bar_controller.h

Issue 384105: Mac: Animate the bookmark bar showing/hiding. (Closed)
Patch Set: Comments added per rohitrao's review. Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONTROLLER_H_
6 #define CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONTROLLER_H_ 6 #define CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONTROLLER_H_
7 7
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #include <map> 9 #include <map>
10 10
11 #include "base/scoped_nsobject.h" 11 #include "base/scoped_nsobject.h"
12 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "chrome/browser/cocoa/bookmark_bar_bridge.h" 13 #include "chrome/browser/cocoa/bookmark_bar_bridge.h"
14 #import "chrome/browser/cocoa/bookmark_bar_toolbar_view.h" 14 #import "chrome/browser/cocoa/bookmark_bar_toolbar_view.h"
15 #include "chrome/browser/cocoa/tab_strip_model_observer_bridge.h" 15 #include "chrome/browser/cocoa/tab_strip_model_observer_bridge.h"
16 #include "webkit/glue/window_open_disposition.h" 16 #include "webkit/glue/window_open_disposition.h"
17 17
18 @class BackgroundGradientView; 18 @class BookmarkBarController;
19 @class BookmarkBarStateController;
20 class BookmarkModel; 19 class BookmarkModel;
21 class BookmarkNode; 20 class BookmarkNode;
22 @class BookmarkBarView; 21 @class BookmarkBarView;
23 class Browser; 22 class Browser;
24 @protocol ToolbarCompressable;
25 class GURL; 23 class GURL;
26 @class MenuButton; 24 @class MenuButton;
27 class Profile; 25 class Profile;
28 class PrefService; 26 class PrefService;
27 class TabContents;
29 @class ToolbarController; 28 @class ToolbarController;
30 @protocol ViewResizer; 29 @protocol ViewResizer;
31 30
32 namespace bookmarks { 31 namespace bookmarks {
33 32
34 // Magic numbers from Cole 33 // Magic numbers from Cole
35 const CGFloat kDefaultBookmarkWidth = 150.0; 34 const CGFloat kDefaultBookmarkWidth = 150.0;
36 const CGFloat kBookmarkVerticalPadding = 2.0; 35 const CGFloat kBookmarkVerticalPadding = 2.0;
37 const CGFloat kBookmarkHorizontalPadding = 1.0; 36 const CGFloat kBookmarkHorizontalPadding = 1.0;
38 37
39 const CGFloat kNoBookmarksHorizontalOffset = 5.0; 38 const CGFloat kNoBookmarksHorizontalOffset = 5.0;
40 const CGFloat kNoBookmarksVerticalOffset = 22.0; 39 const CGFloat kNoBookmarksVerticalOffset = 22.0;
41 const CGFloat kNoBookmarksNTPVerticalOffset = 28.0; 40 const CGFloat kNoBookmarksNTPVerticalOffset = 28.0;
42 41
43 } // namespace 42 // States for the bookmark bar.
43 enum VisualState {
44 kInvalidState = 0,
45 kHiddenState = 1,
46 kShowingState = 2,
47 kDetachedState = 3,
48 };
49
50 } // namespace bookmarks
51
52 // The interface for the bookmark bar controller's delegate. Currently, the
53 // delegate is the BWC and is responsible for ensuring that the toolbar is
54 // displayed correctly (as specified by |-getDesiredToolbarHeightCompression|
55 // and |-shouldToolbarShowDivider|) at the beginning and at the end of an
56 // animation (or after a state change).
57 @protocol BookmarkBarControllerDelegate
58
59 // Sent when the state has changed (after any animation), but before the final
60 // display update.
61 - (void)bookmarkBar:(BookmarkBarController*)controller
62 didChangeFromState:(bookmarks::VisualState)oldState
63 toState:(bookmarks::VisualState)newState;
64
65 // Sent before the animation begins.
66 - (void)bookmarkBar:(BookmarkBarController*)controller
67 willAnimateFromState:(bookmarks::VisualState)oldState
68 toState:(bookmarks::VisualState)newState;
69
70 @end
44 71
45 // A controller for the bookmark bar in the browser window. Handles showing 72 // A controller for the bookmark bar in the browser window. Handles showing
46 // and hiding based on the preference in the given profile. 73 // and hiding based on the preference in the given profile.
47 @interface BookmarkBarController : 74 @interface BookmarkBarController :
48 NSViewController<BookmarkBarToolbarViewController> { 75 NSViewController<BookmarkBarToolbarViewController> {
49 @private 76 @private
77 // The visual state of the bookmark bar. If an animation is running, this is
78 // set to the "destination" and |lastVisualState_| is set to the "original"
79 // state. This is set to |kInvalidState| on initialization (when the
80 // appropriate state is not yet known).
81 bookmarks::VisualState visualState_;
82
83 // The "original" state of the bookmark bar if an animation is running,
84 // otherwise it should be |kInvalidState|.
85 bookmarks::VisualState lastVisualState_;
86
50 Browser* browser_; // weak; owned by its window 87 Browser* browser_; // weak; owned by its window
51 BookmarkModel* bookmarkModel_; // weak; part of the profile owned by the 88 BookmarkModel* bookmarkModel_; // weak; part of the profile owned by the
52 // top-level Browser object. 89 // top-level Browser object.
53 90
54 // Our initial view width, which is applied in awakeFromNib. 91 // Our initial view width, which is applied in awakeFromNib.
55 float initialWidth_; 92 CGFloat initialWidth_;
56 93
57 // BookmarkNodes have a 64bit id. NSMenuItems have a 32bit tag used 94 // BookmarkNodes have a 64bit id. NSMenuItems have a 32bit tag used
58 // to represent the bookmark node they refer to. This map provides 95 // to represent the bookmark node they refer to. This map provides
59 // a mapping from one to the other, so we can properly identify the 96 // a mapping from one to the other, so we can properly identify the
60 // node from the item. When adding items in, we start with seedId_. 97 // node from the item. When adding items in, we start with seedId_.
61 int32 seedId_; 98 int32 seedId_;
62 std::map<int32,int64> menuTagMap_; 99 std::map<int32,int64> menuTagMap_;
63 100
64 // Our bookmark buttons, ordered from L-->R. 101 // Our bookmark buttons, ordered from L-->R.
65 scoped_nsobject<NSMutableArray> buttons_; 102 scoped_nsobject<NSMutableArray> buttons_;
66 103
67 // The folder image so we can use one copy for all buttons 104 // The folder image so we can use one copy for all buttons
68 scoped_nsobject<NSImage> folderImage_; 105 scoped_nsobject<NSImage> folderImage_;
69 106
70 // The default image, so we can use one copy for all buttons. 107 // The default image, so we can use one copy for all buttons.
71 scoped_nsobject<NSImage> defaultImage_; 108 scoped_nsobject<NSImage> defaultImage_;
72 109
73 // If the bar is disabled, we hide it and ignore show/hide commands. 110 // If the bar is disabled, we hide it and ignore show/hide commands.
74 // Set when using fullscreen mode. 111 // Set when using fullscreen mode.
75 BOOL barIsEnabled_; 112 BOOL barIsEnabled_;
76 113
77 // Bridge from Chrome-style C++ notifications (e.g. derived from 114 // Bridge from Chrome-style C++ notifications (e.g. derived from
78 // BookmarkModelObserver) 115 // BookmarkModelObserver)
79 scoped_ptr<BookmarkBarBridge> bridge_; 116 scoped_ptr<BookmarkBarBridge> bridge_;
80 117
81 // Delegate that is alerted about whether it should be compressed because 118 // Delegate that is informed about state changes in the bookmark bar.
82 // it's right next to us. 119 id<BookmarkBarControllerDelegate> delegate_; // weak
83 id<ToolbarCompressable> compressDelegate_; // weak
84 120
85 // Delegate that can resize us. 121 // Delegate that can resize us.
86 id<ViewResizer> resizeDelegate_; // weak 122 id<ViewResizer> resizeDelegate_; // weak
87 123
88 // Lets us get TabSelectedAt notifications.
89 scoped_ptr<TabStripModelObserverBridge> tabObserver_;
90
91 IBOutlet BookmarkBarView* buttonView_; 124 IBOutlet BookmarkBarView* buttonView_;
92 IBOutlet MenuButton* offTheSideButton_; // aka the chevron 125 IBOutlet MenuButton* offTheSideButton_; // aka the chevron
93 IBOutlet NSMenu* buttonContextMenu_; 126 IBOutlet NSMenu* buttonContextMenu_;
94 127
95 // "Other bookmarks" button on the right side. 128 // "Other bookmarks" button on the right side.
96 scoped_nsobject<NSButton> otherBookmarksButton_; 129 scoped_nsobject<NSButton> otherBookmarksButton_;
97 } 130 }
98 131
132 @property(readonly, nonatomic) bookmarks::VisualState visualState;
133 @property(readonly, nonatomic) bookmarks::VisualState lastVisualState;
134 @property(assign, nonatomic) id<BookmarkBarControllerDelegate> delegate;
135
99 // Initializes the bookmark bar controller with the given browser 136 // Initializes the bookmark bar controller with the given browser
100 // profile and delegates. 137 // profile and delegates.
101 - (id)initWithBrowser:(Browser*)browser 138 - (id)initWithBrowser:(Browser*)browser
102 initialWidth:(float)initialWidth 139 initialWidth:(CGFloat)initialWidth
103 compressDelegate:(id<ToolbarCompressable>)compressDelegate 140 delegate:(id<BookmarkBarControllerDelegate>)delegate
104 resizeDelegate:(id<ViewResizer>)resizeDelegate; 141 resizeDelegate:(id<ViewResizer>)resizeDelegate;
105 142
106 // Returns the backdrop to the bookmark bar. 143 // Updates the bookmark bar (from its current, possibly in-transition) state to
107 - (BackgroundGradientView*)backgroundGradientView; 144 // the one appropriate for the new conditions.
145 - (void)updateAndShowNormalBar:(BOOL)showNormalBar
146 showDetachedBar:(BOOL)showDetachedBar
147 withAnimation:(BOOL)animate;
108 148
109 // Tell the bar to show itself if needed (e.g. if the kShowBookmarkBar 149 // Update the visible state of the bookmark bar.
110 // is set). Called once after the controller is first created.
111 - (void)showIfNeeded;
112
113 // Update the visible state of the bookmark bar based on the current value of
114 // -[BookmarkBarController isAlwaysVisible].
115 - (void)updateVisibility; 150 - (void)updateVisibility;
116 151
117 // Turn on or off the bookmark bar and prevent or reallow its 152 // Turn on or off the bookmark bar and prevent or reallow its
118 // appearance. On disable, toggle off if shown. On enable, show only 153 // appearance. On disable, toggle off if shown. On enable, show only
119 // if needed. For fullscreen mode. 154 // if needed. For fullscreen mode.
120 - (void)setBookmarkBarEnabled:(BOOL)enabled; 155 - (void)setBookmarkBarEnabled:(BOOL)enabled;
121 156
122 // Returns YES if the bookmarks bar is currently visible, either because the 157 // Returns YES if the bookmarks bar is currently visible (as a normal toolbar or
123 // user has asked for it to always be visible, or because the current tab is the 158 // as a detached bar on the NTP), NO otherwise.
124 // New Tab page.
125 - (BOOL)isVisible; 159 - (BOOL)isVisible;
126 160
127 // Returns true if the bookmark bar needs to be shown currently because a tab 161 // Returns YES if an animation is currently running, NO otherwise.
128 // that requires it is selected. The bookmark bar will have a different 162 - (BOOL)isAnimationRunning;
129 // appearance when it is shown if isAlwaysVisible returns NO.
130 - (BOOL)isNewTabPage;
131 163
132 // Returns true if the bookmark bar is visible for all tabs. (This corresponds 164 // Returns YES if the bookmarks bar is (to be) shown as part of the normal
133 // to the user having selected "Always show the bookmark bar") 165 // toolbar, NO otherwise. This is exclusive of |-isShownAsDetachedBar|.
134 - (BOOL)isAlwaysVisible; 166 - (BOOL)isShownAsToolbar;
167
168 // Returns YES if the bookmarks bar is (to be) shown as a detached bar, NO
169 // otherwise; required for the |BookmarkBarToolbarViewController| protocol. This
170 // is exclusive of |-isShownAsToolbar|.
171 - (BOOL)isShownAsDetachedBar;
172
173 // Returns the amount by which the toolbar above should be compressed.
174 - (CGFloat)getDesiredToolbarHeightCompression;
175
176 // Returns whether or not the toolbar above should show the divider.
177 - (BOOL)shouldToolbarShowDivider;
135 178
136 // Returns true if at least one bookmark was added. 179 // Returns true if at least one bookmark was added.
137 - (BOOL)addURLs:(NSArray*)urls withTitles:(NSArray*)titles at:(NSPoint)point; 180 - (BOOL)addURLs:(NSArray*)urls withTitles:(NSArray*)titles at:(NSPoint)point;
138 181
139 // Actions for manipulating bookmarks. 182 // Actions for manipulating bookmarks.
140 // From a button, ... 183 // From a button, ...
141 - (IBAction)openBookmark:(id)sender; 184 - (IBAction)openBookmark:(id)sender;
142 - (IBAction)openFolderMenuFromButton:(id)sender; 185 - (IBAction)openFolderMenuFromButton:(id)sender;
143 // From a context menu over the button, ... 186 // From a context menu over the button, ...
144 - (IBAction)openBookmarkInNewForegroundTab:(id)sender; 187 - (IBAction)openBookmarkInNewForegroundTab:(id)sender;
(...skipping 25 matching lines...) Expand all
170 - (void)nodeRemoved:(BookmarkModel*)model 213 - (void)nodeRemoved:(BookmarkModel*)model
171 parent:(const BookmarkNode*)oldParent index:(int)index; 214 parent:(const BookmarkNode*)oldParent index:(int)index;
172 - (void)nodeChanged:(BookmarkModel*)model 215 - (void)nodeChanged:(BookmarkModel*)model
173 node:(const BookmarkNode*)node; 216 node:(const BookmarkNode*)node;
174 - (void)nodeFavIconLoaded:(BookmarkModel*)model 217 - (void)nodeFavIconLoaded:(BookmarkModel*)model
175 node:(const BookmarkNode*)node; 218 node:(const BookmarkNode*)node;
176 - (void)nodeChildrenReordered:(BookmarkModel*)model 219 - (void)nodeChildrenReordered:(BookmarkModel*)model
177 node:(const BookmarkNode*)node; 220 node:(const BookmarkNode*)node;
178 @end 221 @end
179 222
180
181 // These APIs should only be used by unit tests (or used internally). 223 // These APIs should only be used by unit tests (or used internally).
182 @interface BookmarkBarController(InternalOrTestingAPI) 224 @interface BookmarkBarController(InternalOrTestingAPI)
183 - (void)openURL:(GURL)url disposition:(WindowOpenDisposition)disposition; 225 - (void)openURL:(GURL)url disposition:(WindowOpenDisposition)disposition;
184 - (NSCell*)cellForBookmarkNode:(const BookmarkNode*)node; 226 - (NSCell*)cellForBookmarkNode:(const BookmarkNode*)node;
185 - (void)clearBookmarkBar; 227 - (void)clearBookmarkBar;
186 - (BookmarkBarView*)buttonView; 228 - (BookmarkBarView*)buttonView;
187 - (NSArray*)buttons; 229 - (NSArray*)buttons;
188 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell xOffset:(int*)xOffset; 230 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell xOffset:(int*)xOffset;
189 - (void)checkForBookmarkButtonGrowth:(NSButton*)button; 231 - (void)checkForBookmarkButtonGrowth:(NSButton*)button;
190 - (void)frameDidChange; 232 - (void)frameDidChange;
191 - (BOOL)offTheSideButtonIsHidden; 233 - (BOOL)offTheSideButtonIsHidden;
192 - (NSMenu *)menuForFolderNode:(const BookmarkNode*)node; 234 - (NSMenu *)menuForFolderNode:(const BookmarkNode*)node;
193 - (int64)nodeIdFromMenuTag:(int32)tag; 235 - (int64)nodeIdFromMenuTag:(int32)tag;
194 - (int32)menuTagFromNodeId:(int64)menuid; 236 - (int32)menuTagFromNodeId:(int64)menuid;
195 - (void)buildOffTheSideMenu; 237 - (void)buildOffTheSideMenu;
196 - (NSMenu*)offTheSideMenu; 238 - (NSMenu*)offTheSideMenu;
197 - (NSButton*)offTheSideButton; 239 - (NSButton*)offTheSideButton;
198 - (NSButton*)otherBookmarksButton; 240 - (NSButton*)otherBookmarksButton;
199 @end 241 @end
200 242
201 #endif // CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONTROLLER_H_ 243 #endif // CHROME_BROWSER_COCOA_BOOKMARK_BAR_CONTROLLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/bookmark_bar_bridge_unittest.mm ('k') | chrome/browser/cocoa/bookmark_bar_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698