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

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

Issue 1941583002: [Mac][Material Design] Update bookmarks bar to Material Design. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ready for review. 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"
71 #include "ui/gfx/image/image.h" 72 #include "ui/gfx/image/image.h"
72 #include "ui/resources/grit/ui_resources.h" 73 #include "ui/resources/grit/ui_resources.h"
73 74
74 using base::UserMetricsAction; 75 using base::UserMetricsAction;
75 using bookmarks::BookmarkModel; 76 using bookmarks::BookmarkModel;
76 using bookmarks::BookmarkNode; 77 using bookmarks::BookmarkNode;
77 using bookmarks::BookmarkNodeData; 78 using bookmarks::BookmarkNodeData;
78 using content::OpenURLParams; 79 using content::OpenURLParams;
79 using content::Referrer; 80 using content::Referrer;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 - (void)createOtherBookmarksButton; 238 - (void)createOtherBookmarksButton;
238 - (void)createAppsPageShortcutButton; 239 - (void)createAppsPageShortcutButton;
239 - (void)openAppsPage:(id)sender; 240 - (void)openAppsPage:(id)sender;
240 - (void)centerNoItemsLabel; 241 - (void)centerNoItemsLabel;
241 - (void)positionRightSideButtons; 242 - (void)positionRightSideButtons;
242 - (void)watchForExitEvent:(BOOL)watch; 243 - (void)watchForExitEvent:(BOOL)watch;
243 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate; 244 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate;
244 245
245 @end 246 @end
246 247
248 namespace bookmarks {
249
250 CGFloat BookmarkHorizontalPadding() {
251 if (!ui::MaterialDesignController::IsModeMaterial()) {
252 return 1.0;
253 }
254 return 16.0;
255 }
256
257 CGFloat BookmarkVerticalPadding() {
258 if (!ui::MaterialDesignController::IsModeMaterial()) {
259 return 2.0;
260 }
261 return 4.0;
262 }
263
264 CGFloat BookmarkLeftMargin() {
265 if (!ui::MaterialDesignController::IsModeMaterial()) {
266 return 2.0;
267 }
268 return 10.0;
269 }
270
271 CGFloat BookmarkRightMargin() {
272 if (!ui::MaterialDesignController::IsModeMaterial()) {
273 return 2.0;
274 }
275 return 10.0;
276 }
277
278 } // namespace bookmarks
279
247 @implementation BookmarkBarController 280 @implementation BookmarkBarController
248 281
249 @synthesize currentState = currentState_; 282 @synthesize currentState = currentState_;
250 @synthesize lastState = lastState_; 283 @synthesize lastState = lastState_;
251 @synthesize isAnimationRunning = isAnimationRunning_; 284 @synthesize isAnimationRunning = isAnimationRunning_;
252 @synthesize delegate = delegate_; 285 @synthesize delegate = delegate_;
253 @synthesize stateAnimationsEnabled = stateAnimationsEnabled_; 286 @synthesize stateAnimationsEnabled = stateAnimationsEnabled_;
254 @synthesize innerContentAnimationsEnabled = innerContentAnimationsEnabled_; 287 @synthesize innerContentAnimationsEnabled = innerContentAnimationsEnabled_;
255 288
256 - (id)initWithBrowser:(Browser*)browser 289 - (id)initWithBrowser:(Browser*)browser
(...skipping 11 matching lines...) Expand all
268 ManagedBookmarkServiceFactory::GetForProfile(browser_->profile()); 301 ManagedBookmarkServiceFactory::GetForProfile(browser_->profile());
269 buttons_.reset([[NSMutableArray alloc] init]); 302 buttons_.reset([[NSMutableArray alloc] init]);
270 delegate_ = delegate; 303 delegate_ = delegate;
271 folderTarget_.reset( 304 folderTarget_.reset(
272 [[BookmarkFolderTarget alloc] initWithController:self 305 [[BookmarkFolderTarget alloc] initWithController:self
273 profile:browser_->profile()]); 306 profile:browser_->profile()]);
274 307
275 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 308 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
276 folderImage_.reset( 309 folderImage_.reset(
277 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER).CopyNSImage()); 310 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER).CopyNSImage());
311 if (ui::MaterialDesignController::IsModeMaterial()) {
312 folderImageWhite_.reset(
313 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER_WHITE).CopyNSImage());
314 }
278 defaultImage_.reset( 315 defaultImage_.reset(
279 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage()); 316 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage());
280 317
281 innerContentAnimationsEnabled_ = YES; 318 innerContentAnimationsEnabled_ = YES;
282 stateAnimationsEnabled_ = YES; 319 stateAnimationsEnabled_ = YES;
283 320
284 // Register for theme changes, bookmark button pulsing, ... 321 // Register for theme changes, bookmark button pulsing, ...
285 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; 322 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
286 [defaultCenter addObserver:self 323 [defaultCenter addObserver:self
287 selector:@selector(themeDidChangeNotification:) 324 selector:@selector(themeDidChangeNotification:)
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 563
527 // Change the layout of the bookmark bar's subviews in response to a visibility 564 // 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). 565 // change (e.g., show or hide the bar) or style change (attached or floating).
529 - (void)layoutSubviews { 566 - (void)layoutSubviews {
530 NSRect frame = [[self view] frame]; 567 NSRect frame = [[self view] frame];
531 NSRect buttonViewFrame = NSMakeRect(0, 0, NSWidth(frame), NSHeight(frame)); 568 NSRect buttonViewFrame = NSMakeRect(0, 0, NSWidth(frame), NSHeight(frame));
532 569
533 // Add padding to the detached bookmark bar. 570 // Add padding to the detached bookmark bar.
534 // The state of our morph (if any); 1 is total bubble, 0 is the regular bar. 571 // The state of our morph (if any); 1 is total bubble, 0 is the regular bar.
535 CGFloat morph = [self detachedMorphProgress]; 572 CGFloat morph = [self detachedMorphProgress];
536 CGFloat padding = bookmarks::kNTPBookmarkBarPadding; 573 CGFloat padding = 0;
574 if (ui::MaterialDesignController::IsModeMaterial()) {
575 padding = bookmarks::kMaterialNTPBookmarkBarPadding;
576 } else {
577 padding = bookmarks::kNTPBookmarkBarPadding;
578 }
537 buttonViewFrame = 579 buttonViewFrame =
538 NSInsetRect(buttonViewFrame, morph * padding, morph * padding); 580 NSInsetRect(buttonViewFrame, morph * padding, morph * padding);
539 581
540 [buttonView_ setFrame:buttonViewFrame]; 582 [buttonView_ setFrame:buttonViewFrame];
541 583
542 // Update bookmark button backgrounds. 584 // Update bookmark button backgrounds.
543 if ([self isAnimationRunning]) { 585 if ([self isAnimationRunning]) {
544 for (NSButton* button in buttons_.get()) 586 for (NSButton* button in buttons_.get())
545 [button setNeedsDisplay:YES]; 587 [button setNeedsDisplay:YES];
546 // Update the apps and other buttons explicitly, since they are not in the 588 // 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]) 665 andState:BookmarkBar::DETACHED])
624 return static_cast<CGFloat>([self detachedMorphProgress]); 666 return static_cast<CGFloat>([self detachedMorphProgress]);
625 667
626 // If we ever need any other animation cases, code would go here. 668 // If we ever need any other animation cases, code would go here.
627 } 669 }
628 670
629 // In general, only show the divider when it's in the normal showing state. 671 // In general, only show the divider when it's in the normal showing state.
630 return [self isInState:BookmarkBar::SHOW] ? 0 : 1; 672 return [self isInState:BookmarkBar::SHOW] ? 0 : 1;
631 } 673 }
632 674
633 - (NSImage*)faviconForNode:(const BookmarkNode*)node { 675 - (NSImage*)faviconForNode:(const BookmarkNode*)node
676 forADarkTheme:(BOOL)forADarkTheme {
634 if (!node) 677 if (!node)
635 return defaultImage_; 678 return defaultImage_;
636 679
637 if (node == managedBookmarkService_->managed_node()) { 680 if (forADarkTheme && ui::MaterialDesignController::IsModeMaterial()) {
638 // Most users never see this node, so the image is only loaded if needed. 681 if (node == managedBookmarkService_->managed_node()) {
639 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 682 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
640 return rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER_MANAGED).ToNSImage(); 683 return rb.GetNativeImageNamed(
684 IDR_BOOKMARK_BAR_FOLDER_MANAGED_WHITE).ToNSImage();
685 }
686
687 if (node == managedBookmarkService_->supervised_node()) {
688 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
689 return rb.GetNativeImageNamed(
690 IDR_BOOKMARK_BAR_FOLDER_SUPERVISED_WHITE).ToNSImage();
691 }
692
693 if (node->is_folder())
694 return folderImageWhite_;
695 } else {
696 if (node == managedBookmarkService_->managed_node()) {
697 // Most users never see this node, so the image is only loaded if needed.
698 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
699 return rb.GetNativeImageNamed(
700 IDR_BOOKMARK_BAR_FOLDER_MANAGED).ToNSImage();
701 }
702
703 if (node == managedBookmarkService_->supervised_node()) {
704 // Most users never see this node, so the image is only loaded if needed.
705 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
706 return rb.GetNativeImageNamed(
707 IDR_BOOKMARK_BAR_FOLDER_SUPERVISED).ToNSImage();
708 }
709
710 if (node->is_folder())
711 return folderImage_;
641 } 712 }
642 713
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); 714 const gfx::Image& favicon = bookmarkModel_->GetFavicon(node);
654 if (!favicon.IsEmpty()) 715 if (!favicon.IsEmpty())
655 return favicon.ToNSImage(); 716 return favicon.ToNSImage();
656 717
657 return defaultImage_; 718 return defaultImage_;
658 } 719 }
659 720
660 - (void)closeFolderAndStopTrackingMenus { 721 - (void)closeFolderAndStopTrackingMenus {
661 showFolderMenus_ = NO; 722 showFolderMenus_ = NO;
662 [self closeAllBookmarkFolders]; 723 [self closeAllBookmarkFolders];
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 881
821 - (BookmarkLaunchLocation)bookmarkLaunchLocation { 882 - (BookmarkLaunchLocation)bookmarkLaunchLocation {
822 return currentState_ == BookmarkBar::DETACHED ? 883 return currentState_ == BookmarkBar::DETACHED ?
823 BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR : 884 BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR :
824 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR; 885 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR;
825 } 886 }
826 887
827 // Position the right-side buttons including the off-the-side chevron. 888 // Position the right-side buttons including the off-the-side chevron.
828 - (void)positionRightSideButtons { 889 - (void)positionRightSideButtons {
829 int maxX = NSMaxX([[self buttonView] bounds]) - 890 int maxX = NSMaxX([[self buttonView] bounds]) -
830 bookmarks::kBookmarkHorizontalPadding; 891 bookmarks::BookmarkHorizontalPadding();
831 int right = maxX; 892 int right = maxX;
832 893
833 int ignored = 0; 894 int ignored = 0;
834 NSRect frame = [self frameForBookmarkButtonFromCell: 895 NSRect frame = [self frameForBookmarkButtonFromCell:
835 [otherBookmarksButton_ cell] xOffset:&ignored]; 896 [otherBookmarksButton_ cell] xOffset:&ignored];
836 if (![otherBookmarksButton_ isHidden]) { 897 if (![otherBookmarksButton_ isHidden]) {
837 right -= NSWidth(frame); 898 right -= NSWidth(frame);
838 frame.origin.x = right; 899 frame.origin.x = right;
839 } else { 900 } else {
840 frame.origin.x = maxX - NSWidth(frame); 901 frame.origin.x = maxX - NSWidth(frame);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 } 1106 }
1046 1107
1047 // Recursively add the given bookmark node and all its children to 1108 // Recursively add the given bookmark node and all its children to
1048 // menu, one menu item per node. 1109 // menu, one menu item per node.
1049 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu { 1110 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu {
1050 NSString* title = [BookmarkMenuCocoaController menuTitleForNode:child]; 1111 NSString* title = [BookmarkMenuCocoaController menuTitleForNode:child];
1051 NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title 1112 NSMenuItem* item = [[[NSMenuItem alloc] initWithTitle:title
1052 action:nil 1113 action:nil
1053 keyEquivalent:@""] autorelease]; 1114 keyEquivalent:@""] autorelease];
1054 [menu addItem:item]; 1115 [menu addItem:item];
1055 [item setImage:[self faviconForNode:child]]; 1116 [item setImage:[self faviconForNode:child forADarkTheme:NO]];
1056 if (child->is_folder()) { 1117 if (child->is_folder()) {
1057 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease]; 1118 NSMenu* submenu = [[[NSMenu alloc] initWithTitle:title] autorelease];
1058 [menu setSubmenu:submenu forItem:item]; 1119 [menu setSubmenu:submenu forItem:item];
1059 if (!child->empty()) { 1120 if (!child->empty()) {
1060 [self addFolderNode:child toMenu:submenu]; // potentially recursive 1121 [self addFolderNode:child toMenu:submenu]; // potentially recursive
1061 } else { 1122 } else {
1062 [self tagEmptyMenu:submenu]; 1123 [self tagEmptyMenu:submenu];
1063 } 1124 }
1064 } else { 1125 } else {
1065 [item setTarget:self]; 1126 [item setTarget:self];
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1131 } 1192 }
1132 1193
1133 // TODO(jrg): write a "build bar" so there is a nice spot for things 1194 // 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 1195 // like the contextual menu which is invoked when not over a
1135 // bookmark. On Safari that menu has a "new folder" option. 1196 // bookmark. On Safari that menu has a "new folder" option.
1136 - (void)addNodesToButtonList:(const BookmarkNode*)node { 1197 - (void)addNodesToButtonList:(const BookmarkNode*)node {
1137 [self showOrHideNoItemContainerForNode:node]; 1198 [self showOrHideNoItemContainerForNode:node];
1138 1199
1139 CGFloat maxViewX = NSMaxX([[self view] bounds]); 1200 CGFloat maxViewX = NSMaxX([[self view] bounds]);
1140 int xOffset = 1201 int xOffset =
1141 bookmarks::kBookmarkLeftMargin - bookmarks::kBookmarkHorizontalPadding; 1202 bookmarks::BookmarkLeftMargin() - bookmarks::BookmarkHorizontalPadding();
1142 1203
1143 // Draw the apps bookmark if needed. 1204 // Draw the apps bookmark if needed.
1144 if (![appsPageShortcutButton_ isHidden]) { 1205 if (![appsPageShortcutButton_ isHidden]) {
1145 NSRect frame = 1206 NSRect frame =
1146 [self frameForBookmarkButtonFromCell:[appsPageShortcutButton_ cell] 1207 [self frameForBookmarkButtonFromCell:[appsPageShortcutButton_ cell]
1147 xOffset:&xOffset]; 1208 xOffset:&xOffset];
1148 [appsPageShortcutButton_ setFrame:frame]; 1209 [appsPageShortcutButton_ setFrame:frame];
1149 } 1210 }
1150 1211
1151 // Draw the managed bookmark folder if needed. 1212 // Draw the managed bookmark folder if needed.
1152 if (![managedBookmarksButton_ isHidden]) { 1213 if (![managedBookmarksButton_ isHidden]) {
1153 xOffset += bookmarks::kBookmarkHorizontalPadding; 1214 xOffset += bookmarks::BookmarkHorizontalPadding();
1154 NSRect frame = 1215 NSRect frame =
1155 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell] 1216 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell]
1156 xOffset:&xOffset]; 1217 xOffset:&xOffset];
1157 [managedBookmarksButton_ setFrame:frame]; 1218 [managedBookmarksButton_ setFrame:frame];
1158 } 1219 }
1159 1220
1160 // Draw the supervised bookmark folder if needed. 1221 // Draw the supervised bookmark folder if needed.
1161 if (![supervisedBookmarksButton_ isHidden]) { 1222 if (![supervisedBookmarksButton_ isHidden]) {
1162 xOffset += bookmarks::kBookmarkHorizontalPadding; 1223 xOffset += bookmarks::BookmarkHorizontalPadding();
1163 NSRect frame = 1224 NSRect frame =
1164 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell] 1225 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell]
1165 xOffset:&xOffset]; 1226 xOffset:&xOffset];
1166 [supervisedBookmarksButton_ setFrame:frame]; 1227 [supervisedBookmarksButton_ setFrame:frame];
1167 } 1228 }
1168 1229
1169 for (int i = 0; i < node->child_count(); i++) { 1230 for (int i = 0; i < node->child_count(); i++) {
1170 const BookmarkNode* child = node->GetChild(i); 1231 const BookmarkNode* child = node->GetChild(i);
1171 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; 1232 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset];
1172 if (NSMinX([button frame]) >= maxViewX) { 1233 if (NSMinX([button frame]) >= maxViewX) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 } 1290 }
1230 1291
1231 // Add bookmark buttons to the view only if they are completely 1292 // Add bookmark buttons to the view only if they are completely
1232 // visible and don't overlap the "other bookmarks". Remove buttons 1293 // visible and don't overlap the "other bookmarks". Remove buttons
1233 // which are clipped. Called when building the bookmark bar the first time. 1294 // which are clipped. Called when building the bookmark bar the first time.
1234 - (void)addButtonsToView { 1295 - (void)addButtonsToView {
1235 displayedButtonCount_ = 0; 1296 displayedButtonCount_ = 0;
1236 NSMutableArray* buttons = [self buttons]; 1297 NSMutableArray* buttons = [self buttons];
1237 for (NSButton* button in buttons) { 1298 for (NSButton* button in buttons) {
1238 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) - 1299 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) -
1239 bookmarks::kBookmarkHorizontalPadding)) 1300 bookmarks::BookmarkHorizontalPadding()))
1240 break; 1301 break;
1241 [buttonView_ addSubview:button]; 1302 [buttonView_ addSubview:button];
1242 ++displayedButtonCount_; 1303 ++displayedButtonCount_;
1243 } 1304 }
1244 NSUInteger removalCount = 1305 NSUInteger removalCount =
1245 [buttons count] - (NSUInteger)displayedButtonCount_; 1306 [buttons count] - (NSUInteger)displayedButtonCount_;
1246 if (removalCount > 0) { 1307 if (removalCount > 0) {
1247 NSRange removalRange = NSMakeRange(displayedButtonCount_, removalCount); 1308 NSRange removalRange = NSMakeRange(displayedButtonCount_, removalCount);
1248 [buttons removeObjectsInRange:removalRange]; 1309 [buttons removeObjectsInRange:removalRange];
1249 } 1310 }
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1613 [self shrinkOrHideView:noItemTextfield forMaxX:maxViewX]; 1674 [self shrinkOrHideView:noItemTextfield forMaxX:maxViewX];
1614 } 1675 }
1615 } 1676 }
1616 1677
1617 // Scans through all buttons from left to right, calculating from scratch where 1678 // 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 1679 // they should be based on the preceding widths, until it finds the one
1619 // requested. 1680 // requested.
1620 // Returns NSZeroRect if there is no such button in the bookmark bar. 1681 // 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. 1682 // Enables you to work out where a button will end up when it is done animating.
1622 - (NSRect)finalRectOfButton:(BookmarkButton*)wantedButton { 1683 - (NSRect)finalRectOfButton:(BookmarkButton*)wantedButton {
1623 CGFloat left = bookmarks::kBookmarkLeftMargin; 1684 CGFloat left = bookmarks::BookmarkLeftMargin();
1624 NSRect buttonFrame = NSZeroRect; 1685 NSRect buttonFrame = NSZeroRect;
1625 1686
1626 // Draw the apps bookmark if needed. 1687 // Draw the apps bookmark if needed.
1627 if (![appsPageShortcutButton_ isHidden]) { 1688 if (![appsPageShortcutButton_ isHidden]) {
1628 left = NSMaxX([appsPageShortcutButton_ frame]) + 1689 left = NSMaxX([appsPageShortcutButton_ frame]) +
1629 bookmarks::kBookmarkHorizontalPadding; 1690 bookmarks::BookmarkHorizontalPadding();
1630 } 1691 }
1631 1692
1632 // Draw the managed bookmarks folder if needed. 1693 // Draw the managed bookmarks folder if needed.
1633 if (![managedBookmarksButton_ isHidden]) { 1694 if (![managedBookmarksButton_ isHidden]) {
1634 left = NSMaxX([managedBookmarksButton_ frame]) + 1695 left = NSMaxX([managedBookmarksButton_ frame]) +
1635 bookmarks::kBookmarkHorizontalPadding; 1696 bookmarks::BookmarkHorizontalPadding();
1636 } 1697 }
1637 1698
1638 // Draw the supervised bookmarks folder if needed. 1699 // Draw the supervised bookmarks folder if needed.
1639 if (![supervisedBookmarksButton_ isHidden]) { 1700 if (![supervisedBookmarksButton_ isHidden]) {
1640 left = NSMaxX([supervisedBookmarksButton_ frame]) + 1701 left = NSMaxX([supervisedBookmarksButton_ frame]) +
1641 bookmarks::kBookmarkHorizontalPadding; 1702 bookmarks::BookmarkHorizontalPadding();
1642 } 1703 }
1643 1704
1644 for (NSButton* button in buttons_.get()) { 1705 for (NSButton* button in buttons_.get()) {
1645 // Hidden buttons get no space. 1706 // Hidden buttons get no space.
1646 if ([button isHidden]) 1707 if ([button isHidden])
1647 continue; 1708 continue;
1648 buttonFrame = [button frame]; 1709 buttonFrame = [button frame];
1649 buttonFrame.origin.x = left; 1710 buttonFrame.origin.x = left;
1650 left += buttonFrame.size.width + bookmarks::kBookmarkHorizontalPadding; 1711 left += buttonFrame.size.width + bookmarks::BookmarkHorizontalPadding();
1651 if (button == wantedButton) 1712 if (button == wantedButton)
1652 return buttonFrame; 1713 return buttonFrame;
1653 } 1714 }
1654 return NSZeroRect; 1715 return NSZeroRect;
1655 } 1716 }
1656 1717
1657 // Calculates the final position of the last button in the bar. 1718 // Calculates the final position of the last button in the bar.
1658 // We can't just use [[self buttons] lastObject] frame] because the button 1719 // We can't just use [[self buttons] lastObject] frame] because the button
1659 // may be animating currently. 1720 // may be animating currently.
1660 - (NSRect)finalRectOfLastButton { 1721 - (NSRect)finalRectOfLastButton {
1661 return [self finalRectOfButton:[[self buttons] lastObject]]; 1722 return [self finalRectOfButton:[[self buttons] lastObject]];
1662 } 1723 }
1663 1724
1664 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible { 1725 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible {
1665 CGFloat maxViewX = NSMaxX([buttonView_ bounds]); 1726 CGFloat maxViewX = NSMaxX([buttonView_ bounds]);
1666 // If necessary, pull in the width to account for the Other Bookmarks button. 1727 // If necessary, pull in the width to account for the Other Bookmarks button.
1667 if ([self setOtherBookmarksButtonVisibility]) { 1728 if ([self setOtherBookmarksButtonVisibility]) {
1668 maxViewX = [otherBookmarksButton_ frame].origin.x - 1729 maxViewX = [otherBookmarksButton_ frame].origin.x -
1669 bookmarks::kBookmarkRightMargin; 1730 bookmarks::BookmarkRightMargin();
1670 } 1731 }
1671 1732
1672 [self positionRightSideButtons]; 1733 [self positionRightSideButtons];
1673 // If we're already overflowing, then we need to account for the chevron. 1734 // If we're already overflowing, then we need to account for the chevron.
1674 if (visible) { 1735 if (visible) {
1675 maxViewX = 1736 maxViewX =
1676 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin; 1737 [offTheSideButton_ frame].origin.x - bookmarks::BookmarkRightMargin();
1677 } 1738 }
1678 1739
1679 return maxViewX; 1740 return maxViewX;
1680 } 1741 }
1681 1742
1682 - (void)redistributeButtonsOnBarAsNeeded { 1743 - (void)redistributeButtonsOnBarAsNeeded {
1683 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); 1744 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node();
1684 NSInteger barCount = node->child_count(); 1745 NSInteger barCount = node->child_count();
1685 1746
1686 // Determine the current maximum extent of the visible buttons. 1747 // Determine the current maximum extent of the visible buttons.
(...skipping 18 matching lines...) Expand all
1705 offTheSideButtonVisible = YES; 1766 offTheSideButtonVisible = YES;
1706 maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:YES]; 1767 maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:YES];
1707 } 1768 }
1708 } 1769 }
1709 1770
1710 // As a result of cutting, deleting and dragging, the bar may now have room 1771 // As a result of cutting, deleting and dragging, the bar may now have room
1711 // for more buttons. 1772 // for more buttons.
1712 int xOffset; 1773 int xOffset;
1713 if (displayedButtonCount_ > 0) { 1774 if (displayedButtonCount_ > 0) {
1714 xOffset = NSMaxX([self finalRectOfLastButton]) + 1775 xOffset = NSMaxX([self finalRectOfLastButton]) +
1715 bookmarks::kBookmarkHorizontalPadding; 1776 bookmarks::BookmarkHorizontalPadding();
1716 } else if (![managedBookmarksButton_ isHidden]) { 1777 } else if (![managedBookmarksButton_ isHidden]) {
1717 xOffset = NSMaxX([managedBookmarksButton_ frame]) + 1778 xOffset = NSMaxX([managedBookmarksButton_ frame]) +
1718 bookmarks::kBookmarkHorizontalPadding; 1779 bookmarks::BookmarkHorizontalPadding();
1719 } else if (![supervisedBookmarksButton_ isHidden]) { 1780 } else if (![supervisedBookmarksButton_ isHidden]) {
1720 xOffset = NSMaxX([supervisedBookmarksButton_ frame]) + 1781 xOffset = NSMaxX([supervisedBookmarksButton_ frame]) +
1721 bookmarks::kBookmarkHorizontalPadding; 1782 bookmarks::BookmarkHorizontalPadding();
1722 } else if (![appsPageShortcutButton_ isHidden]) { 1783 } else if (![appsPageShortcutButton_ isHidden]) {
1723 xOffset = NSMaxX([appsPageShortcutButton_ frame]) + 1784 xOffset = NSMaxX([appsPageShortcutButton_ frame]) +
1724 bookmarks::kBookmarkHorizontalPadding; 1785 bookmarks::BookmarkHorizontalPadding();
1725 } else { 1786 } else {
1726 xOffset = bookmarks::kBookmarkLeftMargin - 1787 xOffset = bookmarks::BookmarkLeftMargin() -
1727 bookmarks::kBookmarkHorizontalPadding; 1788 bookmarks::BookmarkHorizontalPadding();
1728 } 1789 }
1729 for (int i = displayedButtonCount_; i < barCount; ++i) { 1790 for (int i = displayedButtonCount_; i < barCount; ++i) {
1730 const BookmarkNode* child = node->GetChild(i); 1791 const BookmarkNode* child = node->GetChild(i);
1731 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; 1792 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset];
1732 // If we're testing against the last possible button then account 1793 // If we're testing against the last possible button then account
1733 // for the chevron no longer needing to be shown. 1794 // for the chevron no longer needing to be shown.
1734 if (i == barCount - 1) 1795 if (i == barCount - 1)
1735 maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:NO]; 1796 maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:NO];
1736 if (NSMaxX([button frame]) > maxViewX) { 1797 if (NSMaxX([button frame]) > maxViewX) {
1737 [button setDelegate:nil]; 1798 [button setDelegate:nil];
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 // can be important if a bookmark is deleted (via bookmark sync) 1867 // can be important if a bookmark is deleted (via bookmark sync)
1807 // while in the middle of a drag. The "drag completed" code 1868 // while in the middle of a drag. The "drag completed" code
1808 // (e.g. [BookmarkBarView performDragOperationForBookmarkButton:]) is 1869 // (e.g. [BookmarkBarView performDragOperationForBookmarkButton:]) is
1809 // careful enough to bail if there is no data found at "drop" time. 1870 // careful enough to bail if there is no data found at "drop" time.
1810 [[NSPasteboard pasteboardWithName:NSDragPboard] clearContents]; 1871 [[NSPasteboard pasteboardWithName:NSDragPboard] clearContents];
1811 } 1872 }
1812 1873
1813 // Return an autoreleased NSCell suitable for a bookmark button. 1874 // Return an autoreleased NSCell suitable for a bookmark button.
1814 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. 1875 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class.
1815 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)node { 1876 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)node {
1816 NSImage* image = node ? [self faviconForNode:node] : nil; 1877 BOOL darkTheme = [[[self view] window] hasDarkTheme];
1878 NSImage* image = node ? [self faviconForNode:node forADarkTheme:darkTheme]
1879 : nil;
1817 BookmarkButtonCell* cell = 1880 BookmarkButtonCell* cell =
1818 [BookmarkButtonCell buttonCellForNode:node 1881 [BookmarkButtonCell buttonCellForNode:node
1819 text:nil 1882 text:nil
1820 image:image 1883 image:image
1821 menuController:contextMenuController_]; 1884 menuController:contextMenuController_];
1822 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback]; 1885 if (ui::MaterialDesignController::IsModeMaterial()) {
1886 [cell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback];
1887 } else {
1888 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback];
1889 }
1823 1890
1824 // Note: a quirk of setting a cell's text color is that it won't work 1891 // 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. 1892 // until the cell is associated with a button, so we can't theme the cell yet.
1826 1893
1827 return cell; 1894 return cell;
1828 } 1895 }
1829 1896
1830 // Return an autoreleased NSCell suitable for a special button displayed on the 1897 // Return an autoreleased NSCell suitable for a special button displayed on the
1831 // bookmark bar that is not attached to any bookmark node. 1898 // bookmark bar that is not attached to any bookmark node.
1832 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. 1899 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class.
1833 - (BookmarkButtonCell*)cellForCustomButtonWithText:(NSString*)text 1900 - (BookmarkButtonCell*)cellForCustomButtonWithText:(NSString*)text
1834 image:(NSImage*)image { 1901 image:(NSImage*)image {
1835 BookmarkButtonCell* cell = 1902 BookmarkButtonCell* cell =
1836 [BookmarkButtonCell buttonCellWithText:text 1903 [BookmarkButtonCell buttonCellWithText:text
1837 image:image 1904 image:image
1838 menuController:contextMenuController_]; 1905 menuController:contextMenuController_];
1839 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback]; 1906 if (ui::MaterialDesignController::IsModeMaterial()) {
1907 [cell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback];
1908 } else {
1909 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback];
1910 }
1840 1911
1841 // Note: a quirk of setting a cell's text color is that it won't work 1912 // 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. 1913 // until the cell is associated with a button, so we can't theme the cell yet.
1843 1914
1844 return cell; 1915 return cell;
1845 } 1916 }
1846 1917
1847 // Returns a frame appropriate for the given bookmark cell, suitable 1918 // Returns a frame appropriate for the given bookmark cell, suitable
1848 // for creating an NSButton that will contain it. |xOffset| is the X 1919 // 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 1920 // offset for the frame; it is increased to be an appropriate X offset
1850 // for the next button. 1921 // for the next button.
1851 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell 1922 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell
1852 xOffset:(int*)xOffset { 1923 xOffset:(int*)xOffset {
1853 DCHECK(xOffset); 1924 DCHECK(xOffset);
1854 NSRect bounds = [buttonView_ bounds]; 1925 NSRect bounds = [buttonView_ bounds];
1855 bounds.size.height = bookmarks::kBookmarkButtonHeight; 1926 if (ui::MaterialDesignController::IsModeMaterial()) {
1927 bounds.size.height = bookmarks::kMaterialBookmarkButtonHeight;
1928 } else {
1929 bounds.size.height = bookmarks::kBookmarkButtonHeight;
1930 }
1856 1931
1857 NSRect frame = NSInsetRect(bounds, 1932 NSRect frame = NSInsetRect(bounds,
1858 bookmarks::kBookmarkHorizontalPadding, 1933 bookmarks::BookmarkHorizontalPadding(),
1859 bookmarks::kBookmarkVerticalPadding); 1934 bookmarks::BookmarkVerticalPadding());
1860 frame.size.width = [self widthForBookmarkButtonCell:cell]; 1935 frame.size.width = [self widthForBookmarkButtonCell:cell];
1861 1936
1862 // Add an X offset based on what we've already done 1937 // Add an X offset based on what we've already done
1863 frame.origin.x += *xOffset; 1938 frame.origin.x += *xOffset;
1864 1939
1865 // And up the X offset for next time. 1940 // And up the X offset for next time.
1866 *xOffset = NSMaxX(frame); 1941 *xOffset = NSMaxX(frame);
1867 1942
1868 return frame; 1943 return frame;
1869 } 1944 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
2152 // Set insertionPos_ and hasInsertionPos_, and make insertion space for a 2227 // Set insertionPos_ and hasInsertionPos_, and make insertion space for a
2153 // hypothetical drop with the new button having a left edge of |where|. 2228 // hypothetical drop with the new button having a left edge of |where|.
2154 // Gets called only by our view. 2229 // Gets called only by our view.
2155 - (void)setDropInsertionPos:(CGFloat)where { 2230 - (void)setDropInsertionPos:(CGFloat)where {
2156 if (!hasInsertionPos_ || where != insertionPos_) { 2231 if (!hasInsertionPos_ || where != insertionPos_) {
2157 insertionPos_ = where; 2232 insertionPos_ = where;
2158 hasInsertionPos_ = YES; 2233 hasInsertionPos_ = YES;
2159 CGFloat left; 2234 CGFloat left;
2160 if (![supervisedBookmarksButton_ isHidden]) { 2235 if (![supervisedBookmarksButton_ isHidden]) {
2161 left = NSMaxX([supervisedBookmarksButton_ frame]) + 2236 left = NSMaxX([supervisedBookmarksButton_ frame]) +
2162 bookmarks::kBookmarkHorizontalPadding; 2237 bookmarks::BookmarkHorizontalPadding();
2163 } else if (![managedBookmarksButton_ isHidden]) { 2238 } else if (![managedBookmarksButton_ isHidden]) {
2164 left = NSMaxX([managedBookmarksButton_ frame]) + 2239 left = NSMaxX([managedBookmarksButton_ frame]) +
2165 bookmarks::kBookmarkHorizontalPadding; 2240 bookmarks::BookmarkHorizontalPadding();
2166 } else if (![appsPageShortcutButton_ isHidden]) { 2241 } else if (![appsPageShortcutButton_ isHidden]) {
2167 left = NSMaxX([appsPageShortcutButton_ frame]) + 2242 left = NSMaxX([appsPageShortcutButton_ frame]) +
2168 bookmarks::kBookmarkHorizontalPadding; 2243 bookmarks::BookmarkHorizontalPadding();
2169 } else { 2244 } else {
2170 left = bookmarks::kBookmarkLeftMargin; 2245 left = bookmarks::BookmarkLeftMargin();
2171 } 2246 }
2172 CGFloat paddingWidth = bookmarks::kDefaultBookmarkWidth; 2247 CGFloat paddingWidth = bookmarks::kDefaultBookmarkWidth;
2173 BookmarkButton* draggedButton = [BookmarkButton draggedButton]; 2248 BookmarkButton* draggedButton = [BookmarkButton draggedButton];
2174 if (draggedButton) { 2249 if (draggedButton) {
2175 paddingWidth = std::min(bookmarks::kDefaultBookmarkWidth, 2250 paddingWidth = std::min(bookmarks::kDefaultBookmarkWidth,
2176 NSWidth([draggedButton frame])); 2251 NSWidth([draggedButton frame]));
2177 } 2252 }
2178 // Put all the buttons where they belong, with all buttons to the right 2253 // 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. 2254 // of the insertion point shuffling right to make space for it.
2180 [NSAnimationContext beginGrouping]; 2255 [NSAnimationContext beginGrouping];
2181 [[NSAnimationContext currentContext] 2256 [[NSAnimationContext currentContext]
2182 setDuration:kDragAndDropAnimationDuration]; 2257 setDuration:kDragAndDropAnimationDuration];
2183 for (NSButton* button in buttons_.get()) { 2258 for (NSButton* button in buttons_.get()) {
2184 // Hidden buttons get no space. 2259 // Hidden buttons get no space.
2185 if ([button isHidden]) 2260 if ([button isHidden])
2186 continue; 2261 continue;
2187 NSRect buttonFrame = [button frame]; 2262 NSRect buttonFrame = [button frame];
2188 buttonFrame.origin.x = left; 2263 buttonFrame.origin.x = left;
2189 // Update "left" for next time around. 2264 // Update "left" for next time around.
2190 left += buttonFrame.size.width; 2265 left += buttonFrame.size.width;
2191 if (left > insertionPos_) 2266 if (left > insertionPos_)
2192 buttonFrame.origin.x += paddingWidth; 2267 buttonFrame.origin.x += paddingWidth;
2193 left += bookmarks::kBookmarkHorizontalPadding; 2268 left += bookmarks::BookmarkHorizontalPadding();
2194 if (innerContentAnimationsEnabled_) 2269 if (innerContentAnimationsEnabled_)
2195 [[button animator] setFrame:buttonFrame]; 2270 [[button animator] setFrame:buttonFrame];
2196 else 2271 else
2197 [button setFrame:buttonFrame]; 2272 [button setFrame:buttonFrame];
2198 } 2273 }
2199 [NSAnimationContext endGrouping]; 2274 [NSAnimationContext endGrouping];
2200 } 2275 }
2201 } 2276 }
2202 2277
2203 // Put all visible bookmark bar buttons in their normal locations, either with 2278 // Put all visible bookmark bar buttons in their normal locations, either with
2204 // or without animation according to the |animate| flag. 2279 // or without animation according to the |animate| flag.
2205 // This is generally useful, so is called from various places internally. 2280 // This is generally useful, so is called from various places internally.
2206 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate { 2281 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate {
2207 2282
2208 // Position the apps bookmark if needed. 2283 // Position the apps bookmark if needed.
2209 CGFloat left = bookmarks::kBookmarkLeftMargin; 2284 CGFloat left = bookmarks::BookmarkLeftMargin();
2210 if (![appsPageShortcutButton_ isHidden]) { 2285 if (![appsPageShortcutButton_ isHidden]) {
2211 int xOffset = 2286 int xOffset = bookmarks::BookmarkLeftMargin() -
2212 bookmarks::kBookmarkLeftMargin - bookmarks::kBookmarkHorizontalPadding; 2287 bookmarks::BookmarkHorizontalPadding();
2213 NSRect frame = 2288 NSRect frame =
2214 [self frameForBookmarkButtonFromCell:[appsPageShortcutButton_ cell] 2289 [self frameForBookmarkButtonFromCell:[appsPageShortcutButton_ cell]
2215 xOffset:&xOffset]; 2290 xOffset:&xOffset];
2216 [appsPageShortcutButton_ setFrame:frame]; 2291 [appsPageShortcutButton_ setFrame:frame];
2217 left = xOffset + bookmarks::kBookmarkHorizontalPadding; 2292 left = xOffset + bookmarks::BookmarkHorizontalPadding();
2218 } 2293 }
2219 2294
2220 // Position the managed bookmarks folder if needed. 2295 // Position the managed bookmarks folder if needed.
2221 if (![managedBookmarksButton_ isHidden]) { 2296 if (![managedBookmarksButton_ isHidden]) {
2222 int xOffset = left; 2297 int xOffset = left;
2223 NSRect frame = 2298 NSRect frame =
2224 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell] 2299 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell]
2225 xOffset:&xOffset]; 2300 xOffset:&xOffset];
2226 [managedBookmarksButton_ setFrame:frame]; 2301 [managedBookmarksButton_ setFrame:frame];
2227 left = xOffset + bookmarks::kBookmarkHorizontalPadding; 2302 left = xOffset + bookmarks::BookmarkHorizontalPadding();
2228 } 2303 }
2229 2304
2230 // Position the supervised bookmarks folder if needed. 2305 // Position the supervised bookmarks folder if needed.
2231 if (![supervisedBookmarksButton_ isHidden]) { 2306 if (![supervisedBookmarksButton_ isHidden]) {
2232 int xOffset = left; 2307 int xOffset = left;
2233 NSRect frame = 2308 NSRect frame =
2234 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell] 2309 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell]
2235 xOffset:&xOffset]; 2310 xOffset:&xOffset];
2236 [supervisedBookmarksButton_ setFrame:frame]; 2311 [supervisedBookmarksButton_ setFrame:frame];
2237 left = xOffset + bookmarks::kBookmarkHorizontalPadding; 2312 left = xOffset + bookmarks::BookmarkHorizontalPadding();
2238 } 2313 }
2239 2314
2240 animate &= innerContentAnimationsEnabled_; 2315 animate &= innerContentAnimationsEnabled_;
2241 2316
2242 for (NSButton* button in buttons_.get()) { 2317 for (NSButton* button in buttons_.get()) {
2243 // Hidden buttons get no space. 2318 // Hidden buttons get no space.
2244 if ([button isHidden]) 2319 if ([button isHidden])
2245 continue; 2320 continue;
2246 NSRect buttonFrame = [button frame]; 2321 NSRect buttonFrame = [button frame];
2247 buttonFrame.origin.x = left; 2322 buttonFrame.origin.x = left;
2248 left += buttonFrame.size.width + bookmarks::kBookmarkHorizontalPadding; 2323 left += buttonFrame.size.width + bookmarks::BookmarkHorizontalPadding();
2249 if (animate) 2324 if (animate)
2250 [[button animator] setFrame:buttonFrame]; 2325 [[button animator] setFrame:buttonFrame];
2251 else 2326 else
2252 [button setFrame:buttonFrame]; 2327 [button setFrame:buttonFrame];
2253 } 2328 }
2254 } 2329 }
2255 2330
2256 // Clear insertion flag, remove insertion space and put all visible bookmark 2331 // Clear insertion flag, remove insertion space and put all visible bookmark
2257 // bar buttons in their normal locations. 2332 // bar buttons in their normal locations.
2258 // Gets called only by our view. 2333 // 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 2442 // 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 2443 // buttons all placed, then "scooted over" as the favicons load. If
2369 // this looks bad I may need to change widthForBookmarkButtonCell to 2444 // this looks bad I may need to change widthForBookmarkButtonCell to
2370 // add space for an image even if not there on the assumption that 2445 // add space for an image even if not there on the assumption that
2371 // favicons will eventually load. 2446 // favicons will eventually load.
2372 - (void)nodeFaviconLoaded:(BookmarkModel*)model 2447 - (void)nodeFaviconLoaded:(BookmarkModel*)model
2373 node:(const BookmarkNode*)node { 2448 node:(const BookmarkNode*)node {
2374 for (BookmarkButton* button in buttons_.get()) { 2449 for (BookmarkButton* button in buttons_.get()) {
2375 const BookmarkNode* cellnode = [button bookmarkNode]; 2450 const BookmarkNode* cellnode = [button bookmarkNode];
2376 if (cellnode == node) { 2451 if (cellnode == node) {
2452 BOOL darkTheme = [[[self view] window] hasDarkTheme];
2453 NSImage* theImage = [self faviconForNode:node forADarkTheme:darkTheme];
2377 [[button cell] setBookmarkCellText:[button title] 2454 [[button cell] setBookmarkCellText:[button title]
2378 image:[self faviconForNode:node]]; 2455 image:theImage];
2379 // Adding an image means we might need more room for the 2456 // Adding an image means we might need more room for the
2380 // bookmark. Test for it by growing the button (if needed) 2457 // bookmark. Test for it by growing the button (if needed)
2381 // and shifting everything else over. 2458 // and shifting everything else over.
2382 [self checkForBookmarkButtonGrowth:button]; 2459 [self checkForBookmarkButtonGrowth:button];
2383 return; 2460 return;
2384 } 2461 }
2385 } 2462 }
2386 2463
2387 if (folderController_) 2464 if (folderController_)
2388 [folderController_ faviconLoadedForNode:node]; 2465 [folderController_ faviconLoadedForNode:node];
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
2531 [self resetAllButtonPositionsWithAnimation:YES]; 2608 [self resetAllButtonPositionsWithAnimation:YES];
2532 } 2609 }
2533 2610
2534 2611
2535 #pragma mark BookmarkButtonControllerProtocol 2612 #pragma mark BookmarkButtonControllerProtocol
2536 2613
2537 // Close all bookmark folders. "Folder" here is the fake menu for 2614 // Close all bookmark folders. "Folder" here is the fake menu for
2538 // bookmark folders, not a button context menu. 2615 // bookmark folders, not a button context menu.
2539 - (void)closeAllBookmarkFolders { 2616 - (void)closeAllBookmarkFolders {
2540 [self watchForExitEvent:NO]; 2617 [self watchForExitEvent:NO];
2618
2619 // Grab the parent button under Material Design to make sure that the
2620 // highlighting that was applied while revealing the menu is turned off.
2621 BookmarkButton* parentButton = nil;
2622 if (!ui::MaterialDesignController::IsModeMaterial()) {
2623 parentButton = [folderController_ parentButton];
2624 }
2541 [folderController_ close]; 2625 [folderController_ close];
2626 [[parentButton cell] setHighlighted:NO];
2627 [parentButton setNeedsDisplay:YES];
2542 folderController_ = nil; 2628 folderController_ = nil;
2543 } 2629 }
2544 2630
2545 - (void)closeBookmarkFolder:(id)sender { 2631 - (void)closeBookmarkFolder:(id)sender {
2546 // We're the top level, so close one means close them all. 2632 // We're the top level, so close one means close them all.
2547 [self closeAllBookmarkFolders]; 2633 [self closeAllBookmarkFolders];
2548 } 2634 }
2549 2635
2550 - (BookmarkModel*)bookmarkModel { 2636 - (BookmarkModel*)bookmarkModel {
2551 return bookmarkModel_; 2637 return bookmarkModel_;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2674 } 2760 }
2675 2761
2676 // Return YES if we should show the drop indicator, else NO. 2762 // Return YES if we should show the drop indicator, else NO.
2677 - (BOOL)shouldShowIndicatorShownForPoint:(NSPoint)point { 2763 - (BOOL)shouldShowIndicatorShownForPoint:(NSPoint)point {
2678 return ![self buttonForDroppingOnAtPoint:point]; 2764 return ![self buttonForDroppingOnAtPoint:point];
2679 } 2765 }
2680 2766
2681 // Return the x position for a drop indicator. 2767 // Return the x position for a drop indicator.
2682 - (CGFloat)indicatorPosForDragToPoint:(NSPoint)point { 2768 - (CGFloat)indicatorPosForDragToPoint:(NSPoint)point {
2683 CGFloat x = 0; 2769 CGFloat x = 0;
2684 CGFloat halfHorizontalPadding = 0.5 * bookmarks::kBookmarkHorizontalPadding; 2770 CGFloat halfHorizontalPadding = 0.5 * bookmarks::BookmarkHorizontalPadding();
2685 int destIndex = [self indexForDragToPoint:point]; 2771 int destIndex = [self indexForDragToPoint:point];
2686 int numButtons = displayedButtonCount_; 2772 int numButtons = displayedButtonCount_;
2687 2773
2688 CGFloat leftmostX; 2774 CGFloat leftmostX;
2689 if (![supervisedBookmarksButton_ isHidden]) { 2775 if (![supervisedBookmarksButton_ isHidden]) {
2690 leftmostX = 2776 leftmostX =
2691 NSMaxX([supervisedBookmarksButton_ frame]) + halfHorizontalPadding; 2777 NSMaxX([supervisedBookmarksButton_ frame]) + halfHorizontalPadding;
2692 } else if (![managedBookmarksButton_ isHidden]) { 2778 } else if (![managedBookmarksButton_ isHidden]) {
2693 leftmostX = NSMaxX([managedBookmarksButton_ frame]) + halfHorizontalPadding; 2779 leftmostX = NSMaxX([managedBookmarksButton_ frame]) + halfHorizontalPadding;
2694 } else if (![appsPageShortcutButton_ isHidden]) { 2780 } else if (![appsPageShortcutButton_ isHidden]) {
2695 leftmostX = NSMaxX([appsPageShortcutButton_ frame]) + halfHorizontalPadding; 2781 leftmostX = NSMaxX([appsPageShortcutButton_ frame]) + halfHorizontalPadding;
2696 } else { 2782 } else {
2697 leftmostX = bookmarks::kBookmarkLeftMargin - halfHorizontalPadding; 2783 leftmostX = bookmarks::BookmarkLeftMargin() - halfHorizontalPadding;
2698 } 2784 }
2699 2785
2700 // If it's a drop strictly between existing buttons ... 2786 // If it's a drop strictly between existing buttons ...
2701 if (destIndex == 0) { 2787 if (destIndex == 0) {
2702 x = leftmostX; 2788 x = leftmostX;
2703 } else if (destIndex > 0 && destIndex < numButtons) { 2789 } else if (destIndex > 0 && destIndex < numButtons) {
2704 // ... put the indicator right between the buttons. 2790 // ... put the indicator right between the buttons.
2705 BookmarkButton* button = 2791 BookmarkButton* button =
2706 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex-1)]; 2792 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex-1)];
2707 DCHECK(button); 2793 DCHECK(button);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2790 - (void)openAll:(const BookmarkNode*)node 2876 - (void)openAll:(const BookmarkNode*)node
2791 disposition:(WindowOpenDisposition)disposition { 2877 disposition:(WindowOpenDisposition)disposition {
2792 [self closeFolderAndStopTrackingMenus]; 2878 [self closeFolderAndStopTrackingMenus];
2793 chrome::OpenAll([[self view] window], browser_, node, disposition, 2879 chrome::OpenAll([[self view] window], browser_, node, disposition,
2794 browser_->profile()); 2880 browser_->profile());
2795 } 2881 }
2796 2882
2797 - (void)addButtonForNode:(const BookmarkNode*)node 2883 - (void)addButtonForNode:(const BookmarkNode*)node
2798 atIndex:(NSInteger)buttonIndex { 2884 atIndex:(NSInteger)buttonIndex {
2799 int newOffset = 2885 int newOffset =
2800 bookmarks::kBookmarkLeftMargin - bookmarks::kBookmarkHorizontalPadding; 2886 bookmarks::BookmarkLeftMargin() - bookmarks::BookmarkHorizontalPadding();
2801 if (buttonIndex == -1) 2887 if (buttonIndex == -1)
2802 buttonIndex = [buttons_ count]; // New button goes at the end. 2888 buttonIndex = [buttons_ count]; // New button goes at the end.
2803 if (buttonIndex <= (NSInteger)[buttons_ count]) { 2889 if (buttonIndex <= (NSInteger)[buttons_ count]) {
2804 if (buttonIndex) { 2890 if (buttonIndex) {
2805 BookmarkButton* targetButton = [buttons_ objectAtIndex:buttonIndex - 1]; 2891 BookmarkButton* targetButton = [buttons_ objectAtIndex:buttonIndex - 1];
2806 NSRect targetFrame = [targetButton frame]; 2892 NSRect targetFrame = [targetButton frame];
2807 newOffset = targetFrame.origin.x + NSWidth(targetFrame) + 2893 newOffset = targetFrame.origin.x + NSWidth(targetFrame) +
2808 bookmarks::kBookmarkHorizontalPadding; 2894 bookmarks::BookmarkHorizontalPadding();
2809 } 2895 }
2810 BookmarkButton* newButton = [self buttonForNode:node xOffset:&newOffset]; 2896 BookmarkButton* newButton = [self buttonForNode:node xOffset:&newOffset];
2811 ++displayedButtonCount_; 2897 ++displayedButtonCount_;
2812 [buttons_ insertObject:newButton atIndex:buttonIndex]; 2898 [buttons_ insertObject:newButton atIndex:buttonIndex];
2813 [buttonView_ addSubview:newButton]; 2899 [buttonView_ addSubview:newButton];
2814 [self resetAllButtonPositionsWithAnimation:NO]; 2900 [self resetAllButtonPositionsWithAnimation:NO];
2815 // See if any buttons need to be pushed off to or brought in from the side. 2901 // See if any buttons need to be pushed off to or brought in from the side.
2816 [self reconfigureBookmarkBar]; 2902 [self reconfigureBookmarkBar];
2817 } else { 2903 } else {
2818 // A button from somewhere else (not the bar) is being moved to the 2904 // 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: 3026 - (id<BookmarkButtonControllerProtocol>)controllerForNode:
2941 (const BookmarkNode*)node { 3027 (const BookmarkNode*)node {
2942 // See if it's in the bar, then if it is in the hierarchy of visible 3028 // See if it's in the bar, then if it is in the hierarchy of visible
2943 // folder menus. 3029 // folder menus.
2944 if (bookmarkModel_->bookmark_bar_node() == node) 3030 if (bookmarkModel_->bookmark_bar_node() == node)
2945 return self; 3031 return self;
2946 return [folderController_ controllerForNode:node]; 3032 return [folderController_ controllerForNode:node];
2947 } 3033 }
2948 3034
2949 @end 3035 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698