Chromium Code Reviews| Index: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm |
| index 36901ced5414c1c1afc75a8ac1672e145a6f0179..42706e1adff429ff6159563184ef227bba9afef8 100644 |
| --- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm |
| +++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm |
| @@ -220,10 +220,12 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| - (int)preferredHeight; |
| - (void)addButtonsToView; |
| - (BOOL)setManagedBookmarksButtonVisibility; |
| +- (BOOL)setSupervisedBookmarksButtonVisibility; |
| - (BOOL)setOtherBookmarksButtonVisibility; |
| - (BOOL)setAppsPageShortcutButtonVisibility; |
| - (BookmarkButton*)createCustomBookmarkButtonForCell:(NSCell*)cell; |
| - (void)createManagedBookmarksButton; |
| +- (void)createSupervisedBookmarksButton; |
| - (void)createOtherBookmarksButton; |
| - (void)createAppsPageShortcutButton; |
| - (void)openAppsPage:(id)sender; |
| @@ -329,6 +331,10 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| [managedBookmarksButton_ setIsContinuousPulsing:doPulse]; |
| return; |
| } |
| + if ([supervisedBookmarksButton_ bookmarkNode] == node) { |
| + [supervisedBookmarksButton_ setIsContinuousPulsing:doPulse]; |
| + return; |
| + } |
| if ([otherBookmarksButton_ bookmarkNode] == node) { |
| [otherBookmarksButton_ setIsContinuousPulsing:doPulse]; |
| return; |
| @@ -500,6 +506,7 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| // buttons_ array. |
| [appsPageShortcutButton_ setNeedsDisplay:YES]; |
| [managedBookmarksButton_ setNeedsDisplay:YES]; |
| + [supervisedBookmarksButton_ setNeedsDisplay:YES]; |
| [otherBookmarksButton_ setNeedsDisplay:YES]; |
| } |
| } |
| @@ -512,10 +519,13 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| } |
| - (void)updateExtraButtonsVisibility { |
| - if (!appsPageShortcutButton_.get() || !managedBookmarksButton_.get()) |
| + if (!appsPageShortcutButton_.get() || |
| + !managedBookmarksButton_.get() || |
| + !supervisedBookmarksButton_.get()) |
|
Alexei Svitkine (slow)
2015/01/23 16:06:13
Nit: add {}'s
Marc Treib
2015/01/26 12:27:42
Done.
|
| return; |
| [self setAppsPageShortcutButtonVisibility]; |
| [self setManagedBookmarksButtonVisibility]; |
| + [self setSupervisedBookmarksButtonVisibility]; |
| [self resetAllButtonPositionsWithAnimation:NO]; |
| [self reconfigureBookmarkBar]; |
| } |
| @@ -588,6 +598,13 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| return rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER_MANAGED).ToNSImage(); |
| } |
| + if (node == bookmarkClient_->supervised_node()) { |
| + // Most users never see this node, so the image is only loaded if needed. |
| + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| + return rb.GetNativeImageNamed( |
| + IDR_BOOKMARK_BAR_FOLDER_SUPERVISED).ToNSImage(); |
| + } |
| + |
| if (node->is_folder()) |
| return folderImage_; |
| @@ -1102,6 +1119,15 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| [managedBookmarksButton_ setFrame:frame]; |
| } |
| + // Draw the supervised bookmark folder if needed. |
| + if (![supervisedBookmarksButton_ isHidden]) { |
| + xOffset += bookmarks::kBookmarkHorizontalPadding; |
| + NSRect frame = |
| + [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell] |
| + xOffset:&xOffset]; |
| + [supervisedBookmarksButton_ setFrame:frame]; |
| + } |
| + |
| for (int i = 0; i < node->child_count(); i++) { |
| const BookmarkNode* child = node->GetChild(i); |
| BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; |
| @@ -1185,7 +1211,7 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| } |
| } |
| -// Shows or hides the Other Bookmarks button as appropriate, and returns |
| +// Shows or hides the Managed Bookmarks button as appropriate, and returns |
| // whether it ended up visible. |
| - (BOOL)setManagedBookmarksButtonVisibility { |
| if (!managedBookmarksButton_.get()) |
| @@ -1203,6 +1229,21 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| return visible; |
| } |
| +// Shows or hides the Supervised Bookmarks button as appropriate, and returns |
| +// whether it ended up visible. |
| +- (BOOL)setSupervisedBookmarksButtonVisibility { |
| + if (!supervisedBookmarksButton_.get()) |
|
Alexei Svitkine (slow)
2015/01/23 16:06:13
This code is basically identical to -setManagedBoo
Marc Treib
2015/01/26 12:27:42
It's not quite identical - for the managed button,
|
| + return NO; |
| + |
| + BOOL visible = ![supervisedBookmarksButton_ bookmarkNode]->empty(); |
| + BOOL currentVisibility = ![supervisedBookmarksButton_ isHidden]; |
| + if (currentVisibility != visible) { |
| + [supervisedBookmarksButton_ setHidden:!visible]; |
| + [self resetAllButtonPositionsWithAnimation:NO]; |
| + } |
| + return visible; |
| +} |
| + |
| // Shows or hides the Other Bookmarks button as appropriate, and returns |
| // whether it ended up visible. |
| - (BOOL)setOtherBookmarksButtonVisibility { |
| @@ -1267,6 +1308,27 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| [self setManagedBookmarksButtonVisibility]; |
| } |
| +// Creates the button for "Supervised Bookmarks", but does not position it. |
| +- (void)createSupervisedBookmarksButton { |
| + if (supervisedBookmarksButton_.get()) { |
| + // The button's already there, but its visibility may have changed. |
| + [self setSupervisedBookmarksButtonVisibility]; |
| + |
|
Alexei Svitkine (slow)
2015/01/23 16:06:13
Nit: Remove empty line.
Marc Treib
2015/01/26 12:27:42
Done.
|
| + return; |
| + } |
| + |
| + NSCell* cell = [self cellForBookmarkNode:bookmarkClient_->supervised_node()]; |
| + supervisedBookmarksButton_.reset( |
| + [self createCustomBookmarkButtonForCell:cell]); |
| + [supervisedBookmarksButton_ |
| + setAction:@selector(openBookmarkFolderFromButton:)]; |
| + view_id_util::SetID(supervisedBookmarksButton_.get(), |
| + VIEW_ID_SUPERVISED_BOOKMARKS); |
| + [buttonView_ addSubview:supervisedBookmarksButton_.get()]; |
| + |
| + [self setSupervisedBookmarksButtonVisibility]; |
| +} |
| + |
| // Creates the button for "Other Bookmarks", but does not position it. |
| - (void)createOtherBookmarksButton { |
| // Can't create this until the model is loaded, but only need to |
| @@ -1423,6 +1485,7 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| - (void)reconfigureBookmarkBar { |
| [self setManagedBookmarksButtonVisibility]; |
| + [self setSupervisedBookmarksButtonVisibility]; |
| [self redistributeButtonsOnBarAsNeeded]; |
| [self positionRightSideButtons]; |
| [self configureOffTheSideButtonContentsAndVisibility]; |
| @@ -1495,6 +1558,11 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| noItemsRect.origin.x += width; |
| importBookmarksRect.origin.x += width; |
| } |
| + if (![supervisedBookmarksButton_ isHidden]) { |
| + float width = NSWidth([supervisedBookmarksButton_ frame]); |
| + noItemsRect.origin.x += width; |
| + importBookmarksRect.origin.x += width; |
| + } |
| [noItemTextfield setFrame:noItemsRect]; |
| [noItemTextfield setHidden:NO]; |
| NSButton* importBookmarksButton = [buttonView_ importBookmarksButton]; |
| @@ -1527,6 +1595,12 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| bookmarks::kBookmarkHorizontalPadding; |
| } |
| + // Draw the supervised bookmarks folder if needed. |
| + if (![supervisedBookmarksButton_ isHidden]) { |
| + left = NSMaxX([supervisedBookmarksButton_ frame]) + |
| + bookmarks::kBookmarkHorizontalPadding; |
| + } |
| + |
| for (NSButton* button in buttons_.get()) { |
| // Hidden buttons get no space. |
| if ([button isHidden]) |
| @@ -1602,6 +1676,9 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| } else if (![managedBookmarksButton_ isHidden]) { |
| xOffset = NSMaxX([managedBookmarksButton_ frame]) + |
| bookmarks::kBookmarkHorizontalPadding; |
| + } else if (![supervisedBookmarksButton_ isHidden]) { |
| + xOffset = NSMaxX([supervisedBookmarksButton_ frame]) + |
| + bookmarks::kBookmarkHorizontalPadding; |
| } else if (![appsPageShortcutButton_ isHidden]) { |
| xOffset = NSMaxX([appsPageShortcutButton_ frame]) + |
| bookmarks::kBookmarkHorizontalPadding; |
| @@ -1809,6 +1886,7 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
| [cell setTextColor:color]; |
| } |
| [[managedBookmarksButton_ cell] setTextColor:color]; |
| + [[supervisedBookmarksButton_ cell] setTextColor:color]; |
| [[otherBookmarksButton_ cell] setTextColor:color]; |
| [[appsPageShortcutButton_ cell] setTextColor:color]; |
| } |
| @@ -2038,7 +2116,10 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { |
| insertionPos_ = where; |
| hasInsertionPos_ = YES; |
| CGFloat left; |
| - if (![managedBookmarksButton_ isHidden]) { |
| + if (![supervisedBookmarksButton_ isHidden]) { |
| + left = NSMaxX([supervisedBookmarksButton_ frame]) + |
| + bookmarks::kBookmarkHorizontalPadding; |
| + } else if (![managedBookmarksButton_ isHidden]) { |
| left = NSMaxX([managedBookmarksButton_ frame]) + |
| bookmarks::kBookmarkHorizontalPadding; |
| } else if (![appsPageShortcutButton_ isHidden]) { |
| @@ -2105,6 +2186,16 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { |
| left = xOffset + bookmarks::kBookmarkHorizontalPadding; |
| } |
| + // Position the supervised bookmarks folder if needed. |
| + if (![supervisedBookmarksButton_ isHidden]) { |
| + int xOffset = left; |
| + NSRect frame = |
| + [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell] |
| + xOffset:&xOffset]; |
| + [supervisedBookmarksButton_ setFrame:frame]; |
| + left = xOffset + bookmarks::kBookmarkHorizontalPadding; |
| + } |
| + |
| animate &= innerContentAnimationsEnabled_; |
| for (NSButton* button in buttons_.get()) { |
| @@ -2152,6 +2243,7 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { |
| [self clearBookmarkBar]; |
| [self createAppsPageShortcutButton]; |
| [self createManagedBookmarksButton]; |
| + [self createSupervisedBookmarksButton]; |
| [self addNodesToButtonList:node]; |
| [self createOtherBookmarksButton]; |
| [self updateTheme:[[[self view] window] themeProvider]]; |
| @@ -2556,12 +2648,16 @@ static BOOL ValueInRangeInclusive(CGFloat low, CGFloat value, CGFloat high) { |
| int numButtons = displayedButtonCount_; |
| CGFloat leftmostX; |
| - if (![managedBookmarksButton_ isHidden]) |
| + if (![supervisedBookmarksButton_ isHidden]) { |
| + leftmostX = |
| + NSMaxX([supervisedBookmarksButton_ frame]) + halfHorizontalPadding; |
| + } else if (![managedBookmarksButton_ isHidden]) { |
| leftmostX = NSMaxX([managedBookmarksButton_ frame]) + halfHorizontalPadding; |
| - else if (![appsPageShortcutButton_ isHidden]) |
| + } else if (![appsPageShortcutButton_ isHidden]) { |
| leftmostX = NSMaxX([appsPageShortcutButton_ frame]) + halfHorizontalPadding; |
| - else |
| + } else { |
| leftmostX = bookmarks::kBookmarkLeftMargin - halfHorizontalPadding; |
| + } |
| // If it's a drop strictly between existing buttons ... |
| if (destIndex == 0) { |