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

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

Issue 2853123002: Revert of [Mac] Refactor bookmark bar controller (Closed)
Patch Set: 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>
14 13
15 #import "base/mac/cocoa_protocols.h" 14 #import "base/mac/cocoa_protocols.h"
16 #include "base/mac/scoped_nsobject.h" 15 #include "base/mac/scoped_nsobject.h"
17 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_bridge.h" 16 #include "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_bridge.h"
18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h" 17 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_constants.h"
19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_state.h" 18 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_state.h"
20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h" 19 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_toolbar_view.h"
21 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h" 20 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_button.h"
22 #import "chrome/browser/ui/cocoa/has_weak_browser_pointer.h" 21 #import "chrome/browser/ui/cocoa/has_weak_browser_pointer.h"
23 #include "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" 22 #include "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 // Folder3. Without this delay, that'll cause Sub to be closed before 126 // Folder3. Without this delay, that'll cause Sub to be closed before
128 // you get there, since a "hover over" of Folder3 gets activated. 127 // you get there, since a "hover over" of Folder3 gets activated.
129 // It's subtle but without the delay it feels broken. 128 // It's subtle but without the delay it feels broken.
130 // 129 //
131 // This is only really a problem with vertical menu --> vertical menu 130 // This is only really a problem with vertical menu --> vertical menu
132 // movement; the bookmark bar (horizontal menu, sort of) seems fine, 131 // movement; the bookmark bar (horizontal menu, sort of) seems fine,
133 // perhaps because mouse move direction is purely vertical so there is 132 // perhaps because mouse move direction is purely vertical so there is
134 // no opportunity for overlap. 133 // no opportunity for overlap.
135 const NSTimeInterval kDragHoverCloseDelay = 0.4; 134 const NSTimeInterval kDragHoverCloseDelay = 0.4;
136 135
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
198 } // namespace bookmarks 136 } // namespace bookmarks
199 137
200 // The interface for the bookmark bar controller's delegate. Currently, the 138 // The interface for the bookmark bar controller's delegate. Currently, the
201 // delegate is the BWC and is responsible for ensuring that the toolbar is 139 // delegate is the BWC and is responsible for ensuring that the toolbar is
202 // displayed correctly (as specified by |-getDesiredToolbarHeightCompression| 140 // displayed correctly (as specified by |-getDesiredToolbarHeightCompression|
203 // and |-toolbarDividerOpacity|) at the beginning and at the end of an animation 141 // and |-toolbarDividerOpacity|) at the beginning and at the end of an animation
204 // (or after a state change). 142 // (or after a state change).
205 @protocol BookmarkBarControllerDelegate 143 @protocol BookmarkBarControllerDelegate
206 144
207 // Sent when the state has changed (after any animation), but before the final 145 // 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
281 BookmarkBarFolderController* folderController_; 219 BookmarkBarFolderController* folderController_;
282 220
283 // The event tap that allows monitoring of all events, to properly close with 221 // The event tap that allows monitoring of all events, to properly close with
284 // a click outside the bounds of the window. 222 // a click outside the bounds of the window.
285 id exitEventTap_; 223 id exitEventTap_;
286 224
287 base::scoped_nsobject<BookmarkBarView> 225 base::scoped_nsobject<BookmarkBarView>
288 buttonView_; // Contains 'no items' text fields. 226 buttonView_; // Contains 'no items' text fields.
289 base::scoped_nsobject<BookmarkButton> offTheSideButton_; // aka the chevron. 227 base::scoped_nsobject<BookmarkButton> offTheSideButton_; // aka the chevron.
290 228
229 NSRect originalNoItemsRect_; // Original, pre-resized field rect.
230 NSRect originalImportBookmarksRect_; // Original, pre-resized field rect.
231
291 // "Apps" button on the left side. 232 // "Apps" button on the left side.
292 base::scoped_nsobject<BookmarkButton> appsPageShortcutButton_; 233 base::scoped_nsobject<BookmarkButton> appsPageShortcutButton_;
293 234
294 // "Managed bookmarks" button on the left side, next to the apps button. 235 // "Managed bookmarks" button on the left side, next to the apps button.
295 base::scoped_nsobject<BookmarkButton> managedBookmarksButton_; 236 base::scoped_nsobject<BookmarkButton> managedBookmarksButton_;
296 237
297 // "Supervised bookmarks" button on the left side, next to the apps button. 238 // "Supervised bookmarks" button on the left side, next to the apps button.
298 base::scoped_nsobject<BookmarkButton> supervisedBookmarksButton_; 239 base::scoped_nsobject<BookmarkButton> supervisedBookmarksButton_;
299 240
300 // "Other bookmarks" button on the right side. 241 // "Other bookmarks" button on the right side.
301 base::scoped_nsobject<BookmarkButton> otherBookmarksButton_; 242 base::scoped_nsobject<BookmarkButton> otherBookmarksButton_;
302 243
303 // When doing a drag, this is folder button "hovered over" which we 244 // When doing a drag, this is folder button "hovered over" which we
304 // may want to open after a short delay. There are cases where a 245 // may want to open after a short delay. There are cases where a
305 // mouse-enter can open a folder (e.g. if the menus are "active") 246 // mouse-enter can open a folder (e.g. if the menus are "active")
306 // but that doesn't use this variable or need a delay so "hover" is 247 // but that doesn't use this variable or need a delay so "hover" is
307 // the wrong term. 248 // the wrong term.
308 base::scoped_nsobject<BookmarkButton> hoverButton_; 249 base::scoped_nsobject<BookmarkButton> hoverButton_;
309 250
310 // We save the view width when we add bookmark buttons. This lets 251 // We save the view width when we add bookmark buttons. This lets
311 // us avoid a rebuild until we've grown the window bigger than our 252 // us avoid a rebuild until we've grown the window bigger than our
312 // initial build. 253 // initial build.
313 CGFloat savedFrameWidth_; 254 CGFloat savedFrameWidth_;
314 255
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
315 // A state flag which tracks when the bar's folder menus should be shown. 265 // A state flag which tracks when the bar's folder menus should be shown.
316 // An initial click in any of the folder buttons turns this on and 266 // An initial click in any of the folder buttons turns this on and
317 // one of the following will turn it off: another click in the button, 267 // one of the following will turn it off: another click in the button,
318 // the window losing focus, a click somewhere other than in the bar 268 // the window losing focus, a click somewhere other than in the bar
319 // or a folder menu. 269 // or a folder menu.
320 BOOL showFolderMenus_; 270 BOOL showFolderMenus_;
321 271
322 // If YES then state changes (for example, from hidden to shown) are animated. 272 // If YES then state changes (for example, from hidden to shown) are animated.
323 // This is turned off for unit tests. 273 // This is turned off for unit tests.
324 BOOL stateAnimationsEnabled_; 274 BOOL stateAnimationsEnabled_;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 parent:(const bookmarks::BookmarkNode*)oldParent 420 parent:(const bookmarks::BookmarkNode*)oldParent
471 index:(int)index; 421 index:(int)index;
472 - (void)nodeFaviconLoaded:(bookmarks::BookmarkModel*)model 422 - (void)nodeFaviconLoaded:(bookmarks::BookmarkModel*)model
473 node:(const bookmarks::BookmarkNode*)node; 423 node:(const bookmarks::BookmarkNode*)node;
474 - (void)nodeChildrenReordered:(bookmarks::BookmarkModel*)model 424 - (void)nodeChildrenReordered:(bookmarks::BookmarkModel*)model
475 node:(const bookmarks::BookmarkNode*)node; 425 node:(const bookmarks::BookmarkNode*)node;
476 @end 426 @end
477 427
478 // These APIs should only be used by unit tests (or used internally). 428 // These APIs should only be used by unit tests (or used internally).
479 @interface BookmarkBarController(InternalOrTestingAPI) 429 @interface BookmarkBarController(InternalOrTestingAPI)
480 - (bookmarks::BookmarkBarLayout)layoutFromCurrentState;
481 - (void)applyLayout:(const bookmarks::BookmarkBarLayout&)layout
482 animated:(BOOL)animated;
483 - (void)openBookmarkFolder:(id)sender; 430 - (void)openBookmarkFolder:(id)sender;
484 - (void)openOrCloseBookmarkFolderForOffTheSideButton; 431 - (void)openOrCloseBookmarkFolderForOffTheSideButton;
485 - (BookmarkBarView*)buttonView; 432 - (BookmarkBarView*)buttonView;
486 - (NSMutableArray*)buttons; 433 - (NSMutableArray*)buttons;
487 - (BookmarkButton*)otherBookmarksButton; 434 - (BOOL)offTheSideButtonIsHidden;
488 - (BookmarkButton*)managedBookmarksButton; 435 - (BOOL)appsPageShortcutButtonIsHidden;
489 - (BookmarkButton*)supervisedBookmarksButton;
490 - (BookmarkButton*)otherBookmarksButton; 436 - (BookmarkButton*)otherBookmarksButton;
491 - (BookmarkBarFolderController*)folderController; 437 - (BookmarkBarFolderController*)folderController;
492 - (id)folderTarget; 438 - (id)folderTarget;
439 - (int)displayedButtonCount;
493 - (void)openURL:(GURL)url disposition:(WindowOpenDisposition)disposition; 440 - (void)openURL:(GURL)url disposition:(WindowOpenDisposition)disposition;
494 - (void)clearBookmarkBar; 441 - (void)clearBookmarkBar;
495 - (BookmarkButtonCell*)cellForBookmarkNode:(const bookmarks::BookmarkNode*)node; 442 - (BookmarkButtonCell*)cellForBookmarkNode:(const bookmarks::BookmarkNode*)node;
496 - (BookmarkButtonCell*)cellForCustomButtonWithText:(NSString*)text 443 - (BookmarkButtonCell*)cellForCustomButtonWithText:(NSString*)text
497 image:(NSImage*)image; 444 image:(NSImage*)image;
445 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell xOffset:(int*)xOffset;
498 - (void)checkForBookmarkButtonGrowth:(NSButton*)button; 446 - (void)checkForBookmarkButtonGrowth:(NSButton*)button;
499 - (void)frameDidChange; 447 - (void)frameDidChange;
500 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider; 448 - (void)updateTheme:(const ui::ThemeProvider*)themeProvider;
501 - (BookmarkButton*)buttonForDroppingOnAtPoint:(NSPoint)point; 449 - (BookmarkButton*)buttonForDroppingOnAtPoint:(NSPoint)point;
502 - (BOOL)isEventAnExitEvent:(NSEvent*)event; 450 - (BOOL)isEventAnExitEvent:(NSEvent*)event;
451 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX;
503 - (void)unhighlightBookmark:(const bookmarks::BookmarkNode*)node; 452 - (void)unhighlightBookmark:(const bookmarks::BookmarkNode*)node;
504 453
505 @end 454 @end
506 455
507 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_ 456 #endif // CHROME_BROWSER_UI_COCOA_BOOKMARKS_BOOKMARK_BAR_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698