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 1986963004: Revert of [Mac][Material Design] Update bookmarks bar to Material Design. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #import "base/mac/bundle_locations.h" 9 #import "base/mac/bundle_locations.h"
10 #import "base/mac/foundation_util.h" 10 #import "base/mac/foundation_util.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #include "content/public/browser/user_metrics.h" 60 #include "content/public/browser/user_metrics.h"
61 #include "content/public/browser/web_contents.h" 61 #include "content/public/browser/web_contents.h"
62 #include "extensions/browser/extension_registry.h" 62 #include "extensions/browser/extension_registry.h"
63 #include "extensions/common/extension.h" 63 #include "extensions/common/extension.h"
64 #include "extensions/common/extension_set.h" 64 #include "extensions/common/extension_set.h"
65 #include "grit/theme_resources.h" 65 #include "grit/theme_resources.h"
66 #include "ui/base/clipboard/clipboard_util_mac.h" 66 #include "ui/base/clipboard/clipboard_util_mac.h"
67 #import "ui/base/cocoa/cocoa_base_utils.h" 67 #import "ui/base/cocoa/cocoa_base_utils.h"
68 #import "ui/base/cocoa/nsview_additions.h" 68 #import "ui/base/cocoa/nsview_additions.h"
69 #include "ui/base/l10n/l10n_util_mac.h" 69 #include "ui/base/l10n/l10n_util_mac.h"
70 #include "ui/base/material_design/material_design_controller.h"
71 #include "ui/base/resource/resource_bundle.h" 70 #include "ui/base/resource/resource_bundle.h"
72 #include "ui/gfx/color_palette.h"
73 #include "ui/gfx/image/image.h" 71 #include "ui/gfx/image/image.h"
74 #include "ui/gfx/image/image_skia_util_mac.h"
75 #include "ui/gfx/paint_vector_icon.h"
76 #include "ui/gfx/vector_icons_public.h"
77 #include "ui/resources/grit/ui_resources.h" 72 #include "ui/resources/grit/ui_resources.h"
78 73
79 using base::UserMetricsAction; 74 using base::UserMetricsAction;
80 using bookmarks::BookmarkModel; 75 using bookmarks::BookmarkModel;
81 using bookmarks::BookmarkNode; 76 using bookmarks::BookmarkNode;
82 using bookmarks::BookmarkNodeData; 77 using bookmarks::BookmarkNodeData;
83 using content::OpenURLParams; 78 using content::OpenURLParams;
84 using content::Referrer; 79 using content::Referrer;
85 using content::WebContents; 80 using content::WebContents;
86 81
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 - (void)createOtherBookmarksButton; 237 - (void)createOtherBookmarksButton;
243 - (void)createAppsPageShortcutButton; 238 - (void)createAppsPageShortcutButton;
244 - (void)openAppsPage:(id)sender; 239 - (void)openAppsPage:(id)sender;
245 - (void)centerNoItemsLabel; 240 - (void)centerNoItemsLabel;
246 - (void)positionRightSideButtons; 241 - (void)positionRightSideButtons;
247 - (void)watchForExitEvent:(BOOL)watch; 242 - (void)watchForExitEvent:(BOOL)watch;
248 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate; 243 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate;
249 244
250 @end 245 @end
251 246
252 namespace bookmarks {
253
254 CGFloat BookmarkHorizontalPadding() {
255 if (!ui::MaterialDesignController::IsModeMaterial()) {
256 return 1.0;
257 }
258 return 16.0;
259 }
260
261 CGFloat BookmarkVerticalPadding() {
262 if (!ui::MaterialDesignController::IsModeMaterial()) {
263 return 2.0;
264 }
265 return 4.0;
266 }
267
268 CGFloat BookmarkLeftMargin() {
269 if (!ui::MaterialDesignController::IsModeMaterial()) {
270 return 2.0;
271 }
272 return 10.0;
273 }
274
275 CGFloat BookmarkRightMargin() {
276 if (!ui::MaterialDesignController::IsModeMaterial()) {
277 return 2.0;
278 }
279 return 10.0;
280 }
281
282 } // namespace bookmarks
283
284 @implementation BookmarkBarController 247 @implementation BookmarkBarController
285 248
286 @synthesize currentState = currentState_; 249 @synthesize currentState = currentState_;
287 @synthesize lastState = lastState_; 250 @synthesize lastState = lastState_;
288 @synthesize isAnimationRunning = isAnimationRunning_; 251 @synthesize isAnimationRunning = isAnimationRunning_;
289 @synthesize delegate = delegate_; 252 @synthesize delegate = delegate_;
290 @synthesize stateAnimationsEnabled = stateAnimationsEnabled_; 253 @synthesize stateAnimationsEnabled = stateAnimationsEnabled_;
291 @synthesize innerContentAnimationsEnabled = innerContentAnimationsEnabled_; 254 @synthesize innerContentAnimationsEnabled = innerContentAnimationsEnabled_;
292 255
293 - (id)initWithBrowser:(Browser*)browser 256 - (id)initWithBrowser:(Browser*)browser
(...skipping 11 matching lines...) Expand all
305 ManagedBookmarkServiceFactory::GetForProfile(browser_->profile()); 268 ManagedBookmarkServiceFactory::GetForProfile(browser_->profile());
306 buttons_.reset([[NSMutableArray alloc] init]); 269 buttons_.reset([[NSMutableArray alloc] init]);
307 delegate_ = delegate; 270 delegate_ = delegate;
308 folderTarget_.reset( 271 folderTarget_.reset(
309 [[BookmarkFolderTarget alloc] initWithController:self 272 [[BookmarkFolderTarget alloc] initWithController:self
310 profile:browser_->profile()]); 273 profile:browser_->profile()]);
311 274
312 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 275 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
313 folderImage_.reset( 276 folderImage_.reset(
314 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER).CopyNSImage()); 277 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER).CopyNSImage());
315 if (ui::MaterialDesignController::IsModeMaterial()) {
316 folderImageWhite_.reset(
317 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER_WHITE).CopyNSImage());
318 }
319 defaultImage_.reset( 278 defaultImage_.reset(
320 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage()); 279 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage());
321 280
322 innerContentAnimationsEnabled_ = YES; 281 innerContentAnimationsEnabled_ = YES;
323 stateAnimationsEnabled_ = YES; 282 stateAnimationsEnabled_ = YES;
324 283
325 // Register for theme changes, bookmark button pulsing, ... 284 // Register for theme changes, bookmark button pulsing, ...
326 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; 285 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
327 [defaultCenter addObserver:self 286 [defaultCenter addObserver:self
328 selector:@selector(themeDidChangeNotification:) 287 selector:@selector(themeDidChangeNotification:)
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 return; 418 return;
460 } 419 }
461 420
462 // We default to NOT open, which means height=0. 421 // We default to NOT open, which means height=0.
463 DCHECK([[self view] isHidden]); // Hidden so it's OK to change. 422 DCHECK([[self view] isHidden]); // Hidden so it's OK to change.
464 423
465 // Set our initial height to zero, since that is what the superview 424 // Set our initial height to zero, since that is what the superview
466 // expects. We will resize ourselves open later if needed. 425 // expects. We will resize ourselves open later if needed.
467 [[self view] setFrame:NSMakeRect(0, 0, initialWidth_, 0)]; 426 [[self view] setFrame:NSMakeRect(0, 0, initialWidth_, 0)];
468 427
469 const bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial();
470
471 // Complete init of the "off the side" button, as much as we can. 428 // Complete init of the "off the side" button, as much as we can.
472 if (isModeMaterial) { 429 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
473 [offTheSideButton_ setImage:[self offTheSideButtonImage:NO]]; 430 [offTheSideButton_ setImage:
474 BookmarkButtonCell* offTheSideCell = [offTheSideButton_ cell]; 431 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_CHEVRONS).ToNSImage()];
475 [offTheSideCell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback]; 432 [offTheSideButton_.draggableButton setDraggable:NO];
476 [offTheSideCell setImagePosition:NSImageOnly]; 433 [offTheSideButton_.draggableButton setActsOnMouseDown:YES];
477 } else {
478 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
479 [offTheSideButton_ setImage:
480 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_CHEVRONS).ToNSImage()];
481 [offTheSideButton_.draggableButton setDraggable:NO];
482 [offTheSideButton_.draggableButton setActsOnMouseDown:YES];
483 }
484 434
485 // We are enabled by default. 435 // We are enabled by default.
486 barIsEnabled_ = YES; 436 barIsEnabled_ = YES;
487 437
488 // Remember the original sizes of the 'no items' and 'import bookmarks' 438 // Remember the original sizes of the 'no items' and 'import bookmarks'
489 // fields to aid in resizing when the window frame changes. 439 // fields to aid in resizing when the window frame changes.
490 originalNoItemsRect_ = [[buttonView_ noItemTextfield] frame]; 440 originalNoItemsRect_ = [[buttonView_ noItemTextfield] frame];
491 originalImportBookmarksRect_ = [[buttonView_ importBookmarksButton] frame]; 441 originalImportBookmarksRect_ = [[buttonView_ importBookmarksButton] frame];
492 if (isModeMaterial) {
493 // Bookmark buttons are shorter and start farther from the bookmark bar's
494 // left edge so adjust the positions of the noItems and importBookmarks
495 // textfields.
496 const CGFloat kMaterialBookmarksTextfieldOffsetX = 14;
497 const CGFloat kMaterialBookmarksTextfieldOffsetY = -2;
498 originalNoItemsRect_.origin =
499 NSOffsetRect(originalNoItemsRect_,
500 kMaterialBookmarksTextfieldOffsetX,
501 kMaterialBookmarksTextfieldOffsetY).origin;
502 [[buttonView_ noItemTextfield] setFrame:originalNoItemsRect_];
503
504 originalImportBookmarksRect_.origin =
505 NSOffsetRect(originalImportBookmarksRect_,
506 kMaterialBookmarksTextfieldOffsetX,
507 kMaterialBookmarksTextfieldOffsetY).origin;
508 [[buttonView_ importBookmarksButton] setFrame:originalImportBookmarksRect_];
509 }
510 442
511 // To make life happier when the bookmark bar is floating, the chevron is a 443 // To make life happier when the bookmark bar is floating, the chevron is a
512 // child of the button view. 444 // child of the button view.
513 [offTheSideButton_ removeFromSuperview]; 445 [offTheSideButton_ removeFromSuperview];
514 [buttonView_ addSubview:offTheSideButton_]; 446 [buttonView_ addSubview:offTheSideButton_];
515 447
516 // When resized we may need to add new buttons, or remove them (if 448 // When resized we may need to add new buttons, or remove them (if
517 // no longer visible), or add/remove the "off the side" menu. 449 // no longer visible), or add/remove the "off the side" menu.
518 [[self view] setPostsFrameChangedNotifications:YES]; 450 [[self view] setPostsFrameChangedNotifications:YES];
519 [[NSNotificationCenter defaultCenter] 451 [[NSNotificationCenter defaultCenter]
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 526
595 // Change the layout of the bookmark bar's subviews in response to a visibility 527 // Change the layout of the bookmark bar's subviews in response to a visibility
596 // change (e.g., show or hide the bar) or style change (attached or floating). 528 // change (e.g., show or hide the bar) or style change (attached or floating).
597 - (void)layoutSubviews { 529 - (void)layoutSubviews {
598 NSRect frame = [[self view] frame]; 530 NSRect frame = [[self view] frame];
599 NSRect buttonViewFrame = NSMakeRect(0, 0, NSWidth(frame), NSHeight(frame)); 531 NSRect buttonViewFrame = NSMakeRect(0, 0, NSWidth(frame), NSHeight(frame));
600 532
601 // Add padding to the detached bookmark bar. 533 // Add padding to the detached bookmark bar.
602 // The state of our morph (if any); 1 is total bubble, 0 is the regular bar. 534 // The state of our morph (if any); 1 is total bubble, 0 is the regular bar.
603 CGFloat morph = [self detachedMorphProgress]; 535 CGFloat morph = [self detachedMorphProgress];
604 CGFloat padding = 0; 536 CGFloat padding = bookmarks::kNTPBookmarkBarPadding;
605 if (ui::MaterialDesignController::IsModeMaterial()) {
606 padding = bookmarks::kMaterialNTPBookmarkBarPadding;
607 } else {
608 padding = bookmarks::kNTPBookmarkBarPadding;
609 }
610 buttonViewFrame = 537 buttonViewFrame =
611 NSInsetRect(buttonViewFrame, morph * padding, morph * padding); 538 NSInsetRect(buttonViewFrame, morph * padding, morph * padding);
612 539
613 [buttonView_ setFrame:buttonViewFrame]; 540 [buttonView_ setFrame:buttonViewFrame];
614 541
615 // Update bookmark button backgrounds. 542 // Update bookmark button backgrounds.
616 if ([self isAnimationRunning]) { 543 if ([self isAnimationRunning]) {
617 for (NSButton* button in buttons_.get()) 544 for (NSButton* button in buttons_.get())
618 [button setNeedsDisplay:YES]; 545 [button setNeedsDisplay:YES];
619 // Update the apps and other buttons explicitly, since they are not in the 546 // Update the apps and other buttons explicitly, since they are not in the
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 andState:BookmarkBar::DETACHED]) 623 andState:BookmarkBar::DETACHED])
697 return static_cast<CGFloat>([self detachedMorphProgress]); 624 return static_cast<CGFloat>([self detachedMorphProgress]);
698 625
699 // If we ever need any other animation cases, code would go here. 626 // If we ever need any other animation cases, code would go here.
700 } 627 }
701 628
702 // In general, only show the divider when it's in the normal showing state. 629 // In general, only show the divider when it's in the normal showing state.
703 return [self isInState:BookmarkBar::SHOW] ? 0 : 1; 630 return [self isInState:BookmarkBar::SHOW] ? 0 : 1;
704 } 631 }
705 632
706 - (NSImage*)faviconForNode:(const BookmarkNode*)node 633 - (NSImage*)faviconForNode:(const BookmarkNode*)node {
707 forADarkTheme:(BOOL)forADarkTheme {
708 if (!node) 634 if (!node)
709 return defaultImage_; 635 return defaultImage_;
710 636
711 if (forADarkTheme && ui::MaterialDesignController::IsModeMaterial()) { 637 if (node == managedBookmarkService_->managed_node()) {
712 if (node == managedBookmarkService_->managed_node()) { 638 // Most users never see this node, so the image is only loaded if needed.
713 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 639 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
714 return rb.GetNativeImageNamed( 640 return rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER_MANAGED).ToNSImage();
715 IDR_BOOKMARK_BAR_FOLDER_MANAGED_WHITE).ToNSImage(); 641 }
716 }
717 642
718 if (node == managedBookmarkService_->supervised_node()) { 643 if (node == managedBookmarkService_->supervised_node()) {
719 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 644 // Most users never see this node, so the image is only loaded if needed.
720 return rb.GetNativeImageNamed( 645 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
721 IDR_BOOKMARK_BAR_FOLDER_SUPERVISED_WHITE).ToNSImage(); 646 return rb.GetNativeImageNamed(
722 } 647 IDR_BOOKMARK_BAR_FOLDER_SUPERVISED).ToNSImage();
648 }
723 649
724 if (node->is_folder()) 650 if (node->is_folder())
725 return folderImageWhite_; 651 return folderImage_;
726 } else {
727 if (node == managedBookmarkService_->managed_node()) {
728 // Most users never see this node, so the image is only loaded if needed.
729 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
730 return rb.GetNativeImageNamed(
731 IDR_BOOKMARK_BAR_FOLDER_MANAGED).ToNSImage();
732 }
733
734 if (node == managedBookmarkService_->supervised_node()) {
735 // Most users never see this node, so the image is only loaded if needed.
736 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
737 return rb.GetNativeImageNamed(
738 IDR_BOOKMARK_BAR_FOLDER_SUPERVISED).ToNSImage();
739 }
740
741 if (node->is_folder())
742 return folderImage_;
743 }
744 652
745 const gfx::Image& favicon = bookmarkModel_->GetFavicon(node); 653 const gfx::Image& favicon = bookmarkModel_->GetFavicon(node);
746 if (!favicon.IsEmpty()) 654 if (!favicon.IsEmpty())
747 return favicon.ToNSImage(); 655 return favicon.ToNSImage();
748 656
749 return defaultImage_; 657 return defaultImage_;
750 } 658 }
751 659
752 - (void)closeFolderAndStopTrackingMenus { 660 - (void)closeFolderAndStopTrackingMenus {
753 showFolderMenus_ = NO; 661 showFolderMenus_ = NO;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 // Click on the "off the side" button (chevron), which opens like a folder 804 // Click on the "off the side" button (chevron), which opens like a folder
897 // button but isn't exactly a parent folder. 805 // button but isn't exactly a parent folder.
898 - (IBAction)openOffTheSideFolderFromButton:(id)sender { 806 - (IBAction)openOffTheSideFolderFromButton:(id)sender {
899 [self openBookmarkFolder:sender]; 807 [self openBookmarkFolder:sender];
900 } 808 }
901 809
902 - (IBAction)importBookmarks:(id)sender { 810 - (IBAction)importBookmarks:(id)sender {
903 chrome::ShowImportDialog(browser_); 811 chrome::ShowImportDialog(browser_);
904 } 812 }
905 813
906 - (NSButton*)offTheSideButton {
907 return offTheSideButton_;
908 }
909
910 - (NSImage*)offTheSideButtonImage:(BOOL)forDarkMode {
911 const int kIconSize = 16;
912 SkColor vectorIconColor = forDarkMode ? SkColorSetA(SK_ColorWHITE, 0xCC)
913 : gfx::kChromeIconGrey;
914 return NSImageFromImageSkia(
915 gfx::CreateVectorIcon(gfx::VectorIconId::OVERFLOW_CHEVRON,
916 kIconSize,
917 vectorIconColor));
918 }
919
920 #pragma mark Private Methods 814 #pragma mark Private Methods
921 815
922 // Called after a theme change took place, possibly for a different profile. 816 // Called after a theme change took place, possibly for a different profile.
923 - (void)themeDidChangeNotification:(NSNotification*)notification { 817 - (void)themeDidChangeNotification:(NSNotification*)notification {
924 [self updateTheme:[[[self view] window] themeProvider]]; 818 [self updateTheme:[[[self view] window] themeProvider]];
925 } 819 }
926 820
927 - (BookmarkLaunchLocation)bookmarkLaunchLocation { 821 - (BookmarkLaunchLocation)bookmarkLaunchLocation {
928 return currentState_ == BookmarkBar::DETACHED ? 822 return currentState_ == BookmarkBar::DETACHED ?
929 BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR : 823 BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR :
930 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR; 824 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR;
931 } 825 }
932 826
933 // Position the right-side buttons including the off-the-side chevron. 827 // Position the right-side buttons including the off-the-side chevron.
934 - (void)positionRightSideButtons { 828 - (void)positionRightSideButtons {
935 int maxX = NSMaxX([[self buttonView] bounds]) - 829 int maxX = NSMaxX([[self buttonView] bounds]) -
936 bookmarks::BookmarkHorizontalPadding(); 830 bookmarks::kBookmarkHorizontalPadding;
937 int right = maxX; 831 int right = maxX;
938 832
939 int ignored = 0; 833 int ignored = 0;
940 NSRect frame = [self frameForBookmarkButtonFromCell: 834 NSRect frame = [self frameForBookmarkButtonFromCell:
941 [otherBookmarksButton_ cell] xOffset:&ignored]; 835 [otherBookmarksButton_ cell] xOffset:&ignored];
942 if (![otherBookmarksButton_ isHidden]) { 836 if (![otherBookmarksButton_ isHidden]) {
943 right -= NSWidth(frame); 837 right -= NSWidth(frame);
944 frame.origin.x = right; 838 frame.origin.x = right;
945 } else { 839 } else {
946 frame.origin.x = maxX - NSWidth(frame); 840 frame.origin.x = maxX - NSWidth(frame);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 } 1045 }
1152 1046
1153 // Recursively add the given bookmark node and all its children to 1047 // Recursively add the given bookmark node and all its children to
1154 // menu, one menu item per node. 1048 // menu, one menu item per node.
1155 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu { 1049 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu {
1156 NSString* title = [BookmarkMenuCocoaController menuTitleForNode:child]; 1050 NSString* title = [BookmarkMenuCocoaController menuTitleForNode:child];
1157 NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title 1051 NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title
1158 action:nil 1052 action:nil
1159 keyEquivalent:@""] autorelease]; 1053 keyEquivalent:@""] autorelease];
1160 [menu addItem:item]; 1054 [menu addItem:item];
1161 [item setImage:[self faviconForNode:child forADarkTheme:NO]]; 1055 [item setImage:[self faviconForNode:child]];
1162 if (child->is_folder()) { 1056 if (child->is_folder()) {
1163 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease]; 1057 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease];
1164 [menu setSubmenu:submenu forItem:item]; 1058 [menu setSubmenu:submenu forItem:item];
1165 if (!child->empty()) { 1059 if (!child->empty()) {
1166 [self addFolderNode:child toMenu:submenu]; // potentially recursive 1060 [self addFolderNode:child toMenu:submenu]; // potentially recursive
1167 } else { 1061 } else {
1168 [self tagEmptyMenu:submenu]; 1062 [self tagEmptyMenu:submenu];
1169 } 1063 }
1170 } else { 1064 } else {
1171 [item setTarget:self]; 1065 [item setTarget:self];
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 } 1131 }
1238 1132
1239 // TODO(jrg): write a "build bar" so there is a nice spot for things 1133 // TODO(jrg): write a "build bar" so there is a nice spot for things
1240 // like the contextual menu which is invoked when not over a 1134 // like the contextual menu which is invoked when not over a
1241 // bookmark. On Safari that menu has a "new folder" option. 1135 // bookmark. On Safari that menu has a "new folder" option.
1242 - (void)addNodesToButtonList:(const BookmarkNode*)node { 1136 - (void)addNodesToButtonList:(const BookmarkNode*)node {
1243 [self showOrHideNoItemContainerForNode:node]; 1137 [self showOrHideNoItemContainerForNode:node];
1244 1138
1245 CGFloat maxViewX = NSMaxX([[self view] bounds]); 1139 CGFloat maxViewX = NSMaxX([[self view] bounds]);
1246 int xOffset = 1140 int xOffset =
1247 bookmarks::BookmarkLeftMargin() - bookmarks::BookmarkHorizontalPadding(); 1141 bookmarks::kBookmarkLeftMargin - bookmarks::kBookmarkHorizontalPadding;
1248 1142
1249 // Draw the apps bookmark if needed. 1143 // Draw the apps bookmark if needed.
1250 if (![appsPageShortcutButton_ isHidden]) { 1144 if (![appsPageShortcutButton_ isHidden]) {
1251 NSRect frame = 1145 NSRect frame =
1252 [self frameForBookmarkButtonFromCell:[appsPageShortcutButton_ cell] 1146 [self frameForBookmarkButtonFromCell:[appsPageShortcutButton_ cell]
1253 xOffset:&xOffset]; 1147 xOffset:&xOffset];
1254 [appsPageShortcutButton_ setFrame:frame]; 1148 [appsPageShortcutButton_ setFrame:frame];
1255 } 1149 }
1256 1150
1257 // Draw the managed bookmark folder if needed. 1151 // Draw the managed bookmark folder if needed.
1258 if (![managedBookmarksButton_ isHidden]) { 1152 if (![managedBookmarksButton_ isHidden]) {
1259 xOffset += bookmarks::BookmarkHorizontalPadding(); 1153 xOffset += bookmarks::kBookmarkHorizontalPadding;
1260 NSRect frame = 1154 NSRect frame =
1261 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell] 1155 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell]
1262 xOffset:&xOffset]; 1156 xOffset:&xOffset];
1263 [managedBookmarksButton_ setFrame:frame]; 1157 [managedBookmarksButton_ setFrame:frame];
1264 } 1158 }
1265 1159
1266 // Draw the supervised bookmark folder if needed. 1160 // Draw the supervised bookmark folder if needed.
1267 if (![supervisedBookmarksButton_ isHidden]) { 1161 if (![supervisedBookmarksButton_ isHidden]) {
1268 xOffset += bookmarks::BookmarkHorizontalPadding(); 1162 xOffset += bookmarks::kBookmarkHorizontalPadding;
1269 NSRect frame = 1163 NSRect frame =
1270 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell] 1164 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell]
1271 xOffset:&xOffset]; 1165 xOffset:&xOffset];
1272 [supervisedBookmarksButton_ setFrame:frame]; 1166 [supervisedBookmarksButton_ setFrame:frame];
1273 } 1167 }
1274 1168
1275 for (int i = 0; i < node->child_count(); i++) { 1169 for (int i = 0; i < node->child_count(); i++) {
1276 const BookmarkNode* child = node->GetChild(i); 1170 const BookmarkNode* child = node->GetChild(i);
1277 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; 1171 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset];
1278 if (NSMinX([button frame]) >= maxViewX) { 1172 if (NSMinX([button frame]) >= maxViewX) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 } 1229 }
1336 1230
1337 // Add bookmark buttons to the view only if they are completely 1231 // Add bookmark buttons to the view only if they are completely
1338 // visible and don't overlap the "other bookmarks". Remove buttons 1232 // visible and don't overlap the "other bookmarks". Remove buttons
1339 // which are clipped. Called when building the bookmark bar the first time. 1233 // which are clipped. Called when building the bookmark bar the first time.
1340 - (void)addButtonsToView { 1234 - (void)addButtonsToView {
1341 displayedButtonCount_ = 0; 1235 displayedButtonCount_ = 0;
1342 NSMutableArray* buttons = [self buttons]; 1236 NSMutableArray* buttons = [self buttons];
1343 for (NSButton* button in buttons) { 1237 for (NSButton* button in buttons) {
1344 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) - 1238 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) -
1345 bookmarks::BookmarkHorizontalPadding())) 1239 bookmarks::kBookmarkHorizontalPadding))
1346 break; 1240 break;
1347 [buttonView_ addSubview:button]; 1241 [buttonView_ addSubview:button];
1348 ++displayedButtonCount_; 1242 ++displayedButtonCount_;
1349 } 1243 }
1350 NSUInteger removalCount = 1244 NSUInteger removalCount =
1351 [buttons count] - (NSUInteger)displayedButtonCount_; 1245 [buttons count] - (NSUInteger)displayedButtonCount_;
1352 if (removalCount > 0) { 1246 if (removalCount > 0) {
1353 NSRange removalRange = NSMakeRange(displayedButtonCount_, removalCount); 1247 NSRange removalRange = NSMakeRange(displayedButtonCount_, removalCount);
1354 [buttons removeObjectsInRange:removalRange]; 1248 [buttons removeObjectsInRange:removalRange];
1355 } 1249 }
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 [self shrinkOrHideView:noItemTextfield forMaxX:maxViewX]; 1613 [self shrinkOrHideView:noItemTextfield forMaxX:maxViewX];
1720 } 1614 }
1721 } 1615 }
1722 1616
1723 // Scans through all buttons from left to right, calculating from scratch where 1617 // Scans through all buttons from left to right, calculating from scratch where
1724 // they should be based on the preceding widths, until it finds the one 1618 // they should be based on the preceding widths, until it finds the one
1725 // requested. 1619 // requested.
1726 // Returns NSZeroRect if there is no such button in the bookmark bar. 1620 // Returns NSZeroRect if there is no such button in the bookmark bar.
1727 // Enables you to work out where a button will end up when it is done animating. 1621 // Enables you to work out where a button will end up when it is done animating.
1728 - (NSRect)finalRectOfButton:(BookmarkButton*)wantedButton { 1622 - (NSRect)finalRectOfButton:(BookmarkButton*)wantedButton {
1729 CGFloat left = bookmarks::BookmarkLeftMargin(); 1623 CGFloat left = bookmarks::kBookmarkLeftMargin;
1730 NSRect buttonFrame = NSZeroRect; 1624 NSRect buttonFrame = NSZeroRect;
1731 1625
1732 // Draw the apps bookmark if needed. 1626 // Draw the apps bookmark if needed.
1733 if (![appsPageShortcutButton_ isHidden]) { 1627 if (![appsPageShortcutButton_ isHidden]) {
1734 left = NSMaxX([appsPageShortcutButton_ frame]) + 1628 left = NSMaxX([appsPageShortcutButton_ frame]) +
1735 bookmarks::BookmarkHorizontalPadding(); 1629 bookmarks::kBookmarkHorizontalPadding;
1736 } 1630 }
1737 1631
1738 // Draw the managed bookmarks folder if needed. 1632 // Draw the managed bookmarks folder if needed.
1739 if (![managedBookmarksButton_ isHidden]) { 1633 if (![managedBookmarksButton_ isHidden]) {
1740 left = NSMaxX([managedBookmarksButton_ frame]) + 1634 left = NSMaxX([managedBookmarksButton_ frame]) +
1741 bookmarks::BookmarkHorizontalPadding(); 1635 bookmarks::kBookmarkHorizontalPadding;
1742 } 1636 }
1743 1637
1744 // Draw the supervised bookmarks folder if needed. 1638 // Draw the supervised bookmarks folder if needed.
1745 if (![supervisedBookmarksButton_ isHidden]) { 1639 if (![supervisedBookmarksButton_ isHidden]) {
1746 left = NSMaxX([supervisedBookmarksButton_ frame]) + 1640 left = NSMaxX([supervisedBookmarksButton_ frame]) +
1747 bookmarks::BookmarkHorizontalPadding(); 1641 bookmarks::kBookmarkHorizontalPadding;
1748 } 1642 }
1749 1643
1750 for (NSButton* button in buttons_.get()) { 1644 for (NSButton* button in buttons_.get()) {
1751 // Hidden buttons get no space. 1645 // Hidden buttons get no space.
1752 if ([button isHidden]) 1646 if ([button isHidden])
1753 continue; 1647 continue;
1754 buttonFrame = [button frame]; 1648 buttonFrame = [button frame];
1755 buttonFrame.origin.x = left; 1649 buttonFrame.origin.x = left;
1756 left += buttonFrame.size.width + bookmarks::BookmarkHorizontalPadding(); 1650 left += buttonFrame.size.width + bookmarks::kBookmarkHorizontalPadding;
1757 if (button == wantedButton) 1651 if (button == wantedButton)
1758 return buttonFrame; 1652 return buttonFrame;
1759 } 1653 }
1760 return NSZeroRect; 1654 return NSZeroRect;
1761 } 1655 }
1762 1656
1763 // Calculates the final position of the last button in the bar. 1657 // Calculates the final position of the last button in the bar.
1764 // We can't just use [[self buttons] lastObject] frame] because the button 1658 // We can't just use [[self buttons] lastObject] frame] because the button
1765 // may be animating currently. 1659 // may be animating currently.
1766 - (NSRect)finalRectOfLastButton { 1660 - (NSRect)finalRectOfLastButton {
1767 return [self finalRectOfButton:[[self buttons] lastObject]]; 1661 return [self finalRectOfButton:[[self buttons] lastObject]];
1768 } 1662 }
1769 1663
1770 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible { 1664 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible {
1771 CGFloat maxViewX = NSMaxX([buttonView_ bounds]); 1665 CGFloat maxViewX = NSMaxX([buttonView_ bounds]);
1772 // If necessary, pull in the width to account for the Other Bookmarks button. 1666 // If necessary, pull in the width to account for the Other Bookmarks button.
1773 if ([self setOtherBookmarksButtonVisibility]) { 1667 if ([self setOtherBookmarksButtonVisibility]) {
1774 maxViewX = [otherBookmarksButton_ frame].origin.x - 1668 maxViewX = [otherBookmarksButton_ frame].origin.x -
1775 bookmarks::BookmarkRightMargin(); 1669 bookmarks::kBookmarkRightMargin;
1776 } 1670 }
1777 1671
1778 [self positionRightSideButtons]; 1672 [self positionRightSideButtons];
1779 // If we're already overflowing, then we need to account for the chevron. 1673 // If we're already overflowing, then we need to account for the chevron.
1780 if (visible) { 1674 if (visible) {
1781 maxViewX = 1675 maxViewX =
1782 [offTheSideButton_ frame].origin.x - bookmarks::BookmarkRightMargin(); 1676 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin;
1783 } 1677 }
1784 1678
1785 return maxViewX; 1679 return maxViewX;
1786 } 1680 }
1787 1681
1788 - (void)redistributeButtonsOnBarAsNeeded { 1682 - (void)redistributeButtonsOnBarAsNeeded {
1789 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); 1683 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node();
1790 NSInteger barCount = node->child_count(); 1684 NSInteger barCount = node->child_count();
1791 1685
1792 // Determine the current maximum extent of the visible buttons. 1686 // Determine the current maximum extent of the visible buttons.
(...skipping 17 matching lines...) Expand all
1810 if (!offTheSideButtonVisible) { 1704 if (!offTheSideButtonVisible) {
1811 offTheSideButtonVisible = YES; 1705 offTheSideButtonVisible = YES;
1812 maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:YES]; 1706 maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:YES];
1813 } 1707 }
1814 } 1708 }
1815 1709
1816 // As a result of cutting, deleting and dragging, the bar may now have room 1710 // As a result of cutting, deleting and dragging, the bar may now have room
1817 // for more buttons. 1711 // for more buttons.
1818 int xOffset; 1712 int xOffset;
1819 if (displayedButtonCount_ > 0) { 1713 if (displayedButtonCount_ > 0) {
1820 xOffset = NSMaxX([self finalRectOfLastButton]); 1714 xOffset = NSMaxX([self finalRectOfLastButton]) +
1821 1715 bookmarks::kBookmarkHorizontalPadding;
1822 // Adding the padding here causes the distance between button 1 and 2 to
1823 // be twice the padding instead of 1x. Pre-Material Design the padding was
1824 // 1pt, so this bug was not noticeable. With MD's padding, this error puts
1825 // 32pts of space between buttons.
1826 if (!ui::MaterialDesignController::IsModeMaterial()) {
1827 xOffset += bookmarks::BookmarkHorizontalPadding();
1828 }
1829 } else if (![managedBookmarksButton_ isHidden]) { 1716 } else if (![managedBookmarksButton_ isHidden]) {
1830 xOffset = NSMaxX([managedBookmarksButton_ frame]) + 1717 xOffset = NSMaxX([managedBookmarksButton_ frame]) +
1831 bookmarks::BookmarkHorizontalPadding(); 1718 bookmarks::kBookmarkHorizontalPadding;
1832 } else if (![supervisedBookmarksButton_ isHidden]) { 1719 } else if (![supervisedBookmarksButton_ isHidden]) {
1833 xOffset = NSMaxX([supervisedBookmarksButton_ frame]) + 1720 xOffset = NSMaxX([supervisedBookmarksButton_ frame]) +
1834 bookmarks::BookmarkHorizontalPadding(); 1721 bookmarks::kBookmarkHorizontalPadding;
1835 } else if (![appsPageShortcutButton_ isHidden]) { 1722 } else if (![appsPageShortcutButton_ isHidden]) {
1836 xOffset = NSMaxX([appsPageShortcutButton_ frame]) + 1723 xOffset = NSMaxX([appsPageShortcutButton_ frame]) +
1837 bookmarks::BookmarkHorizontalPadding(); 1724 bookmarks::kBookmarkHorizontalPadding;
1838 } else { 1725 } else {
1839 xOffset = bookmarks::BookmarkLeftMargin() - 1726 xOffset = bookmarks::kBookmarkLeftMargin -
1840 bookmarks::BookmarkHorizontalPadding(); 1727 bookmarks::kBookmarkHorizontalPadding;
1841 } 1728 }
1842 for (int i = displayedButtonCount_; i < barCount; ++i) { 1729 for (int i = displayedButtonCount_; i < barCount; ++i) {
1843 const BookmarkNode* child = node->GetChild(i); 1730 const BookmarkNode* child = node->GetChild(i);
1844 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; 1731 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset];
1845 // If we're testing against the last possible button then account 1732 // If we're testing against the last possible button then account
1846 // for the chevron no longer needing to be shown. 1733 // for the chevron no longer needing to be shown.
1847 if (i == barCount - 1) 1734 if (i == barCount - 1)
1848 maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:NO]; 1735 maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:NO];
1849 if (NSMaxX([button frame]) > maxViewX) { 1736 if (NSMaxX([button frame]) > maxViewX) {
1850 [button setDelegate:nil]; 1737 [button setDelegate:nil];
(...skipping 13 matching lines...) Expand all
1864 #pragma mark Private Methods Exposed for Testing 1751 #pragma mark Private Methods Exposed for Testing
1865 1752
1866 - (BookmarkBarView*)buttonView { 1753 - (BookmarkBarView*)buttonView {
1867 return buttonView_; 1754 return buttonView_;
1868 } 1755 }
1869 1756
1870 - (NSMutableArray*)buttons { 1757 - (NSMutableArray*)buttons {
1871 return buttons_.get(); 1758 return buttons_.get();
1872 } 1759 }
1873 1760
1761 - (NSButton*)offTheSideButton {
1762 return offTheSideButton_;
1763 }
1764
1874 - (NSButton*)appsPageShortcutButton { 1765 - (NSButton*)appsPageShortcutButton {
1875 return appsPageShortcutButton_; 1766 return appsPageShortcutButton_;
1876 } 1767 }
1877 1768
1878 - (BOOL)offTheSideButtonIsHidden { 1769 - (BOOL)offTheSideButtonIsHidden {
1879 return [offTheSideButton_ isHidden]; 1770 return [offTheSideButton_ isHidden];
1880 } 1771 }
1881 1772
1882 - (BOOL)appsPageShortcutButtonIsHidden { 1773 - (BOOL)appsPageShortcutButtonIsHidden {
1883 return [appsPageShortcutButton_ isHidden]; 1774 return [appsPageShortcutButton_ isHidden];
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 // can be important if a bookmark is deleted (via bookmark sync) 1806 // can be important if a bookmark is deleted (via bookmark sync)
1916 // while in the middle of a drag. The "drag completed" code 1807 // while in the middle of a drag. The "drag completed" code
1917 // (e.g. [BookmarkBarView performDragOperationForBookmarkButton:]) is 1808 // (e.g. [BookmarkBarView performDragOperationForBookmarkButton:]) is
1918 // careful enough to bail if there is no data found at "drop" time. 1809 // careful enough to bail if there is no data found at "drop" time.
1919 [[NSPasteboard pasteboardWithName:NSDragPboard] clearContents]; 1810 [[NSPasteboard pasteboardWithName:NSDragPboard] clearContents];
1920 } 1811 }
1921 1812
1922 // Return an autoreleased NSCell suitable for a bookmark button. 1813 // Return an autoreleased NSCell suitable for a bookmark button.
1923 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. 1814 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class.
1924 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)node { 1815 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)node {
1925 BOOL darkTheme = [[[self view] window] hasDarkTheme]; 1816 NSImage* image = node ? [self faviconForNode:node] : nil;
1926 NSImage* image = node ? [self faviconForNode:node forADarkTheme:darkTheme]
1927 : nil;
1928 BookmarkButtonCell* cell = 1817 BookmarkButtonCell* cell =
1929 [BookmarkButtonCell buttonCellForNode:node 1818 [BookmarkButtonCell buttonCellForNode:node
1930 text:nil 1819 text:nil
1931 image:image 1820 image:image
1932 menuController:contextMenuController_]; 1821 menuController:contextMenuController_];
1933 if (ui::MaterialDesignController::IsModeMaterial()) { 1822 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback];
1934 [cell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback];
1935 } else {
1936 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback];
1937 }
1938 1823
1939 // Note: a quirk of setting a cell's text color is that it won't work 1824 // Note: a quirk of setting a cell's text color is that it won't work
1940 // until the cell is associated with a button, so we can't theme the cell yet. 1825 // until the cell is associated with a button, so we can't theme the cell yet.
1941 1826
1942 return cell; 1827 return cell;
1943 } 1828 }
1944 1829
1945 // Return an autoreleased NSCell suitable for a special button displayed on the 1830 // Return an autoreleased NSCell suitable for a special button displayed on the
1946 // bookmark bar that is not attached to any bookmark node. 1831 // bookmark bar that is not attached to any bookmark node.
1947 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. 1832 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class.
1948 - (BookmarkButtonCell*)cellForCustomButtonWithText:(NSString*)text 1833 - (BookmarkButtonCell*)cellForCustomButtonWithText:(NSString*)text
1949 image:(NSImage*)image { 1834 image:(NSImage*)image {
1950 BookmarkButtonCell* cell = 1835 BookmarkButtonCell* cell =
1951 [BookmarkButtonCell buttonCellWithText:text 1836 [BookmarkButtonCell buttonCellWithText:text
1952 image:image 1837 image:image
1953 menuController:contextMenuController_]; 1838 menuController:contextMenuController_];
1954 if (ui::MaterialDesignController::IsModeMaterial()) { 1839 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback];
1955 [cell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback];
1956 } else {
1957 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback];
1958 }
1959 1840
1960 // Note: a quirk of setting a cell's text color is that it won't work 1841 // Note: a quirk of setting a cell's text color is that it won't work
1961 // until the cell is associated with a button, so we can't theme the cell yet. 1842 // until the cell is associated with a button, so we can't theme the cell yet.
1962 1843
1963 return cell; 1844 return cell;
1964 } 1845 }
1965 1846
1966 // Returns a frame appropriate for the given bookmark cell, suitable 1847 // Returns a frame appropriate for the given bookmark cell, suitable
1967 // for creating an NSButton that will contain it. |xOffset| is the X 1848 // for creating an NSButton that will contain it. |xOffset| is the X
1968 // offset for the frame; it is increased to be an appropriate X offset 1849 // offset for the frame; it is increased to be an appropriate X offset
1969 // for the next button. 1850 // for the next button.
1970 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell 1851 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell
1971 xOffset:(int*)xOffset { 1852 xOffset:(int*)xOffset {
1972 DCHECK(xOffset); 1853 DCHECK(xOffset);
1973 NSRect bounds = [buttonView_ bounds]; 1854 NSRect bounds = [buttonView_ bounds];
1974 if (ui::MaterialDesignController::IsModeMaterial()) { 1855 bounds.size.height = bookmarks::kBookmarkButtonHeight;
1975 bounds.size.height = bookmarks::kMaterialBookmarkButtonHeight;
1976 } else {
1977 bounds.size.height = bookmarks::kBookmarkButtonHeight;
1978 }
1979 1856
1980 NSRect frame = NSInsetRect(bounds, 1857 NSRect frame = NSInsetRect(bounds,
1981 bookmarks::BookmarkHorizontalPadding(), 1858 bookmarks::kBookmarkHorizontalPadding,
1982 bookmarks::BookmarkVerticalPadding()); 1859 bookmarks::kBookmarkVerticalPadding);
1983 frame.size.width = [self widthForBookmarkButtonCell:cell]; 1860 frame.size.width = [self widthForBookmarkButtonCell:cell];
1984 1861
1985 // Add an X offset based on what we've already done 1862 // Add an X offset based on what we've already done
1986 frame.origin.x += *xOffset; 1863 frame.origin.x += *xOffset;
1987 1864
1988 // And up the X offset for next time. 1865 // And up the X offset for next time.
1989 *xOffset = NSMaxX(frame); 1866 *xOffset = NSMaxX(frame);
1990 1867
1991 return frame; 1868 return frame;
1992 } 1869 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
2275 // Set insertionPos_ and hasInsertionPos_, and make insertion space for a 2152 // Set insertionPos_ and hasInsertionPos_, and make insertion space for a
2276 // hypothetical drop with the new button having a left edge of |where|. 2153 // hypothetical drop with the new button having a left edge of |where|.
2277 // Gets called only by our view. 2154 // Gets called only by our view.
2278 - (void)setDropInsertionPos:(CGFloat)where { 2155 - (void)setDropInsertionPos:(CGFloat)where {
2279 if (!hasInsertionPos_ || where != insertionPos_) { 2156 if (!hasInsertionPos_ || where != insertionPos_) {
2280 insertionPos_ = where; 2157 insertionPos_ = where;
2281 hasInsertionPos_ = YES; 2158 hasInsertionPos_ = YES;
2282 CGFloat left; 2159 CGFloat left;
2283 if (![supervisedBookmarksButton_ isHidden]) { 2160 if (![supervisedBookmarksButton_ isHidden]) {
2284 left = NSMaxX([supervisedBookmarksButton_ frame]) + 2161 left = NSMaxX([supervisedBookmarksButton_ frame]) +
2285 bookmarks::BookmarkHorizontalPadding(); 2162 bookmarks::kBookmarkHorizontalPadding;
2286 } else if (![managedBookmarksButton_ isHidden]) { 2163 } else if (![managedBookmarksButton_ isHidden]) {
2287 left = NSMaxX([managedBookmarksButton_ frame]) + 2164 left = NSMaxX([managedBookmarksButton_ frame]) +
2288 bookmarks::BookmarkHorizontalPadding(); 2165 bookmarks::kBookmarkHorizontalPadding;
2289 } else if (![appsPageShortcutButton_ isHidden]) { 2166 } else if (![appsPageShortcutButton_ isHidden]) {
2290 left = NSMaxX([appsPageShortcutButton_ frame]) + 2167 left = NSMaxX([appsPageShortcutButton_ frame]) +
2291 bookmarks::BookmarkHorizontalPadding(); 2168 bookmarks::kBookmarkHorizontalPadding;
2292 } else { 2169 } else {
2293 left = bookmarks::BookmarkLeftMargin(); 2170 left = bookmarks::kBookmarkLeftMargin;
2294 } 2171 }
2295 CGFloat paddingWidth = bookmarks::kDefaultBookmarkWidth; 2172 CGFloat paddingWidth = bookmarks::kDefaultBookmarkWidth;
2296 BookmarkButton* draggedButton = [BookmarkButton draggedButton]; 2173 BookmarkButton* draggedButton = [BookmarkButton draggedButton];
2297 if (draggedButton) { 2174 if (draggedButton) {
2298 paddingWidth = std::min(bookmarks::kDefaultBookmarkWidth, 2175 paddingWidth = std::min(bookmarks::kDefaultBookmarkWidth,
2299 NSWidth([draggedButton frame])); 2176 NSWidth([draggedButton frame]));
2300 } 2177 }
2301 // Put all the buttons where they belong, with all buttons to the right 2178 // Put all the buttons where they belong, with all buttons to the right
2302 // of the insertion point shuffling right to make space for it. 2179 // of the insertion point shuffling right to make space for it.
2303 [NSAnimationContext beginGrouping]; 2180 [NSAnimationContext beginGrouping];
2304 [[NSAnimationContext currentContext] 2181 [[NSAnimationContext currentContext]
2305 setDuration:kDragAndDropAnimationDuration]; 2182 setDuration:kDragAndDropAnimationDuration];
2306 for (NSButton* button in buttons_.get()) { 2183 for (NSButton* button in buttons_.get()) {
2307 // Hidden buttons get no space. 2184 // Hidden buttons get no space.
2308 if ([button isHidden]) 2185 if ([button isHidden])
2309 continue; 2186 continue;
2310 NSRect buttonFrame = [button frame]; 2187 NSRect buttonFrame = [button frame];
2311 buttonFrame.origin.x = left; 2188 buttonFrame.origin.x = left;
2312 // Update "left" for next time around. 2189 // Update "left" for next time around.
2313 left += buttonFrame.size.width; 2190 left += buttonFrame.size.width;
2314 if (left > insertionPos_) 2191 if (left > insertionPos_)
2315 buttonFrame.origin.x += paddingWidth; 2192 buttonFrame.origin.x += paddingWidth;
2316 left += bookmarks::BookmarkHorizontalPadding(); 2193 left += bookmarks::kBookmarkHorizontalPadding;
2317 if (innerContentAnimationsEnabled_) 2194 if (innerContentAnimationsEnabled_)
2318 [[button animator] setFrame:buttonFrame]; 2195 [[button animator] setFrame:buttonFrame];
2319 else 2196 else
2320 [button setFrame:buttonFrame]; 2197 [button setFrame:buttonFrame];
2321 } 2198 }
2322 [NSAnimationContext endGrouping]; 2199 [NSAnimationContext endGrouping];
2323 } 2200 }
2324 } 2201 }
2325 2202
2326 // Put all visible bookmark bar buttons in their normal locations, either with 2203 // Put all visible bookmark bar buttons in their normal locations, either with
2327 // or without animation according to the |animate| flag. 2204 // or without animation according to the |animate| flag.
2328 // This is generally useful, so is called from various places internally. 2205 // This is generally useful, so is called from various places internally.
2329 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate { 2206 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate {
2330 2207
2331 // Position the apps bookmark if needed. 2208 // Position the apps bookmark if needed.
2332 CGFloat left = bookmarks::BookmarkLeftMargin(); 2209 CGFloat left = bookmarks::kBookmarkLeftMargin;
2333 if (![appsPageShortcutButton_ isHidden]) { 2210 if (![appsPageShortcutButton_ isHidden]) {
2334 int xOffset = bookmarks::BookmarkLeftMargin() - 2211 int xOffset =
2335 bookmarks::BookmarkHorizontalPadding(); 2212 bookmarks::kBookmarkLeftMargin - bookmarks::kBookmarkHorizontalPadding;
2336 NSRect frame = 2213 NSRect frame =
2337 [self frameForBookmarkButtonFromCell:[appsPageShortcutButton_ cell] 2214 [self frameForBookmarkButtonFromCell:[appsPageShortcutButton_ cell]
2338 xOffset:&xOffset]; 2215 xOffset:&xOffset];
2339 [appsPageShortcutButton_ setFrame:frame]; 2216 [appsPageShortcutButton_ setFrame:frame];
2340 left = xOffset + bookmarks::BookmarkHorizontalPadding(); 2217 left = xOffset + bookmarks::kBookmarkHorizontalPadding;
2341 } 2218 }
2342 2219
2343 // Position the managed bookmarks folder if needed. 2220 // Position the managed bookmarks folder if needed.
2344 if (![managedBookmarksButton_ isHidden]) { 2221 if (![managedBookmarksButton_ isHidden]) {
2345 int xOffset = left; 2222 int xOffset = left;
2346 NSRect frame = 2223 NSRect frame =
2347 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell] 2224 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell]
2348 xOffset:&xOffset]; 2225 xOffset:&xOffset];
2349 [managedBookmarksButton_ setFrame:frame]; 2226 [managedBookmarksButton_ setFrame:frame];
2350 left = xOffset + bookmarks::BookmarkHorizontalPadding(); 2227 left = xOffset + bookmarks::kBookmarkHorizontalPadding;
2351 } 2228 }
2352 2229
2353 // Position the supervised bookmarks folder if needed. 2230 // Position the supervised bookmarks folder if needed.
2354 if (![supervisedBookmarksButton_ isHidden]) { 2231 if (![supervisedBookmarksButton_ isHidden]) {
2355 int xOffset = left; 2232 int xOffset = left;
2356 NSRect frame = 2233 NSRect frame =
2357 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell] 2234 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell]
2358 xOffset:&xOffset]; 2235 xOffset:&xOffset];
2359 [supervisedBookmarksButton_ setFrame:frame]; 2236 [supervisedBookmarksButton_ setFrame:frame];
2360 left = xOffset + bookmarks::BookmarkHorizontalPadding(); 2237 left = xOffset + bookmarks::kBookmarkHorizontalPadding;
2361 } 2238 }
2362 2239
2363 animate &= innerContentAnimationsEnabled_; 2240 animate &= innerContentAnimationsEnabled_;
2364 2241
2365 for (NSButton* button in buttons_.get()) { 2242 for (NSButton* button in buttons_.get()) {
2366 // Hidden buttons get no space. 2243 // Hidden buttons get no space.
2367 if ([button isHidden]) 2244 if ([button isHidden])
2368 continue; 2245 continue;
2369 NSRect buttonFrame = [button frame]; 2246 NSRect buttonFrame = [button frame];
2370 buttonFrame.origin.x = left; 2247 buttonFrame.origin.x = left;
2371 left += buttonFrame.size.width + bookmarks::BookmarkHorizontalPadding(); 2248 left += buttonFrame.size.width + bookmarks::kBookmarkHorizontalPadding;
2372 if (animate) 2249 if (animate)
2373 [[button animator] setFrame:buttonFrame]; 2250 [[button animator] setFrame:buttonFrame];
2374 else 2251 else
2375 [button setFrame:buttonFrame]; 2252 [button setFrame:buttonFrame];
2376 } 2253 }
2377 } 2254 }
2378 2255
2379 // Clear insertion flag, remove insertion space and put all visible bookmark 2256 // Clear insertion flag, remove insertion space and put all visible bookmark
2380 // bar buttons in their normal locations. 2257 // bar buttons in their normal locations.
2381 // Gets called only by our view. 2258 // Gets called only by our view.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
2490 // TODO(jrg): if the bookmark bar is open on launch, we see the 2367 // TODO(jrg): if the bookmark bar is open on launch, we see the
2491 // buttons all placed, then "scooted over" as the favicons load. If 2368 // buttons all placed, then "scooted over" as the favicons load. If
2492 // this looks bad I may need to change widthForBookmarkButtonCell to 2369 // this looks bad I may need to change widthForBookmarkButtonCell to
2493 // add space for an image even if not there on the assumption that 2370 // add space for an image even if not there on the assumption that
2494 // favicons will eventually load. 2371 // favicons will eventually load.
2495 - (void)nodeFaviconLoaded:(BookmarkModel*)model 2372 - (void)nodeFaviconLoaded:(BookmarkModel*)model
2496 node:(const BookmarkNode*)node { 2373 node:(const BookmarkNode*)node {
2497 for (BookmarkButton* button in buttons_.get()) { 2374 for (BookmarkButton* button in buttons_.get()) {
2498 const BookmarkNode* cellnode = [button bookmarkNode]; 2375 const BookmarkNode* cellnode = [button bookmarkNode];
2499 if (cellnode == node) { 2376 if (cellnode == node) {
2500 BOOL darkTheme = [[[self view] window] hasDarkTheme];
2501 NSImage* theImage = [self faviconForNode:node forADarkTheme:darkTheme];
2502 [[button cell] setBookmarkCellText:[button title] 2377 [[button cell] setBookmarkCellText:[button title]
2503 image:theImage]; 2378 image:[self faviconForNode:node]];
2504 // Adding an image means we might need more room for the 2379 // Adding an image means we might need more room for the
2505 // bookmark. Test for it by growing the button (if needed) 2380 // bookmark. Test for it by growing the button (if needed)
2506 // and shifting everything else over. 2381 // and shifting everything else over.
2507 [self checkForBookmarkButtonGrowth:button]; 2382 [self checkForBookmarkButtonGrowth:button];
2508 return; 2383 return;
2509 } 2384 }
2510 } 2385 }
2511 2386
2512 if (folderController_) 2387 if (folderController_)
2513 [folderController_ faviconLoadedForNode:node]; 2388 [folderController_ faviconLoadedForNode:node];
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
2656 [self resetAllButtonPositionsWithAnimation:YES]; 2531 [self resetAllButtonPositionsWithAnimation:YES];
2657 } 2532 }
2658 2533
2659 2534
2660 #pragma mark BookmarkButtonControllerProtocol 2535 #pragma mark BookmarkButtonControllerProtocol
2661 2536
2662 // Close all bookmark folders. "Folder" here is the fake menu for 2537 // Close all bookmark folders. "Folder" here is the fake menu for
2663 // bookmark folders, not a button context menu. 2538 // bookmark folders, not a button context menu.
2664 - (void)closeAllBookmarkFolders { 2539 - (void)closeAllBookmarkFolders {
2665 [self watchForExitEvent:NO]; 2540 [self watchForExitEvent:NO];
2666
2667 // Grab the parent button under Material Design to make sure that the
2668 // highlighting that was applied while revealing the menu is turned off.
2669 BookmarkButton* parentButton = nil;
2670 if (ui::MaterialDesignController::IsModeMaterial()) {
2671 parentButton = [folderController_ parentButton];
2672 }
2673 [folderController_ close]; 2541 [folderController_ close];
2674 [[parentButton cell] setHighlighted:NO];
2675 [parentButton setNeedsDisplay:YES];
2676 folderController_ = nil; 2542 folderController_ = nil;
2677 } 2543 }
2678 2544
2679 - (void)closeBookmarkFolder:(id)sender { 2545 - (void)closeBookmarkFolder:(id)sender {
2680 // We're the top level, so close one means close them all. 2546 // We're the top level, so close one means close them all.
2681 [self closeAllBookmarkFolders]; 2547 [self closeAllBookmarkFolders];
2682 } 2548 }
2683 2549
2684 - (BookmarkModel*)bookmarkModel { 2550 - (BookmarkModel*)bookmarkModel {
2685 return bookmarkModel_; 2551 return bookmarkModel_;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2808 } 2674 }
2809 2675
2810 // Return YES if we should show the drop indicator, else NO. 2676 // Return YES if we should show the drop indicator, else NO.
2811 - (BOOL)shouldShowIndicatorShownForPoint:(NSPoint)point { 2677 - (BOOL)shouldShowIndicatorShownForPoint:(NSPoint)point {
2812 return ![self buttonForDroppingOnAtPoint:point]; 2678 return ![self buttonForDroppingOnAtPoint:point];
2813 } 2679 }
2814 2680
2815 // Return the x position for a drop indicator. 2681 // Return the x position for a drop indicator.
2816 - (CGFloat)indicatorPosForDragToPoint:(NSPoint)point { 2682 - (CGFloat)indicatorPosForDragToPoint:(NSPoint)point {
2817 CGFloat x = 0; 2683 CGFloat x = 0;
2818 CGFloat halfHorizontalPadding = 0.5 * bookmarks::BookmarkHorizontalPadding(); 2684 CGFloat halfHorizontalPadding = 0.5 * bookmarks::kBookmarkHorizontalPadding;
2819 int destIndex = [self indexForDragToPoint:point]; 2685 int destIndex = [self indexForDragToPoint:point];
2820 int numButtons = displayedButtonCount_; 2686 int numButtons = displayedButtonCount_;
2821 2687
2822 CGFloat leftmostX; 2688 CGFloat leftmostX;
2823 if (![supervisedBookmarksButton_ isHidden]) { 2689 if (![supervisedBookmarksButton_ isHidden]) {
2824 leftmostX = 2690 leftmostX =
2825 NSMaxX([supervisedBookmarksButton_ frame]) + halfHorizontalPadding; 2691 NSMaxX([supervisedBookmarksButton_ frame]) + halfHorizontalPadding;
2826 } else if (![managedBookmarksButton_ isHidden]) { 2692 } else if (![managedBookmarksButton_ isHidden]) {
2827 leftmostX = NSMaxX([managedBookmarksButton_ frame]) + halfHorizontalPadding; 2693 leftmostX = NSMaxX([managedBookmarksButton_ frame]) + halfHorizontalPadding;
2828 } else if (![appsPageShortcutButton_ isHidden]) { 2694 } else if (![appsPageShortcutButton_ isHidden]) {
2829 leftmostX = NSMaxX([appsPageShortcutButton_ frame]) + halfHorizontalPadding; 2695 leftmostX = NSMaxX([appsPageShortcutButton_ frame]) + halfHorizontalPadding;
2830 } else { 2696 } else {
2831 leftmostX = bookmarks::BookmarkLeftMargin() - halfHorizontalPadding; 2697 leftmostX = bookmarks::kBookmarkLeftMargin - halfHorizontalPadding;
2832 } 2698 }
2833 2699
2834 // If it's a drop strictly between existing buttons ... 2700 // If it's a drop strictly between existing buttons ...
2835 if (destIndex == 0) { 2701 if (destIndex == 0) {
2836 x = leftmostX; 2702 x = leftmostX;
2837 } else if (destIndex > 0 && destIndex < numButtons) { 2703 } else if (destIndex > 0 && destIndex < numButtons) {
2838 // ... put the indicator right between the buttons. 2704 // ... put the indicator right between the buttons.
2839 BookmarkButton* button = 2705 BookmarkButton* button =
2840 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex-1)]; 2706 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex-1)];
2841 DCHECK(button); 2707 DCHECK(button);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2924 - (void)openAll:(const BookmarkNode*)node 2790 - (void)openAll:(const BookmarkNode*)node
2925 disposition:(WindowOpenDisposition)disposition { 2791 disposition:(WindowOpenDisposition)disposition {
2926 [self closeFolderAndStopTrackingMenus]; 2792 [self closeFolderAndStopTrackingMenus];
2927 chrome::OpenAll([[self view] window], browser_, node, disposition, 2793 chrome::OpenAll([[self view] window], browser_, node, disposition,
2928 browser_->profile()); 2794 browser_->profile());
2929 } 2795 }
2930 2796
2931 - (void)addButtonForNode:(const BookmarkNode*)node 2797 - (void)addButtonForNode:(const BookmarkNode*)node
2932 atIndex:(NSInteger)buttonIndex { 2798 atIndex:(NSInteger)buttonIndex {
2933 int newOffset = 2799 int newOffset =
2934 bookmarks::BookmarkLeftMargin() - bookmarks::BookmarkHorizontalPadding(); 2800 bookmarks::kBookmarkLeftMargin - bookmarks::kBookmarkHorizontalPadding;
2935 if (buttonIndex == -1) 2801 if (buttonIndex == -1)
2936 buttonIndex = [buttons_ count]; // New button goes at the end. 2802 buttonIndex = [buttons_ count]; // New button goes at the end.
2937 if (buttonIndex <= (NSInteger)[buttons_ count]) { 2803 if (buttonIndex <= (NSInteger)[buttons_ count]) {
2938 if (buttonIndex) { 2804 if (buttonIndex) {
2939 BookmarkButton* targetButton = [buttons_ objectAtIndex:buttonIndex - 1]; 2805 BookmarkButton* targetButton = [buttons_ objectAtIndex:buttonIndex - 1];
2940 NSRect targetFrame = [targetButton frame]; 2806 NSRect targetFrame = [targetButton frame];
2941 newOffset = targetFrame.origin.x + NSWidth(targetFrame) + 2807 newOffset = targetFrame.origin.x + NSWidth(targetFrame) +
2942 bookmarks::BookmarkHorizontalPadding(); 2808 bookmarks::kBookmarkHorizontalPadding;
2943 } 2809 }
2944 BookmarkButton* newButton = [self buttonForNode:node xOffset:&newOffset]; 2810 BookmarkButton* newButton = [self buttonForNode:node xOffset:&newOffset];
2945 ++displayedButtonCount_; 2811 ++displayedButtonCount_;
2946 [buttons_ insertObject:newButton atIndex:buttonIndex]; 2812 [buttons_ insertObject:newButton atIndex:buttonIndex];
2947 [buttonView_ addSubview:newButton]; 2813 [buttonView_ addSubview:newButton];
2948 [self resetAllButtonPositionsWithAnimation:NO]; 2814 [self resetAllButtonPositionsWithAnimation:NO];
2949 // See if any buttons need to be pushed off to or brought in from the side. 2815 // See if any buttons need to be pushed off to or brought in from the side.
2950 [self reconfigureBookmarkBar]; 2816 [self reconfigureBookmarkBar];
2951 } else { 2817 } else {
2952 // A button from somewhere else (not the bar) is being moved to the 2818 // A button from somewhere else (not the bar) is being moved to the
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
3074 - (id<BookmarkButtonControllerProtocol>)controllerForNode: 2940 - (id<BookmarkButtonControllerProtocol>)controllerForNode:
3075 (const BookmarkNode*)node { 2941 (const BookmarkNode*)node {
3076 // See if it's in the bar, then if it is in the hierarchy of visible 2942 // See if it's in the bar, then if it is in the hierarchy of visible
3077 // folder menus. 2943 // folder menus.
3078 if (bookmarkModel_->bookmark_bar_node() == node) 2944 if (bookmarkModel_->bookmark_bar_node() == node)
3079 return self; 2945 return self;
3080 return [folderController_ controllerForNode:node]; 2946 return [folderController_ controllerForNode:node];
3081 } 2947 }
3082 2948
3083 @end 2949 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698