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 ea5563b1131c293622a63758180ea11124282b8d..bbcdb1f4794669d81d99849c412f5dd6788fd76b 100644 |
--- a/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm |
+++ b/chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.mm |
@@ -220,11 +220,14 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
- (void)clearMenuTagMap; |
- (int)preferredHeight; |
- (void)addButtonsToView; |
+- (BOOL)setBookmarkButtonVisibility; |
- (BOOL)setManagedBookmarksButtonVisibility; |
+- (BOOL)setSupervisedBookmarksButtonVisibility; |
- (BOOL)setOtherBookmarksButtonVisibility; |
- (BOOL)setAppsPageShortcutButtonVisibility; |
- (BookmarkButton*)createCustomBookmarkButtonForCell:(NSCell*)cell; |
- (void)createManagedBookmarksButton; |
+- (void)createSupervisedBookmarksButton; |
- (void)createOtherBookmarksButton; |
- (void)createAppsPageShortcutButton; |
- (void)openAppsPage:(id)sender; |
@@ -330,6 +333,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; |
@@ -501,6 +508,7 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
// buttons_ array. |
[appsPageShortcutButton_ setNeedsDisplay:YES]; |
[managedBookmarksButton_ setNeedsDisplay:YES]; |
+ [supervisedBookmarksButton_ setNeedsDisplay:YES]; |
[otherBookmarksButton_ setNeedsDisplay:YES]; |
} |
} |
@@ -513,10 +521,14 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
} |
- (void)updateExtraButtonsVisibility { |
- if (!appsPageShortcutButton_.get() || !managedBookmarksButton_.get()) |
+ if (!appsPageShortcutButton_.get() || |
+ !managedBookmarksButton_.get() || |
+ !supervisedBookmarksButton_.get()) { |
return; |
+ } |
[self setAppsPageShortcutButtonVisibility]; |
[self setManagedBookmarksButtonVisibility]; |
+ [self setSupervisedBookmarksButtonVisibility]; |
[self resetAllButtonPositionsWithAnimation:NO]; |
[self reconfigureBookmarkBar]; |
} |
@@ -589,6 +601,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_; |
@@ -1103,6 +1122,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]; |
@@ -1186,33 +1214,49 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
} |
} |
-// Shows or hides the Other Bookmarks button as appropriate, and returns |
-// whether it ended up visible. |
-- (BOOL)setManagedBookmarksButtonVisibility { |
- if (!managedBookmarksButton_.get()) |
+// Shows or hides the Managed, Supervised, or Other Bookmarks button as |
+// appropriate, and returns whether it ended up visible. |
+- (BOOL)setBookmarkButtonVisibility:(BookmarkButton*)button |
+ canShow:(BOOL)show |
+ resetAllButtonPositions:(BOOL)resetButtons { |
+ if (!button) |
return NO; |
- PrefService* prefs = browser_->profile()->GetPrefs(); |
- BOOL visible = |
- ![managedBookmarksButton_ bookmarkNode]->empty() && |
- prefs->GetBoolean(bookmarks::prefs::kShowManagedBookmarksInBookmarkBar); |
- BOOL currentVisibility = ![managedBookmarksButton_ isHidden]; |
+ BOOL visible = ![button bookmarkNode]->empty() && show; |
+ BOOL currentVisibility = ![button isHidden]; |
if (currentVisibility != visible) { |
- [managedBookmarksButton_ setHidden:!visible]; |
- [self resetAllButtonPositionsWithAnimation:NO]; |
+ [button setHidden:!visible]; |
+ if (resetButtons) |
+ [self resetAllButtonPositionsWithAnimation:NO]; |
} |
return visible; |
} |
+// Shows or hides the Managed Bookmarks button as appropriate, and returns |
+// whether it ended up visible. |
+- (BOOL)setManagedBookmarksButtonVisibility { |
+ PrefService* prefs = browser_->profile()->GetPrefs(); |
+ BOOL prefIsSet = |
+ prefs->GetBoolean(bookmarks::prefs::kShowManagedBookmarksInBookmarkBar); |
+ return [self setBookmarkButtonVisibility:managedBookmarksButton_.get() |
+ canShow:prefIsSet |
+ resetAllButtonPositions:YES]; |
+} |
+ |
+// Shows or hides the Supervised Bookmarks button as appropriate, and returns |
+// whether it ended up visible. |
+- (BOOL)setSupervisedBookmarksButtonVisibility { |
+ return [self setBookmarkButtonVisibility:supervisedBookmarksButton_.get() |
+ canShow:YES |
+ resetAllButtonPositions:YES]; |
+} |
+ |
// Shows or hides the Other Bookmarks button as appropriate, and returns |
// whether it ended up visible. |
- (BOOL)setOtherBookmarksButtonVisibility { |
- if (!otherBookmarksButton_.get()) |
- return NO; |
- |
- BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty(); |
- [otherBookmarksButton_ setHidden:!visible]; |
- return visible; |
+ return [self setBookmarkButtonVisibility:otherBookmarksButton_.get() |
+ canShow:YES |
+ resetAllButtonPositions:NO]; |
} |
// Shows or hides the Apps button as appropriate, and returns whether it ended |
@@ -1268,6 +1312,26 @@ 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]; |
+ 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 |
@@ -1424,6 +1488,7 @@ void RecordAppLaunch(Profile* profile, GURL url) { |
- (void)reconfigureBookmarkBar { |
[self setManagedBookmarksButtonVisibility]; |
+ [self setSupervisedBookmarksButtonVisibility]; |
[self redistributeButtonsOnBarAsNeeded]; |
[self positionRightSideButtons]; |
[self configureOffTheSideButtonContentsAndVisibility]; |
@@ -1496,6 +1561,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]; |
@@ -1528,6 +1598,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]) |
@@ -1603,6 +1679,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; |
@@ -1810,6 +1889,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]; |
} |
@@ -2039,7 +2119,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]) { |
@@ -2106,6 +2189,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()) { |
@@ -2153,6 +2246,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]]; |
@@ -2557,12 +2651,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) { |