Chromium Code Reviews| 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; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 name:kWillEnterFullscreenNotification | 387 name:kWillEnterFullscreenNotification |
| 389 object:nil]; | 388 object:nil]; |
| 390 [[NSNotificationCenter defaultCenter] | 389 [[NSNotificationCenter defaultCenter] |
| 391 addObserver:self | 390 addObserver:self |
| 392 selector:@selector(willEnterOrLeaveFullscreen:) | 391 selector:@selector(willEnterOrLeaveFullscreen:) |
| 393 name:kWillLeaveFullscreenNotification | 392 name:kWillLeaveFullscreenNotification |
| 394 object:nil]; | 393 object:nil]; |
| 395 | 394 |
| 396 // Don't pass ourself along (as 'self') until our init is completely | 395 // Don't pass ourself along (as 'self') until our init is completely |
| 397 // done. Thus, this call is (almost) last. | 396 // done. Thus, this call is (almost) last. |
| 398 bridge_.reset(new BookmarkBarBridge(self, bookmarkModel_)); | 397 bridge_.reset(new BookmarkBarBridge(browser_->profile(), self, |
| 398 bookmarkModel_)); | |
| 399 } | 399 } |
| 400 | 400 |
| 401 // Called by our main view (a BookmarkBarView) when it gets moved to a | 401 // Called by our main view (a BookmarkBarView) when it gets moved to a |
| 402 // window. We perform operations which need to know the relevant | 402 // 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 | 403 // window (e.g. watch for a window close) so they can't be performed |
| 404 // earlier (such as in awakeFromNib). | 404 // earlier (such as in awakeFromNib). |
| 405 - (void)viewDidMoveToWindow { | 405 - (void)viewDidMoveToWindow { |
| 406 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; | 406 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| 407 | 407 |
| 408 // Remove any existing notifications before registering for new ones. | 408 // 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]; | 468 [buttonView_ setFrame:buttonViewFrame]; |
| 469 } | 469 } |
| 470 | 470 |
| 471 // We don't change a preference; we only change visibility. Preference changing | 471 // We don't change a preference; we only change visibility. Preference changing |
| 472 // (global state) is handled in |BrowserWindowCocoa::ToggleBookmarkBar()|. We | 472 // (global state) is handled in |BrowserWindowCocoa::ToggleBookmarkBar()|. We |
| 473 // simply update based on what we're told. | 473 // simply update based on what we're told. |
| 474 - (void)updateVisibility { | 474 - (void)updateVisibility { |
| 475 [self showBookmarkBarWithAnimation:NO]; | 475 [self showBookmarkBarWithAnimation:NO]; |
| 476 } | 476 } |
| 477 | 477 |
| 478 - (void)updateAppsPageShortcutButtonVisibility { | |
| 479 [self setAppsPageShortcutButtonVisibility]; | |
| 480 [self reconfigureBookmarkBar]; | |
| 481 } | |
| 482 | |
| 478 - (void)updateHiddenState { | 483 - (void)updateHiddenState { |
| 479 BOOL oldHidden = [[self view] isHidden]; | 484 BOOL oldHidden = [[self view] isHidden]; |
| 480 BOOL newHidden = ![self isVisible]; | 485 BOOL newHidden = ![self isVisible]; |
| 481 if (oldHidden != newHidden) | 486 if (oldHidden != newHidden) |
| 482 [[self view] setHidden:newHidden]; | 487 [[self view] setHidden:newHidden]; |
| 483 } | 488 } |
| 484 | 489 |
| 485 - (void)setBookmarkBarEnabled:(BOOL)enabled { | 490 - (void)setBookmarkBarEnabled:(BOOL)enabled { |
| 486 if (enabled != barIsEnabled_) { | 491 if (enabled != barIsEnabled_) { |
| 487 barIsEnabled_ = enabled; | 492 barIsEnabled_ = enabled; |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 877 DCHECK([[self view] isKindOfClass:[AnimatableView class]]); | 882 DCHECK([[self view] isKindOfClass:[AnimatableView class]]); |
| 878 return (AnimatableView*)[self view]; | 883 return (AnimatableView*)[self view]; |
| 879 } | 884 } |
| 880 | 885 |
| 881 - (bookmark_utils::BookmarkLaunchLocation)bookmarkLaunchLocation { | 886 - (bookmark_utils::BookmarkLaunchLocation)bookmarkLaunchLocation { |
| 882 return currentState_ == BookmarkBar::DETACHED ? | 887 return currentState_ == BookmarkBar::DETACHED ? |
| 883 bookmark_utils::LAUNCH_DETACHED_BAR : | 888 bookmark_utils::LAUNCH_DETACHED_BAR : |
| 884 bookmark_utils::LAUNCH_ATTACHED_BAR; | 889 bookmark_utils::LAUNCH_ATTACHED_BAR; |
| 885 } | 890 } |
| 886 | 891 |
| 887 // Position the off-the-side chevron to the left of the otherBookmarks button, | 892 // 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. | 893 - (void)positionSideButtons { |
| 889 - (void)positionOffTheSideButton { | 894 int maxX = NSMaxX([[self buttonView] bounds]) - |
| 890 NSRect frame = [offTheSideButton_ frame]; | 895 bookmarks::kBookmarkHorizontalPadding; |
| 896 int right = maxX; | |
| 897 | |
| 898 int ignored = 0; | |
| 899 NSRect frame = [self frameForBookmarkButtonFromCell: | |
| 900 [appsPageShortcutButton_ cell] xOffset:&ignored]; | |
| 901 if (![appsPageShortcutButton_ isHidden]) { | |
| 902 right -= NSWidth(frame); | |
| 903 frame.origin.x = right; | |
| 904 } else { | |
| 905 frame.origin.x = maxX - NSWidth(frame); | |
| 906 } | |
| 907 [appsPageShortcutButton_ setFrame:frame]; | |
| 908 | |
| 909 frame = [self frameForBookmarkButtonFromCell: | |
| 910 [otherBookmarksButton_ cell] xOffset:&ignored]; | |
| 911 if (![otherBookmarksButton_ isHidden]) { | |
| 912 right -= NSWidth(frame); | |
| 913 frame.origin.x = right; | |
| 914 } else { | |
| 915 frame.origin.x = maxX - NSWidth(frame); | |
| 916 } | |
| 917 [otherBookmarksButton_ setFrame:frame]; | |
| 918 | |
| 919 frame = [offTheSideButton_ frame]; | |
| 891 frame.size.height = bookmarks::kBookmarkFolderButtonHeight; | 920 frame.size.height = bookmarks::kBookmarkFolderButtonHeight; |
| 892 if (otherBookmarksButton_.get() && ![otherBookmarksButton_ isHidden]) { | 921 right -= frame.size.width; |
| 893 frame.origin.x = ([otherBookmarksButton_ frame].origin.x - | 922 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]; | 923 [offTheSideButton_ setFrame:frame]; |
| 900 } | 924 } |
| 901 | 925 |
| 902 // Configure the off-the-side button (e.g. specify the node range, | 926 // Configure the off-the-side button (e.g. specify the node range, |
| 903 // check if we should enable or disable it, etc). | 927 // check if we should enable or disable it, etc). |
| 904 - (void)configureOffTheSideButtonContentsAndVisibility { | 928 - (void)configureOffTheSideButtonContentsAndVisibility { |
| 905 // If deleting a button while off-the-side is open, buttons may be | 929 // If deleting a button while off-the-side is open, buttons may be |
| 906 // promoted from off-the-side to the bar. Accomodate. | 930 // promoted from off-the-side to the bar. Accomodate. |
| 907 if (folderController_ && | 931 if (folderController_ && |
| 908 ([folderController_ parentButton] == offTheSideButton_)) { | 932 ([folderController_ parentButton] == offTheSideButton_)) { |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1339 } else { | 1363 } else { |
| 1340 // Make the button do something | 1364 // Make the button do something |
| 1341 [button setTarget:self]; | 1365 [button setTarget:self]; |
| 1342 [button setAction:@selector(openBookmark:)]; | 1366 [button setAction:@selector(openBookmark:)]; |
| 1343 if (node->is_url()) | 1367 if (node->is_url()) |
| 1344 [button setToolTip:[BookmarkMenuCocoaController tooltipForNode:node]]; | 1368 [button setToolTip:[BookmarkMenuCocoaController tooltipForNode:node]]; |
| 1345 } | 1369 } |
| 1346 return [[button.get() retain] autorelease]; | 1370 return [[button.get() retain] autorelease]; |
| 1347 } | 1371 } |
| 1348 | 1372 |
| 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 | 1373 // Add bookmark buttons to the view only if they are completely |
| 1362 // visible and don't overlap the "other bookmarks". Remove buttons | 1374 // visible and don't overlap the "other bookmarks". Remove buttons |
| 1363 // which are clipped. Called when building the bookmark bar the first time. | 1375 // which are clipped. Called when building the bookmark bar the first time. |
| 1364 - (void)addButtonsToView { | 1376 - (void)addButtonsToView { |
| 1365 displayedButtonCount_ = 0; | 1377 displayedButtonCount_ = 0; |
| 1366 NSMutableArray* buttons = [self buttons]; | 1378 NSMutableArray* buttons = [self buttons]; |
| 1367 for (NSButton* button in buttons) { | 1379 for (NSButton* button in buttons) { |
| 1368 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) - | 1380 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) - |
| 1369 bookmarks::kBookmarkHorizontalPadding)) | 1381 bookmarks::kBookmarkHorizontalPadding)) |
| 1370 break; | 1382 break; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1383 // whether it ended up visible. | 1395 // whether it ended up visible. |
| 1384 - (BOOL)setOtherBookmarksButtonVisibility { | 1396 - (BOOL)setOtherBookmarksButtonVisibility { |
| 1385 if (!otherBookmarksButton_.get()) | 1397 if (!otherBookmarksButton_.get()) |
| 1386 return NO; | 1398 return NO; |
| 1387 | 1399 |
| 1388 BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty(); | 1400 BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty(); |
| 1389 [otherBookmarksButton_ setHidden:!visible]; | 1401 [otherBookmarksButton_ setHidden:!visible]; |
| 1390 return visible; | 1402 return visible; |
| 1391 } | 1403 } |
| 1392 | 1404 |
| 1393 // Create the button for "Other Bookmarks" on the right of the bar. | 1405 // Shows or hides the Apps button as appropriate, and returns whether it ended |
| 1406 // up visible. | |
| 1407 - (BOOL)setAppsPageShortcutButtonVisibility { | |
| 1408 if (!appsPageShortcutButton_.get()) | |
| 1409 return NO; | |
| 1410 | |
| 1411 BOOL visible = bookmarkModel_->IsLoaded() && | |
| 1412 chrome::search::IsInstantExtendedAPIEnabled() && | |
| 1413 browser_->profile()->GetPrefs()->GetBoolean( | |
| 1414 prefs::kShowAppsShortcutInBookmarkBar); | |
| 1415 [appsPageShortcutButton_ setHidden:!visible]; | |
| 1416 return visible; | |
| 1417 } | |
| 1418 | |
| 1419 // Creates a bookmark bar button that does not correspond to a regular bookmark | |
| 1420 // or folder. It is used by the "Other Bookmarks" and the "Apps" buttons. | |
| 1421 - (BookmarkButton*)createCustomBookmarksButton:(NSCell*)cell { | |
|
Alexei Svitkine (slow)
2013/03/08 19:45:48
Don't pass the cell in and just call -setCell: fro
beaudoin
2013/03/08 22:07:17
Looks like -setCell must be called before -setDele
| |
| 1422 | |
|
Alexei Svitkine (slow)
2013/03/08 19:45:48
Remove empty line.
beaudoin
2013/03/08 22:07:17
Done.
| |
| 1423 BookmarkButton* button = [[BookmarkButton alloc] init]; | |
| 1424 [[button draggableButton] setDraggable:NO]; | |
| 1425 [[button draggableButton] setActsOnMouseDown:YES]; | |
| 1426 // Peg at right; keep same height as bar. | |
| 1427 [button setAutoresizingMask:(NSViewMinXMargin)]; | |
| 1428 [button setCell:cell]; | |
| 1429 [button setDelegate:self]; | |
| 1430 [button setTarget:self]; | |
| 1431 // Make sure this button, like all other BookmarkButtons, lives | |
| 1432 // until the end of the current event loop. | |
| 1433 [[button retain] autorelease]; | |
| 1434 return button; | |
| 1435 } | |
| 1436 | |
| 1437 // Create the button for "Other Bookmarks", but does not position it. | |
| 1394 - (void)createOtherBookmarksButton { | 1438 - (void)createOtherBookmarksButton { |
| 1395 // Can't create this until the model is loaded, but only need to | 1439 // Can't create this until the model is loaded, but only need to |
| 1396 // create it once. | 1440 // create it once. |
| 1397 if (otherBookmarksButton_.get()) { | 1441 if (otherBookmarksButton_.get()) { |
| 1398 [self setOtherBookmarksButtonVisibility]; | 1442 [self setOtherBookmarksButtonVisibility]; |
| 1399 return; | 1443 return; |
| 1400 } | 1444 } |
| 1401 | 1445 |
| 1402 // TODO(jrg): remove duplicate code | |
| 1403 NSCell* cell = [self cellForBookmarkNode:bookmarkModel_->other_node()]; | 1446 NSCell* cell = [self cellForBookmarkNode:bookmarkModel_->other_node()]; |
| 1404 int ignored = 0; | 1447 otherBookmarksButton_.reset([self createCustomBookmarksButton:cell]); |
| 1405 NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:&ignored]; | 1448 [otherBookmarksButton_ setAction:@selector(openBookmarkFolderFromButton:)]; |
| 1406 frame.origin.x = [[self buttonView] bounds].size.width - frame.size.width; | 1449 view_id_util::SetID(otherBookmarksButton_.get(), VIEW_ID_OTHER_BOOKMARKS); |
| 1407 frame.origin.x -= bookmarks::kBookmarkHorizontalPadding; | 1450 [buttonView_ addSubview:otherBookmarksButton_.get()]; |
| 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 | 1451 |
| 1426 [self setOtherBookmarksButtonVisibility]; | 1452 [self setOtherBookmarksButtonVisibility]; |
| 1453 } | |
| 1427 | 1454 |
| 1428 // Now that it's here, move the chevron over. | 1455 // Create the button for "Apps", but does not position it. |
| 1429 [self positionOffTheSideButton]; | 1456 - (void)createAppsPageShortcutButton { |
| 1457 // Can't create this until the model is loaded, but only need to | |
| 1458 // create it once. | |
| 1459 if (appsPageShortcutButton_.get()) { | |
| 1460 [self setAppsPageShortcutButtonVisibility]; | |
| 1461 return; | |
| 1462 } | |
| 1463 | |
| 1464 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 1465 NSString* text = l10n_util::GetNSString(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME); | |
| 1466 NSImage* image = rb.GetNativeImageNamed(IDR_WEBSTORE_ICON_16).ToNSImage(); | |
| 1467 NSCell* cell = [self cellForCustomButton:text | |
| 1468 withImage:image]; | |
| 1469 appsPageShortcutButton_.reset([self createCustomBookmarksButton:cell]); | |
| 1470 [appsPageShortcutButton_ setAction:@selector(openAppsPage:)]; | |
| 1471 NSString* tooltip = | |
| 1472 l10n_util::GetNSString(IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP); | |
| 1473 [appsPageShortcutButton_ setToolTip:tooltip]; | |
| 1474 [buttonView_ addSubview:appsPageShortcutButton_.get()]; | |
| 1475 | |
| 1476 [self setAppsPageShortcutButtonVisibility]; | |
| 1477 } | |
| 1478 | |
| 1479 - (IBAction)openAppsPage:(id)sender { | |
| 1480 chrome::ShowAppLauncherPage(browser_); | |
| 1481 bookmark_utils::RecordAppsPageOpen([self bookmarkLaunchLocation]); | |
| 1430 } | 1482 } |
| 1431 | 1483 |
| 1432 // Now that the model is loaded, set the bookmark bar root as the node | 1484 // Now that the model is loaded, set the bookmark bar root as the node |
| 1433 // represented by the bookmark bar (default, background) menu. | 1485 // represented by the bookmark bar (default, background) menu. |
| 1434 - (void)setNodeForBarMenu { | 1486 - (void)setNodeForBarMenu { |
| 1435 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); | 1487 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); |
| 1436 BookmarkMenu* menu = static_cast<BookmarkMenu*>([[self view] menu]); | 1488 BookmarkMenu* menu = static_cast<BookmarkMenu*>([[self view] menu]); |
| 1437 | 1489 |
| 1438 // Make sure types are compatible | 1490 // Make sure types are compatible |
| 1439 DCHECK(sizeof(long long) == sizeof(int64)); | 1491 DCHECK(sizeof(long long) == sizeof(int64)); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1537 } | 1589 } |
| 1538 | 1590 |
| 1539 // Delegate method for |AnimatableView| (a superclass of | 1591 // Delegate method for |AnimatableView| (a superclass of |
| 1540 // |BookmarkBarToolbarView|). | 1592 // |BookmarkBarToolbarView|). |
| 1541 - (void)animationDidEnd:(NSAnimation*)animation { | 1593 - (void)animationDidEnd:(NSAnimation*)animation { |
| 1542 [self finalizeState]; | 1594 [self finalizeState]; |
| 1543 } | 1595 } |
| 1544 | 1596 |
| 1545 - (void)reconfigureBookmarkBar { | 1597 - (void)reconfigureBookmarkBar { |
| 1546 [self redistributeButtonsOnBarAsNeeded]; | 1598 [self redistributeButtonsOnBarAsNeeded]; |
| 1547 [self positionOffTheSideButton]; | 1599 [self positionSideButtons]; |
| 1548 [self configureOffTheSideButtonContentsAndVisibility]; | 1600 [self configureOffTheSideButtonContentsAndVisibility]; |
| 1549 [self centerNoItemsLabel]; | 1601 [self centerNoItemsLabel]; |
| 1550 } | 1602 } |
| 1551 | 1603 |
| 1552 // Determine if the given |view| can completely fit within the constraint of | 1604 // 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 | 1605 // 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 | 1606 // width. If the minimum width is not achievable then hide the view. Return YES |
| 1555 // if the view was hidden. | 1607 // if the view was hidden. |
| 1556 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX { | 1608 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX { |
| 1557 BOOL wasHidden = NO; | 1609 BOOL wasHidden = NO; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1638 | 1690 |
| 1639 // Calculates the final position of the last button in the bar. | 1691 // Calculates the final position of the last button in the bar. |
| 1640 // We can't just use [[self buttons] lastObject] frame] because the button | 1692 // We can't just use [[self buttons] lastObject] frame] because the button |
| 1641 // may be animating currently. | 1693 // may be animating currently. |
| 1642 - (NSRect)finalRectOfLastButton { | 1694 - (NSRect)finalRectOfLastButton { |
| 1643 return [self finalRectOfButton:[[self buttons] lastObject]]; | 1695 return [self finalRectOfButton:[[self buttons] lastObject]]; |
| 1644 } | 1696 } |
| 1645 | 1697 |
| 1646 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible { | 1698 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible { |
| 1647 CGFloat maxViewX = NSMaxX([buttonView_ bounds]); | 1699 CGFloat maxViewX = NSMaxX([buttonView_ bounds]); |
| 1648 // If necessary, pull in the width to account for the Other Bookmarks button. | 1700 // If necessary, pull in the width to account for the Other Bookmarks or Apps |
| 1649 if ([self setOtherBookmarksButtonVisibility]) { | 1701 // button. |
| 1650 maxViewX = [otherBookmarksButton_.get() frame].origin.x - | 1702 const BOOL otherButtonVisible = [self setOtherBookmarksButtonVisibility]; |
| 1703 const BOOL appsButtonVisible = [self setAppsPageShortcutButtonVisibility]; | |
| 1704 if (otherButtonVisible || appsButtonVisible) { | |
| 1705 BookmarkButton* leftMostRightAlignedButton = otherButtonVisible ? | |
| 1706 otherBookmarksButton_.get() : appsPageShortcutButton_.get(); | |
| 1707 maxViewX = [leftMostRightAlignedButton frame].origin.x - | |
| 1651 bookmarks::kBookmarkRightMargin; | 1708 bookmarks::kBookmarkRightMargin; |
| 1652 } | 1709 } |
| 1653 | 1710 |
| 1654 [self positionOffTheSideButton]; | 1711 [self positionSideButtons]; |
| 1655 // If we're already overflowing, then we need to account for the chevron. | 1712 // If we're already overflowing, then we need to account for the chevron. |
| 1656 if (visible) { | 1713 if (visible) { |
| 1657 maxViewX = | 1714 maxViewX = |
| 1658 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin; | 1715 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin; |
| 1659 } | 1716 } |
| 1660 | 1717 |
| 1661 return maxViewX; | 1718 return maxViewX; |
| 1662 } | 1719 } |
| 1663 | 1720 |
| 1664 - (void)redistributeButtonsOnBarAsNeeded { | 1721 - (void)redistributeButtonsOnBarAsNeeded { |
| 1665 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); | 1722 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); |
| 1666 NSInteger barCount = node->child_count(); | 1723 NSInteger barCount = node->child_count(); |
| 1667 | 1724 |
| 1668 // Determine the current maximum extent of the visible buttons. | 1725 // Determine the current maximum extent of the visible buttons. |
| 1669 [self positionOffTheSideButton]; | 1726 [self positionSideButtons]; |
| 1670 CGFloat maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible: | 1727 CGFloat maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible: |
| 1671 (barCount > displayedButtonCount_)]; | 1728 (barCount > displayedButtonCount_)]; |
| 1672 | 1729 |
| 1673 // As a result of pasting or dragging, the bar may now have more buttons | 1730 // 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 | 1731 // than will fit so remove any which overflow. They will be shown in |
| 1675 // the off-the-side folder. | 1732 // the off-the-side folder. |
| 1676 while (displayedButtonCount_ > 0) { | 1733 while (displayedButtonCount_ > 0) { |
| 1677 BookmarkButton* button = [buttons_ lastObject]; | 1734 BookmarkButton* button = [buttons_ lastObject]; |
| 1678 if (NSMaxX([self finalRectOfLastButton]) < maxViewX) | 1735 if (NSMaxX([self finalRectOfLastButton]) < maxViewX) |
| 1679 break; | 1736 break; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1781 cellText:nil | 1838 cellText:nil |
| 1782 cellImage:image]; | 1839 cellImage:image]; |
| 1783 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback]; | 1840 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback]; |
| 1784 | 1841 |
| 1785 // Note: a quirk of setting a cell's text color is that it won't work | 1842 // Note: a quirk of setting a cell's text color is that it won't work |
| 1786 // until the cell is associated with a button, so we can't theme the cell yet. | 1843 // until the cell is associated with a button, so we can't theme the cell yet. |
| 1787 | 1844 |
| 1788 return cell; | 1845 return cell; |
| 1789 } | 1846 } |
| 1790 | 1847 |
| 1848 // Return an autoreleased NSCell suitable for a special button displayed on the | |
| 1849 // bookmark bar that is not attached to any bookmarknode but not attached to. | |
| 1850 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. | |
| 1851 - (BookmarkButtonCell*)cellForCustomButton:(NSString*)text | |
| 1852 withImage:(NSImage*)image { | |
| 1853 BookmarkButtonCell* cell = | |
| 1854 [BookmarkButtonCell buttonCellForContextMenu:buttonFolderContextMenu_ | |
|
Alexei Svitkine (slow)
2013/03/08 19:45:48
-buttonCellForContextMenu: doesn't make sense.
I
beaudoin
2013/03/08 22:07:17
Done.
| |
| 1855 cellText:text | |
| 1856 cellImage:image]; | |
| 1857 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback]; | |
| 1858 | |
| 1859 // Note: a quirk of setting a cell's text color is that it won't work | |
| 1860 // until the cell is associated with a button, so we can't theme the cell yet. | |
| 1861 | |
| 1862 return cell; | |
| 1863 } | |
| 1864 | |
| 1791 // Returns a frame appropriate for the given bookmark cell, suitable | 1865 // Returns a frame appropriate for the given bookmark cell, suitable |
| 1792 // for creating an NSButton that will contain it. |xOffset| is the X | 1866 // for creating an NSButton that will contain it. |xOffset| is the X |
| 1793 // offset for the frame; it is increased to be an appropriate X offset | 1867 // offset for the frame; it is increased to be an appropriate X offset |
| 1794 // for the next button. | 1868 // for the next button. |
| 1795 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell | 1869 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell |
| 1796 xOffset:(int*)xOffset { | 1870 xOffset:(int*)xOffset { |
| 1797 DCHECK(xOffset); | 1871 DCHECK(xOffset); |
| 1798 NSRect bounds = [buttonView_ bounds]; | 1872 NSRect bounds = [buttonView_ bounds]; |
| 1799 bounds.size.height = bookmarks::kBookmarkButtonHeight; | 1873 bounds.size.height = bookmarks::kBookmarkButtonHeight; |
| 1800 | 1874 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1879 if (!themeProvider) | 1953 if (!themeProvider) |
| 1880 return; | 1954 return; |
| 1881 NSColor* color = | 1955 NSColor* color = |
| 1882 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT, | 1956 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT, |
| 1883 true); | 1957 true); |
| 1884 for (BookmarkButton* button in buttons_.get()) { | 1958 for (BookmarkButton* button in buttons_.get()) { |
| 1885 BookmarkButtonCell* cell = [button cell]; | 1959 BookmarkButtonCell* cell = [button cell]; |
| 1886 [cell setTextColor:color]; | 1960 [cell setTextColor:color]; |
| 1887 } | 1961 } |
| 1888 [[otherBookmarksButton_ cell] setTextColor:color]; | 1962 [[otherBookmarksButton_ cell] setTextColor:color]; |
| 1963 [[appsPageShortcutButton_ cell] setTextColor:color]; | |
| 1889 } | 1964 } |
| 1890 | 1965 |
| 1891 // Return YES if the event indicates an exit from the bookmark bar | 1966 // 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. | 1967 // 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 | 1968 // At this time we are watching the area that includes all popup |
| 1894 // bookmark folder windows. | 1969 // bookmark folder windows. |
| 1895 - (BOOL)isEventAnExitEvent:(NSEvent*)event { | 1970 - (BOOL)isEventAnExitEvent:(NSEvent*)event { |
| 1896 NSWindow* eventWindow = [event window]; | 1971 NSWindow* eventWindow = [event window]; |
| 1897 NSWindow* myWindow = [[self view] window]; | 1972 NSWindow* myWindow = [[self view] window]; |
| 1898 switch ([event type]) { | 1973 switch ([event type]) { |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2180 // See: http://crbug.com/36614 | 2255 // See: http://crbug.com/36614 |
| 2181 if (folderController_) | 2256 if (folderController_) |
| 2182 [self closeAllBookmarkFolders]; | 2257 [self closeAllBookmarkFolders]; |
| 2183 | 2258 |
| 2184 // Brute force nuke and build. | 2259 // Brute force nuke and build. |
| 2185 savedFrameWidth_ = NSWidth([[self view] frame]); | 2260 savedFrameWidth_ = NSWidth([[self view] frame]); |
| 2186 const BookmarkNode* node = model->bookmark_bar_node(); | 2261 const BookmarkNode* node = model->bookmark_bar_node(); |
| 2187 [self clearBookmarkBar]; | 2262 [self clearBookmarkBar]; |
| 2188 [self addNodesToButtonList:node]; | 2263 [self addNodesToButtonList:node]; |
| 2189 [self createOtherBookmarksButton]; | 2264 [self createOtherBookmarksButton]; |
| 2265 [self createAppsPageShortcutButton]; | |
| 2190 [self updateTheme:[[[self view] window] themeProvider]]; | 2266 [self updateTheme:[[[self view] window] themeProvider]]; |
| 2191 [self positionOffTheSideButton]; | 2267 [self positionSideButtons]; |
| 2192 [self addNonBookmarkButtonsToView]; | |
| 2193 [self addButtonsToView]; | 2268 [self addButtonsToView]; |
| 2194 [self configureOffTheSideButtonContentsAndVisibility]; | 2269 [self configureOffTheSideButtonContentsAndVisibility]; |
| 2195 [self setNodeForBarMenu]; | 2270 [self setNodeForBarMenu]; |
| 2196 [self reconfigureBookmarkBar]; | 2271 [self reconfigureBookmarkBar]; |
| 2197 } | 2272 } |
| 2198 | 2273 |
| 2199 - (void)beingDeleted:(BookmarkModel*)model { | 2274 - (void)beingDeleted:(BookmarkModel*)model { |
| 2200 // The browser may be being torn down; little is safe to do. As an | 2275 // 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. | 2276 // example, it may not be safe to clear the pasteboard. |
| 2202 // http://crbug.com/38665 | 2277 // http://crbug.com/38665 |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2843 return buttonContextMenu_; | 2918 return buttonContextMenu_; |
| 2844 } | 2919 } |
| 2845 | 2920 |
| 2846 // Intentionally ignores ownership issues; used for testing and we try | 2921 // Intentionally ignores ownership issues; used for testing and we try |
| 2847 // to minimize touching the object passed in (likely a mock). | 2922 // to minimize touching the object passed in (likely a mock). |
| 2848 - (void)setButtonContextMenu:(id)menu { | 2923 - (void)setButtonContextMenu:(id)menu { |
| 2849 buttonContextMenu_ = menu; | 2924 buttonContextMenu_ = menu; |
| 2850 } | 2925 } |
| 2851 | 2926 |
| 2852 @end | 2927 @end |
| OLD | NEW |