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

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

Issue 769153007: Managed bookmarks for supervised users (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix build (Android & unit_tests) Created 5 years, 10 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 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // buttons showing. If too many then show the off-the-side list, if none 213 // buttons showing. If too many then show the off-the-side list, if none
214 // then show the no items label. 214 // then show the no items label.
215 - (void)reconfigureBookmarkBar; 215 - (void)reconfigureBookmarkBar;
216 216
217 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu; 217 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu;
218 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu; 218 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu;
219 - (void)tagEmptyMenu:(NSMenu*)menu; 219 - (void)tagEmptyMenu:(NSMenu*)menu;
220 - (void)clearMenuTagMap; 220 - (void)clearMenuTagMap;
221 - (int)preferredHeight; 221 - (int)preferredHeight;
222 - (void)addButtonsToView; 222 - (void)addButtonsToView;
223 - (BOOL)setBookmarkButtonVisibility;
223 - (BOOL)setManagedBookmarksButtonVisibility; 224 - (BOOL)setManagedBookmarksButtonVisibility;
225 - (BOOL)setSupervisedBookmarksButtonVisibility;
224 - (BOOL)setOtherBookmarksButtonVisibility; 226 - (BOOL)setOtherBookmarksButtonVisibility;
225 - (BOOL)setAppsPageShortcutButtonVisibility; 227 - (BOOL)setAppsPageShortcutButtonVisibility;
226 - (BookmarkButton*)createCustomBookmarkButtonForCell:(NSCell*)cell; 228 - (BookmarkButton*)createCustomBookmarkButtonForCell:(NSCell*)cell;
227 - (void)createManagedBookmarksButton; 229 - (void)createManagedBookmarksButton;
230 - (void)createSupervisedBookmarksButton;
228 - (void)createOtherBookmarksButton; 231 - (void)createOtherBookmarksButton;
229 - (void)createAppsPageShortcutButton; 232 - (void)createAppsPageShortcutButton;
230 - (void)openAppsPage:(id)sender; 233 - (void)openAppsPage:(id)sender;
231 - (void)centerNoItemsLabel; 234 - (void)centerNoItemsLabel;
232 - (void)positionRightSideButtons; 235 - (void)positionRightSideButtons;
233 - (void)watchForExitEvent:(BOOL)watch; 236 - (void)watchForExitEvent:(BOOL)watch;
234 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate; 237 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate;
235 238
236 @end 239 @end
237 240
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 for (BookmarkButton* button in [self buttons]) { 326 for (BookmarkButton* button in [self buttons]) {
324 if ([button bookmarkNode] == node) { 327 if ([button bookmarkNode] == node) {
325 [button setIsContinuousPulsing:doPulse]; 328 [button setIsContinuousPulsing:doPulse];
326 return; 329 return;
327 } 330 }
328 } 331 }
329 if ([managedBookmarksButton_ bookmarkNode] == node) { 332 if ([managedBookmarksButton_ bookmarkNode] == node) {
330 [managedBookmarksButton_ setIsContinuousPulsing:doPulse]; 333 [managedBookmarksButton_ setIsContinuousPulsing:doPulse];
331 return; 334 return;
332 } 335 }
336 if ([supervisedBookmarksButton_ bookmarkNode] == node) {
337 [supervisedBookmarksButton_ setIsContinuousPulsing:doPulse];
338 return;
339 }
333 if ([otherBookmarksButton_ bookmarkNode] == node) { 340 if ([otherBookmarksButton_ bookmarkNode] == node) {
334 [otherBookmarksButton_ setIsContinuousPulsing:doPulse]; 341 [otherBookmarksButton_ setIsContinuousPulsing:doPulse];
335 return; 342 return;
336 } 343 }
337 if (node->parent() == bookmarkModel_->bookmark_bar_node()) { 344 if (node->parent() == bookmarkModel_->bookmark_bar_node()) {
338 [offTheSideButton_ setIsContinuousPulsing:doPulse]; 345 [offTheSideButton_ setIsContinuousPulsing:doPulse];
339 return; 346 return;
340 } 347 }
341 348
342 NOTREACHED() << "no bookmark button found to pulse!"; 349 NOTREACHED() << "no bookmark button found to pulse!";
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 [buttonView_ setFrame:buttonViewFrame]; 501 [buttonView_ setFrame:buttonViewFrame];
495 502
496 // Update bookmark button backgrounds. 503 // Update bookmark button backgrounds.
497 if ([self isAnimationRunning]) { 504 if ([self isAnimationRunning]) {
498 for (NSButton* button in buttons_.get()) 505 for (NSButton* button in buttons_.get())
499 [button setNeedsDisplay:YES]; 506 [button setNeedsDisplay:YES];
500 // Update the apps and other buttons explicitly, since they are not in the 507 // Update the apps and other buttons explicitly, since they are not in the
501 // buttons_ array. 508 // buttons_ array.
502 [appsPageShortcutButton_ setNeedsDisplay:YES]; 509 [appsPageShortcutButton_ setNeedsDisplay:YES];
503 [managedBookmarksButton_ setNeedsDisplay:YES]; 510 [managedBookmarksButton_ setNeedsDisplay:YES];
511 [supervisedBookmarksButton_ setNeedsDisplay:YES];
504 [otherBookmarksButton_ setNeedsDisplay:YES]; 512 [otherBookmarksButton_ setNeedsDisplay:YES];
505 } 513 }
506 } 514 }
507 515
508 // We don't change a preference; we only change visibility. Preference changing 516 // We don't change a preference; we only change visibility. Preference changing
509 // (global state) is handled in |chrome::ToggleBookmarkBarWhenVisible()|. We 517 // (global state) is handled in |chrome::ToggleBookmarkBarWhenVisible()|. We
510 // simply update based on what we're told. 518 // simply update based on what we're told.
511 - (void)updateVisibility { 519 - (void)updateVisibility {
512 [self showBookmarkBarWithAnimation:NO]; 520 [self showBookmarkBarWithAnimation:NO];
513 } 521 }
514 522
515 - (void)updateExtraButtonsVisibility { 523 - (void)updateExtraButtonsVisibility {
516 if (!appsPageShortcutButton_.get() || !managedBookmarksButton_.get()) 524 if (!appsPageShortcutButton_.get() ||
525 !managedBookmarksButton_.get() ||
526 !supervisedBookmarksButton_.get()) {
517 return; 527 return;
528 }
518 [self setAppsPageShortcutButtonVisibility]; 529 [self setAppsPageShortcutButtonVisibility];
519 [self setManagedBookmarksButtonVisibility]; 530 [self setManagedBookmarksButtonVisibility];
531 [self setSupervisedBookmarksButtonVisibility];
520 [self resetAllButtonPositionsWithAnimation:NO]; 532 [self resetAllButtonPositionsWithAnimation:NO];
521 [self reconfigureBookmarkBar]; 533 [self reconfigureBookmarkBar];
522 } 534 }
523 535
524 - (void)updateHiddenState { 536 - (void)updateHiddenState {
525 BOOL oldHidden = [[self view] isHidden]; 537 BOOL oldHidden = [[self view] isHidden];
526 BOOL newHidden = ![self isVisible]; 538 BOOL newHidden = ![self isVisible];
527 if (oldHidden != newHidden) 539 if (oldHidden != newHidden)
528 [[self view] setHidden:newHidden]; 540 [[self view] setHidden:newHidden];
529 } 541 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 - (NSImage*)faviconForNode:(const BookmarkNode*)node { 594 - (NSImage*)faviconForNode:(const BookmarkNode*)node {
583 if (!node) 595 if (!node)
584 return defaultImage_; 596 return defaultImage_;
585 597
586 if (node == bookmarkClient_->managed_node()) { 598 if (node == bookmarkClient_->managed_node()) {
587 // Most users never see this node, so the image is only loaded if needed. 599 // Most users never see this node, so the image is only loaded if needed.
588 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 600 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
589 return rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER_MANAGED).ToNSImage(); 601 return rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER_MANAGED).ToNSImage();
590 } 602 }
591 603
604 if (node == bookmarkClient_->supervised_node()) {
605 // Most users never see this node, so the image is only loaded if needed.
606 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
607 return rb.GetNativeImageNamed(
608 IDR_BOOKMARK_BAR_FOLDER_SUPERVISED).ToNSImage();
609 }
610
592 if (node->is_folder()) 611 if (node->is_folder())
593 return folderImage_; 612 return folderImage_;
594 613
595 const gfx::Image& favicon = bookmarkModel_->GetFavicon(node); 614 const gfx::Image& favicon = bookmarkModel_->GetFavicon(node);
596 if (!favicon.IsEmpty()) 615 if (!favicon.IsEmpty())
597 return favicon.ToNSImage(); 616 return favicon.ToNSImage();
598 617
599 return defaultImage_; 618 return defaultImage_;
600 } 619 }
601 620
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 1115
1097 // Draw the managed bookmark folder if needed. 1116 // Draw the managed bookmark folder if needed.
1098 if (![managedBookmarksButton_ isHidden]) { 1117 if (![managedBookmarksButton_ isHidden]) {
1099 xOffset += bookmarks::kBookmarkHorizontalPadding; 1118 xOffset += bookmarks::kBookmarkHorizontalPadding;
1100 NSRect frame = 1119 NSRect frame =
1101 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell] 1120 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell]
1102 xOffset:&xOffset]; 1121 xOffset:&xOffset];
1103 [managedBookmarksButton_ setFrame:frame]; 1122 [managedBookmarksButton_ setFrame:frame];
1104 } 1123 }
1105 1124
1125 // Draw the supervised bookmark folder if needed.
1126 if (![supervisedBookmarksButton_ isHidden]) {
1127 xOffset += bookmarks::kBookmarkHorizontalPadding;
1128 NSRect frame =
1129 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell]
1130 xOffset:&xOffset];
1131 [supervisedBookmarksButton_ setFrame:frame];
1132 }
1133
1106 for (int i = 0; i < node->child_count(); i++) { 1134 for (int i = 0; i < node->child_count(); i++) {
1107 const BookmarkNode* child = node->GetChild(i); 1135 const BookmarkNode* child = node->GetChild(i);
1108 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; 1136 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset];
1109 if (NSMinX([button frame]) >= maxViewX) { 1137 if (NSMinX([button frame]) >= maxViewX) {
1110 [button setDelegate:nil]; 1138 [button setDelegate:nil];
1111 break; 1139 break;
1112 } 1140 }
1113 [buttons_ addObject:button]; 1141 [buttons_ addObject:button];
1114 } 1142 }
1115 } 1143 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 ++displayedButtonCount_; 1207 ++displayedButtonCount_;
1180 } 1208 }
1181 NSUInteger removalCount = 1209 NSUInteger removalCount =
1182 [buttons count] - (NSUInteger)displayedButtonCount_; 1210 [buttons count] - (NSUInteger)displayedButtonCount_;
1183 if (removalCount > 0) { 1211 if (removalCount > 0) {
1184 NSRange removalRange = NSMakeRange(displayedButtonCount_, removalCount); 1212 NSRange removalRange = NSMakeRange(displayedButtonCount_, removalCount);
1185 [buttons removeObjectsInRange:removalRange]; 1213 [buttons removeObjectsInRange:removalRange];
1186 } 1214 }
1187 } 1215 }
1188 1216
1189 // Shows or hides the Other Bookmarks button as appropriate, and returns 1217 // Shows or hides the Managed, Supervised, or Other Bookmarks button as
1218 // appropriate, and returns whether it ended up visible.
1219 - (BOOL)setBookmarkButtonVisibility:(BookmarkButton*)button
1220 canShow:(BOOL)show
1221 resetAllButtonPositions:(BOOL)resetButtons {
1222 if (!button)
1223 return NO;
1224
1225 BOOL visible = ![button bookmarkNode]->empty() && show;
1226 BOOL currentVisibility = ![button isHidden];
1227 if (currentVisibility != visible) {
1228 [button setHidden:!visible];
1229 if (resetButtons)
1230 [self resetAllButtonPositionsWithAnimation:NO];
1231 }
1232 return visible;
1233 }
1234
1235 // Shows or hides the Managed Bookmarks button as appropriate, and returns
1190 // whether it ended up visible. 1236 // whether it ended up visible.
1191 - (BOOL)setManagedBookmarksButtonVisibility { 1237 - (BOOL)setManagedBookmarksButtonVisibility {
1192 if (!managedBookmarksButton_.get()) 1238 PrefService* prefs = browser_->profile()->GetPrefs();
1193 return NO; 1239 BOOL prefIsSet =
1240 prefs->GetBoolean(bookmarks::prefs::kShowManagedBookmarksInBookmarkBar);
1241 return [self setBookmarkButtonVisibility:managedBookmarksButton_.get()
1242 canShow:prefIsSet
1243 resetAllButtonPositions:YES];
1244 }
1194 1245
1195 PrefService* prefs = browser_->profile()->GetPrefs(); 1246 // Shows or hides the Supervised Bookmarks button as appropriate, and returns
1196 BOOL visible = 1247 // whether it ended up visible.
1197 ![managedBookmarksButton_ bookmarkNode]->empty() && 1248 - (BOOL)setSupervisedBookmarksButtonVisibility {
1198 prefs->GetBoolean(bookmarks::prefs::kShowManagedBookmarksInBookmarkBar); 1249 return [self setBookmarkButtonVisibility:supervisedBookmarksButton_.get()
1199 BOOL currentVisibility = ![managedBookmarksButton_ isHidden]; 1250 canShow:YES
1200 if (currentVisibility != visible) { 1251 resetAllButtonPositions:YES];
1201 [managedBookmarksButton_ setHidden:!visible];
1202 [self resetAllButtonPositionsWithAnimation:NO];
1203 }
1204 return visible;
1205 } 1252 }
1206 1253
1207 // Shows or hides the Other Bookmarks button as appropriate, and returns 1254 // Shows or hides the Other Bookmarks button as appropriate, and returns
1208 // whether it ended up visible. 1255 // whether it ended up visible.
1209 - (BOOL)setOtherBookmarksButtonVisibility { 1256 - (BOOL)setOtherBookmarksButtonVisibility {
1210 if (!otherBookmarksButton_.get()) 1257 return [self setBookmarkButtonVisibility:otherBookmarksButton_.get()
1211 return NO; 1258 canShow:YES
1212 1259 resetAllButtonPositions:NO];
1213 BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty();
1214 [otherBookmarksButton_ setHidden:!visible];
1215 return visible;
1216 } 1260 }
1217 1261
1218 // Shows or hides the Apps button as appropriate, and returns whether it ended 1262 // Shows or hides the Apps button as appropriate, and returns whether it ended
1219 // up visible. 1263 // up visible.
1220 - (BOOL)setAppsPageShortcutButtonVisibility { 1264 - (BOOL)setAppsPageShortcutButtonVisibility {
1221 if (!appsPageShortcutButton_.get()) 1265 if (!appsPageShortcutButton_.get())
1222 return NO; 1266 return NO;
1223 1267
1224 BOOL visible = bookmarkModel_->loaded() && 1268 BOOL visible = bookmarkModel_->loaded() &&
1225 chrome::ShouldShowAppsShortcutInBookmarkBar( 1269 chrome::ShouldShowAppsShortcutInBookmarkBar(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 1305
1262 NSCell* cell = [self cellForBookmarkNode:bookmarkClient_->managed_node()]; 1306 NSCell* cell = [self cellForBookmarkNode:bookmarkClient_->managed_node()];
1263 managedBookmarksButton_.reset([self createCustomBookmarkButtonForCell:cell]); 1307 managedBookmarksButton_.reset([self createCustomBookmarkButtonForCell:cell]);
1264 [managedBookmarksButton_ setAction:@selector(openBookmarkFolderFromButton:)]; 1308 [managedBookmarksButton_ setAction:@selector(openBookmarkFolderFromButton:)];
1265 view_id_util::SetID(managedBookmarksButton_.get(), VIEW_ID_MANAGED_BOOKMARKS); 1309 view_id_util::SetID(managedBookmarksButton_.get(), VIEW_ID_MANAGED_BOOKMARKS);
1266 [buttonView_ addSubview:managedBookmarksButton_.get()]; 1310 [buttonView_ addSubview:managedBookmarksButton_.get()];
1267 1311
1268 [self setManagedBookmarksButtonVisibility]; 1312 [self setManagedBookmarksButtonVisibility];
1269 } 1313 }
1270 1314
1315 // Creates the button for "Supervised Bookmarks", but does not position it.
1316 - (void)createSupervisedBookmarksButton {
1317 if (supervisedBookmarksButton_.get()) {
1318 // The button's already there, but its visibility may have changed.
1319 [self setSupervisedBookmarksButtonVisibility];
1320 return;
1321 }
1322
1323 NSCell* cell = [self cellForBookmarkNode:bookmarkClient_->supervised_node()];
1324 supervisedBookmarksButton_.reset(
1325 [self createCustomBookmarkButtonForCell:cell]);
1326 [supervisedBookmarksButton_
1327 setAction:@selector(openBookmarkFolderFromButton:)];
1328 view_id_util::SetID(supervisedBookmarksButton_.get(),
1329 VIEW_ID_SUPERVISED_BOOKMARKS);
1330 [buttonView_ addSubview:supervisedBookmarksButton_.get()];
1331
1332 [self setSupervisedBookmarksButtonVisibility];
1333 }
1334
1271 // Creates the button for "Other Bookmarks", but does not position it. 1335 // Creates the button for "Other Bookmarks", but does not position it.
1272 - (void)createOtherBookmarksButton { 1336 - (void)createOtherBookmarksButton {
1273 // Can't create this until the model is loaded, but only need to 1337 // Can't create this until the model is loaded, but only need to
1274 // create it once. 1338 // create it once.
1275 if (otherBookmarksButton_.get()) { 1339 if (otherBookmarksButton_.get()) {
1276 [self setOtherBookmarksButtonVisibility]; 1340 [self setOtherBookmarksButtonVisibility];
1277 return; 1341 return;
1278 } 1342 }
1279 1343
1280 NSCell* cell = [self cellForBookmarkNode:bookmarkModel_->other_node()]; 1344 NSCell* cell = [self cellForBookmarkNode:bookmarkModel_->other_node()];
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 } 1481 }
1418 1482
1419 // Delegate method for |AnimatableView| (a superclass of 1483 // Delegate method for |AnimatableView| (a superclass of
1420 // |BookmarkBarToolbarView|). 1484 // |BookmarkBarToolbarView|).
1421 - (void)animationDidEnd:(NSAnimation*)animation { 1485 - (void)animationDidEnd:(NSAnimation*)animation {
1422 [self finalizeState]; 1486 [self finalizeState];
1423 } 1487 }
1424 1488
1425 - (void)reconfigureBookmarkBar { 1489 - (void)reconfigureBookmarkBar {
1426 [self setManagedBookmarksButtonVisibility]; 1490 [self setManagedBookmarksButtonVisibility];
1491 [self setSupervisedBookmarksButtonVisibility];
1427 [self redistributeButtonsOnBarAsNeeded]; 1492 [self redistributeButtonsOnBarAsNeeded];
1428 [self positionRightSideButtons]; 1493 [self positionRightSideButtons];
1429 [self configureOffTheSideButtonContentsAndVisibility]; 1494 [self configureOffTheSideButtonContentsAndVisibility];
1430 [self centerNoItemsLabel]; 1495 [self centerNoItemsLabel];
1431 } 1496 }
1432 1497
1433 // Determine if the given |view| can completely fit within the constraint of 1498 // Determine if the given |view| can completely fit within the constraint of
1434 // maximum x, given by |maxViewX|, and, if not, narrow the view up to a minimum 1499 // maximum x, given by |maxViewX|, and, if not, narrow the view up to a minimum
1435 // width. If the minimum width is not achievable then hide the view. Return YES 1500 // width. If the minimum width is not achievable then hide the view. Return YES
1436 // if the view was hidden. 1501 // if the view was hidden.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 if (![appsPageShortcutButton_ isHidden]) { 1554 if (![appsPageShortcutButton_ isHidden]) {
1490 float width = NSWidth([appsPageShortcutButton_ frame]); 1555 float width = NSWidth([appsPageShortcutButton_ frame]);
1491 noItemsRect.origin.x += width; 1556 noItemsRect.origin.x += width;
1492 importBookmarksRect.origin.x += width; 1557 importBookmarksRect.origin.x += width;
1493 } 1558 }
1494 if (![managedBookmarksButton_ isHidden]) { 1559 if (![managedBookmarksButton_ isHidden]) {
1495 float width = NSWidth([managedBookmarksButton_ frame]); 1560 float width = NSWidth([managedBookmarksButton_ frame]);
1496 noItemsRect.origin.x += width; 1561 noItemsRect.origin.x += width;
1497 importBookmarksRect.origin.x += width; 1562 importBookmarksRect.origin.x += width;
1498 } 1563 }
1564 if (![supervisedBookmarksButton_ isHidden]) {
1565 float width = NSWidth([supervisedBookmarksButton_ frame]);
1566 noItemsRect.origin.x += width;
1567 importBookmarksRect.origin.x += width;
1568 }
1499 [noItemTextfield setFrame:noItemsRect]; 1569 [noItemTextfield setFrame:noItemsRect];
1500 [noItemTextfield setHidden:NO]; 1570 [noItemTextfield setHidden:NO];
1501 NSButton* importBookmarksButton = [buttonView_ importBookmarksButton]; 1571 NSButton* importBookmarksButton = [buttonView_ importBookmarksButton];
1502 [importBookmarksButton setFrame:importBookmarksRect]; 1572 [importBookmarksButton setFrame:importBookmarksRect];
1503 [importBookmarksButton setHidden:NO]; 1573 [importBookmarksButton setHidden:NO];
1504 // Check each to see if they need to be shrunk or hidden. 1574 // Check each to see if they need to be shrunk or hidden.
1505 if ([self shrinkOrHideView:importBookmarksButton forMaxX:maxViewX]) 1575 if ([self shrinkOrHideView:importBookmarksButton forMaxX:maxViewX])
1506 [self shrinkOrHideView:noItemTextfield forMaxX:maxViewX]; 1576 [self shrinkOrHideView:noItemTextfield forMaxX:maxViewX];
1507 } 1577 }
1508 } 1578 }
(...skipping 12 matching lines...) Expand all
1521 left = NSMaxX([appsPageShortcutButton_ frame]) + 1591 left = NSMaxX([appsPageShortcutButton_ frame]) +
1522 bookmarks::kBookmarkHorizontalPadding; 1592 bookmarks::kBookmarkHorizontalPadding;
1523 } 1593 }
1524 1594
1525 // Draw the managed bookmarks folder if needed. 1595 // Draw the managed bookmarks folder if needed.
1526 if (![managedBookmarksButton_ isHidden]) { 1596 if (![managedBookmarksButton_ isHidden]) {
1527 left = NSMaxX([managedBookmarksButton_ frame]) + 1597 left = NSMaxX([managedBookmarksButton_ frame]) +
1528 bookmarks::kBookmarkHorizontalPadding; 1598 bookmarks::kBookmarkHorizontalPadding;
1529 } 1599 }
1530 1600
1601 // Draw the supervised bookmarks folder if needed.
1602 if (![supervisedBookmarksButton_ isHidden]) {
1603 left = NSMaxX([supervisedBookmarksButton_ frame]) +
1604 bookmarks::kBookmarkHorizontalPadding;
1605 }
1606
1531 for (NSButton* button in buttons_.get()) { 1607 for (NSButton* button in buttons_.get()) {
1532 // Hidden buttons get no space. 1608 // Hidden buttons get no space.
1533 if ([button isHidden]) 1609 if ([button isHidden])
1534 continue; 1610 continue;
1535 buttonFrame = [button frame]; 1611 buttonFrame = [button frame];
1536 buttonFrame.origin.x = left; 1612 buttonFrame.origin.x = left;
1537 left += buttonFrame.size.width + bookmarks::kBookmarkHorizontalPadding; 1613 left += buttonFrame.size.width + bookmarks::kBookmarkHorizontalPadding;
1538 if (button == wantedButton) 1614 if (button == wantedButton)
1539 return buttonFrame; 1615 return buttonFrame;
1540 } 1616 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 1672
1597 // As a result of cutting, deleting and dragging, the bar may now have room 1673 // As a result of cutting, deleting and dragging, the bar may now have room
1598 // for more buttons. 1674 // for more buttons.
1599 int xOffset; 1675 int xOffset;
1600 if (displayedButtonCount_ > 0) { 1676 if (displayedButtonCount_ > 0) {
1601 xOffset = NSMaxX([self finalRectOfLastButton]) + 1677 xOffset = NSMaxX([self finalRectOfLastButton]) +
1602 bookmarks::kBookmarkHorizontalPadding; 1678 bookmarks::kBookmarkHorizontalPadding;
1603 } else if (![managedBookmarksButton_ isHidden]) { 1679 } else if (![managedBookmarksButton_ isHidden]) {
1604 xOffset = NSMaxX([managedBookmarksButton_ frame]) + 1680 xOffset = NSMaxX([managedBookmarksButton_ frame]) +
1605 bookmarks::kBookmarkHorizontalPadding; 1681 bookmarks::kBookmarkHorizontalPadding;
1682 } else if (![supervisedBookmarksButton_ isHidden]) {
1683 xOffset = NSMaxX([supervisedBookmarksButton_ frame]) +
1684 bookmarks::kBookmarkHorizontalPadding;
1606 } else if (![appsPageShortcutButton_ isHidden]) { 1685 } else if (![appsPageShortcutButton_ isHidden]) {
1607 xOffset = NSMaxX([appsPageShortcutButton_ frame]) + 1686 xOffset = NSMaxX([appsPageShortcutButton_ frame]) +
1608 bookmarks::kBookmarkHorizontalPadding; 1687 bookmarks::kBookmarkHorizontalPadding;
1609 } else { 1688 } else {
1610 xOffset = bookmarks::kBookmarkLeftMargin - 1689 xOffset = bookmarks::kBookmarkLeftMargin -
1611 bookmarks::kBookmarkHorizontalPadding; 1690 bookmarks::kBookmarkHorizontalPadding;
1612 } 1691 }
1613 for (int i = displayedButtonCount_; i < barCount; ++i) { 1692 for (int i = displayedButtonCount_; i < barCount; ++i) {
1614 const BookmarkNode* child = node->GetChild(i); 1693 const BookmarkNode* child = node->GetChild(i);
1615 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; 1694 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset];
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1803 - (void)updateTheme:(ui::ThemeProvider*)themeProvider { 1882 - (void)updateTheme:(ui::ThemeProvider*)themeProvider {
1804 if (!themeProvider) 1883 if (!themeProvider)
1805 return; 1884 return;
1806 NSColor* color = 1885 NSColor* color =
1807 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT); 1886 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
1808 for (BookmarkButton* button in buttons_.get()) { 1887 for (BookmarkButton* button in buttons_.get()) {
1809 BookmarkButtonCell* cell = [button cell]; 1888 BookmarkButtonCell* cell = [button cell];
1810 [cell setTextColor:color]; 1889 [cell setTextColor:color];
1811 } 1890 }
1812 [[managedBookmarksButton_ cell] setTextColor:color]; 1891 [[managedBookmarksButton_ cell] setTextColor:color];
1892 [[supervisedBookmarksButton_ cell] setTextColor:color];
1813 [[otherBookmarksButton_ cell] setTextColor:color]; 1893 [[otherBookmarksButton_ cell] setTextColor:color];
1814 [[appsPageShortcutButton_ cell] setTextColor:color]; 1894 [[appsPageShortcutButton_ cell] setTextColor:color];
1815 } 1895 }
1816 1896
1817 // Return YES if the event indicates an exit from the bookmark bar 1897 // Return YES if the event indicates an exit from the bookmark bar
1818 // folder menus. E.g. "click outside" of the area we are watching. 1898 // folder menus. E.g. "click outside" of the area we are watching.
1819 // At this time we are watching the area that includes all popup 1899 // At this time we are watching the area that includes all popup
1820 // bookmark folder windows. 1900 // bookmark folder windows.
1821 - (BOOL)isEventAnExitEvent:(NSEvent*)event { 1901 - (BOOL)isEventAnExitEvent:(NSEvent*)event {
1822 NSWindow* eventWindow = [event window]; 1902 NSWindow* eventWindow = [event window];
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
2032 } 2112 }
2033 2113
2034 // Set insertionPos_ and hasInsertionPos_, and make insertion space for a 2114 // Set insertionPos_ and hasInsertionPos_, and make insertion space for a
2035 // hypothetical drop with the new button having a left edge of |where|. 2115 // hypothetical drop with the new button having a left edge of |where|.
2036 // Gets called only by our view. 2116 // Gets called only by our view.
2037 - (void)setDropInsertionPos:(CGFloat)where { 2117 - (void)setDropInsertionPos:(CGFloat)where {
2038 if (!hasInsertionPos_ || where != insertionPos_) { 2118 if (!hasInsertionPos_ || where != insertionPos_) {
2039 insertionPos_ = where; 2119 insertionPos_ = where;
2040 hasInsertionPos_ = YES; 2120 hasInsertionPos_ = YES;
2041 CGFloat left; 2121 CGFloat left;
2042 if (![managedBookmarksButton_ isHidden]) { 2122 if (![supervisedBookmarksButton_ isHidden]) {
2123 left = NSMaxX([supervisedBookmarksButton_ frame]) +
2124 bookmarks::kBookmarkHorizontalPadding;
2125 } else if (![managedBookmarksButton_ isHidden]) {
2043 left = NSMaxX([managedBookmarksButton_ frame]) + 2126 left = NSMaxX([managedBookmarksButton_ frame]) +
2044 bookmarks::kBookmarkHorizontalPadding; 2127 bookmarks::kBookmarkHorizontalPadding;
2045 } else if (![appsPageShortcutButton_ isHidden]) { 2128 } else if (![appsPageShortcutButton_ isHidden]) {
2046 left = NSMaxX([appsPageShortcutButton_ frame]) + 2129 left = NSMaxX([appsPageShortcutButton_ frame]) +
2047 bookmarks::kBookmarkHorizontalPadding; 2130 bookmarks::kBookmarkHorizontalPadding;
2048 } else { 2131 } else {
2049 left = bookmarks::kBookmarkLeftMargin; 2132 left = bookmarks::kBookmarkLeftMargin;
2050 } 2133 }
2051 CGFloat paddingWidth = bookmarks::kDefaultBookmarkWidth; 2134 CGFloat paddingWidth = bookmarks::kDefaultBookmarkWidth;
2052 BookmarkButton* draggedButton = [BookmarkButton draggedButton]; 2135 BookmarkButton* draggedButton = [BookmarkButton draggedButton];
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 // Position the managed bookmarks folder if needed. 2182 // Position the managed bookmarks folder if needed.
2100 if (![managedBookmarksButton_ isHidden]) { 2183 if (![managedBookmarksButton_ isHidden]) {
2101 int xOffset = left; 2184 int xOffset = left;
2102 NSRect frame = 2185 NSRect frame =
2103 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell] 2186 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell]
2104 xOffset:&xOffset]; 2187 xOffset:&xOffset];
2105 [managedBookmarksButton_ setFrame:frame]; 2188 [managedBookmarksButton_ setFrame:frame];
2106 left = xOffset + bookmarks::kBookmarkHorizontalPadding; 2189 left = xOffset + bookmarks::kBookmarkHorizontalPadding;
2107 } 2190 }
2108 2191
2192 // Position the supervised bookmarks folder if needed.
2193 if (![supervisedBookmarksButton_ isHidden]) {
2194 int xOffset = left;
2195 NSRect frame =
2196 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell]
2197 xOffset:&xOffset];
2198 [supervisedBookmarksButton_ setFrame:frame];
2199 left = xOffset + bookmarks::kBookmarkHorizontalPadding;
2200 }
2201
2109 animate &= innerContentAnimationsEnabled_; 2202 animate &= innerContentAnimationsEnabled_;
2110 2203
2111 for (NSButton* button in buttons_.get()) { 2204 for (NSButton* button in buttons_.get()) {
2112 // Hidden buttons get no space. 2205 // Hidden buttons get no space.
2113 if ([button isHidden]) 2206 if ([button isHidden])
2114 continue; 2207 continue;
2115 NSRect buttonFrame = [button frame]; 2208 NSRect buttonFrame = [button frame];
2116 buttonFrame.origin.x = left; 2209 buttonFrame.origin.x = left;
2117 left += buttonFrame.size.width + bookmarks::kBookmarkHorizontalPadding; 2210 left += buttonFrame.size.width + bookmarks::kBookmarkHorizontalPadding;
2118 if (animate) 2211 if (animate)
(...skipping 27 matching lines...) Expand all
2146 // See: http://crbug.com/36614 2239 // See: http://crbug.com/36614
2147 if (folderController_) 2240 if (folderController_)
2148 [self closeAllBookmarkFolders]; 2241 [self closeAllBookmarkFolders];
2149 2242
2150 // Brute force nuke and build. 2243 // Brute force nuke and build.
2151 savedFrameWidth_ = NSWidth([[self view] frame]); 2244 savedFrameWidth_ = NSWidth([[self view] frame]);
2152 const BookmarkNode* node = model->bookmark_bar_node(); 2245 const BookmarkNode* node = model->bookmark_bar_node();
2153 [self clearBookmarkBar]; 2246 [self clearBookmarkBar];
2154 [self createAppsPageShortcutButton]; 2247 [self createAppsPageShortcutButton];
2155 [self createManagedBookmarksButton]; 2248 [self createManagedBookmarksButton];
2249 [self createSupervisedBookmarksButton];
2156 [self addNodesToButtonList:node]; 2250 [self addNodesToButtonList:node];
2157 [self createOtherBookmarksButton]; 2251 [self createOtherBookmarksButton];
2158 [self updateTheme:[[[self view] window] themeProvider]]; 2252 [self updateTheme:[[[self view] window] themeProvider]];
2159 [self positionRightSideButtons]; 2253 [self positionRightSideButtons];
2160 [self addButtonsToView]; 2254 [self addButtonsToView];
2161 [self configureOffTheSideButtonContentsAndVisibility]; 2255 [self configureOffTheSideButtonContentsAndVisibility];
2162 [self reconfigureBookmarkBar]; 2256 [self reconfigureBookmarkBar];
2163 } 2257 }
2164 2258
2165 - (void)beingDeleted:(BookmarkModel*)model { 2259 - (void)beingDeleted:(BookmarkModel*)model {
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 } 2644 }
2551 2645
2552 // Return the x position for a drop indicator. 2646 // Return the x position for a drop indicator.
2553 - (CGFloat)indicatorPosForDragToPoint:(NSPoint)point { 2647 - (CGFloat)indicatorPosForDragToPoint:(NSPoint)point {
2554 CGFloat x = 0; 2648 CGFloat x = 0;
2555 CGFloat halfHorizontalPadding = 0.5 * bookmarks::kBookmarkHorizontalPadding; 2649 CGFloat halfHorizontalPadding = 0.5 * bookmarks::kBookmarkHorizontalPadding;
2556 int destIndex = [self indexForDragToPoint:point]; 2650 int destIndex = [self indexForDragToPoint:point];
2557 int numButtons = displayedButtonCount_; 2651 int numButtons = displayedButtonCount_;
2558 2652
2559 CGFloat leftmostX; 2653 CGFloat leftmostX;
2560 if (![managedBookmarksButton_ isHidden]) 2654 if (![supervisedBookmarksButton_ isHidden]) {
2655 leftmostX =
2656 NSMaxX([supervisedBookmarksButton_ frame]) + halfHorizontalPadding;
2657 } else if (![managedBookmarksButton_ isHidden]) {
2561 leftmostX = NSMaxX([managedBookmarksButton_ frame]) + halfHorizontalPadding; 2658 leftmostX = NSMaxX([managedBookmarksButton_ frame]) + halfHorizontalPadding;
2562 else if (![appsPageShortcutButton_ isHidden]) 2659 } else if (![appsPageShortcutButton_ isHidden]) {
2563 leftmostX = NSMaxX([appsPageShortcutButton_ frame]) + halfHorizontalPadding; 2660 leftmostX = NSMaxX([appsPageShortcutButton_ frame]) + halfHorizontalPadding;
2564 else 2661 } else {
2565 leftmostX = bookmarks::kBookmarkLeftMargin - halfHorizontalPadding; 2662 leftmostX = bookmarks::kBookmarkLeftMargin - halfHorizontalPadding;
2663 }
2566 2664
2567 // If it's a drop strictly between existing buttons ... 2665 // If it's a drop strictly between existing buttons ...
2568 if (destIndex == 0) { 2666 if (destIndex == 0) {
2569 x = leftmostX; 2667 x = leftmostX;
2570 } else if (destIndex > 0 && destIndex < numButtons) { 2668 } else if (destIndex > 0 && destIndex < numButtons) {
2571 // ... put the indicator right between the buttons. 2669 // ... put the indicator right between the buttons.
2572 BookmarkButton* button = 2670 BookmarkButton* button =
2573 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex-1)]; 2671 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex-1)];
2574 DCHECK(button); 2672 DCHECK(button);
2575 NSRect buttonFrame = [button frame]; 2673 NSRect buttonFrame = [button frame];
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
2807 - (id<BookmarkButtonControllerProtocol>)controllerForNode: 2905 - (id<BookmarkButtonControllerProtocol>)controllerForNode:
2808 (const BookmarkNode*)node { 2906 (const BookmarkNode*)node {
2809 // See if it's in the bar, then if it is in the hierarchy of visible 2907 // See if it's in the bar, then if it is in the hierarchy of visible
2810 // folder menus. 2908 // folder menus.
2811 if (bookmarkModel_->bookmark_bar_node() == node) 2909 if (bookmarkModel_->bookmark_bar_node() == node)
2812 return self; 2910 return self;
2813 return [folderController_ controllerForNode:node]; 2911 return [folderController_ controllerForNode:node];
2814 } 2912 }
2815 2913
2816 @end 2914 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698