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

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: Fixed failing sync-related tests. 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
Alexei Svitkine (slow) 2013/03/08 19:45:48 Remove the comment about the apps page button here
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
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_->profile(), self,
402 bookmarkModel_));
399 } 403 }
400 404
401 // Called by our main view (a BookmarkBarView) when it gets moved to a 405 // Called by our main view (a BookmarkBarView) when it gets moved to a
402 // window. We perform operations which need to know the relevant 406 // 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 407 // window (e.g. watch for a window close) so they can't be performed
404 // earlier (such as in awakeFromNib). 408 // earlier (such as in awakeFromNib).
405 - (void)viewDidMoveToWindow { 409 - (void)viewDidMoveToWindow {
406 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; 410 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
407 411
408 // Remove any existing notifications before registering for new ones. 412 // Remove any existing notifications before registering for new ones.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 [buttonView_ setFrame:buttonViewFrame]; 472 [buttonView_ setFrame:buttonViewFrame];
469 } 473 }
470 474
471 // We don't change a preference; we only change visibility. Preference changing 475 // We don't change a preference; we only change visibility. Preference changing
472 // (global state) is handled in |BrowserWindowCocoa::ToggleBookmarkBar()|. We 476 // (global state) is handled in |BrowserWindowCocoa::ToggleBookmarkBar()|. We
473 // simply update based on what we're told. 477 // simply update based on what we're told.
474 - (void)updateVisibility { 478 - (void)updateVisibility {
475 [self showBookmarkBarWithAnimation:NO]; 479 [self showBookmarkBarWithAnimation:NO];
476 } 480 }
477 481
482 - (void)updateAppsPageShortcutButtonVisibility {
483 [self setAppsPageShortcutButtonVisibility];
484 [self reconfigureBookmarkBar];
485 }
486
478 - (void)updateHiddenState { 487 - (void)updateHiddenState {
479 BOOL oldHidden = [[self view] isHidden]; 488 BOOL oldHidden = [[self view] isHidden];
480 BOOL newHidden = ![self isVisible]; 489 BOOL newHidden = ![self isVisible];
481 if (oldHidden != newHidden) 490 if (oldHidden != newHidden)
482 [[self view] setHidden:newHidden]; 491 [[self view] setHidden:newHidden];
483 } 492 }
484 493
485 - (void)setBookmarkBarEnabled:(BOOL)enabled { 494 - (void)setBookmarkBarEnabled:(BOOL)enabled {
486 if (enabled != barIsEnabled_) { 495 if (enabled != barIsEnabled_) {
487 barIsEnabled_ = enabled; 496 barIsEnabled_ = enabled;
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 DCHECK([[self view] isKindOfClass:[AnimatableView class]]); 886 DCHECK([[self view] isKindOfClass:[AnimatableView class]]);
878 return (AnimatableView*)[self view]; 887 return (AnimatableView*)[self view];
879 } 888 }
880 889
881 - (bookmark_utils::BookmarkLaunchLocation)bookmarkLaunchLocation { 890 - (bookmark_utils::BookmarkLaunchLocation)bookmarkLaunchLocation {
882 return currentState_ == BookmarkBar::DETACHED ? 891 return currentState_ == BookmarkBar::DETACHED ?
883 bookmark_utils::LAUNCH_DETACHED_BAR : 892 bookmark_utils::LAUNCH_DETACHED_BAR :
884 bookmark_utils::LAUNCH_ATTACHED_BAR; 893 bookmark_utils::LAUNCH_ATTACHED_BAR;
885 } 894 }
886 895
887 // Position the off-the-side chevron to the left of the otherBookmarks button, 896 // 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. 897 - (void)positionSideButtons {
889 - (void)positionOffTheSideButton { 898 int maxX = NSMaxX([[self buttonView] bounds]) -
890 NSRect frame = [offTheSideButton_ frame]; 899 bookmarks::kBookmarkHorizontalPadding;
900 int right = maxX;
901
902 int ignored = 0;
903 NSRect frame = [self frameForBookmarkButtonFromCell:
904 [appsPageShortcutButton_ cell] xOffset:&ignored];
905 if (![appsPageShortcutButton_ isHidden]) {
906 right -= NSWidth(frame);
907 frame.origin.x = right;
908 } else {
909 frame.origin.x = maxX - NSWidth(frame);
910 }
911 [appsPageShortcutButton_ setFrame:frame];
912
913 frame = [self frameForBookmarkButtonFromCell:
914 [otherBookmarksButton_ cell] xOffset:&ignored];
915 if (![otherBookmarksButton_ isHidden]) {
916 right -= NSWidth(frame);
917 frame.origin.x = right;
918 } else {
919 frame.origin.x = maxX - NSWidth(frame);
920 }
921 [otherBookmarksButton_ setFrame:frame];
922
923 frame = [offTheSideButton_ frame];
891 frame.size.height = bookmarks::kBookmarkFolderButtonHeight; 924 frame.size.height = bookmarks::kBookmarkFolderButtonHeight;
892 if (otherBookmarksButton_.get() && ![otherBookmarksButton_ isHidden]) { 925 right -= frame.size.width;
893 frame.origin.x = ([otherBookmarksButton_ frame].origin.x - 926 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]; 927 [offTheSideButton_ setFrame:frame];
900 } 928 }
901 929
902 // Configure the off-the-side button (e.g. specify the node range, 930 // Configure the off-the-side button (e.g. specify the node range,
903 // check if we should enable or disable it, etc). 931 // check if we should enable or disable it, etc).
904 - (void)configureOffTheSideButtonContentsAndVisibility { 932 - (void)configureOffTheSideButtonContentsAndVisibility {
905 // If deleting a button while off-the-side is open, buttons may be 933 // If deleting a button while off-the-side is open, buttons may be
906 // promoted from off-the-side to the bar. Accomodate. 934 // promoted from off-the-side to the bar. Accomodate.
907 if (folderController_ && 935 if (folderController_ &&
908 ([folderController_ parentButton] == offTheSideButton_)) { 936 ([folderController_ parentButton] == offTheSideButton_)) {
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 } else { 1367 } else {
1340 // Make the button do something 1368 // Make the button do something
1341 [button setTarget:self]; 1369 [button setTarget:self];
1342 [button setAction:@selector(openBookmark:)]; 1370 [button setAction:@selector(openBookmark:)];
1343 if (node->is_url()) 1371 if (node->is_url())
1344 [button setToolTip:[BookmarkMenuCocoaController tooltipForNode:node]]; 1372 [button setToolTip:[BookmarkMenuCocoaController tooltipForNode:node]];
1345 } 1373 }
1346 return [[button.get() retain] autorelease]; 1374 return [[button.get() retain] autorelease];
1347 } 1375 }
1348 1376
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 1377 // Add bookmark buttons to the view only if they are completely
1362 // visible and don't overlap the "other bookmarks". Remove buttons 1378 // visible and don't overlap the "other bookmarks". Remove buttons
1363 // which are clipped. Called when building the bookmark bar the first time. 1379 // which are clipped. Called when building the bookmark bar the first time.
1364 - (void)addButtonsToView { 1380 - (void)addButtonsToView {
1365 displayedButtonCount_ = 0; 1381 displayedButtonCount_ = 0;
1366 NSMutableArray* buttons = [self buttons]; 1382 NSMutableArray* buttons = [self buttons];
1367 for (NSButton* button in buttons) { 1383 for (NSButton* button in buttons) {
1368 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) - 1384 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) -
1369 bookmarks::kBookmarkHorizontalPadding)) 1385 bookmarks::kBookmarkHorizontalPadding))
1370 break; 1386 break;
(...skipping 12 matching lines...) Expand all
1383 // whether it ended up visible. 1399 // whether it ended up visible.
1384 - (BOOL)setOtherBookmarksButtonVisibility { 1400 - (BOOL)setOtherBookmarksButtonVisibility {
1385 if (!otherBookmarksButton_.get()) 1401 if (!otherBookmarksButton_.get())
1386 return NO; 1402 return NO;
1387 1403
1388 BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty(); 1404 BOOL visible = ![otherBookmarksButton_ bookmarkNode]->empty();
1389 [otherBookmarksButton_ setHidden:!visible]; 1405 [otherBookmarksButton_ setHidden:!visible];
1390 return visible; 1406 return visible;
1391 } 1407 }
1392 1408
1393 // Create the button for "Other Bookmarks" on the right of the bar. 1409 // Shows or hides the Apps button as appropriate, and returns whether it ended
1410 // up visible.
1411 - (BOOL)setAppsPageShortcutButtonVisibility {
1412 if (!appsPageShortcutButton_.get())
1413 return NO;
1414
1415 BOOL visible = bookmarkModel_->IsLoaded() &&
1416 chrome::search::IsInstantExtendedAPIEnabled() &&
1417 browser_->profile()->GetPrefs()->GetBoolean(
1418 prefs::kShowAppsShortcutInBookmarkBar);
1419 [appsPageShortcutButton_ setHidden:!visible];
1420 return visible;
1421 }
1422
1423 // Creates a bookmark bar button that does not correspond to a regular bookmark
1424 // or folder. It is used by the "Other Bookmarks" and the "Apps" buttons.
1425 - (BookmarkButton*)createCustomBookmarksButton:(const BookmarkNode*)node {
1426 NSCell* cell = [self cellForBookmarkNode:node];
1427 BookmarkButton* button = [[BookmarkButton alloc] init];
1428 [[button draggableButton] setDraggable:NO];
1429 [[button draggableButton] setActsOnMouseDown:YES];
1430 // Peg at right; keep same height as bar.
1431 [button setAutoresizingMask:(NSViewMinXMargin)];
1432 [button setCell:cell];
1433 [button setDelegate:self];
1434 [button setTarget:self];
1435 // Make sure this button, like all other BookmarkButtons, lives
1436 // until the end of the current event loop.
1437 [[button retain] autorelease];
1438 return button;
1439 }
1440
1441 // Create the button for "Other Bookmarks", but does not position it.
1394 - (void)createOtherBookmarksButton { 1442 - (void)createOtherBookmarksButton {
1395 // Can't create this until the model is loaded, but only need to 1443 // Can't create this until the model is loaded, but only need to
1396 // create it once. 1444 // create it once.
1397 if (otherBookmarksButton_.get()) { 1445 if (otherBookmarksButton_.get()) {
1398 [self setOtherBookmarksButtonVisibility]; 1446 [self setOtherBookmarksButtonVisibility];
1399 return; 1447 return;
1400 } 1448 }
1401 1449
1402 // TODO(jrg): remove duplicate code 1450 otherBookmarksButton_.reset(
1403 NSCell* cell = [self cellForBookmarkNode:bookmarkModel_->other_node()]; 1451 [self createCustomBookmarksButton:bookmarkModel_->other_node()]);
1404 int ignored = 0; 1452 [otherBookmarksButton_ setAction:@selector(openBookmarkFolderFromButton:)];
1405 NSRect frame = [self frameForBookmarkButtonFromCell:cell xOffset:&ignored]; 1453 view_id_util::SetID(otherBookmarksButton_.get(), VIEW_ID_OTHER_BOOKMARKS);
1406 frame.origin.x = [[self buttonView] bounds].size.width - frame.size.width; 1454 [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 1455
1426 [self setOtherBookmarksButtonVisibility]; 1456 [self setOtherBookmarksButtonVisibility];
1457 }
1427 1458
1428 // Now that it's here, move the chevron over. 1459 // Create the button for "Apps", but does not position it.
1429 [self positionOffTheSideButton]; 1460 - (void)createAppsPageShortcutButton {
1461 // Can't create this until the model is loaded, but only need to
1462 // create it once.
1463 if (appsPageShortcutButton_.get()) {
1464 [self setAppsPageShortcutButtonVisibility];
1465 return;
1466 }
1467
1468 appsPageShortcutButton_.reset(
1469 [self createCustomBookmarksButton:bookmarkModel_->apps_node()]);
1470 [appsPageShortcutButton_ setAction:@selector(openAppsPage:)];
1471 NSString* tooltip =
1472 l10n_util::GetNSString(IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP);
1473 [appsPageShortcutButton_ setToolTip:tooltip];
1474 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1475 [appsPageShortcutButton_ setImage:
1476 rb.GetNativeImageNamed(IDR_WEBSTORE_ICON_16).ToNSImage()];
1477 [buttonView_ addSubview:appsPageShortcutButton_.get()];
1478
1479 [self setAppsPageShortcutButtonVisibility];
1480 }
1481
1482 - (IBAction)openAppsPage:(id)sender {
1483 chrome::ShowAppLauncherPage(browser_);
1484 bookmark_utils::RecordAppsPageOpen([self bookmarkLaunchLocation]);
1430 } 1485 }
1431 1486
1432 // Now that the model is loaded, set the bookmark bar root as the node 1487 // Now that the model is loaded, set the bookmark bar root as the node
1433 // represented by the bookmark bar (default, background) menu. 1488 // represented by the bookmark bar (default, background) menu.
1434 - (void)setNodeForBarMenu { 1489 - (void)setNodeForBarMenu {
1435 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); 1490 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node();
1436 BookmarkMenu* menu = static_cast<BookmarkMenu*>([[self view] menu]); 1491 BookmarkMenu* menu = static_cast<BookmarkMenu*>([[self view] menu]);
1437 1492
1438 // Make sure types are compatible 1493 // Make sure types are compatible
1439 DCHECK(sizeof(long long) == sizeof(int64)); 1494 DCHECK(sizeof(long long) == sizeof(int64));
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 } 1592 }
1538 1593
1539 // Delegate method for |AnimatableView| (a superclass of 1594 // Delegate method for |AnimatableView| (a superclass of
1540 // |BookmarkBarToolbarView|). 1595 // |BookmarkBarToolbarView|).
1541 - (void)animationDidEnd:(NSAnimation*)animation { 1596 - (void)animationDidEnd:(NSAnimation*)animation {
1542 [self finalizeState]; 1597 [self finalizeState];
1543 } 1598 }
1544 1599
1545 - (void)reconfigureBookmarkBar { 1600 - (void)reconfigureBookmarkBar {
1546 [self redistributeButtonsOnBarAsNeeded]; 1601 [self redistributeButtonsOnBarAsNeeded];
1547 [self positionOffTheSideButton]; 1602 [self positionSideButtons];
1548 [self configureOffTheSideButtonContentsAndVisibility]; 1603 [self configureOffTheSideButtonContentsAndVisibility];
1549 [self centerNoItemsLabel]; 1604 [self centerNoItemsLabel];
1550 } 1605 }
1551 1606
1552 // Determine if the given |view| can completely fit within the constraint of 1607 // 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 1608 // 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 1609 // width. If the minimum width is not achievable then hide the view. Return YES
1555 // if the view was hidden. 1610 // if the view was hidden.
1556 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX { 1611 - (BOOL)shrinkOrHideView:(NSView*)view forMaxX:(CGFloat)maxViewX {
1557 BOOL wasHidden = NO; 1612 BOOL wasHidden = NO;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 1693
1639 // Calculates the final position of the last button in the bar. 1694 // Calculates the final position of the last button in the bar.
1640 // We can't just use [[self buttons] lastObject] frame] because the button 1695 // We can't just use [[self buttons] lastObject] frame] because the button
1641 // may be animating currently. 1696 // may be animating currently.
1642 - (NSRect)finalRectOfLastButton { 1697 - (NSRect)finalRectOfLastButton {
1643 return [self finalRectOfButton:[[self buttons] lastObject]]; 1698 return [self finalRectOfButton:[[self buttons] lastObject]];
1644 } 1699 }
1645 1700
1646 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible { 1701 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible {
1647 CGFloat maxViewX = NSMaxX([buttonView_ bounds]); 1702 CGFloat maxViewX = NSMaxX([buttonView_ bounds]);
1648 // If necessary, pull in the width to account for the Other Bookmarks button. 1703 // If necessary, pull in the width to account for the Other Bookmarks or Apps
1649 if ([self setOtherBookmarksButtonVisibility]) { 1704 // button.
1650 maxViewX = [otherBookmarksButton_.get() frame].origin.x - 1705 const BOOL otherButtonVisible = [self setOtherBookmarksButtonVisibility];
1706 const BOOL appsButtonVisible = [self setAppsPageShortcutButtonVisibility];
1707 if (otherButtonVisible || appsButtonVisible) {
1708 BookmarkButton* leftMostRightAlignedButton = otherButtonVisible ?
1709 otherBookmarksButton_.get() : appsPageShortcutButton_.get();
1710 maxViewX = [leftMostRightAlignedButton frame].origin.x -
1651 bookmarks::kBookmarkRightMargin; 1711 bookmarks::kBookmarkRightMargin;
1652 } 1712 }
1653 1713
1654 [self positionOffTheSideButton]; 1714 [self positionSideButtons];
1655 // If we're already overflowing, then we need to account for the chevron. 1715 // If we're already overflowing, then we need to account for the chevron.
1656 if (visible) { 1716 if (visible) {
1657 maxViewX = 1717 maxViewX =
1658 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin; 1718 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin;
1659 } 1719 }
1660 1720
1661 return maxViewX; 1721 return maxViewX;
1662 } 1722 }
1663 1723
1664 - (void)redistributeButtonsOnBarAsNeeded { 1724 - (void)redistributeButtonsOnBarAsNeeded {
1665 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); 1725 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node();
1666 NSInteger barCount = node->child_count(); 1726 NSInteger barCount = node->child_count();
1667 1727
1668 // Determine the current maximum extent of the visible buttons. 1728 // Determine the current maximum extent of the visible buttons.
1669 [self positionOffTheSideButton]; 1729 [self positionSideButtons];
1670 CGFloat maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible: 1730 CGFloat maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:
1671 (barCount > displayedButtonCount_)]; 1731 (barCount > displayedButtonCount_)];
1672 1732
1673 // As a result of pasting or dragging, the bar may now have more buttons 1733 // 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 1734 // than will fit so remove any which overflow. They will be shown in
1675 // the off-the-side folder. 1735 // the off-the-side folder.
1676 while (displayedButtonCount_ > 0) { 1736 while (displayedButtonCount_ > 0) {
1677 BookmarkButton* button = [buttons_ lastObject]; 1737 BookmarkButton* button = [buttons_ lastObject];
1678 if (NSMaxX([self finalRectOfLastButton]) < maxViewX) 1738 if (NSMaxX([self finalRectOfLastButton]) < maxViewX)
1679 break; 1739 break;
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1879 if (!themeProvider) 1939 if (!themeProvider)
1880 return; 1940 return;
1881 NSColor* color = 1941 NSColor* color =
1882 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT, 1942 themeProvider->GetNSColor(ThemeProperties::COLOR_BOOKMARK_TEXT,
1883 true); 1943 true);
1884 for (BookmarkButton* button in buttons_.get()) { 1944 for (BookmarkButton* button in buttons_.get()) {
1885 BookmarkButtonCell* cell = [button cell]; 1945 BookmarkButtonCell* cell = [button cell];
1886 [cell setTextColor:color]; 1946 [cell setTextColor:color];
1887 } 1947 }
1888 [[otherBookmarksButton_ cell] setTextColor:color]; 1948 [[otherBookmarksButton_ cell] setTextColor:color];
1949 [[appsPageShortcutButton_ cell] setTextColor:color];
1889 } 1950 }
1890 1951
1891 // Return YES if the event indicates an exit from the bookmark bar 1952 // 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. 1953 // 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 1954 // At this time we are watching the area that includes all popup
1894 // bookmark folder windows. 1955 // bookmark folder windows.
1895 - (BOOL)isEventAnExitEvent:(NSEvent*)event { 1956 - (BOOL)isEventAnExitEvent:(NSEvent*)event {
1896 NSWindow* eventWindow = [event window]; 1957 NSWindow* eventWindow = [event window];
1897 NSWindow* myWindow = [[self view] window]; 1958 NSWindow* myWindow = [[self view] window];
1898 switch ([event type]) { 1959 switch ([event type]) {
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
2180 // See: http://crbug.com/36614 2241 // See: http://crbug.com/36614
2181 if (folderController_) 2242 if (folderController_)
2182 [self closeAllBookmarkFolders]; 2243 [self closeAllBookmarkFolders];
2183 2244
2184 // Brute force nuke and build. 2245 // Brute force nuke and build.
2185 savedFrameWidth_ = NSWidth([[self view] frame]); 2246 savedFrameWidth_ = NSWidth([[self view] frame]);
2186 const BookmarkNode* node = model->bookmark_bar_node(); 2247 const BookmarkNode* node = model->bookmark_bar_node();
2187 [self clearBookmarkBar]; 2248 [self clearBookmarkBar];
2188 [self addNodesToButtonList:node]; 2249 [self addNodesToButtonList:node];
2189 [self createOtherBookmarksButton]; 2250 [self createOtherBookmarksButton];
2251 [self createAppsPageShortcutButton];
2190 [self updateTheme:[[[self view] window] themeProvider]]; 2252 [self updateTheme:[[[self view] window] themeProvider]];
2191 [self positionOffTheSideButton]; 2253 [self positionSideButtons];
2192 [self addNonBookmarkButtonsToView];
2193 [self addButtonsToView]; 2254 [self addButtonsToView];
2194 [self configureOffTheSideButtonContentsAndVisibility]; 2255 [self configureOffTheSideButtonContentsAndVisibility];
2195 [self setNodeForBarMenu]; 2256 [self setNodeForBarMenu];
2196 [self reconfigureBookmarkBar]; 2257 [self reconfigureBookmarkBar];
2197 } 2258 }
2198 2259
2199 - (void)beingDeleted:(BookmarkModel*)model { 2260 - (void)beingDeleted:(BookmarkModel*)model {
2200 // The browser may be being torn down; little is safe to do. As an 2261 // 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. 2262 // example, it may not be safe to clear the pasteboard.
2202 // http://crbug.com/38665 2263 // http://crbug.com/38665
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
2843 return buttonContextMenu_; 2904 return buttonContextMenu_;
2844 } 2905 }
2845 2906
2846 // Intentionally ignores ownership issues; used for testing and we try 2907 // Intentionally ignores ownership issues; used for testing and we try
2847 // to minimize touching the object passed in (likely a mock). 2908 // to minimize touching the object passed in (likely a mock).
2848 - (void)setButtonContextMenu:(id)menu { 2909 - (void)setButtonContextMenu:(id)menu {
2849 buttonContextMenu_ = menu; 2910 buttonContextMenu_ = menu;
2850 } 2911 }
2851 2912
2852 @end 2913 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/bookmarks/bookmark_bar_controller.h ('k') | chrome/browser/ui/views/bookmarks/bookmark_bar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698