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