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

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

Issue 2751573002: [Mac] Refactor bookmark bar controller (Closed)
Patch Set: Factor layout tests to helper, address CL comments Created 3 years, 7 months 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) 2012 The Chromium Authors. All rights reserved. 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 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_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_
7 7
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <unordered_map>
13 14
14 #import "base/mac/cocoa_protocols.h" 15 #import "base/mac/cocoa_protocols.h"
15 #include "base/mac/scoped_nsobject.h" 16 #include "base/mac/scoped_nsobject.h"
16 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_bridge.h" 17 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_bridge.h"
17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" 18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h"
18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_state.h" 19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_state.h"
19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h" 20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h"
20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" 21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
21 #import "chrome/browser/ui/cocoa/has_weak_browser_pointer.h" 22 #import "chrome/browser/ui/cocoa/has_weak_browser_pointer.h"
22 #include "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" 23 #include "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // Folder3. Without this delay, that'll cause Sub to be closed before 127 // Folder3. Without this delay, that'll cause Sub to be closed before
127 // you get there, since a "hover over" of Folder3 gets activated. 128 // you get there, since a "hover over" of Folder3 gets activated.
128 // It's subtle but without the delay it feels broken. 129 // It's subtle but without the delay it feels broken.
129 // 130 //
130 // This is only really a problem with vertical menu --> vertical menu 131 // This is only really a problem with vertical menu --> vertical menu
131 // movement; the bookmark bar (horizontal menu, sort of) seems fine, 132 // movement; the bookmark bar (horizontal menu, sort of) seems fine,
132 // perhaps because mouse move direction is purely vertical so there is 133 // perhaps because mouse move direction is purely vertical so there is
133 // no opportunity for overlap. 134 // no opportunity for overlap.
134 const NSTimeInterval kDragHoverCloseDelay = 0.4; 135 const NSTimeInterval kDragHoverCloseDelay = 0.4;
135 136
137 enum BookmarkBarVisibleElementsMask {
138 kVisibleElementsMaskNone = 0,
139 kVisibleElementsMaskAppsButton = 1 << 0,
140 kVisibleElementsMaskManagedBookmarksButton = 1 << 1,
141 kVisibleElementsMaskSupervisedBookmarksButton = 1 << 2,
142 kVisibleElementsMaskOffTheSideButton = 1 << 3,
143 kVisibleElementsMaskOtherBookmarksButton = 1 << 4,
144 kVisibleElementsMaskNoItemTextField = 1 << 5,
145 kVisibleElementsMaskImportBookmarksButton = 1 << 6,
146 };
147
148 // Specifies the location and visibility of the various sub-elements
149 // of the bookmark bar. Allows calculating the layout and actually
150 // applying it to views to be decoupled. For example, applying
151 // the layout in an RTL context transforms all horizontal offsets
152 // transparently.
153 struct BookmarkBarLayout {
154 public:
155 BookmarkBarLayout();
156 ~BookmarkBarLayout();
157 BookmarkBarLayout(BookmarkBarLayout&& other);
158 BookmarkBarLayout& operator=(BookmarkBarLayout&& other);
159
160 bool IsAppsButtonVisible() const {
161 return visible_elements & kVisibleElementsMaskAppsButton;
162 }
163 bool IsManagedBookmarksButtonVisible() const {
164 return visible_elements & kVisibleElementsMaskManagedBookmarksButton;
165 }
166 bool IsSupervisedBookmarksButtonVisible() const {
167 return visible_elements & kVisibleElementsMaskSupervisedBookmarksButton;
168 }
169 bool IsOffTheSideButtonVisible() const {
170 return visible_elements & kVisibleElementsMaskOffTheSideButton;
171 }
172 bool IsOtherBookmarksButtonVisible() const {
173 return visible_elements & kVisibleElementsMaskOtherBookmarksButton;
174 }
175 bool IsNoItemTextFieldVisible() const {
176 return visible_elements & kVisibleElementsMaskNoItemTextField;
177 }
178 bool IsImportBookmarksButtonVisible() const {
179 return visible_elements & kVisibleElementsMaskImportBookmarksButton;
180 }
181 size_t VisibleButtonCount() const { return button_offsets.size(); }
182
183 unsigned int visible_elements;
184 CGFloat apps_button_offset;
185 CGFloat managed_bookmarks_button_offset;
186 CGFloat supervised_bookmarks_button_offset;
187 CGFloat off_the_side_button_offset;
188 CGFloat other_bookmarks_button_offset;
189 CGFloat no_item_textfield_offset;
190 CGFloat no_item_textfield_width;
191 CGFloat import_bookmarks_button_offset;
192 CGFloat import_bookmarks_button_width;
193 CGFloat max_x;
194
195 std::unordered_map<int64_t, CGFloat> button_offsets;
196 };
197
136 } // namespace bookmarks 198 } // namespace bookmarks
137 199
138 // The interface for the bookmark bar controller's delegate. Currently, the 200 // The interface for the bookmark bar controller's delegate. Currently, the
139 // delegate is the BWC and is responsible for ensuring that the toolbar is 201 // delegate is the BWC and is responsible for ensuring that the toolbar is
140 // displayed correctly (as specified by |-getDesiredToolbarHeightCompression| 202 // displayed correctly (as specified by |-getDesiredToolbarHeightCompression|
141 // and |-toolbarDividerOpacity|) at the beginning and at the end of an animation 203 // and |-toolbarDividerOpacity|) at the beginning and at the end of an animation
142 // (or after a state change). 204 // (or after a state change).
143 @protocol BookmarkBarControllerDelegate 205 @protocol BookmarkBarControllerDelegate
144 206
145 // Sent when the state has changed (after any animation), but before the final 207 // Sent when the state has changed (after any animation), but before the final
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 BookmarkBarFolderController* folderController_; 281 BookmarkBarFolderController* folderController_;
220 282
221 // The event tap that allows monitoring of all events, to properly close with 283 // The event tap that allows monitoring of all events, to properly close with
222 // a click outside the bounds of the window. 284 // a click outside the bounds of the window.
223 id exitEventTap_; 285 id exitEventTap_;
224 286
225 base::scoped_nsobject<BookmarkBarView> 287 base::scoped_nsobject<BookmarkBarView>
226 buttonView_; // Contains 'no items' text fields. 288 buttonView_; // Contains 'no items' text fields.
227 base::scoped_nsobject<BookmarkButton> offTheSideButton_; // aka the chevron. 289 base::scoped_nsobject<BookmarkButton> offTheSideButton_; // aka the chevron.
228 290
229 NSRect originalNoItemsRect_; // Original, pre-resized field rect.
230 NSRect originalImportBookmarksRect_; // Original, pre-resized field rect.
231
232 // "Apps" button on the left side. 291 // "Apps" button on the left side.
233 base::scoped_nsobject<BookmarkButton> appsPageShortcutButton_; 292 base::scoped_nsobject<BookmarkButton> appsPageShortcutButton_;
234 293
235 // "Managed bookmarks" button on the left side, next to the apps button. 294 // "Managed bookmarks" button on the left side, next to the apps button.
236 base::scoped_nsobject<BookmarkButton> managedBookmarksButton_; 295 base::scoped_nsobject<BookmarkButton> managedBookmarksButton_;
237 296
238 // "Supervised bookmarks" button on the left side, next to the apps button. 297 // "Supervised bookmarks" button on the left side, next to the apps button.
239 base::scoped_nsobject<BookmarkButton> supervisedBookmarksButton_; 298 base::scoped_nsobject<BookmarkButton> supervisedBookmarksButton_;
240 299
241 // "Other bookmarks" button on the right side. 300 // "Other bookmarks" button on the right side.
242 base::scoped_nsobject<BookmarkButton> otherBookmarksButton_; 301 base::scoped_nsobject<BookmarkButton> otherBookmarksButton_;
243 302
244 // When doing a drag, this is folder button "hovered over" which we 303 // When doing a drag, this is folder button "hovered over" which we
245 // may want to open after a short delay. There are cases where a 304 // may want to open after a short delay. There are cases where a
246 // mouse-enter can open a folder (e.g. if the menus are "active") 305 // mouse-enter can open a folder (e.g. if the menus are "active")
247 // but that doesn't use this variable or need a delay so "hover" is 306 // but that doesn't use this variable or need a delay so "hover" is
248 // the wrong term. 307 // the wrong term.
249 base::scoped_nsobject<BookmarkButton> hoverButton_; 308 base::scoped_nsobject<BookmarkButton> hoverButton_;
250 309
251 // We save the view width when we add bookmark buttons. This lets 310 // We save the view width when we add bookmark buttons. This lets
252 // us avoid a rebuild until we've grown the window bigger than our 311 // us avoid a rebuild until we've grown the window bigger than our
253 // initial build. 312 // initial build.
254 CGFloat savedFrameWidth_; 313 CGFloat savedFrameWidth_;
255 314
256 // The number of buttons we display in the bookmark bar. This does
257 // not include the "off the side" chevron or the "Other Bookmarks"
258 // button. We use this number to determine if we need to display
259 // the chevron, and to know what to place in the chevron's menu.
260 // Since we create everything before doing layout we can't be sure
261 // that all bookmark buttons we create will be visible. Thus,
262 // [buttons_ count] isn't a definitive check.
263 int displayedButtonCount_;
264
265 // A state flag which tracks when the bar's folder menus should be shown. 315 // A state flag which tracks when the bar's folder menus should be shown.
266 // An initial click in any of the folder buttons turns this on and 316 // An initial click in any of the folder buttons turns this on and
267 // one of the following will turn it off: another click in the button, 317 // one of the following will turn it off: another click in the button,
268 // the window losing focus, a click somewhere other than in the bar 318 // the window losing focus, a click somewhere other than in the bar
269 // or a folder menu. 319 // or a folder menu.
270 BOOL showFolderMenus_; 320 BOOL showFolderMenus_;
271 321
272 // If YES then state changes (for example, from hidden to shown) are animated. 322 // If YES then state changes (for example, from hidden to shown) are animated.
273 // This is turned off for unit tests. 323 // This is turned off for unit tests.
274 BOOL stateAnimationsEnabled_; 324 BOOL stateAnimationsEnabled_;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 parent:(const bookmarks::BookmarkNode*)oldParent 470 parent:(const bookmarks::BookmarkNode*)oldParent
421 index:(int)index; 471 index:(int)index;
422 - (void)nodeFaviconLoaded:(bookmarks::BookmarkModel*)model 472 - (void)nodeFaviconLoaded:(bookmarks::BookmarkModel*)model
423 node:(const bookmarks::BookmarkNode*)node; 473 node:(const bookmarks::BookmarkNode*)node;
424 - (void)nodeChildrenReordered:(bookmarks::BookmarkModel*)model 474 - (void)nodeChildrenReordered:(bookmarks::BookmarkModel*)model
425 node:(const bookmarks::BookmarkNode*)node; 475 node:(const bookmarks::BookmarkNode*)node;
426 @end 476 @end
427 477
428 // These APIs should only be used by unit tests (or used internally). 478 // These APIs should only be used by unit tests (or used internally).
429 @interface BookmarkBarController(InternalOrTestingAPI) 479 @interface BookmarkBarController(InternalOrTestingAPI)
480 - (bookmarks::BookmarkBarLayout)layoutFromCurrentState;
481 - (void)applyLayout:(const bookmarks::BookmarkBarLayout&)layout
482 animated:(BOOL)animated;
430 - (void)openBookmarkFolder:(id)sender; 483 - (void)openBookmarkFolder:(id)sender;
431 - (void)openOrCloseBookmarkFolderForOffTheSideButton; 484 - (void)openOrCloseBookmarkFolderForOffTheSideButton;
432 - (BookmarkBarView*)buttonView; 485 - (BookmarkBarView*)buttonView;
433 - (NSMutableArray*)buttons; 486 - (NSMutableArray*)buttons;
434 - (BOOL)offTheSideButtonIsHidden; 487 - (BookmarkButton*)otherBookmarksButton;
435 - (BOOL)appsPageShortcutButtonIsHidden; 488 - (BookmarkButton*)managedBookmarksButton;
489 - (BookmarkButton*)supervisedBookmarksButton;
436 - (BookmarkButton*)otherBookmarksButton; 490 - (BookmarkButton*)otherBookmarksButton;
437 - (BookmarkBarFolderController*)folderController; 491 - (BookmarkBarFolderController*)folderController;
438 - (id)folderTarget; 492 - (id)folderTarget;
439 - (int)displayedButtonCount;
440 - (void)openURL:(GURL)url disposition:(WindowOpenDisposition)disposition; 493 - (void)openURL:(GURL)url disposition:(WindowOpenDisposition)disposition;
441 - (void)clearBookmarkBar; 494 - (void)clearBookmarkBar;
442 - (BookmarkButtonCell*)cellForBookmarkNode:(const bookmarks::BookmarkNode*)node; 495 - (BookmarkButtonCell*)cellForBookmarkNode:(const bookmarks::BookmarkNode*)node;
443 - (BookmarkButtonCell*)cellForCustomButtonWithText:(NSString*)text 496 - (BookmarkButtonCell*)cellForCustomButtonWithText:(NSString*)text
444 image:(NSImage*)image; 497 image:(NSImage*)image;
445 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell xOffset:(int*)xOffset;
446 - (void)checkForBookmarkButtonGrowth:(NSButton*)button; 498 - (void)checkForBookmarkButtonGrowth:(NSButton*)button;
447 - (void)frameDidChange; 499 - (void)frameDidChange;
448 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider; 500 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider;
449 - (BookmarkButton*)buttonForDroppingOnAtPoint:(NSPoint)point; 501 - (BookmarkButton*)buttonForDroppingOnAtPoint:(NSPoint)point;
450 - (BOOL)isEventAnExitEvent:(NSEvent*)event; 502 - (BOOL)isEventAnExitEvent:(NSEvent*)event;
451 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX;
452 - (void)unhighlightBookmark:(const bookmarks::BookmarkNode*)node; 503 - (void)unhighlightBookmark:(const bookmarks::BookmarkNode*)node;
453 504
454 @end 505 @end
455 506
456 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_ 507 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698