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

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

Issue 12550006: Mac: Add a shortcut to open the Apps page from the bookmark bar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h"
6 6
7 #include "base/mac/bundle_locations.h" 7 #include "base/mac/bundle_locations.h"
8 #include "base/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
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
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 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 DCHECK([[self view] isKindOfClass:[AnimatableView class]]); 880 DCHECK([[self view] isKindOfClass:[AnimatableView class]]);
878 return (AnimatableView*)[self view]; 881 return (AnimatableView*)[self view];
879 } 882 }
880 883
881 - (bookmark_utils::BookmarkLaunchLocation)bookmarkLaunchLocation { 884 - (bookmark_utils::BookmarkLaunchLocation)bookmarkLaunchLocation {
882 return currentState_ == BookmarkBar::DETACHED ? 885 return currentState_ == BookmarkBar::DETACHED ?
883 bookmark_utils::LAUNCH_DETACHED_BAR : 886 bookmark_utils::LAUNCH_DETACHED_BAR :
884 bookmark_utils::LAUNCH_ATTACHED_BAR; 887 bookmark_utils::LAUNCH_ATTACHED_BAR;
885 } 888 }
886 889
887 // Position the off-the-side chevron to the left of the otherBookmarks button, 890 // 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. 891 - (void)positionSideButtons {
889 - (void)positionOffTheSideButton { 892 int right = NSMaxX([[self buttonView] bounds]) -
893 bookmarks::kBookmarkHorizontalPadding;
894 if (![appsPageShortcutButton_ isHidden]) {
895 int ignored = 0;
896 NSRect frame = [self frameForBookmarkButtonFromCell:
897 [appsPageShortcutButton_ cell] xOffset:&ignored];
898 right -= frame.size.width;
899 frame.origin.x = right;
900 [appsPageShortcutButton_ setFrame:frame];
901 }
902 if (![otherBookmarksButton_ isHidden]) {
903 int ignored = 0;
904 NSRect frame = [self frameForBookmarkButtonFromCell:
905 [otherBookmarksButton_ cell] xOffset:&ignored];
906 right -= frame.size.width;
907 frame.origin.x = right;
908 [otherBookmarksButton_ setFrame:frame];
909 }
910
890 NSRect frame = [offTheSideButton_ frame]; 911 NSRect frame = [offTheSideButton_ frame];
891 frame.size.height = bookmarks::kBookmarkFolderButtonHeight; 912 frame.size.height = bookmarks::kBookmarkFolderButtonHeight;
892 if (otherBookmarksButton_.get() && ![otherBookmarksButton_ isHidden]) { 913 right -= frame.size.width;
893 frame.origin.x = ([otherBookmarksButton_ frame].origin.x - 914 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]; 915 [offTheSideButton_ setFrame:frame];
900 } 916 }
901 917
902 // Configure the off-the-side button (e.g. specify the node range, 918 // Configure the off-the-side button (e.g. specify the node range,
903 // check if we should enable or disable it, etc). 919 // check if we should enable or disable it, etc).
904 - (void)configureOffTheSideButtonContentsAndVisibility { 920 - (void)configureOffTheSideButtonContentsAndVisibility {
905 // If deleting a button while off-the-side is open, buttons may be 921 // If deleting a button while off-the-side is open, buttons may be
906 // promoted from off-the-side to the bar. Accomodate. 922 // promoted from off-the-side to the bar. Accomodate.
907 if (folderController_ && 923 if (folderController_ &&
908 ([folderController_ parentButton] == offTheSideButton_)) { 924 ([folderController_ parentButton] == offTheSideButton_)) {
909 [folderController_ reconfigureMenu]; 925 [folderController_ reconfigureMenu];
910 } 926 }
911 927
912 [[offTheSideButton_ cell] setStartingChildIndex:displayedButtonCount_]; 928 [[offTheSideButton_ cell] setStartingChildIndex:displayedButtonCount_];
913 [[offTheSideButton_ cell] 929 [[offTheSideButton_ cell]
914 setBookmarkNode:bookmarkModel_->bookmark_bar_node()]; 930 setBookmarkNode:bookmarkModel_->bookmark_bar_node()];
Alexei Svitkine (slow) 2013/03/07 15:56:59 Nit: Remove this from the diff.
beaudoin 2013/03/07 21:03:54 Done.
915 int bookmarkChildren = bookmarkModel_->bookmark_bar_node()->child_count(); 931 int bookmarkChildren = bookmarkModel_->bookmark_bar_node()->child_count();
916 if (bookmarkChildren > displayedButtonCount_) { 932 if (bookmarkChildren > displayedButtonCount_) {
917 [offTheSideButton_ setHidden:NO]; 933 [offTheSideButton_ setHidden:NO];
918 } else { 934 } else {
919 // If we just deleted the last item in an off-the-side menu so the 935 // If we just deleted the last item in an off-the-side menu so the
920 // button will be going away, make sure the menu goes away. 936 // button will be going away, make sure the menu goes away.
921 if (folderController_ && 937 if (folderController_ &&
922 ([folderController_ parentButton] == offTheSideButton_)) 938 ([folderController_ parentButton] == offTheSideButton_))
923 [self closeAllBookmarkFolders]; 939 [self closeAllBookmarkFolders];
924 // (And hide the button, too.) 940 // (And hide the button, too.)
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 } else { 1355 } else {
1340 // Make the button do something 1356 // Make the button do something
1341 [button setTarget:self]; 1357 [button setTarget:self];
1342 [button setAction:@selector(openBookmark:)]; 1358 [button setAction:@selector(openBookmark:)];
1343 if (node->is_url()) 1359 if (node->is_url())
1344 [button setToolTip:[BookmarkMenuCocoaController tooltipForNode:node]]; 1360 [button setToolTip:[BookmarkMenuCocoaController tooltipForNode:node]];
1345 } 1361 }
1346 return [[button.get() retain] autorelease]; 1362 return [[button.get() retain] autorelease];
1347 } 1363 }
1348 1364
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 1365 // Add bookmark buttons to the view only if they are completely
1362 // visible and don't overlap the "other bookmarks". Remove buttons 1366 // visible and don't overlap the "other bookmarks". Remove buttons
1363 // which are clipped. Called when building the bookmark bar the first time. 1367 // which are clipped. Called when building the bookmark bar the first time.
1364 - (void)addButtonsToView { 1368 - (void)addButtonsToView {
1365 displayedButtonCount_ = 0; 1369 displayedButtonCount_ = 0;
1366 NSMutableArray* buttons = [self buttons]; 1370 NSMutableArray* buttons = [self buttons];
1367 for (NSButton* button in buttons) { 1371 for (NSButton* button in buttons) {
1368 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) - 1372 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) -
1369 bookmarks::kBookmarkHorizontalPadding)) 1373 bookmarks::kBookmarkHorizontalPadding))
1370 break; 1374 break;
(...skipping 12 matching lines...) Expand all
1383 // whether it ended up visible. 1387 // whether it ended up visible.
1384 - (BOOL)setOtherBookmarksButtonVisibility { 1388 - (BOOL)setOtherBookmarksButtonVisibility {
1385 if (!otherBookmarksButton_.get()) 1389 if (!otherBookmarksButton_.get())
1386 return NO; 1390 return NO;
1387 1391
1388 BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty(); 1392 BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty();
1389 [otherBookmarksButton_ setHidden:!visible]; 1393 [otherBookmarksButton_ setHidden:!visible];
1390 return visible; 1394 return visible;
1391 } 1395 }
1392 1396
1393 // Create the button for "Other Bookmarks" on the right of the bar. 1397 // Shows or hides the Apps button as appropriate, and returns whether it ended
1398 // up visible.
1399 - (BOOL)setAppsPageShortcutButtonVisibility {
1400 if (!appsPageShortcutButton_.get())
1401 return NO;
1402
1403 // TODO(beaudoin): Take into account the preference state.
1404 BOOL visible = chrome::search::IsInstantExtendedAPIEnabled();
1405 [appsPageShortcutButton_ setHidden:!visible];
1406 return visible;
1407 }
1408
1409 - (BookmarkButton*)createCustomBookmarksButton:(const BookmarkNode*)node {
Alexei Svitkine (slow) 2013/03/07 15:56:59 Nit: Add a comment.
beaudoin 2013/03/07 21:03:54 Done.
1410 NSCell* cell = [self cellForBookmarkNode:node];
1411 BookmarkButton* button = [[BookmarkButton alloc] init];
1412 [[button draggableButton] setDraggable:NO];
1413 [[button draggableButton] setActsOnMouseDown:YES];
1414 // Peg at right; keep same height as bar.
1415 [button setAutoresizingMask:(NSViewMinXMargin)];
1416 [button setCell:cell];
1417 [button setDelegate:self];
1418 [button setTarget:self];
1419 // Make sure this button, like all other BookmarkButtons, lives
1420 // until the end of the current event loop.
1421 [[button retain] autorelease];
1422 return button;
1423 }
1424
1425 // Create the button for "Other Bookmarks", but does not position it.
1394 - (void)createOtherBookmarksButton { 1426 - (void)createOtherBookmarksButton {
1395 // Can't create this until the model is loaded, but only need to 1427 // Can't create this until the model is loaded, but only need to
1396 // create it once. 1428 // create it once.
1397 if (otherBookmarksButton_.get()) { 1429 if (otherBookmarksButton_.get()) {
1398 [self setOtherBookmarksButtonVisibility]; 1430 [self setOtherBookmarksButtonVisibility];
1399 return; 1431 return;
1400 } 1432 }
1401 1433
1402 // TODO(jrg): remove duplicate code 1434 otherBookmarksButton_.reset(
1403 NSCell* cell = [self cellForBookmarkNode:bookmarkModel_->other_node()]; 1435 [self createCustomBookmarksButton:bookmarkModel_->other_node()]);
1404 int ignored = 0; 1436 [otherBookmarksButton_ setAction:@selector(openBookmarkFolderFromButton:)];
1405 NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:&ignored]; 1437 view_id_util::SetID(otherBookmarksButton_.get(), VIEW_ID_OTHER_BOOKMARKS);
1406 frame.origin.x = [[self buttonView] bounds].size.width - frame.size.width; 1438 [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 1439
1426 [self setOtherBookmarksButtonVisibility]; 1440 [self setOtherBookmarksButtonVisibility];
1441 }
1427 1442
1428 // Now that it's here, move the chevron over. 1443 // Create the button for "Apps", but does not position it.
1429 [self positionOffTheSideButton]; 1444 - (void)createAppsPageShortcutButton {
1445 // Can't create this until the model is loaded, but only need to
1446 // create it once.
1447 if (appsPageShortcutButton_.get()) {
1448 [self setAppsPageShortcutButtonVisibility];
1449 return;
1450 }
1451
1452 appsPageShortcutButton_.reset(
1453 [self createCustomBookmarksButton:bookmarkModel_->apps_node()]);
1454 [appsPageShortcutButton_ setAction:@selector(openAppsPage:)];
1455 NSString* tooltip =
1456 l10n_util::GetNSString(IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP);
1457 [appsPageShortcutButton_ setToolTip:tooltip];
1458 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1459 [appsPageShortcutButton_ setImage:
1460 rb.GetNativeImageNamed(IDR_WEBSTORE_ICON_16).ToNSImage()];
1461 [buttonView_ addSubview:appsPageShortcutButton_.get()];
1462
1463 [self setAppsPageShortcutButtonVisibility];
1464 }
1465
1466 - (IBAction)openAppsPage:(id)sender {
1467 chrome::ShowAppLauncherPage(browser_);
1468 bookmark_utils::RecordAppsPageOpen([self bookmarkLaunchLocation]);
1430 } 1469 }
1431 1470
1432 // Now that the model is loaded, set the bookmark bar root as the node 1471 // Now that the model is loaded, set the bookmark bar root as the node
1433 // represented by the bookmark bar (default, background) menu. 1472 // represented by the bookmark bar (default, background) menu.
1434 - (void)setNodeForBarMenu { 1473 - (void)setNodeForBarMenu {
1435 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); 1474 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node();
1436 BookmarkMenu* menu = static_cast<BookmarkMenu*>([[self view] menu]); 1475 BookmarkMenu* menu = static_cast<BookmarkMenu*>([[self view] menu]);
1437 1476
1438 // Make sure types are compatible 1477 // Make sure types are compatible
1439 DCHECK(sizeof(long long) == sizeof(int64)); 1478 DCHECK(sizeof(long long) == sizeof(int64));
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 } 1576 }
1538 1577
1539 // Delegate method for |AnimatableView| (a superclass of 1578 // Delegate method for |AnimatableView| (a superclass of
1540 // |BookmarkBarToolbarView|). 1579 // |BookmarkBarToolbarView|).
1541 - (void)animationDidEnd:(NSAnimation*)animation { 1580 - (void)animationDidEnd:(NSAnimation*)animation {
1542 [self finalizeState]; 1581 [self finalizeState];
1543 } 1582 }
1544 1583
1545 - (void)reconfigureBookmarkBar { 1584 - (void)reconfigureBookmarkBar {
1546 [self redistributeButtonsOnBarAsNeeded]; 1585 [self redistributeButtonsOnBarAsNeeded];
1547 [self positionOffTheSideButton]; 1586 [self positionSideButtons];
1548 [self configureOffTheSideButtonContentsAndVisibility]; 1587 [self configureOffTheSideButtonContentsAndVisibility];
1549 [self centerNoItemsLabel]; 1588 [self centerNoItemsLabel];
1550 } 1589 }
1551 1590
1552 // Determine if the given |view| can completely fit within the constraint of 1591 // 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 1592 // 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 1593 // width. If the minimum width is not achievable then hide the view. Return YES
1555 // if the view was hidden. 1594 // if the view was hidden.
1556 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX { 1595 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX {
1557 BOOL wasHidden = NO; 1596 BOOL wasHidden = NO;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 1677
1639 // Calculates the final position of the last button in the bar. 1678 // Calculates the final position of the last button in the bar.
1640 // We can't just use [[self buttons] lastObject] frame] because the button 1679 // We can't just use [[self buttons] lastObject] frame] because the button
1641 // may be animating currently. 1680 // may be animating currently.
1642 - (NSRect)finalRectOfLastButton { 1681 - (NSRect)finalRectOfLastButton {
1643 return [self finalRectOfButton:[[self buttons] lastObject]]; 1682 return [self finalRectOfButton:[[self buttons] lastObject]];
1644 } 1683 }
1645 1684
1646 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible { 1685 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible {
1647 CGFloat maxViewX = NSMaxX([buttonView_ bounds]); 1686 CGFloat maxViewX = NSMaxX([buttonView_ bounds]);
1648 // If necessary, pull in the width to account for the Other Bookmarks button. 1687 // If necessary, pull in the width to account for the Other Bookmarks or Apps
1649 if ([self setOtherBookmarksButtonVisibility]) { 1688 // button.
1650 maxViewX = [otherBookmarksButton_.get() frame].origin.x - 1689 const BOOL otherButtonVisible = [self setOtherBookmarksButtonVisibility];
1690 const BOOL appsButtonVisible = [self setAppsPageShortcutButtonVisibility];
1691 if (otherButtonVisible || appsButtonVisible) {
1692 BookmarkButton* leftMostRightAlignedButton = otherButtonVisible ?
1693 otherBookmarksButton_.get() : appsPageShortcutButton_.get();
1694 maxViewX = [leftMostRightAlignedButton frame].origin.x -
1651 bookmarks::kBookmarkRightMargin; 1695 bookmarks::kBookmarkRightMargin;
1652 } 1696 }
1653 1697
1654 [self positionOffTheSideButton]; 1698 [self positionSideButtons];
1655 // If we're already overflowing, then we need to account for the chevron. 1699 // If we're already overflowing, then we need to account for the chevron.
1656 if (visible) { 1700 if (visible) {
1657 maxViewX = 1701 maxViewX =
1658 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin; 1702 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin;
1659 } 1703 }
1660 1704
1661 return maxViewX; 1705 return maxViewX;
1662 } 1706 }
1663 1707
1664 - (void)redistributeButtonsOnBarAsNeeded { 1708 - (void)redistributeButtonsOnBarAsNeeded {
1665 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); 1709 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node();
1666 NSInteger barCount = node->child_count(); 1710 NSInteger barCount = node->child_count();
1667 1711
1668 // Determine the current maximum extent of the visible buttons. 1712 // Determine the current maximum extent of the visible buttons.
1669 [self positionOffTheSideButton]; 1713 [self positionSideButtons];
1670 CGFloat maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible: 1714 CGFloat maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:
1671 (barCount > displayedButtonCount_)]; 1715 (barCount > displayedButtonCount_)];
1672 1716
1673 // As a result of pasting or dragging, the bar may now have more buttons 1717 // 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 1718 // than will fit so remove any which overflow. They will be shown in
1675 // the off-the-side folder. 1719 // the off-the-side folder.
1676 while (displayedButtonCount_ > 0) { 1720 while (displayedButtonCount_ > 0) {
1677 BookmarkButton* button = [buttons_ lastObject]; 1721 BookmarkButton* button = [buttons_ lastObject];
1678 if (NSMaxX([self finalRectOfLastButton]) < maxViewX) 1722 if (NSMaxX([self finalRectOfLastButton]) < maxViewX)
1679 break; 1723 break;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 if (!themeProvider) 1923 if (!themeProvider)
1880 return; 1924 return;
1881 NSColor* color = 1925 NSColor* color =
1882 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT, 1926 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT,
1883 true); 1927 true);
1884 for (BookmarkButton* button in buttons_.get()) { 1928 for (BookmarkButton* button in buttons_.get()) {
1885 BookmarkButtonCell* cell = [button cell]; 1929 BookmarkButtonCell* cell = [button cell];
1886 [cell setTextColor:color]; 1930 [cell setTextColor:color];
1887 } 1931 }
1888 [[otherBookmarksButton_ cell] setTextColor:color]; 1932 [[otherBookmarksButton_ cell] setTextColor:color];
1933 [[appsPageShortcutButton_ cell] setTextColor:color];
1889 } 1934 }
1890 1935
1891 // Return YES if the event indicates an exit from the bookmark bar 1936 // 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. 1937 // 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 1938 // At this time we are watching the area that includes all popup
1894 // bookmark folder windows. 1939 // bookmark folder windows.
1895 - (BOOL)isEventAnExitEvent:(NSEvent*)event { 1940 - (BOOL)isEventAnExitEvent:(NSEvent*)event {
1896 NSWindow* eventWindow = [event window]; 1941 NSWindow* eventWindow = [event window];
1897 NSWindow* myWindow = [[self view] window]; 1942 NSWindow* myWindow = [[self view] window];
1898 switch ([event type]) { 1943 switch ([event type]) {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
2180 // See: http://crbug.com/36614 2225 // See: http://crbug.com/36614
2181 if (folderController_) 2226 if (folderController_)
2182 [self closeAllBookmarkFolders]; 2227 [self closeAllBookmarkFolders];
2183 2228
2184 // Brute force nuke and build. 2229 // Brute force nuke and build.
2185 savedFrameWidth_ = NSWidth([[self view] frame]); 2230 savedFrameWidth_ = NSWidth([[self view] frame]);
2186 const BookmarkNode* node = model->bookmark_bar_node(); 2231 const BookmarkNode* node = model->bookmark_bar_node();
2187 [self clearBookmarkBar]; 2232 [self clearBookmarkBar];
2188 [self addNodesToButtonList:node]; 2233 [self addNodesToButtonList:node];
2189 [self createOtherBookmarksButton]; 2234 [self createOtherBookmarksButton];
2235 [self createAppsPageShortcutButton];
2190 [self updateTheme:[[[self view] window] themeProvider]]; 2236 [self updateTheme:[[[self view] window] themeProvider]];
2191 [self positionOffTheSideButton]; 2237 [self positionSideButtons];
2192 [self addNonBookmarkButtonsToView];
2193 [self addButtonsToView]; 2238 [self addButtonsToView];
2194 [self configureOffTheSideButtonContentsAndVisibility]; 2239 [self configureOffTheSideButtonContentsAndVisibility];
2195 [self setNodeForBarMenu]; 2240 [self setNodeForBarMenu];
2196 [self reconfigureBookmarkBar]; 2241 [self reconfigureBookmarkBar];
2197 } 2242 }
2198 2243
2199 - (void)beingDeleted:(BookmarkModel*)model { 2244 - (void)beingDeleted:(BookmarkModel*)model {
2200 // The browser may be being torn down; little is safe to do. As an 2245 // 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. 2246 // example, it may not be safe to clear the pasteboard.
2202 // http://crbug.com/38665 2247 // http://crbug.com/38665
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
2843 return buttonContextMenu_; 2888 return buttonContextMenu_;
2844 } 2889 }
2845 2890
2846 // Intentionally ignores ownership issues; used for testing and we try 2891 // Intentionally ignores ownership issues; used for testing and we try
2847 // to minimize touching the object passed in (likely a mock). 2892 // to minimize touching the object passed in (likely a mock).
2848 - (void)setButtonContextMenu:(id)menu { 2893 - (void)setButtonContextMenu:(id)menu {
2849 buttonContextMenu_ = menu; 2894 buttonContextMenu_ = menu;
2850 } 2895 }
2851 2896
2852 @end 2897 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698