| OLD | NEW |
| 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 - (void)createOtherBookmarksButton; | 242 - (void)createOtherBookmarksButton; |
| 243 - (void)createAppsPageShortcutButton; | 243 - (void)createAppsPageShortcutButton; |
| 244 - (void)openAppsPage:(id)sender; | 244 - (void)openAppsPage:(id)sender; |
| 245 - (void)centerNoItemsLabel; | 245 - (void)centerNoItemsLabel; |
| 246 - (void)positionRightSideButtons; | 246 - (void)positionRightSideButtons; |
| 247 - (void)watchForExitEvent:(BOOL)watch; | 247 - (void)watchForExitEvent:(BOOL)watch; |
| 248 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate; | 248 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate; |
| 249 | 249 |
| 250 @end | 250 @end |
| 251 | 251 |
| 252 namespace bookmarks { | |
| 253 | |
| 254 CGFloat BookmarkHorizontalPadding() { | |
| 255 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 256 return 1.0; | |
| 257 } | |
| 258 return 4.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 8.0; | |
| 273 } | |
| 274 | |
| 275 CGFloat BookmarkRightMargin() { | |
| 276 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 277 return 2.0; | |
| 278 } | |
| 279 return 8.0; | |
| 280 } | |
| 281 | |
| 282 } // namespace bookmarks | |
| 283 | |
| 284 @implementation BookmarkBarController | 252 @implementation BookmarkBarController |
| 285 | 253 |
| 286 @synthesize currentState = currentState_; | 254 @synthesize currentState = currentState_; |
| 287 @synthesize lastState = lastState_; | 255 @synthesize lastState = lastState_; |
| 288 @synthesize isAnimationRunning = isAnimationRunning_; | 256 @synthesize isAnimationRunning = isAnimationRunning_; |
| 289 @synthesize delegate = delegate_; | 257 @synthesize delegate = delegate_; |
| 290 @synthesize stateAnimationsEnabled = stateAnimationsEnabled_; | 258 @synthesize stateAnimationsEnabled = stateAnimationsEnabled_; |
| 291 @synthesize innerContentAnimationsEnabled = innerContentAnimationsEnabled_; | 259 @synthesize innerContentAnimationsEnabled = innerContentAnimationsEnabled_; |
| 292 | 260 |
| 293 - (id)initWithBrowser:(Browser*)browser | 261 - (id)initWithBrowser:(Browser*)browser |
| (...skipping 12 matching lines...) Expand all Loading... |
| 306 ManagedBookmarkServiceFactory::GetForProfile(browser_->profile()); | 274 ManagedBookmarkServiceFactory::GetForProfile(browser_->profile()); |
| 307 buttons_.reset([[NSMutableArray alloc] init]); | 275 buttons_.reset([[NSMutableArray alloc] init]); |
| 308 delegate_ = delegate; | 276 delegate_ = delegate; |
| 309 folderTarget_.reset( | 277 folderTarget_.reset( |
| 310 [[BookmarkFolderTarget alloc] initWithController:self | 278 [[BookmarkFolderTarget alloc] initWithController:self |
| 311 profile:browser_->profile()]); | 279 profile:browser_->profile()]); |
| 312 | 280 |
| 313 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 281 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 314 folderImage_.reset( | 282 folderImage_.reset( |
| 315 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER).CopyNSImage()); | 283 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER).CopyNSImage()); |
| 316 if (ui::MaterialDesignController::IsModeMaterial()) { | 284 folderImageWhite_.reset( |
| 317 folderImageWhite_.reset( | 285 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER_WHITE).CopyNSImage()); |
| 318 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_FOLDER_WHITE).CopyNSImage()); | |
| 319 | 286 |
| 320 const int kIconSize = 16; | 287 const int kIconSize = 16; |
| 321 defaultImage_.reset([NSImageFromImageSkia( | 288 defaultImage_.reset([NSImageFromImageSkia( |
| 322 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_HTTP, | 289 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_HTTP, |
| 323 kIconSize, | 290 kIconSize, |
| 324 gfx::kChromeIconGrey)) retain]); | 291 gfx::kChromeIconGrey)) retain]); |
| 325 defaultImageIncognito_.reset([NSImageFromImageSkia( | 292 defaultImageIncognito_.reset([NSImageFromImageSkia( |
| 326 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_HTTP, | 293 gfx::CreateVectorIcon(gfx::VectorIconId::OMNIBOX_HTTP, |
| 327 kIconSize, | 294 kIconSize, |
| 328 SkColorSetA(SK_ColorWHITE, 0xCC))) retain]); | 295 SkColorSetA(SK_ColorWHITE, 0xCC))) retain]); |
| 329 } else { | |
| 330 defaultImage_.reset( | |
| 331 rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON).CopyNSImage()); | |
| 332 defaultImageIncognito_.reset([defaultImage_.get() retain]); | |
| 333 } | |
| 334 | 296 |
| 335 innerContentAnimationsEnabled_ = YES; | 297 innerContentAnimationsEnabled_ = YES; |
| 336 stateAnimationsEnabled_ = YES; | 298 stateAnimationsEnabled_ = YES; |
| 337 | 299 |
| 338 // Register for theme changes, bookmark button pulsing, ... | 300 // Register for theme changes, bookmark button pulsing, ... |
| 339 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; | 301 NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter]; |
| 340 [defaultCenter addObserver:self | 302 [defaultCenter addObserver:self |
| 341 selector:@selector(themeDidChangeNotification:) | 303 selector:@selector(themeDidChangeNotification:) |
| 342 name:kBrowserThemeDidChangeNotification | 304 name:kBrowserThemeDidChangeNotification |
| 343 object:nil]; | 305 object:nil]; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 return; | 434 return; |
| 473 } | 435 } |
| 474 | 436 |
| 475 // We default to NOT open, which means height=0. | 437 // We default to NOT open, which means height=0. |
| 476 DCHECK([[self view] isHidden]); // Hidden so it's OK to change. | 438 DCHECK([[self view] isHidden]); // Hidden so it's OK to change. |
| 477 | 439 |
| 478 // Set our initial height to zero, since that is what the superview | 440 // Set our initial height to zero, since that is what the superview |
| 479 // expects. We will resize ourselves open later if needed. | 441 // expects. We will resize ourselves open later if needed. |
| 480 [[self view] setFrame:NSMakeRect(0, 0, initialWidth_, 0)]; | 442 [[self view] setFrame:NSMakeRect(0, 0, initialWidth_, 0)]; |
| 481 | 443 |
| 482 const bool isModeMaterial = ui::MaterialDesignController::IsModeMaterial(); | 444 // Complete init of the "off the side" button, as much as we can. |
| 445 [offTheSideButton_ setImage:[self offTheSideButtonImage:NO]]; |
| 446 BookmarkButtonCell* offTheSideCell = [offTheSideButton_ cell]; |
| 447 [offTheSideCell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback]; |
| 448 [offTheSideCell setImagePosition:NSImageOnly]; |
| 483 | 449 |
| 484 // Complete init of the "off the side" button, as much as we can. | 450 // The cell is configured in the nib to draw a white highlight when clicked. |
| 485 if (isModeMaterial) { | 451 [offTheSideCell setHighlightsBy:NSNoCellMask]; |
| 486 [offTheSideButton_ setImage:[self offTheSideButtonImage:NO]]; | |
| 487 BookmarkButtonCell* offTheSideCell = [offTheSideButton_ cell]; | |
| 488 [offTheSideCell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback]; | |
| 489 [offTheSideCell setImagePosition:NSImageOnly]; | |
| 490 | |
| 491 // The cell is configured in the nib to draw a white highlight when clicked. | |
| 492 [offTheSideCell setHighlightsBy:NSNoCellMask]; | |
| 493 } else { | |
| 494 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
| 495 [offTheSideButton_ setImage: | |
| 496 rb.GetNativeImageNamed(IDR_BOOKMARK_BAR_CHEVRONS).ToNSImage()]; | |
| 497 } | |
| 498 [offTheSideButton_.draggableButton setDraggable:NO]; | 452 [offTheSideButton_.draggableButton setDraggable:NO]; |
| 499 [offTheSideButton_.draggableButton setActsOnMouseDown:YES]; | 453 [offTheSideButton_.draggableButton setActsOnMouseDown:YES]; |
| 500 | 454 |
| 501 // We are enabled by default. | 455 // We are enabled by default. |
| 502 barIsEnabled_ = YES; | 456 barIsEnabled_ = YES; |
| 503 | 457 |
| 504 // Remember the original sizes of the 'no items' and 'import bookmarks' | 458 // Remember the original sizes of the 'no items' and 'import bookmarks' |
| 505 // fields to aid in resizing when the window frame changes. | 459 // fields to aid in resizing when the window frame changes. |
| 506 originalNoItemsRect_ = [[buttonView_ noItemTextfield] frame]; | 460 originalNoItemsRect_ = [[buttonView_ noItemTextfield] frame]; |
| 507 originalImportBookmarksRect_ = [[buttonView_ importBookmarksButton] frame]; | 461 originalImportBookmarksRect_ = [[buttonView_ importBookmarksButton] frame]; |
| 508 if (isModeMaterial) { | |
| 509 // Bookmark buttons start farther from the bookmark bar's left edge so | |
| 510 // adjust the positions of the noItems and importBookmarks textfields. | |
| 511 const CGFloat kMaterialBookmarksTextfieldOffsetX = 14; | |
| 512 originalNoItemsRect_.origin.x += kMaterialBookmarksTextfieldOffsetX; | |
| 513 [[buttonView_ noItemTextfield] setFrame:originalNoItemsRect_]; | |
| 514 | 462 |
| 515 originalImportBookmarksRect_.origin.x += kMaterialBookmarksTextfieldOffsetX; | 463 // Bookmark buttons start farther from the bookmark bar's left edge so |
| 516 [[buttonView_ importBookmarksButton] setFrame:originalImportBookmarksRect_]; | 464 // adjust the positions of the noItems and importBookmarks textfields. |
| 465 const CGFloat kBookmarksTextfieldOffsetX = 14; |
| 466 originalNoItemsRect_.origin.x += kBookmarksTextfieldOffsetX; |
| 467 [[buttonView_ noItemTextfield] setFrame:originalNoItemsRect_]; |
| 517 | 468 |
| 518 // Move the chevron button up 2pts from its position in the xib. | 469 originalImportBookmarksRect_.origin.x += kBookmarksTextfieldOffsetX; |
| 519 NSRect chevronButtonFrame = [offTheSideButton_ frame]; | 470 [[buttonView_ importBookmarksButton] setFrame:originalImportBookmarksRect_]; |
| 520 chevronButtonFrame.origin.y -= 2; | 471 |
| 521 [offTheSideButton_ setFrame:chevronButtonFrame]; | 472 // Move the chevron button up 2pts from its position in the xib. |
| 522 } | 473 NSRect chevronButtonFrame = [offTheSideButton_ frame]; |
| 474 chevronButtonFrame.origin.y -= 2; |
| 475 [offTheSideButton_ setFrame:chevronButtonFrame]; |
| 523 | 476 |
| 524 // To make life happier when the bookmark bar is floating, the chevron is a | 477 // To make life happier when the bookmark bar is floating, the chevron is a |
| 525 // child of the button view. | 478 // child of the button view. |
| 526 [offTheSideButton_ removeFromSuperview]; | 479 [offTheSideButton_ removeFromSuperview]; |
| 527 [buttonView_ addSubview:offTheSideButton_]; | 480 [buttonView_ addSubview:offTheSideButton_]; |
| 528 | 481 |
| 529 // When resized we may need to add new buttons, or remove them (if | 482 // When resized we may need to add new buttons, or remove them (if |
| 530 // no longer visible), or add/remove the "off the side" menu. | 483 // no longer visible), or add/remove the "off the side" menu. |
| 531 [[self view] setPostsFrameChangedNotifications:YES]; | 484 [[self view] setPostsFrameChangedNotifications:YES]; |
| 532 [[NSNotificationCenter defaultCenter] | 485 [[NSNotificationCenter defaultCenter] |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 | 663 |
| 711 // In general, only show the divider when it's in the normal showing state. | 664 // In general, only show the divider when it's in the normal showing state. |
| 712 return [self isInState:BookmarkBar::SHOW] ? 0 : 1; | 665 return [self isInState:BookmarkBar::SHOW] ? 0 : 1; |
| 713 } | 666 } |
| 714 | 667 |
| 715 - (NSImage*)faviconForNode:(const BookmarkNode*)node | 668 - (NSImage*)faviconForNode:(const BookmarkNode*)node |
| 716 forADarkTheme:(BOOL)forADarkTheme { | 669 forADarkTheme:(BOOL)forADarkTheme { |
| 717 if (!node) | 670 if (!node) |
| 718 return forADarkTheme ? defaultImageIncognito_ : defaultImage_; | 671 return forADarkTheme ? defaultImageIncognito_ : defaultImage_; |
| 719 | 672 |
| 720 if (forADarkTheme && ui::MaterialDesignController::IsModeMaterial()) { | 673 if (forADarkTheme) { |
| 721 if (node == managedBookmarkService_->managed_node()) { | 674 if (node == managedBookmarkService_->managed_node()) { |
| 722 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 675 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 723 return rb.GetNativeImageNamed( | 676 return rb.GetNativeImageNamed( |
| 724 IDR_BOOKMARK_BAR_FOLDER_MANAGED_WHITE).ToNSImage(); | 677 IDR_BOOKMARK_BAR_FOLDER_MANAGED_WHITE).ToNSImage(); |
| 725 } | 678 } |
| 726 | 679 |
| 727 if (node == managedBookmarkService_->supervised_node()) { | 680 if (node == managedBookmarkService_->supervised_node()) { |
| 728 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 681 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 729 return rb.GetNativeImageNamed( | 682 return rb.GetNativeImageNamed( |
| 730 IDR_BOOKMARK_BAR_FOLDER_SUPERVISED_WHITE).ToNSImage(); | 683 IDR_BOOKMARK_BAR_FOLDER_SUPERVISED_WHITE).ToNSImage(); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 | 892 |
| 940 - (BookmarkLaunchLocation)bookmarkLaunchLocation { | 893 - (BookmarkLaunchLocation)bookmarkLaunchLocation { |
| 941 return currentState_ == BookmarkBar::DETACHED ? | 894 return currentState_ == BookmarkBar::DETACHED ? |
| 942 BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR : | 895 BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR : |
| 943 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR; | 896 BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR; |
| 944 } | 897 } |
| 945 | 898 |
| 946 // Position the right-side buttons including the off-the-side chevron. | 899 // Position the right-side buttons including the off-the-side chevron. |
| 947 - (void)positionRightSideButtons { | 900 - (void)positionRightSideButtons { |
| 948 int maxX = NSMaxX([[self buttonView] bounds]) - | 901 int maxX = NSMaxX([[self buttonView] bounds]) - |
| 949 bookmarks::BookmarkHorizontalPadding(); | 902 bookmarks::kBookmarkHorizontalPadding; |
| 950 int right = maxX; | 903 int right = maxX; |
| 951 | 904 |
| 952 int ignored = 0; | 905 int ignored = 0; |
| 953 NSRect frame = [self frameForBookmarkButtonFromCell: | 906 NSRect frame = [self frameForBookmarkButtonFromCell: |
| 954 [otherBookmarksButton_ cell] xOffset:&ignored]; | 907 [otherBookmarksButton_ cell] xOffset:&ignored]; |
| 955 if (![otherBookmarksButton_ isHidden]) { | 908 if (![otherBookmarksButton_ isHidden]) { |
| 956 right -= NSWidth(frame); | 909 right -= NSWidth(frame); |
| 957 frame.origin.x = right; | 910 frame.origin.x = right; |
| 958 } else { | 911 } else { |
| 959 frame.origin.x = maxX - NSWidth(frame); | 912 frame.origin.x = maxX - NSWidth(frame); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1141 seedId_ = 0; | 1094 seedId_ = 0; |
| 1142 menuTagMap_.clear(); | 1095 menuTagMap_.clear(); |
| 1143 } | 1096 } |
| 1144 | 1097 |
| 1145 - (int)preferredHeight { | 1098 - (int)preferredHeight { |
| 1146 DCHECK(![self isAnimationRunning]); | 1099 DCHECK(![self isAnimationRunning]); |
| 1147 | 1100 |
| 1148 if (!barIsEnabled_) | 1101 if (!barIsEnabled_) |
| 1149 return 0; | 1102 return 0; |
| 1150 | 1103 |
| 1151 CGFloat lineWidth = 0; | |
| 1152 BOOL isRetina = NO; | |
| 1153 BOOL reduceHeight = NO; | |
| 1154 | |
| 1155 switch (currentState_) { | 1104 switch (currentState_) { |
| 1156 case BookmarkBar::SHOW: | 1105 case BookmarkBar::SHOW: |
| 1157 // When on a Retina display and not using Material Design, | 1106 return chrome::kMinimumBookmarkBarHeight; |
| 1158 // -[ToolbarController baseToolbarHeight] reduces the height of the | |
| 1159 // toolbar by 1pt. In this case the bookmark bar needs to add 1pt of space | |
| 1160 // above the bookmark icons in order to maintain the proper distance from | |
| 1161 // toolbar items. See https://crbug.com/326245 . | |
| 1162 lineWidth = [[self view] cr_lineWidth]; | |
| 1163 isRetina = (lineWidth < 1); | |
| 1164 | |
| 1165 // Only adjust the height if Retina and not Material Design. | |
| 1166 reduceHeight = | |
| 1167 isRetina && !ui::MaterialDesignController::IsModeMaterial(); | |
| 1168 | |
| 1169 return reduceHeight ? chrome::kMinimumBookmarkBarHeight + 1 | |
| 1170 : chrome::kMinimumBookmarkBarHeight; | |
| 1171 case BookmarkBar::DETACHED: | 1107 case BookmarkBar::DETACHED: |
| 1172 return chrome::kNTPBookmarkBarHeight; | 1108 return chrome::kNTPBookmarkBarHeight; |
| 1173 case BookmarkBar::HIDDEN: | 1109 case BookmarkBar::HIDDEN: |
| 1174 return 0; | 1110 return 0; |
| 1175 } | 1111 } |
| 1176 } | 1112 } |
| 1177 | 1113 |
| 1178 // Recursively add the given bookmark node and all its children to | 1114 // Recursively add the given bookmark node and all its children to |
| 1179 // menu, one menu item per node. | 1115 // menu, one menu item per node. |
| 1180 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu { | 1116 - (void)addNode:(const BookmarkNode*)child toMenu:(NSMenu*)menu { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 NSMenu* menu = [[[NSMenu alloc] initWithTitle:title] autorelease]; | 1164 NSMenu* menu = [[[NSMenu alloc] initWithTitle:title] autorelease]; |
| 1229 [self addFolderNode:node toMenu:menu]; | 1165 [self addFolderNode:node toMenu:menu]; |
| 1230 | 1166 |
| 1231 if (![menu numberOfItems]) { | 1167 if (![menu numberOfItems]) { |
| 1232 [self tagEmptyMenu:menu]; | 1168 [self tagEmptyMenu:menu]; |
| 1233 } | 1169 } |
| 1234 return menu; | 1170 return menu; |
| 1235 } | 1171 } |
| 1236 | 1172 |
| 1237 // Return an appropriate width for the given bookmark button cell. | 1173 // Return an appropriate width for the given bookmark button cell. |
| 1238 // The "+2" is needed because, sometimes, Cocoa is off by a tad. | |
| 1239 // Example: for a bookmark named "Moma" or "SFGate", it is one pixel | |
| 1240 // too small. For "FBL" it is 2 pixels too small. | |
| 1241 // For a bookmark named "SFGateFooWoo", it is just fine. | |
| 1242 - (CGFloat)widthForBookmarkButtonCell:(NSCell*)cell { | 1174 - (CGFloat)widthForBookmarkButtonCell:(NSCell*)cell { |
| 1243 CGFloat desired = [cell cellSize].width; | 1175 return std::min([cell cellSize].width, bookmarks::kDefaultBookmarkWidth); |
| 1244 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 1245 desired += 2; | |
| 1246 } | |
| 1247 return std::min(desired, bookmarks::kDefaultBookmarkWidth); | |
| 1248 } | 1176 } |
| 1249 | 1177 |
| 1250 - (IBAction)openBookmarkMenuItem:(id)sender { | 1178 - (IBAction)openBookmarkMenuItem:(id)sender { |
| 1251 int64_t tag = [self nodeIdFromMenuTag:[sender tag]]; | 1179 int64_t tag = [self nodeIdFromMenuTag:[sender tag]]; |
| 1252 const BookmarkNode* node = | 1180 const BookmarkNode* node = |
| 1253 bookmarks::GetBookmarkNodeByID(bookmarkModel_, tag); | 1181 bookmarks::GetBookmarkNodeByID(bookmarkModel_, tag); |
| 1254 WindowOpenDisposition disposition = | 1182 WindowOpenDisposition disposition = |
| 1255 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | 1183 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
| 1256 [self openURL:node->url() disposition:disposition]; | 1184 [self openURL:node->url() disposition:disposition]; |
| 1257 } | 1185 } |
| 1258 | 1186 |
| 1259 // For the given root node of the bookmark bar, show or hide (as | 1187 // For the given root node of the bookmark bar, show or hide (as |
| 1260 // appropriate) the "no items" container (text which says "bookmarks | 1188 // appropriate) the "no items" container (text which says "bookmarks |
| 1261 // go here"). | 1189 // go here"). |
| 1262 - (void)showOrHideNoItemContainerForNode:(const BookmarkNode*)node { | 1190 - (void)showOrHideNoItemContainerForNode:(const BookmarkNode*)node { |
| 1263 BOOL hideNoItemWarning = !node->empty(); | 1191 BOOL hideNoItemWarning = !node->empty(); |
| 1264 [[buttonView_ noItemContainer] setHidden:hideNoItemWarning]; | 1192 [[buttonView_ noItemContainer] setHidden:hideNoItemWarning]; |
| 1265 } | 1193 } |
| 1266 | 1194 |
| 1267 // TODO(jrg): write a "build bar" so there is a nice spot for things | 1195 // TODO(jrg): write a "build bar" so there is a nice spot for things |
| 1268 // like the contextual menu which is invoked when not over a | 1196 // like the contextual menu which is invoked when not over a |
| 1269 // bookmark. On Safari that menu has a "new folder" option. | 1197 // bookmark. On Safari that menu has a "new folder" option. |
| 1270 - (void)addNodesToButtonList:(const BookmarkNode*)node { | 1198 - (void)addNodesToButtonList:(const BookmarkNode*)node { |
| 1271 [self showOrHideNoItemContainerForNode:node]; | 1199 [self showOrHideNoItemContainerForNode:node]; |
| 1272 | 1200 |
| 1273 CGFloat maxViewX = NSMaxX([[self view] bounds]); | 1201 CGFloat maxViewX = NSMaxX([[self view] bounds]); |
| 1274 int xOffset = | 1202 int xOffset = |
| 1275 bookmarks::BookmarkLeftMargin() - bookmarks::BookmarkHorizontalPadding(); | 1203 bookmarks::kBookmarkLeftMargin - bookmarks::kBookmarkHorizontalPadding; |
| 1276 | 1204 |
| 1277 // Draw the apps bookmark if needed. | 1205 // Draw the apps bookmark if needed. |
| 1278 if (![appsPageShortcutButton_ isHidden]) { | 1206 if (![appsPageShortcutButton_ isHidden]) { |
| 1279 NSRect frame = | 1207 NSRect frame = |
| 1280 [self frameForBookmarkButtonFromCell:[appsPageShortcutButton_ cell] | 1208 [self frameForBookmarkButtonFromCell:[appsPageShortcutButton_ cell] |
| 1281 xOffset:&xOffset]; | 1209 xOffset:&xOffset]; |
| 1282 [appsPageShortcutButton_ setFrame:frame]; | 1210 [appsPageShortcutButton_ setFrame:frame]; |
| 1283 } | 1211 } |
| 1284 | 1212 |
| 1285 // Draw the managed bookmark folder if needed. | 1213 // Draw the managed bookmark folder if needed. |
| 1286 if (![managedBookmarksButton_ isHidden]) { | 1214 if (![managedBookmarksButton_ isHidden]) { |
| 1287 xOffset += bookmarks::BookmarkHorizontalPadding(); | 1215 xOffset += bookmarks::kBookmarkHorizontalPadding; |
| 1288 NSRect frame = | 1216 NSRect frame = |
| 1289 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell] | 1217 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell] |
| 1290 xOffset:&xOffset]; | 1218 xOffset:&xOffset]; |
| 1291 [managedBookmarksButton_ setFrame:frame]; | 1219 [managedBookmarksButton_ setFrame:frame]; |
| 1292 } | 1220 } |
| 1293 | 1221 |
| 1294 // Draw the supervised bookmark folder if needed. | 1222 // Draw the supervised bookmark folder if needed. |
| 1295 if (![supervisedBookmarksButton_ isHidden]) { | 1223 if (![supervisedBookmarksButton_ isHidden]) { |
| 1296 xOffset += bookmarks::BookmarkHorizontalPadding(); | 1224 xOffset += bookmarks::kBookmarkHorizontalPadding; |
| 1297 NSRect frame = | 1225 NSRect frame = |
| 1298 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell] | 1226 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell] |
| 1299 xOffset:&xOffset]; | 1227 xOffset:&xOffset]; |
| 1300 [supervisedBookmarksButton_ setFrame:frame]; | 1228 [supervisedBookmarksButton_ setFrame:frame]; |
| 1301 } | 1229 } |
| 1302 | 1230 |
| 1303 for (int i = 0; i < node->child_count(); i++) { | 1231 for (int i = 0; i < node->child_count(); i++) { |
| 1304 const BookmarkNode* child = node->GetChild(i); | 1232 const BookmarkNode* child = node->GetChild(i); |
| 1305 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; | 1233 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; |
| 1306 if (NSMinX([button frame]) >= maxViewX) { | 1234 if (NSMinX([button frame]) >= maxViewX) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1363 } | 1291 } |
| 1364 | 1292 |
| 1365 // Add bookmark buttons to the view only if they are completely | 1293 // Add bookmark buttons to the view only if they are completely |
| 1366 // visible and don't overlap the "other bookmarks". Remove buttons | 1294 // visible and don't overlap the "other bookmarks". Remove buttons |
| 1367 // which are clipped. Called when building the bookmark bar the first time. | 1295 // which are clipped. Called when building the bookmark bar the first time. |
| 1368 - (void)addButtonsToView { | 1296 - (void)addButtonsToView { |
| 1369 displayedButtonCount_ = 0; | 1297 displayedButtonCount_ = 0; |
| 1370 NSMutableArray* buttons = [self buttons]; | 1298 NSMutableArray* buttons = [self buttons]; |
| 1371 for (NSButton* button in buttons) { | 1299 for (NSButton* button in buttons) { |
| 1372 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) - | 1300 if (NSMaxX([button frame]) > (NSMinX([offTheSideButton_ frame]) - |
| 1373 bookmarks::BookmarkHorizontalPadding())) | 1301 bookmarks::kBookmarkHorizontalPadding)) |
| 1374 break; | 1302 break; |
| 1375 [buttonView_ addSubview:button]; | 1303 [buttonView_ addSubview:button]; |
| 1376 ++displayedButtonCount_; | 1304 ++displayedButtonCount_; |
| 1377 } | 1305 } |
| 1378 NSUInteger removalCount = | 1306 NSUInteger removalCount = |
| 1379 [buttons count] - (NSUInteger)displayedButtonCount_; | 1307 [buttons count] - (NSUInteger)displayedButtonCount_; |
| 1380 if (removalCount > 0) { | 1308 if (removalCount > 0) { |
| 1381 NSRange removalRange = NSMakeRange(displayedButtonCount_, removalCount); | 1309 NSRange removalRange = NSMakeRange(displayedButtonCount_, removalCount); |
| 1382 [buttons removeObjectsInRange:removalRange]; | 1310 [buttons removeObjectsInRange:removalRange]; |
| 1383 } | 1311 } |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1747 [self shrinkOrHideView:noItemTextfield forMaxX:maxViewX]; | 1675 [self shrinkOrHideView:noItemTextfield forMaxX:maxViewX]; |
| 1748 } | 1676 } |
| 1749 } | 1677 } |
| 1750 | 1678 |
| 1751 // Scans through all buttons from left to right, calculating from scratch where | 1679 // Scans through all buttons from left to right, calculating from scratch where |
| 1752 // they should be based on the preceding widths, until it finds the one | 1680 // they should be based on the preceding widths, until it finds the one |
| 1753 // requested. | 1681 // requested. |
| 1754 // Returns NSZeroRect if there is no such button in the bookmark bar. | 1682 // Returns NSZeroRect if there is no such button in the bookmark bar. |
| 1755 // Enables you to work out where a button will end up when it is done animating. | 1683 // Enables you to work out where a button will end up when it is done animating. |
| 1756 - (NSRect)finalRectOfButton:(BookmarkButton*)wantedButton { | 1684 - (NSRect)finalRectOfButton:(BookmarkButton*)wantedButton { |
| 1757 CGFloat left = bookmarks::BookmarkLeftMargin(); | 1685 CGFloat left = bookmarks::kBookmarkLeftMargin; |
| 1758 NSRect buttonFrame = NSZeroRect; | 1686 NSRect buttonFrame = NSZeroRect; |
| 1759 | 1687 |
| 1760 // Draw the apps bookmark if needed. | 1688 // Draw the apps bookmark if needed. |
| 1761 if (![appsPageShortcutButton_ isHidden]) { | 1689 if (![appsPageShortcutButton_ isHidden]) { |
| 1762 left = NSMaxX([appsPageShortcutButton_ frame]) + | 1690 left = NSMaxX([appsPageShortcutButton_ frame]) + |
| 1763 bookmarks::BookmarkHorizontalPadding(); | 1691 bookmarks::kBookmarkHorizontalPadding; |
| 1764 } | 1692 } |
| 1765 | 1693 |
| 1766 // Draw the managed bookmarks folder if needed. | 1694 // Draw the managed bookmarks folder if needed. |
| 1767 if (![managedBookmarksButton_ isHidden]) { | 1695 if (![managedBookmarksButton_ isHidden]) { |
| 1768 left = NSMaxX([managedBookmarksButton_ frame]) + | 1696 left = NSMaxX([managedBookmarksButton_ frame]) + |
| 1769 bookmarks::BookmarkHorizontalPadding(); | 1697 bookmarks::kBookmarkHorizontalPadding; |
| 1770 } | 1698 } |
| 1771 | 1699 |
| 1772 // Draw the supervised bookmarks folder if needed. | 1700 // Draw the supervised bookmarks folder if needed. |
| 1773 if (![supervisedBookmarksButton_ isHidden]) { | 1701 if (![supervisedBookmarksButton_ isHidden]) { |
| 1774 left = NSMaxX([supervisedBookmarksButton_ frame]) + | 1702 left = NSMaxX([supervisedBookmarksButton_ frame]) + |
| 1775 bookmarks::BookmarkHorizontalPadding(); | 1703 bookmarks::kBookmarkHorizontalPadding; |
| 1776 } | 1704 } |
| 1777 | 1705 |
| 1778 for (NSButton* button in buttons_.get()) { | 1706 for (NSButton* button in buttons_.get()) { |
| 1779 // Hidden buttons get no space. | 1707 // Hidden buttons get no space. |
| 1780 if ([button isHidden]) | 1708 if ([button isHidden]) |
| 1781 continue; | 1709 continue; |
| 1782 buttonFrame = [button frame]; | 1710 buttonFrame = [button frame]; |
| 1783 buttonFrame.origin.x = left; | 1711 buttonFrame.origin.x = left; |
| 1784 left += buttonFrame.size.width + bookmarks::BookmarkHorizontalPadding(); | 1712 left += buttonFrame.size.width + bookmarks::kBookmarkHorizontalPadding; |
| 1785 if (button == wantedButton) | 1713 if (button == wantedButton) |
| 1786 return buttonFrame; | 1714 return buttonFrame; |
| 1787 } | 1715 } |
| 1788 return NSZeroRect; | 1716 return NSZeroRect; |
| 1789 } | 1717 } |
| 1790 | 1718 |
| 1791 // Calculates the final position of the last button in the bar. | 1719 // Calculates the final position of the last button in the bar. |
| 1792 // We can't just use [[self buttons] lastObject] frame] because the button | 1720 // We can't just use [[self buttons] lastObject] frame] because the button |
| 1793 // may be animating currently. | 1721 // may be animating currently. |
| 1794 - (NSRect)finalRectOfLastButton { | 1722 - (NSRect)finalRectOfLastButton { |
| 1795 return [self finalRectOfButton:[[self buttons] lastObject]]; | 1723 return [self finalRectOfButton:[[self buttons] lastObject]]; |
| 1796 } | 1724 } |
| 1797 | 1725 |
| 1798 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible { | 1726 - (CGFloat)buttonViewMaxXWithOffTheSideButtonIsVisible:(BOOL)visible { |
| 1799 CGFloat maxViewX = NSMaxX([buttonView_ bounds]); | 1727 CGFloat maxViewX = NSMaxX([buttonView_ bounds]); |
| 1800 // If necessary, pull in the width to account for the Other Bookmarks button. | 1728 // If necessary, pull in the width to account for the Other Bookmarks button. |
| 1801 if ([self setOtherBookmarksButtonVisibility]) { | 1729 if ([self setOtherBookmarksButtonVisibility]) { |
| 1802 maxViewX = [otherBookmarksButton_ frame].origin.x - | 1730 maxViewX = [otherBookmarksButton_ frame].origin.x - |
| 1803 bookmarks::BookmarkRightMargin(); | 1731 bookmarks::kBookmarkRightMargin; |
| 1804 } | 1732 } |
| 1805 | 1733 |
| 1806 [self positionRightSideButtons]; | 1734 [self positionRightSideButtons]; |
| 1807 // If we're already overflowing, then we need to account for the chevron. | 1735 // If we're already overflowing, then we need to account for the chevron. |
| 1808 if (visible) { | 1736 if (visible) { |
| 1809 maxViewX = | 1737 maxViewX = |
| 1810 [offTheSideButton_ frame].origin.x - bookmarks::BookmarkRightMargin(); | 1738 [offTheSideButton_ frame].origin.x - bookmarks::kBookmarkRightMargin; |
| 1811 } | 1739 } |
| 1812 | 1740 |
| 1813 return maxViewX; | 1741 return maxViewX; |
| 1814 } | 1742 } |
| 1815 | 1743 |
| 1816 - (void)redistributeButtonsOnBarAsNeeded { | 1744 - (void)redistributeButtonsOnBarAsNeeded { |
| 1817 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); | 1745 const BookmarkNode* node = bookmarkModel_->bookmark_bar_node(); |
| 1818 NSInteger barCount = node->child_count(); | 1746 NSInteger barCount = node->child_count(); |
| 1819 | 1747 |
| 1820 // Determine the current maximum extent of the visible buttons. | 1748 // Determine the current maximum extent of the visible buttons. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1839 offTheSideButtonVisible = YES; | 1767 offTheSideButtonVisible = YES; |
| 1840 maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:YES]; | 1768 maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:YES]; |
| 1841 } | 1769 } |
| 1842 } | 1770 } |
| 1843 | 1771 |
| 1844 // As a result of cutting, deleting and dragging, the bar may now have room | 1772 // As a result of cutting, deleting and dragging, the bar may now have room |
| 1845 // for more buttons. | 1773 // for more buttons. |
| 1846 int xOffset; | 1774 int xOffset; |
| 1847 if (displayedButtonCount_ > 0) { | 1775 if (displayedButtonCount_ > 0) { |
| 1848 xOffset = NSMaxX([self finalRectOfLastButton]); | 1776 xOffset = NSMaxX([self finalRectOfLastButton]); |
| 1849 | |
| 1850 // Adding the padding here causes the distance between button 1 and 2 to | |
| 1851 // be twice the padding instead of 1x. Pre-Material Design the padding was | |
| 1852 // 1pt, so this bug was not noticeable. With MD's padding, this error puts | |
| 1853 // 32pts of space between buttons. | |
| 1854 if (!ui::MaterialDesignController::IsModeMaterial()) { | |
| 1855 xOffset += bookmarks::BookmarkHorizontalPadding(); | |
| 1856 } | |
| 1857 } else if (![managedBookmarksButton_ isHidden]) { | 1777 } else if (![managedBookmarksButton_ isHidden]) { |
| 1858 xOffset = NSMaxX([managedBookmarksButton_ frame]) + | 1778 xOffset = NSMaxX([managedBookmarksButton_ frame]) + |
| 1859 bookmarks::BookmarkHorizontalPadding(); | 1779 bookmarks::kBookmarkHorizontalPadding; |
| 1860 } else if (![supervisedBookmarksButton_ isHidden]) { | 1780 } else if (![supervisedBookmarksButton_ isHidden]) { |
| 1861 xOffset = NSMaxX([supervisedBookmarksButton_ frame]) + | 1781 xOffset = NSMaxX([supervisedBookmarksButton_ frame]) + |
| 1862 bookmarks::BookmarkHorizontalPadding(); | 1782 bookmarks::kBookmarkHorizontalPadding; |
| 1863 } else if (![appsPageShortcutButton_ isHidden]) { | 1783 } else if (![appsPageShortcutButton_ isHidden]) { |
| 1864 xOffset = NSMaxX([appsPageShortcutButton_ frame]) + | 1784 xOffset = NSMaxX([appsPageShortcutButton_ frame]) + |
| 1865 bookmarks::BookmarkHorizontalPadding(); | 1785 bookmarks::kBookmarkHorizontalPadding; |
| 1866 } else { | 1786 } else { |
| 1867 xOffset = bookmarks::BookmarkLeftMargin() - | 1787 xOffset = bookmarks::kBookmarkLeftMargin - |
| 1868 bookmarks::BookmarkHorizontalPadding(); | 1788 bookmarks::kBookmarkHorizontalPadding; |
| 1869 } | 1789 } |
| 1870 for (int i = displayedButtonCount_; i < barCount; ++i) { | 1790 for (int i = displayedButtonCount_; i < barCount; ++i) { |
| 1871 const BookmarkNode* child = node->GetChild(i); | 1791 const BookmarkNode* child = node->GetChild(i); |
| 1872 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; | 1792 BookmarkButton* button = [self buttonForNode:child xOffset:&xOffset]; |
| 1873 // If we're testing against the last possible button then account | 1793 // If we're testing against the last possible button then account |
| 1874 // for the chevron no longer needing to be shown. | 1794 // for the chevron no longer needing to be shown. |
| 1875 if (i == barCount - 1) | 1795 if (i == barCount - 1) |
| 1876 maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:NO]; | 1796 maxViewX = [self buttonViewMaxXWithOffTheSideButtonIsVisible:NO]; |
| 1877 if (NSMaxX([button frame]) > maxViewX) { | 1797 if (NSMaxX([button frame]) > maxViewX) { |
| 1878 [button setDelegate:nil]; | 1798 [button setDelegate:nil]; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1947 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. | 1867 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. |
| 1948 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)node { | 1868 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)node { |
| 1949 BOOL darkTheme = [[[self view] window] hasDarkTheme]; | 1869 BOOL darkTheme = [[[self view] window] hasDarkTheme]; |
| 1950 NSImage* image = node ? [self faviconForNode:node forADarkTheme:darkTheme] | 1870 NSImage* image = node ? [self faviconForNode:node forADarkTheme:darkTheme] |
| 1951 : nil; | 1871 : nil; |
| 1952 BookmarkButtonCell* cell = | 1872 BookmarkButtonCell* cell = |
| 1953 [BookmarkButtonCell buttonCellForNode:node | 1873 [BookmarkButtonCell buttonCellForNode:node |
| 1954 text:nil | 1874 text:nil |
| 1955 image:image | 1875 image:image |
| 1956 menuController:contextMenuController_]; | 1876 menuController:contextMenuController_]; |
| 1957 if (ui::MaterialDesignController::IsModeMaterial()) { | 1877 [cell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback]; |
| 1958 [cell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback]; | |
| 1959 } else { | |
| 1960 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback]; | |
| 1961 } | |
| 1962 | 1878 |
| 1963 // Note: a quirk of setting a cell's text color is that it won't work | 1879 // Note: a quirk of setting a cell's text color is that it won't work |
| 1964 // until the cell is associated with a button, so we can't theme the cell yet. | 1880 // until the cell is associated with a button, so we can't theme the cell yet. |
| 1965 | 1881 |
| 1966 return cell; | 1882 return cell; |
| 1967 } | 1883 } |
| 1968 | 1884 |
| 1969 // Return an autoreleased NSCell suitable for a special button displayed on the | 1885 // Return an autoreleased NSCell suitable for a special button displayed on the |
| 1970 // bookmark bar that is not attached to any bookmark node. | 1886 // bookmark bar that is not attached to any bookmark node. |
| 1971 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. | 1887 // TODO(jrg): move much of the cell config into the BookmarkButtonCell class. |
| 1972 - (BookmarkButtonCell*)cellForCustomButtonWithText:(NSString*)text | 1888 - (BookmarkButtonCell*)cellForCustomButtonWithText:(NSString*)text |
| 1973 image:(NSImage*)image { | 1889 image:(NSImage*)image { |
| 1974 BookmarkButtonCell* cell = | 1890 BookmarkButtonCell* cell = |
| 1975 [BookmarkButtonCell buttonCellWithText:text | 1891 [BookmarkButtonCell buttonCellWithText:text |
| 1976 image:image | 1892 image:image |
| 1977 menuController:contextMenuController_]; | 1893 menuController:contextMenuController_]; |
| 1978 if (ui::MaterialDesignController::IsModeMaterial()) { | 1894 [cell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback]; |
| 1979 [cell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback]; | 1895 [cell setHighlightsBy:NSNoCellMask]; |
| 1980 [cell setHighlightsBy:NSNoCellMask]; | |
| 1981 } else { | |
| 1982 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback]; | |
| 1983 } | |
| 1984 | 1896 |
| 1985 // Note: a quirk of setting a cell's text color is that it won't work | 1897 // Note: a quirk of setting a cell's text color is that it won't work |
| 1986 // until the cell is associated with a button, so we can't theme the cell yet. | 1898 // until the cell is associated with a button, so we can't theme the cell yet. |
| 1987 | 1899 |
| 1988 return cell; | 1900 return cell; |
| 1989 } | 1901 } |
| 1990 | 1902 |
| 1991 // Returns a frame appropriate for the given bookmark cell, suitable | 1903 // Returns a frame appropriate for the given bookmark cell, suitable |
| 1992 // for creating an NSButton that will contain it. |xOffset| is the X | 1904 // for creating an NSButton that will contain it. |xOffset| is the X |
| 1993 // offset for the frame; it is increased to be an appropriate X offset | 1905 // offset for the frame; it is increased to be an appropriate X offset |
| 1994 // for the next button. | 1906 // for the next button. |
| 1995 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell | 1907 - (NSRect)frameForBookmarkButtonFromCell:(NSCell*)cell |
| 1996 xOffset:(int*)xOffset { | 1908 xOffset:(int*)xOffset { |
| 1997 DCHECK(xOffset); | 1909 DCHECK(xOffset); |
| 1998 NSRect bounds = [buttonView_ bounds]; | 1910 NSRect bounds = [buttonView_ bounds]; |
| 1999 bounds.size.height = bookmarks::kBookmarkButtonHeight; | 1911 bounds.size.height = bookmarks::kBookmarkButtonHeight; |
| 2000 | 1912 |
| 2001 NSRect frame = NSInsetRect(bounds, | 1913 NSRect frame = NSInsetRect(bounds, |
| 2002 bookmarks::BookmarkHorizontalPadding(), | 1914 bookmarks::kBookmarkHorizontalPadding, |
| 2003 bookmarks::BookmarkVerticalPadding()); | 1915 bookmarks::kBookmarkVerticalPadding); |
| 2004 frame.size.width = [self widthForBookmarkButtonCell:cell]; | 1916 frame.size.width = [self widthForBookmarkButtonCell:cell]; |
| 2005 | 1917 |
| 2006 // Add an X offset based on what we've already done | 1918 // Add an X offset based on what we've already done |
| 2007 frame.origin.x += *xOffset; | 1919 frame.origin.x += *xOffset; |
| 2008 | 1920 |
| 2009 // And up the X offset for next time. | 1921 // And up the X offset for next time. |
| 2010 *xOffset = NSMaxX(frame); | 1922 *xOffset = NSMaxX(frame); |
| 2011 | 1923 |
| 2012 return frame; | 1924 return frame; |
| 2013 } | 1925 } |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2295 // Set insertionPos_ and hasInsertionPos_, and make insertion space for a | 2207 // Set insertionPos_ and hasInsertionPos_, and make insertion space for a |
| 2296 // hypothetical drop with the new button having a left edge of |where|. | 2208 // hypothetical drop with the new button having a left edge of |where|. |
| 2297 // Gets called only by our view. | 2209 // Gets called only by our view. |
| 2298 - (void)setDropInsertionPos:(CGFloat)where { | 2210 - (void)setDropInsertionPos:(CGFloat)where { |
| 2299 if (!hasInsertionPos_ || where != insertionPos_) { | 2211 if (!hasInsertionPos_ || where != insertionPos_) { |
| 2300 insertionPos_ = where; | 2212 insertionPos_ = where; |
| 2301 hasInsertionPos_ = YES; | 2213 hasInsertionPos_ = YES; |
| 2302 CGFloat left; | 2214 CGFloat left; |
| 2303 if (![supervisedBookmarksButton_ isHidden]) { | 2215 if (![supervisedBookmarksButton_ isHidden]) { |
| 2304 left = NSMaxX([supervisedBookmarksButton_ frame]) + | 2216 left = NSMaxX([supervisedBookmarksButton_ frame]) + |
| 2305 bookmarks::BookmarkHorizontalPadding(); | 2217 bookmarks::kBookmarkHorizontalPadding; |
| 2306 } else if (![managedBookmarksButton_ isHidden]) { | 2218 } else if (![managedBookmarksButton_ isHidden]) { |
| 2307 left = NSMaxX([managedBookmarksButton_ frame]) + | 2219 left = NSMaxX([managedBookmarksButton_ frame]) + |
| 2308 bookmarks::BookmarkHorizontalPadding(); | 2220 bookmarks::kBookmarkHorizontalPadding; |
| 2309 } else if (![appsPageShortcutButton_ isHidden]) { | 2221 } else if (![appsPageShortcutButton_ isHidden]) { |
| 2310 left = NSMaxX([appsPageShortcutButton_ frame]) + | 2222 left = NSMaxX([appsPageShortcutButton_ frame]) + |
| 2311 bookmarks::BookmarkHorizontalPadding(); | 2223 bookmarks::kBookmarkHorizontalPadding; |
| 2312 } else { | 2224 } else { |
| 2313 left = bookmarks::BookmarkLeftMargin(); | 2225 left = bookmarks::kBookmarkLeftMargin; |
| 2314 } | 2226 } |
| 2315 CGFloat paddingWidth = bookmarks::kDefaultBookmarkWidth; | 2227 CGFloat paddingWidth = bookmarks::kDefaultBookmarkWidth; |
| 2316 BookmarkButton* draggedButton = [BookmarkButton draggedButton]; | 2228 BookmarkButton* draggedButton = [BookmarkButton draggedButton]; |
| 2317 if (draggedButton) { | 2229 if (draggedButton) { |
| 2318 paddingWidth = std::min(bookmarks::kDefaultBookmarkWidth, | 2230 paddingWidth = std::min(bookmarks::kDefaultBookmarkWidth, |
| 2319 NSWidth([draggedButton frame])); | 2231 NSWidth([draggedButton frame])); |
| 2320 } | 2232 } |
| 2321 // Put all the buttons where they belong, with all buttons to the right | 2233 // Put all the buttons where they belong, with all buttons to the right |
| 2322 // of the insertion point shuffling right to make space for it. | 2234 // of the insertion point shuffling right to make space for it. |
| 2323 [NSAnimationContext beginGrouping]; | 2235 [NSAnimationContext beginGrouping]; |
| 2324 [[NSAnimationContext currentContext] | 2236 [[NSAnimationContext currentContext] |
| 2325 setDuration:kDragAndDropAnimationDuration]; | 2237 setDuration:kDragAndDropAnimationDuration]; |
| 2326 for (NSButton* button in buttons_.get()) { | 2238 for (NSButton* button in buttons_.get()) { |
| 2327 // Hidden buttons get no space. | 2239 // Hidden buttons get no space. |
| 2328 if ([button isHidden]) | 2240 if ([button isHidden]) |
| 2329 continue; | 2241 continue; |
| 2330 NSRect buttonFrame = [button frame]; | 2242 NSRect buttonFrame = [button frame]; |
| 2331 buttonFrame.origin.x = left; | 2243 buttonFrame.origin.x = left; |
| 2332 // Update "left" for next time around. | 2244 // Update "left" for next time around. |
| 2333 left += buttonFrame.size.width; | 2245 left += buttonFrame.size.width; |
| 2334 if (left > insertionPos_) | 2246 if (left > insertionPos_) |
| 2335 buttonFrame.origin.x += paddingWidth; | 2247 buttonFrame.origin.x += paddingWidth; |
| 2336 left += bookmarks::BookmarkHorizontalPadding(); | 2248 left += bookmarks::kBookmarkHorizontalPadding; |
| 2337 if (innerContentAnimationsEnabled_) | 2249 if (innerContentAnimationsEnabled_) |
| 2338 [[button animator] setFrame:buttonFrame]; | 2250 [[button animator] setFrame:buttonFrame]; |
| 2339 else | 2251 else |
| 2340 [button setFrame:buttonFrame]; | 2252 [button setFrame:buttonFrame]; |
| 2341 } | 2253 } |
| 2342 [NSAnimationContext endGrouping]; | 2254 [NSAnimationContext endGrouping]; |
| 2343 } | 2255 } |
| 2344 } | 2256 } |
| 2345 | 2257 |
| 2346 // Put all visible bookmark bar buttons in their normal locations, either with | 2258 // Put all visible bookmark bar buttons in their normal locations, either with |
| 2347 // or without animation according to the |animate| flag. | 2259 // or without animation according to the |animate| flag. |
| 2348 // This is generally useful, so is called from various places internally. | 2260 // This is generally useful, so is called from various places internally. |
| 2349 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate { | 2261 - (void)resetAllButtonPositionsWithAnimation:(BOOL)animate { |
| 2350 | 2262 |
| 2351 // Position the apps bookmark if needed. | 2263 // Position the apps bookmark if needed. |
| 2352 CGFloat left = bookmarks::BookmarkLeftMargin(); | 2264 CGFloat left = bookmarks::kBookmarkLeftMargin; |
| 2353 if (![appsPageShortcutButton_ isHidden]) { | 2265 if (![appsPageShortcutButton_ isHidden]) { |
| 2354 int xOffset = bookmarks::BookmarkLeftMargin() - | 2266 int xOffset = bookmarks::kBookmarkLeftMargin - |
| 2355 bookmarks::BookmarkHorizontalPadding(); | 2267 bookmarks::kBookmarkHorizontalPadding; |
| 2356 NSRect frame = | 2268 NSRect frame = |
| 2357 [self frameForBookmarkButtonFromCell:[appsPageShortcutButton_ cell] | 2269 [self frameForBookmarkButtonFromCell:[appsPageShortcutButton_ cell] |
| 2358 xOffset:&xOffset]; | 2270 xOffset:&xOffset]; |
| 2359 [appsPageShortcutButton_ setFrame:frame]; | 2271 [appsPageShortcutButton_ setFrame:frame]; |
| 2360 left = xOffset + bookmarks::BookmarkHorizontalPadding(); | 2272 left = xOffset + bookmarks::kBookmarkHorizontalPadding; |
| 2361 } | 2273 } |
| 2362 | 2274 |
| 2363 // Position the managed bookmarks folder if needed. | 2275 // Position the managed bookmarks folder if needed. |
| 2364 if (![managedBookmarksButton_ isHidden]) { | 2276 if (![managedBookmarksButton_ isHidden]) { |
| 2365 int xOffset = left; | 2277 int xOffset = left; |
| 2366 NSRect frame = | 2278 NSRect frame = |
| 2367 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell] | 2279 [self frameForBookmarkButtonFromCell:[managedBookmarksButton_ cell] |
| 2368 xOffset:&xOffset]; | 2280 xOffset:&xOffset]; |
| 2369 [managedBookmarksButton_ setFrame:frame]; | 2281 [managedBookmarksButton_ setFrame:frame]; |
| 2370 left = xOffset + bookmarks::BookmarkHorizontalPadding(); | 2282 left = xOffset + bookmarks::kBookmarkHorizontalPadding; |
| 2371 } | 2283 } |
| 2372 | 2284 |
| 2373 // Position the supervised bookmarks folder if needed. | 2285 // Position the supervised bookmarks folder if needed. |
| 2374 if (![supervisedBookmarksButton_ isHidden]) { | 2286 if (![supervisedBookmarksButton_ isHidden]) { |
| 2375 int xOffset = left; | 2287 int xOffset = left; |
| 2376 NSRect frame = | 2288 NSRect frame = |
| 2377 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell] | 2289 [self frameForBookmarkButtonFromCell:[supervisedBookmarksButton_ cell] |
| 2378 xOffset:&xOffset]; | 2290 xOffset:&xOffset]; |
| 2379 [supervisedBookmarksButton_ setFrame:frame]; | 2291 [supervisedBookmarksButton_ setFrame:frame]; |
| 2380 left = xOffset + bookmarks::BookmarkHorizontalPadding(); | 2292 left = xOffset + bookmarks::kBookmarkHorizontalPadding; |
| 2381 } | 2293 } |
| 2382 | 2294 |
| 2383 animate &= innerContentAnimationsEnabled_; | 2295 animate &= innerContentAnimationsEnabled_; |
| 2384 | 2296 |
| 2385 for (NSButton* button in buttons_.get()) { | 2297 for (NSButton* button in buttons_.get()) { |
| 2386 // Hidden buttons get no space. | 2298 // Hidden buttons get no space. |
| 2387 if ([button isHidden]) | 2299 if ([button isHidden]) |
| 2388 continue; | 2300 continue; |
| 2389 NSRect buttonFrame = [button frame]; | 2301 NSRect buttonFrame = [button frame]; |
| 2390 buttonFrame.origin.x = left; | 2302 buttonFrame.origin.x = left; |
| 2391 left += buttonFrame.size.width + bookmarks::BookmarkHorizontalPadding(); | 2303 left += buttonFrame.size.width + bookmarks::kBookmarkHorizontalPadding; |
| 2392 if (animate) | 2304 if (animate) |
| 2393 [[button animator] setFrame:buttonFrame]; | 2305 [[button animator] setFrame:buttonFrame]; |
| 2394 else | 2306 else |
| 2395 [button setFrame:buttonFrame]; | 2307 [button setFrame:buttonFrame]; |
| 2396 } | 2308 } |
| 2397 } | 2309 } |
| 2398 | 2310 |
| 2399 // Clear insertion flag, remove insertion space and put all visible bookmark | 2311 // Clear insertion flag, remove insertion space and put all visible bookmark |
| 2400 // bar buttons in their normal locations. | 2312 // bar buttons in their normal locations. |
| 2401 // Gets called only by our view. | 2313 // Gets called only by our view. |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2677 } | 2589 } |
| 2678 | 2590 |
| 2679 | 2591 |
| 2680 #pragma mark BookmarkButtonControllerProtocol | 2592 #pragma mark BookmarkButtonControllerProtocol |
| 2681 | 2593 |
| 2682 // Close all bookmark folders. "Folder" here is the fake menu for | 2594 // Close all bookmark folders. "Folder" here is the fake menu for |
| 2683 // bookmark folders, not a button context menu. | 2595 // bookmark folders, not a button context menu. |
| 2684 - (void)closeAllBookmarkFolders { | 2596 - (void)closeAllBookmarkFolders { |
| 2685 [self watchForExitEvent:NO]; | 2597 [self watchForExitEvent:NO]; |
| 2686 | 2598 |
| 2687 // Grab the parent button under Material Design to make sure that the | 2599 // Grab the parent button under to make sure that the highlighting that was |
| 2688 // highlighting that was applied while revealing the menu is turned off. | 2600 // applied while revealing the menu is turned off. |
| 2689 BookmarkButton* parentButton = nil; | 2601 BookmarkButton* parentButton = [folderController_ parentButton]; |
| 2690 if (ui::MaterialDesignController::IsModeMaterial()) { | |
| 2691 parentButton = [folderController_ parentButton]; | |
| 2692 } | |
| 2693 [folderController_ close]; | 2602 [folderController_ close]; |
| 2694 [parentButton setNeedsDisplay:YES]; | 2603 [parentButton setNeedsDisplay:YES]; |
| 2695 folderController_ = nil; | 2604 folderController_ = nil; |
| 2696 } | 2605 } |
| 2697 | 2606 |
| 2698 - (void)closeBookmarkFolder:(id)sender { | 2607 - (void)closeBookmarkFolder:(id)sender { |
| 2699 // We're the top level, so close one means close them all. | 2608 // We're the top level, so close one means close them all. |
| 2700 [self closeAllBookmarkFolders]; | 2609 [self closeAllBookmarkFolders]; |
| 2701 } | 2610 } |
| 2702 | 2611 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2827 } | 2736 } |
| 2828 | 2737 |
| 2829 // Return YES if we should show the drop indicator, else NO. | 2738 // Return YES if we should show the drop indicator, else NO. |
| 2830 - (BOOL)shouldShowIndicatorShownForPoint:(NSPoint)point { | 2739 - (BOOL)shouldShowIndicatorShownForPoint:(NSPoint)point { |
| 2831 return ![self buttonForDroppingOnAtPoint:point]; | 2740 return ![self buttonForDroppingOnAtPoint:point]; |
| 2832 } | 2741 } |
| 2833 | 2742 |
| 2834 // Return the x position for a drop indicator. | 2743 // Return the x position for a drop indicator. |
| 2835 - (CGFloat)indicatorPosForDragToPoint:(NSPoint)point { | 2744 - (CGFloat)indicatorPosForDragToPoint:(NSPoint)point { |
| 2836 CGFloat x = 0; | 2745 CGFloat x = 0; |
| 2837 CGFloat halfHorizontalPadding = 0.5 * bookmarks::BookmarkHorizontalPadding(); | 2746 CGFloat halfHorizontalPadding = 0.5 * bookmarks::kBookmarkHorizontalPadding; |
| 2838 int destIndex = [self indexForDragToPoint:point]; | 2747 int destIndex = [self indexForDragToPoint:point]; |
| 2839 int numButtons = displayedButtonCount_; | 2748 int numButtons = displayedButtonCount_; |
| 2840 | 2749 |
| 2841 CGFloat leftmostX; | 2750 CGFloat leftmostX; |
| 2842 if (![supervisedBookmarksButton_ isHidden]) { | 2751 if (![supervisedBookmarksButton_ isHidden]) { |
| 2843 leftmostX = | 2752 leftmostX = |
| 2844 NSMaxX([supervisedBookmarksButton_ frame]) + halfHorizontalPadding; | 2753 NSMaxX([supervisedBookmarksButton_ frame]) + halfHorizontalPadding; |
| 2845 } else if (![managedBookmarksButton_ isHidden]) { | 2754 } else if (![managedBookmarksButton_ isHidden]) { |
| 2846 leftmostX = NSMaxX([managedBookmarksButton_ frame]) + halfHorizontalPadding; | 2755 leftmostX = NSMaxX([managedBookmarksButton_ frame]) + halfHorizontalPadding; |
| 2847 } else if (![appsPageShortcutButton_ isHidden]) { | 2756 } else if (![appsPageShortcutButton_ isHidden]) { |
| 2848 leftmostX = NSMaxX([appsPageShortcutButton_ frame]) + halfHorizontalPadding; | 2757 leftmostX = NSMaxX([appsPageShortcutButton_ frame]) + halfHorizontalPadding; |
| 2849 } else { | 2758 } else { |
| 2850 leftmostX = bookmarks::BookmarkLeftMargin() - halfHorizontalPadding; | 2759 leftmostX = bookmarks::kBookmarkLeftMargin - halfHorizontalPadding; |
| 2851 } | 2760 } |
| 2852 | 2761 |
| 2853 // If it's a drop strictly between existing buttons ... | 2762 // If it's a drop strictly between existing buttons ... |
| 2854 if (destIndex == 0) { | 2763 if (destIndex == 0) { |
| 2855 x = leftmostX; | 2764 x = leftmostX; |
| 2856 } else if (destIndex > 0 && destIndex < numButtons) { | 2765 } else if (destIndex > 0 && destIndex < numButtons) { |
| 2857 // ... put the indicator right between the buttons. | 2766 // ... put the indicator right between the buttons. |
| 2858 BookmarkButton* button = | 2767 BookmarkButton* button = |
| 2859 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex-1)]; | 2768 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex-1)]; |
| 2860 DCHECK(button); | 2769 DCHECK(button); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2935 - (void)openAll:(const BookmarkNode*)node | 2844 - (void)openAll:(const BookmarkNode*)node |
| 2936 disposition:(WindowOpenDisposition)disposition { | 2845 disposition:(WindowOpenDisposition)disposition { |
| 2937 [self closeFolderAndStopTrackingMenus]; | 2846 [self closeFolderAndStopTrackingMenus]; |
| 2938 chrome::OpenAll([[self view] window], browser_, node, disposition, | 2847 chrome::OpenAll([[self view] window], browser_, node, disposition, |
| 2939 browser_->profile()); | 2848 browser_->profile()); |
| 2940 } | 2849 } |
| 2941 | 2850 |
| 2942 - (void)addButtonForNode:(const BookmarkNode*)node | 2851 - (void)addButtonForNode:(const BookmarkNode*)node |
| 2943 atIndex:(NSInteger)buttonIndex { | 2852 atIndex:(NSInteger)buttonIndex { |
| 2944 int newOffset = | 2853 int newOffset = |
| 2945 bookmarks::BookmarkLeftMargin() - bookmarks::BookmarkHorizontalPadding(); | 2854 bookmarks::kBookmarkLeftMargin - bookmarks::kBookmarkHorizontalPadding; |
| 2946 if (buttonIndex == -1) | 2855 if (buttonIndex == -1) |
| 2947 buttonIndex = [buttons_ count]; // New button goes at the end. | 2856 buttonIndex = [buttons_ count]; // New button goes at the end. |
| 2948 if (buttonIndex <= (NSInteger)[buttons_ count]) { | 2857 if (buttonIndex <= (NSInteger)[buttons_ count]) { |
| 2949 if (buttonIndex) { | 2858 if (buttonIndex) { |
| 2950 BookmarkButton* targetButton = [buttons_ objectAtIndex:buttonIndex - 1]; | 2859 BookmarkButton* targetButton = [buttons_ objectAtIndex:buttonIndex - 1]; |
| 2951 NSRect targetFrame = [targetButton frame]; | 2860 NSRect targetFrame = [targetButton frame]; |
| 2952 newOffset = targetFrame.origin.x + NSWidth(targetFrame) + | 2861 newOffset = targetFrame.origin.x + NSWidth(targetFrame) + |
| 2953 bookmarks::BookmarkHorizontalPadding(); | 2862 bookmarks::kBookmarkHorizontalPadding; |
| 2954 } | 2863 } |
| 2955 BookmarkButton* newButton = [self buttonForNode:node xOffset:&newOffset]; | 2864 BookmarkButton* newButton = [self buttonForNode:node xOffset:&newOffset]; |
| 2956 ++displayedButtonCount_; | 2865 ++displayedButtonCount_; |
| 2957 [buttons_ insertObject:newButton atIndex:buttonIndex]; | 2866 [buttons_ insertObject:newButton atIndex:buttonIndex]; |
| 2958 [buttonView_ addSubview:newButton]; | 2867 [buttonView_ addSubview:newButton]; |
| 2959 [self resetAllButtonPositionsWithAnimation:NO]; | 2868 [self resetAllButtonPositionsWithAnimation:NO]; |
| 2960 // See if any buttons need to be pushed off to or brought in from the side. | 2869 // See if any buttons need to be pushed off to or brought in from the side. |
| 2961 [self reconfigureBookmarkBar]; | 2870 [self reconfigureBookmarkBar]; |
| 2962 } else { | 2871 } else { |
| 2963 // A button from somewhere else (not the bar) is being moved to the | 2872 // 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 Loading... |
| 3085 - (id<BookmarkButtonControllerProtocol>)controllerForNode: | 2994 - (id<BookmarkButtonControllerProtocol>)controllerForNode: |
| 3086 (const BookmarkNode*)node { | 2995 (const BookmarkNode*)node { |
| 3087 // See if it's in the bar, then if it is in the hierarchy of visible | 2996 // See if it's in the bar, then if it is in the hierarchy of visible |
| 3088 // folder menus. | 2997 // folder menus. |
| 3089 if (bookmarkModel_->bookmark_bar_node() == node) | 2998 if (bookmarkModel_->bookmark_bar_node() == node) |
| 3090 return self; | 2999 return self; |
| 3091 return [folderController_ controllerForNode:node]; | 3000 return [folderController_ controllerForNode:node]; |
| 3092 } | 3001 } |
| 3093 | 3002 |
| 3094 @end | 3003 @end |
| OLD | NEW |