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

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

Powered by Google App Engine
This is Rietveld 408576698