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

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

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

Powered by Google App Engine
This is Rietveld 408576698