| 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/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 // Determine the nature of the bookmark bar contents based on the number of | 207 // Determine the nature of the bookmark bar contents based on the number of |
| 208 // buttons showing. If too many then show the off-the-side list, if none | 208 // buttons showing. If too many then show the off-the-side list, if none |
| 209 // then show the no items label. | 209 // then show the no items label. |
| 210 - (void)reconfigureBookmarkBar; | 210 - (void)reconfigureBookmarkBar; |
| 211 | 211 |
| 212 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu; | 212 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu; |
| 213 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu; | 213 - (void)addFolderNode:(const BookmarkNode*)node toMenu:(NSMenu*)menu; |
| 214 - (void)tagEmptyMenu:(NSMenu*)menu; | 214 - (void)tagEmptyMenu:(NSMenu*)menu; |
| 215 - (void)clearMenuTagMap; | 215 - (void)clearMenuTagMap; |
| 216 - (int)preferredHeight; | 216 - (int)preferredHeight; |
| 217 - (void)addNonBookmarkButtonsToView; | |
| 218 - (void)addButtonsToView; | 217 - (void)addButtonsToView; |
| 219 - (void)centerNoItemsLabel; | 218 - (void)centerNoItemsLabel; |
| 220 - (void)setNodeForBarMenu; | 219 - (void)setNodeForBarMenu; |
| 221 - (void)watchForExitEvent:(BOOL)watch; | 220 - (void)watchForExitEvent:(BOOL)watch; |
| 222 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate; | 221 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate; |
| 223 | 222 |
| 224 @end | 223 @end |
| 225 | 224 |
| 226 @implementation BookmarkBarController | 225 @implementation BookmarkBarController |
| 227 | 226 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 return self; | 276 return self; |
| 278 } | 277 } |
| 279 | 278 |
| 280 - (void)pulseBookmarkNotification:(NSNotification*)notification { | 279 - (void)pulseBookmarkNotification:(NSNotification*)notification { |
| 281 NSDictionary* dict = [notification userInfo]; | 280 NSDictionary* dict = [notification userInfo]; |
| 282 const BookmarkNode* node = NULL; | 281 const BookmarkNode* node = NULL; |
| 283 NSValue *value = [dict objectForKey:bookmark_button::kBookmarkKey]; | 282 NSValue *value = [dict objectForKey:bookmark_button::kBookmarkKey]; |
| 284 DCHECK(value); | 283 DCHECK(value); |
| 285 if (value) | 284 if (value) |
| 286 node = static_cast<const BookmarkNode*>([value pointerValue]); | 285 node = static_cast<const BookmarkNode*>([value pointerValue]); |
| 287 NSNumber* number = [dict | 286 NSNumber* number = [dict objectForKey:bookmark_button::kBookmarkPulseFlagKey]; |
| 288 objectForKey:bookmark_button::kBookmarkPulseFlagKey]; | |
| 289 DCHECK(number); | 287 DCHECK(number); |
| 290 BOOL doPulse = number ? [number boolValue] : NO; | 288 BOOL doPulse = number ? [number boolValue] : NO; |
| 291 | 289 |
| 292 // 3 cases: | 290 // 4 cases: |
| 293 // button on the bar: flash it | 291 // button on the bar: flash it |
| 294 // button in "other bookmarks" folder: flash other bookmarks | 292 // button in "other bookmarks" folder: flash other bookmarks |
| 293 // button is "apps page" shortcut: flash it |
| 295 // button in "off the side" folder: flash the chevron | 294 // button in "off the side" folder: flash the chevron |
| 296 for (BookmarkButton* button in [self buttons]) { | 295 for (BookmarkButton* button in [self buttons]) { |
| 297 if ([button bookmarkNode] == node) { | 296 if ([button bookmarkNode] == node) { |
| 298 [button setIsContinuousPulsing:doPulse]; | 297 [button setIsContinuousPulsing:doPulse]; |
| 299 return; | 298 return; |
| 300 } | 299 } |
| 301 } | 300 } |
| 302 if ([otherBookmarksButton_ bookmarkNode] == node) { | 301 if ([otherBookmarksButton_ bookmarkNode] == node) { |
| 303 [otherBookmarksButton_ setIsContinuousPulsing:doPulse]; | 302 [otherBookmarksButton_ setIsContinuousPulsing:doPulse]; |
| 304 return; | 303 return; |
| 305 } | 304 } |
| 305 if ([appsPageShortcutButton_ bookmarkNode] == node) { |
| 306 [appsPageShortcutButton_ setIsContinuousPulsing:doPulse]; |
| 307 return; |
| 308 } |
| 306 if (node->parent() == bookmarkModel_->bookmark_bar_node()) { | 309 if (node->parent() == bookmarkModel_->bookmark_bar_node()) { |
| 307 [offTheSideButton_ setIsContinuousPulsing:doPulse]; | 310 [offTheSideButton_ setIsContinuousPulsing:doPulse]; |
| 308 return; | 311 return; |
| 309 } | 312 } |
| 310 | 313 |
| 311 NOTREACHED() << "no bookmark button found to pulse!"; | 314 NOTREACHED() << "no bookmark button found to pulse!"; |
| 312 } | 315 } |
| 313 | 316 |
| 314 - (void)dealloc { | 317 - (void)dealloc { |
| 315 // Clear delegate so it doesn't get called during stopAnimation. | 318 // Clear delegate so it doesn't get called during stopAnimation. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 name:kWillEnterFullscreenNotification | 391 name:kWillEnterFullscreenNotification |
| 389 object:nil]; | 392 object:nil]; |
| 390 [[NSNotificationCenter defaultCenter] | 393 [[NSNotificationCenter defaultCenter] |
| 391 addObserver:self | 394 addObserver:self |
| 392 selector:@selector(willEnterOrLeaveFullscreen:) | 395 selector:@selector(willEnterOrLeaveFullscreen:) |
| 393 name:kWillLeaveFullscreenNotification | 396 name:kWillLeaveFullscreenNotification |
| 394 object:nil]; | 397 object:nil]; |
| 395 | 398 |
| 396 // Don't pass ourself along (as 'self') until our init is completely | 399 // Don't pass ourself along (as 'self') until our init is completely |
| 397 // done. Thus, this call is (almost) last. | 400 // done. Thus, this call is (almost) last. |
| 398 bridge_.reset(new BookmarkBarBridge(self, bookmarkModel_)); | 401 bridge_.reset(new BookmarkBarBridge(browser_, self, bookmarkModel_)); |
| 399 } | 402 } |
| 400 | 403 |
| 401 // Called by our main view (a BookmarkBarView) when it gets moved to a | 404 // Called by our main view (a BookmarkBarView) when it gets moved to a |
| 402 // window. We perform operations which need to know the relevant | 405 // window. We perform operations which need to know the relevant |
| 403 // window (e.g. watch for a window close) so they can't be performed | 406 // window (e.g. watch for a window close) so they can't be performed |
| 404 // earlier (such as in awakeFromNib). | 407 // earlier (such as in awakeFromNib). |
| 405 - (void)viewDidMoveToWindow { | 408 - (void)viewDidMoveToWindow { |
| 406 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; | 409 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| 407 | 410 |
| 408 // Remove any existing notifications before registering for new ones. | 411 // Remove any existing notifications before registering for new ones. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 [buttonView_ setFrame:buttonViewFrame]; | 471 [buttonView_ setFrame:buttonViewFrame]; |
| 469 } | 472 } |
| 470 | 473 |
| 471 // We don't change a preference; we only change visibility. Preference changing | 474 // We don't change a preference; we only change visibility. Preference changing |
| 472 // (global state) is handled in |BrowserWindowCocoa::ToggleBookmarkBar()|. We | 475 // (global state) is handled in |BrowserWindowCocoa::ToggleBookmarkBar()|. We |
| 473 // simply update based on what we're told. | 476 // simply update based on what we're told. |
| 474 - (void)updateVisibility { | 477 - (void)updateVisibility { |
| 475 [self showBookmarkBarWithAnimation:NO]; | 478 [self showBookmarkBarWithAnimation:NO]; |
| 476 } | 479 } |
| 477 | 480 |
| 481 - (void)updateAppsPageShortcutButtonVisibility { |
| 482 [self setAppsPageShortcutButtonVisibility]; |
| 483 [self reconfigureBookmarkBar]; |
| 484 } |
| 485 |
| 478 - (void)updateHiddenState { | 486 - (void)updateHiddenState { |
| 479 BOOL oldHidden = [[self view] isHidden]; | 487 BOOL oldHidden = [[self view] isHidden]; |
| 480 BOOL newHidden = ![self isVisible]; | 488 BOOL newHidden = ![self isVisible]; |
| 481 if (oldHidden != newHidden) | 489 if (oldHidden != newHidden) |
| 482 [[self view] setHidden:newHidden]; | 490 [[self view] setHidden:newHidden]; |
| 483 } | 491 } |
| 484 | 492 |
| 485 - (void)setBookmarkBarEnabled:(BOOL)enabled { | 493 - (void)setBookmarkBarEnabled:(BOOL)enabled { |
| 486 if (enabled != barIsEnabled_) { | 494 if (enabled != barIsEnabled_) { |
| 487 barIsEnabled_ = enabled; | 495 barIsEnabled_ = enabled; |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 DCHECK([[self view] isKindOfClass:[AnimatableView class]]); | 885 DCHECK([[self view] isKindOfClass:[AnimatableView class]]); |
| 878 return (AnimatableView*)[self view]; | 886 return (AnimatableView*)[self view]; |
| 879 } | 887 } |
| 880 | 888 |
| 881 - (bookmark_utils::BookmarkLaunchLocation)bookmarkLaunchLocation { | 889 - (bookmark_utils::BookmarkLaunchLocation)bookmarkLaunchLocation { |
| 882 return currentState_ == BookmarkBar::DETACHED ? | 890 return currentState_ == BookmarkBar::DETACHED ? |
| 883 bookmark_utils::LAUNCH_DETACHED_BAR : | 891 bookmark_utils::LAUNCH_DETACHED_BAR : |
| 884 bookmark_utils::LAUNCH_ATTACHED_BAR; | 892 bookmark_utils::LAUNCH_ATTACHED_BAR; |
| 885 } | 893 } |
| 886 | 894 |
| 887 // Position the off-the-side chevron to the left of the otherBookmarks button, | 895 // Position the right-side button including the off-the-side chevron. |
| 888 // unless it's hidden in which case it's right aligned on top of it. | 896 - (void)positionSideButtons { |
| 889 - (void)positionOffTheSideButton { | 897 int right = NSMaxX([[self buttonView] bounds]) - |
| 898 bookmarks::kBookmarkHorizontalPadding; |
| 899 if (![appsPageShortcutButton_ isHidden]) { |
| 900 int ignored = 0; |
| 901 NSRect frame = [self frameForBookmarkButtonFromCell: |
| 902 [appsPageShortcutButton_ cell] xOffset:&ignored]; |
| 903 right -= frame.size.width; |
| 904 frame.origin.x = right; |
| 905 [appsPageShortcutButton_ setFrame:frame]; |
| 906 } |
| 907 if (![otherBookmarksButton_ isHidden]) { |
| 908 int ignored = 0; |
| 909 NSRect frame = [self frameForBookmarkButtonFromCell: |
| 910 [otherBookmarksButton_ cell] xOffset:&ignored]; |
| 911 right -= frame.size.width; |
| 912 frame.origin.x = right; |
| 913 [otherBookmarksButton_ setFrame:frame]; |
| 914 } |
| 915 |
| 890 NSRect frame = [offTheSideButton_ frame]; | 916 NSRect frame = [offTheSideButton_ frame]; |
| 891 frame.size.height = bookmarks::kBookmarkFolderButtonHeight; | 917 frame.size.height = bookmarks::kBookmarkFolderButtonHeight; |
| 892 if (otherBookmarksButton_.get() && ![otherBookmarksButton_ isHidden]) { | 918 right -= frame.size.width; |
| 893 frame.origin.x = ([otherBookmarksButton_ frame].origin.x - | 919 frame.origin.x = right; |
| 894 (frame.size.width + | |
| 895 bookmarks::kBookmarkHorizontalPadding)); | |
| 896 } else { | |
| 897 frame.origin.x = (NSMaxX([otherBookmarksButton_ frame]) - frame.size.width); | |
| 898 } | |
| 899 [offTheSideButton_ setFrame:frame]; | 920 [offTheSideButton_ setFrame:frame]; |
| 900 } | 921 } |
| 901 | 922 |
| 902 // Configure the off-the-side button (e.g. specify the node range, | 923 // Configure the off-the-side button (e.g. specify the node range, |
| 903 // check if we should enable or disable it, etc). | 924 // check if we should enable or disable it, etc). |
| 904 - (void)configureOffTheSideButtonContentsAndVisibility { | 925 - (void)configureOffTheSideButtonContentsAndVisibility { |
| 905 // If deleting a button while off-the-side is open, buttons may be | 926 // If deleting a button while off-the-side is open, buttons may be |
| 906 // promoted from off-the-side to the bar. Accomodate. | 927 // promoted from off-the-side to the bar. Accomodate. |
| 907 if (folderController_ && | 928 if (folderController_ && |
| 908 ([folderController_ parentButton] == offTheSideButton_)) { | 929 ([folderController_ parentButton] == offTheSideButton_)) { |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1339 } else { | 1360 } else { |
| 1340 // Make the button do something | 1361 // Make the button do something |
| 1341 [button setTarget:self]; | 1362 [button setTarget:self]; |
| 1342 [button setAction:@selector(openBookmark:)]; | 1363 [button setAction:@selector(openBookmark:)]; |
| 1343 if (node->is_url()) | 1364 if (node->is_url()) |
| 1344 [button setToolTip:[BookmarkMenuCocoaController tooltipForNode:node]]; | 1365 [button setToolTip:[BookmarkMenuCocoaController tooltipForNode:node]]; |
| 1345 } | 1366 } |
| 1346 return [[button.get() retain] autorelease]; | 1367 return [[button.get() retain] autorelease]; |
| 1347 } | 1368 } |
| 1348 | 1369 |
| 1349 // Add non-bookmark buttons to the view. This includes the chevron | |
| 1350 // and the "other bookmarks" button. Technically "other bookmarks" is | |
| 1351 // a bookmark button but it is treated specially. Only needs to be | |
| 1352 // called when these buttons are new or when the bookmark bar is | |
| 1353 // cleared (e.g. on a loaded: call). Unlike addButtonsToView below, | |
| 1354 // we don't need to add/remove these dynamically in response to window | |
| 1355 // resize. | |
| 1356 - (void)addNonBookmarkButtonsToView { | |
| 1357 [buttonView_ addSubview:otherBookmarksButton_.get()]; | |
| 1358 [buttonView_ addSubview:offTheSideButton_]; | |
| 1359 } | |
| 1360 | |
| 1361 // Add bookmark buttons to the view only if they are completely | 1370 // Add bookmark buttons to the view only if they are completely |
| 1362 // visible and don't overlap the "other bookmarks". Remove buttons | 1371 // visible and don't overlap the "other bookmarks". Remove buttons |
| 1363 // which are clipped. Called when building the bookmark bar the first time. | 1372 // which are clipped. Called when building the bookmark bar the first time. |
| 1364 - (void)addButtonsToView { | 1373 - (void)addButtonsToView { |
| 1365 displayedButtonCount_ = 0; | 1374 displayedButtonCount_ = 0; |
| 1366 NSMutableArray* buttons = [self buttons]; | 1375 NSMutableArray* buttons = [self buttons]; |
| 1367 for (NSButton* button in buttons) { | 1376 for (NSButton* button in buttons) { |
| 1368 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) - | 1377 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) - |
| 1369 bookmarks::kBookmarkHorizontalPadding)) | 1378 bookmarks::kBookmarkHorizontalPadding)) |
| 1370 break; | 1379 break; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1383 // whether it ended up visible. | 1392 // whether it ended up visible. |
| 1384 - (BOOL)setOtherBookmarksButtonVisibility { | 1393 - (BOOL)setOtherBookmarksButtonVisibility { |
| 1385 if (!otherBookmarksButton_.get()) | 1394 if (!otherBookmarksButton_.get()) |
| 1386 return NO; | 1395 return NO; |
| 1387 | 1396 |
| 1388 BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty(); | 1397 BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty(); |
| 1389 [otherBookmarksButton_ setHidden:!visible]; | 1398 [otherBookmarksButton_ setHidden:!visible]; |
| 1390 return visible; | 1399 return visible; |
| 1391 } | 1400 } |
| 1392 | 1401 |
| 1393 // Create the button for "Other Bookmarks" on the right of the bar. | 1402 // Shows or hides the Apps button as appropriate, and returns whether it ended |
| 1403 // up visible. |
| 1404 - (BOOL)setAppsPageShortcutButtonVisibility { |
| 1405 if (!appsPageShortcutButton_.get()) |
| 1406 return NO; |
| 1407 |
| 1408 BOOL visible = bookmarkModel_->IsLoaded() && |
| 1409 chrome::search::IsInstantExtendedAPIEnabled() && |
| 1410 browser_->profile()->GetPrefs()->GetBoolean( |
| 1411 prefs::kShowAppsShortcutInBookmarkBar); |
| 1412 [appsPageShortcutButton_ setHidden:!visible]; |
| 1413 return visible; |
| 1414 } |
| 1415 |
| 1416 // Creates a bookmark bar button that does not correspond to a regular bookmark |
| 1417 // or folder. It is used by the "Other Bookmarks" and the "Apps" buttons. |
| 1418 - (BookmarkButton*)createCustomBookmarksButton:(const BookmarkNode*)node { |
| 1419 NSCell* cell = [self cellForBookmarkNode:node]; |
| 1420 BookmarkButton* button = [[BookmarkButton alloc] init]; |
| 1421 [[button draggableButton] setDraggable:NO]; |
| 1422 [[button draggableButton] setActsOnMouseDown:YES]; |
| 1423 // Peg at right; keep same height as bar. |
| 1424 [button setAutoresizingMask:(NSViewMinXMargin)]; |
| 1425 [button setCell:cell]; |
| 1426 [button setDelegate:self]; |
| 1427 [button setTarget:self]; |
| 1428 // Make sure this button, like all other BookmarkButtons, lives |
| 1429 // until the end of the current event loop. |
| 1430 [[button retain] autorelease]; |
| 1431 return button; |
| 1432 } |
| 1433 |
| 1434 // Create the button for "Other Bookmarks", but does not position it. |
| 1394 - (void)createOtherBookmarksButton { | 1435 - (void)createOtherBookmarksButton { |
| 1395 // Can't create this until the model is loaded, but only need to | 1436 // Can't create this until the model is loaded, but only need to |
| 1396 // create it once. | 1437 // create it once. |
| 1397 if (otherBookmarksButton_.get()) { | 1438 if (otherBookmarksButton_.get()) { |
| 1398 [self setOtherBookmarksButtonVisibility]; | 1439 [self setOtherBookmarksButtonVisibility]; |
| 1399 return; | 1440 return; |
| 1400 } | 1441 } |
| 1401 | 1442 |
| 1402 // TODO(jrg): remove duplicate code | 1443 otherBookmarksButton_.reset( |
| 1403 NSCell* cell = [self cellForBookmarkNode:bookmarkModel_->other_node()]; | 1444 [self createCustomBookmarksButton:bookmarkModel_->other_node()]); |
| 1404 int ignored = 0; | 1445 [otherBookmarksButton_ setAction:@selector(openBookmarkFolderFromButton:)]; |
| 1405 NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:&ignored]; | 1446 view_id_util::SetID(otherBookmarksButton_.get(), VIEW_ID_OTHER_BOOKMARKS); |
| 1406 frame.origin.x = [[self buttonView] bounds].size.width - frame.size.width; | 1447 [buttonView_ addSubview:otherBookmarksButton_.get()]; |
| 1407 frame.origin.x -= bookmarks::kBookmarkHorizontalPadding; | |
| 1408 BookmarkButton* button = [[BookmarkButton alloc] initWithFrame:frame]; | |
| 1409 [[button draggableButton] setDraggable:NO]; | |
| 1410 [[button draggableButton] setActsOnMouseDown:YES]; | |
| 1411 otherBookmarksButton_.reset(button); | |
| 1412 view_id_util::SetID(button, VIEW_ID_OTHER_BOOKMARKS); | |
| 1413 | |
| 1414 // Make sure this button, like all other BookmarkButtons, lives | |
| 1415 // until the end of the current event loop. | |
| 1416 [[button retain] autorelease]; | |
| 1417 | |
| 1418 // Peg at right; keep same height as bar. | |
| 1419 [button setAutoresizingMask:(NSViewMinXMargin)]; | |
| 1420 [button setCell:cell]; | |
| 1421 [button setDelegate:self]; | |
| 1422 [button setTarget:self]; | |
| 1423 [button setAction:@selector(openBookmarkFolderFromButton:)]; | |
| 1424 [buttonView_ addSubview:button]; | |
| 1425 | 1448 |
| 1426 [self setOtherBookmarksButtonVisibility]; | 1449 [self setOtherBookmarksButtonVisibility]; |
| 1450 } |
| 1427 | 1451 |
| 1428 // Now that it's here, move the chevron over. | 1452 // Create the button for "Apps", but does not position it. |
| 1429 [self positionOffTheSideButton]; | 1453 - (void)createAppsPageShortcutButton { |
| 1454 // Can't create this until the model is loaded, but only need to |
| 1455 // create it once. |
| 1456 if (appsPageShortcutButton_.get()) { |
| 1457 [self setAppsPageShortcutButtonVisibility]; |
| 1458 return; |
| 1459 } |
| 1460 |
| 1461 appsPageShortcutButton_.reset( |
| 1462 [self createCustomBookmarksButton:bookmarkModel_->apps_node()]); |
| 1463 [appsPageShortcutButton_ setAction:@selector(openAppsPage:)]; |
| 1464 NSString* tooltip = |
| 1465 l10n_util::GetNSString(IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP); |
| 1466 [appsPageShortcutButton_ setToolTip:tooltip]; |
| 1467 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 1468 [appsPageShortcutButton_ setImage: |
| 1469 rb.GetNativeImageNamed(IDR_WEBSTORE_ICON_16).ToNSImage()]; |
| 1470 [buttonView_ addSubview:appsPageShortcutButton_.get()]; |
| 1471 |
| 1472 [self setAppsPageShortcutButtonVisibility]; |
| 1473 } |
| 1474 |
| 1475 - (IBAction)openAppsPage:(id)sender { |
| 1476 chrome::ShowAppLauncherPage(browser_); |
| 1477 bookmark_utils::RecordAppsPageOpen([self bookmarkLaunchLocation]); |
| 1430 } | 1478 } |
| 1431 | 1479 |
| 1432 // Now that the model is loaded, set the bookmark bar root as the node | 1480 // Now that the model is loaded, set the bookmark bar root as the node |
| 1433 // represented by the bookmark bar (default, background) menu. | 1481 // represented by the bookmark bar (default, background) menu. |
| 1434 - (void)setNodeForBarMenu { | 1482 - (void)setNodeForBarMenu { |
| 1435 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); | 1483 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); |
| 1436 BookmarkMenu* menu = static_cast<BookmarkMenu*>([[self view] menu]); | 1484 BookmarkMenu* menu = static_cast<BookmarkMenu*>([[self view] menu]); |
| 1437 | 1485 |
| 1438 // Make sure types are compatible | 1486 // Make sure types are compatible |
| 1439 DCHECK(sizeof(long long) == sizeof(int64)); | 1487 DCHECK(sizeof(long long) == sizeof(int64)); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1537 } | 1585 } |
| 1538 | 1586 |
| 1539 // Delegate method for |AnimatableView| (a superclass of | 1587 // Delegate method for |AnimatableView| (a superclass of |
| 1540 // |BookmarkBarToolbarView|). | 1588 // |BookmarkBarToolbarView|). |
| 1541 - (void)animationDidEnd:(NSAnimation*)animation { | 1589 - (void)animationDidEnd:(NSAnimation*)animation { |
| 1542 [self finalizeState]; | 1590 [self finalizeState]; |
| 1543 } | 1591 } |
| 1544 | 1592 |
| 1545 - (void)reconfigureBookmarkBar { | 1593 - (void)reconfigureBookmarkBar { |
| 1546 [self redistributeButtonsOnBarAsNeeded]; | 1594 [self redistributeButtonsOnBarAsNeeded]; |
| 1547 [self positionOffTheSideButton]; | 1595 [self positionSideButtons]; |
| 1548 [self configureOffTheSideButtonContentsAndVisibility]; | 1596 [self configureOffTheSideButtonContentsAndVisibility]; |
| 1549 [self centerNoItemsLabel]; | 1597 [self centerNoItemsLabel]; |
| 1550 } | 1598 } |
| 1551 | 1599 |
| 1552 // Determine if the given |view| can completely fit within the constraint of | 1600 // Determine if the given |view| can completely fit within the constraint of |
| 1553 // maximum x, given by |maxViewX|, and, if not, narrow the view up to a minimum | 1601 // maximum x, given by |maxViewX|, and, if not, narrow the view up to a minimum |
| 1554 // width. If the minimum width is not achievable then hide the view. Return YES | 1602 // width. If the minimum width is not achievable then hide the view. Return YES |
| 1555 // if the view was hidden. | 1603 // if the view was hidden. |
| 1556 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX { | 1604 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX { |
| 1557 BOOL wasHidden = NO; | 1605 BOOL wasHidden = NO; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1638 | 1686 |
| 1639 // Calculates the final position of the last button in the bar. | 1687 // Calculates the final position of the last button in the bar. |
| 1640 // We can't just use [[self buttons] lastObject] frame] because the button | 1688 // We can't just use [[self buttons] lastObject] frame] because the button |
| 1641 // may be animating currently. | 1689 // may be animating currently. |
| 1642 - (NSRect)finalRectOfLastButton { | 1690 - (NSRect)finalRectOfLastButton { |
| 1643 return [self finalRectOfButton:[[self buttons] lastObject]]; | 1691 return [self finalRectOfButton:[[self buttons] lastObject]]; |
| 1644 } | 1692 } |
| 1645 | 1693 |
| 1646 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible { | 1694 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible { |
| 1647 CGFloat maxViewX = NSMaxX([buttonView_ bounds]); | 1695 CGFloat maxViewX = NSMaxX([buttonView_ bounds]); |
| 1648 // If necessary, pull in the width to account for the Other Bookmarks button. | 1696 // If necessary, pull in the width to account for the Other Bookmarks or Apps |
| 1649 if ([self setOtherBookmarksButtonVisibility]) { | 1697 // button. |
| 1650 maxViewX = [otherBookmarksButton_.get() frame].origin.x - | 1698 const BOOL otherButtonVisible = [self setOtherBookmarksButtonVisibility]; |
| 1699 const BOOL appsButtonVisible = [self setAppsPageShortcutButtonVisibility]; |
| 1700 if (otherButtonVisible || appsButtonVisible) { |
| 1701 BookmarkButton* leftMostRightAlignedButton = otherButtonVisible ? |
| 1702 otherBookmarksButton_.get() : appsPageShortcutButton_.get(); |
| 1703 maxViewX = [leftMostRightAlignedButton frame].origin.x - |
| 1651 bookmarks::kBookmarkRightMargin; | 1704 bookmarks::kBookmarkRightMargin; |
| 1652 } | 1705 } |
| 1653 | 1706 |
| 1654 [self positionOffTheSideButton]; | 1707 [self positionSideButtons]; |
| 1655 // If we're already overflowing, then we need to account for the chevron. | 1708 // If we're already overflowing, then we need to account for the chevron. |
| 1656 if (visible) { | 1709 if (visible) { |
| 1657 maxViewX = | 1710 maxViewX = |
| 1658 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin; | 1711 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin; |
| 1659 } | 1712 } |
| 1660 | 1713 |
| 1661 return maxViewX; | 1714 return maxViewX; |
| 1662 } | 1715 } |
| 1663 | 1716 |
| 1664 - (void)redistributeButtonsOnBarAsNeeded { | 1717 - (void)redistributeButtonsOnBarAsNeeded { |
| 1665 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); | 1718 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); |
| 1666 NSInteger barCount = node->child_count(); | 1719 NSInteger barCount = node->child_count(); |
| 1667 | 1720 |
| 1668 // Determine the current maximum extent of the visible buttons. | 1721 // Determine the current maximum extent of the visible buttons. |
| 1669 [self positionOffTheSideButton]; | 1722 [self positionSideButtons]; |
| 1670 CGFloat maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible: | 1723 CGFloat maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible: |
| 1671 (barCount > displayedButtonCount_)]; | 1724 (barCount > displayedButtonCount_)]; |
| 1672 | 1725 |
| 1673 // As a result of pasting or dragging, the bar may now have more buttons | 1726 // As a result of pasting or dragging, the bar may now have more buttons |
| 1674 // than will fit so remove any which overflow. They will be shown in | 1727 // than will fit so remove any which overflow. They will be shown in |
| 1675 // the off-the-side folder. | 1728 // the off-the-side folder. |
| 1676 while (displayedButtonCount_ > 0) { | 1729 while (displayedButtonCount_ > 0) { |
| 1677 BookmarkButton* button = [buttons_ lastObject]; | 1730 BookmarkButton* button = [buttons_ lastObject]; |
| 1678 if (NSMaxX([self finalRectOfLastButton]) < maxViewX) | 1731 if (NSMaxX([self finalRectOfLastButton]) < maxViewX) |
| 1679 break; | 1732 break; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1879 if (!themeProvider) | 1932 if (!themeProvider) |
| 1880 return; | 1933 return; |
| 1881 NSColor* color = | 1934 NSColor* color = |
| 1882 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT, | 1935 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT, |
| 1883 true); | 1936 true); |
| 1884 for (BookmarkButton* button in buttons_.get()) { | 1937 for (BookmarkButton* button in buttons_.get()) { |
| 1885 BookmarkButtonCell* cell = [button cell]; | 1938 BookmarkButtonCell* cell = [button cell]; |
| 1886 [cell setTextColor:color]; | 1939 [cell setTextColor:color]; |
| 1887 } | 1940 } |
| 1888 [[otherBookmarksButton_ cell] setTextColor:color]; | 1941 [[otherBookmarksButton_ cell] setTextColor:color]; |
| 1942 [[appsPageShortcutButton_ cell] setTextColor:color]; |
| 1889 } | 1943 } |
| 1890 | 1944 |
| 1891 // Return YES if the event indicates an exit from the bookmark bar | 1945 // Return YES if the event indicates an exit from the bookmark bar |
| 1892 // folder menus. E.g. "click outside" of the area we are watching. | 1946 // folder menus. E.g. "click outside" of the area we are watching. |
| 1893 // At this time we are watching the area that includes all popup | 1947 // At this time we are watching the area that includes all popup |
| 1894 // bookmark folder windows. | 1948 // bookmark folder windows. |
| 1895 - (BOOL)isEventAnExitEvent:(NSEvent*)event { | 1949 - (BOOL)isEventAnExitEvent:(NSEvent*)event { |
| 1896 NSWindow* eventWindow = [event window]; | 1950 NSWindow* eventWindow = [event window]; |
| 1897 NSWindow* myWindow = [[self view] window]; | 1951 NSWindow* myWindow = [[self view] window]; |
| 1898 switch ([event type]) { | 1952 switch ([event type]) { |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2180 // See: http://crbug.com/36614 | 2234 // See: http://crbug.com/36614 |
| 2181 if (folderController_) | 2235 if (folderController_) |
| 2182 [self closeAllBookmarkFolders]; | 2236 [self closeAllBookmarkFolders]; |
| 2183 | 2237 |
| 2184 // Brute force nuke and build. | 2238 // Brute force nuke and build. |
| 2185 savedFrameWidth_ = NSWidth([[self view] frame]); | 2239 savedFrameWidth_ = NSWidth([[self view] frame]); |
| 2186 const BookmarkNode* node = model->bookmark_bar_node(); | 2240 const BookmarkNode* node = model->bookmark_bar_node(); |
| 2187 [self clearBookmarkBar]; | 2241 [self clearBookmarkBar]; |
| 2188 [self addNodesToButtonList:node]; | 2242 [self addNodesToButtonList:node]; |
| 2189 [self createOtherBookmarksButton]; | 2243 [self createOtherBookmarksButton]; |
| 2244 [self createAppsPageShortcutButton]; |
| 2190 [self updateTheme:[[[self view] window] themeProvider]]; | 2245 [self updateTheme:[[[self view] window] themeProvider]]; |
| 2191 [self positionOffTheSideButton]; | 2246 [self positionSideButtons]; |
| 2192 [self addNonBookmarkButtonsToView]; | |
| 2193 [self addButtonsToView]; | 2247 [self addButtonsToView]; |
| 2194 [self configureOffTheSideButtonContentsAndVisibility]; | 2248 [self configureOffTheSideButtonContentsAndVisibility]; |
| 2195 [self setNodeForBarMenu]; | 2249 [self setNodeForBarMenu]; |
| 2196 [self reconfigureBookmarkBar]; | 2250 [self reconfigureBookmarkBar]; |
| 2197 } | 2251 } |
| 2198 | 2252 |
| 2199 - (void)beingDeleted:(BookmarkModel*)model { | 2253 - (void)beingDeleted:(BookmarkModel*)model { |
| 2200 // The browser may be being torn down; little is safe to do. As an | 2254 // The browser may be being torn down; little is safe to do. As an |
| 2201 // example, it may not be safe to clear the pasteboard. | 2255 // example, it may not be safe to clear the pasteboard. |
| 2202 // http://crbug.com/38665 | 2256 // http://crbug.com/38665 |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2843 return buttonContextMenu_; | 2897 return buttonContextMenu_; |
| 2844 } | 2898 } |
| 2845 | 2899 |
| 2846 // Intentionally ignores ownership issues; used for testing and we try | 2900 // Intentionally ignores ownership issues; used for testing and we try |
| 2847 // to minimize touching the object passed in (likely a mock). | 2901 // to minimize touching the object passed in (likely a mock). |
| 2848 - (void)setButtonContextMenu:(id)menu { | 2902 - (void)setButtonContextMenu:(id)menu { |
| 2849 buttonContextMenu_ = menu; | 2903 buttonContextMenu_ = menu; |
| 2850 } | 2904 } |
| 2851 | 2905 |
| 2852 @end | 2906 @end |
| OLD | NEW |