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

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

Issue 2200303004: [Mac][Material Design] Adjust bookmark spacing and folder menu drawing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests, changes for icon-only items. Created 4 years, 4 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_folder_controller.h" 5 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/mac/bundle_locations.h" 9 #include "base/mac/bundle_locations.h"
10 #include "base/mac/sdk_forward_declarations.h" 10 #include "base/mac/sdk_forward_declarations.h"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // [NSObject cancelPreviousPerformRequestsWithTarget:self]; 325 // [NSObject cancelPreviousPerformRequestsWithTarget:self];
326 // Because all of our performSelector: calls use withDelay: which 326 // Because all of our performSelector: calls use withDelay: which
327 // retains us. 327 // retains us.
328 [super dealloc]; 328 [super dealloc];
329 } 329 }
330 330
331 - (void)awakeFromNib { 331 - (void)awakeFromNib {
332 NSRect windowFrame = [[self window] frame]; 332 NSRect windowFrame = [[self window] frame];
333 NSRect scrollViewFrame = [scrollView_ frame]; 333 NSRect scrollViewFrame = [scrollView_ frame];
334 padding_ = NSWidth(windowFrame) - NSWidth(scrollViewFrame); 334 padding_ = NSWidth(windowFrame) - NSWidth(scrollViewFrame);
335 // In Material Design, each menu row spans the entire width of the menu.
336 if (ui::MaterialDesignController::IsModeMaterial()) {
337 scrollViewFrame.size.width += padding_;
338 scrollViewFrame.origin.x = 0;
339 // If we leave the scrollview's vertical position and height as is, it will
340 // cover the menu's rounded corners and we'll get a rectangular menu.
341 scrollViewFrame.origin.y += bookmarks::BookmarkVerticalPadding();
342 scrollViewFrame.size.height -= 2 * bookmarks::BookmarkVerticalPadding();
343 [scrollView_ setFrame:scrollViewFrame];
344 padding_ = 0;
345 }
335 verticalScrollArrowHeight_ = NSHeight([scrollUpArrowView_ frame]); 346 verticalScrollArrowHeight_ = NSHeight([scrollUpArrowView_ frame]);
336 347
337 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 348 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
338 NSImage* image = rb.GetNativeImageNamed(IDR_MENU_OVERFLOW_DOWN).ToNSImage(); 349 NSImage* image = rb.GetNativeImageNamed(IDR_MENU_OVERFLOW_DOWN).ToNSImage();
339 [[scrollUpArrowView_.subviews objectAtIndex:0] setImage:image]; 350 [[scrollUpArrowView_.subviews objectAtIndex:0] setImage:image];
340 351
341 image = rb.GetNativeImageNamed(IDR_MENU_OVERFLOW_UP).ToNSImage(); 352 image = rb.GetNativeImageNamed(IDR_MENU_OVERFLOW_UP).ToNSImage();
342 [[scrollDownArrowView_.subviews objectAtIndex:0] setImage:image]; 353 [[scrollDownArrowView_.subviews objectAtIndex:0] setImage:image];
343 } 354 }
344 355
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 forADarkTheme:NO] 394 forADarkTheme:NO]
384 : nil; 395 : nil;
385 BookmarkContextMenuCocoaController* menuController = 396 BookmarkContextMenuCocoaController* menuController =
386 [barController_ menuController]; 397 [barController_ menuController];
387 BookmarkBarFolderButtonCell* cell = 398 BookmarkBarFolderButtonCell* cell =
388 [BookmarkBarFolderButtonCell buttonCellForNode:child 399 [BookmarkBarFolderButtonCell buttonCellForNode:child
389 text:nil 400 text:nil
390 image:image 401 image:image
391 menuController:menuController]; 402 menuController:menuController];
392 if (ui::MaterialDesignController::IsModeMaterial()) { 403 if (ui::MaterialDesignController::IsModeMaterial()) {
393 [cell setTag:kMaterialStandardButtonTypeWithLimitedClickFeedback]; 404 [cell setTag:kMaterialMenuButtonTypeWithLimitedClickFeedback];
394 } else { 405 } else {
395 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback]; 406 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback];
396 } 407 }
397 return cell; 408 return cell;
398 } 409 }
399 410
400 // Redirect to our logic shared with BookmarkBarController. 411 // Redirect to our logic shared with BookmarkBarController.
401 - (IBAction)openBookmarkFolderFromButton:(id)sender { 412 - (IBAction)openBookmarkFolderFromButton:(id)sender {
402 [folderTarget_ openBookmarkFolderFromButton:sender]; 413 [folderTarget_ openBookmarkFolderFromButton:sender];
403 } 414 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 // limited by the abolute minimum and maximum allowable widths. 446 // limited by the abolute minimum and maximum allowable widths.
436 frame.size.width = 447 frame.size.width =
437 std::min(std::max(bookmarks::kBookmarkMenuButtonMinimumWidth, 448 std::min(std::max(bookmarks::kBookmarkMenuButtonMinimumWidth,
438 std::max(frame.size.width, desired)), 449 std::max(frame.size.width, desired)),
439 bookmarks::kBookmarkMenuButtonMaximumWidth); 450 bookmarks::kBookmarkMenuButtonMaximumWidth);
440 451
441 BookmarkButton* button = [[[BookmarkButton alloc] initWithFrame:frame] 452 BookmarkButton* button = [[[BookmarkButton alloc] initWithFrame:frame]
442 autorelease]; 453 autorelease];
443 DCHECK(button); 454 DCHECK(button);
444 455
456 // Folder menu buttons have a flat background color in Material Design.
457 if (ui::MaterialDesignController::IsModeMaterial()) {
458 [button setBackgroundColor:
459 [BookmarkBarFolderWindowContentView backgroundColor]];
460 }
445 [button setCell:cell]; 461 [button setCell:cell];
446 [button setDelegate:self]; 462 [button setDelegate:self];
447 if (node) { 463 if (node) {
448 if (node->is_folder()) { 464 if (node->is_folder()) {
449 [button setTarget:self]; 465 [button setTarget:self];
450 [button setAction:@selector(openBookmarkFolderFromButton:)]; 466 [button setAction:@selector(openBookmarkFolderFromButton:)];
451 } else { 467 } else {
452 // Make the button do something. 468 // Make the button do something.
453 [button setTarget:barController_]; 469 [button setTarget:barController_];
454 [button setAction:@selector(openBookmark:)]; 470 [button setAction:@selector(openBookmark:)];
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 // popping up from the bookmark bar itself. In this case, start 544 // popping up from the bookmark bar itself. In this case, start
529 // BELOW the parent button. Our left is the button left; our top 545 // BELOW the parent button. Our left is the button left; our top
530 // is bottom of button's parent view. 546 // is bottom of button's parent view.
531 NSPoint buttonBottomLeftInScreen = ui::ConvertPointFromWindowToScreen( 547 NSPoint buttonBottomLeftInScreen = ui::ConvertPointFromWindowToScreen(
532 [parentButton_ window], 548 [parentButton_ window],
533 [parentButton_ convertPoint:NSZeroPoint toView:nil]); 549 [parentButton_ convertPoint:NSZeroPoint toView:nil]);
534 NSPoint bookmarkBarBottomLeftInScreen = ui::ConvertPointFromWindowToScreen( 550 NSPoint bookmarkBarBottomLeftInScreen = ui::ConvertPointFromWindowToScreen(
535 [parentButton_ window], 551 [parentButton_ window],
536 [[parentButton_ superview] convertPoint:NSZeroPoint toView:nil]); 552 [[parentButton_ superview] convertPoint:NSZeroPoint toView:nil]);
537 newWindowTopLeft = NSMakePoint( 553 newWindowTopLeft = NSMakePoint(
538 buttonBottomLeftInScreen.x + bookmarks::kBookmarkBarButtonOffset, 554 buttonBottomLeftInScreen.x,
539 bookmarkBarBottomLeftInScreen.y + bookmarks::kBookmarkBarMenuOffset); 555 bookmarkBarBottomLeftInScreen.y + bookmarks::kBookmarkBarMenuOffset);
556 if (!ui::MaterialDesignController::IsModeMaterial()) {
557 newWindowTopLeft.y += bookmarks::kBookmarkBarButtonOffset;
558 }
540 // Make sure the window is on-screen; if not, push left or right. It is 559 // Make sure the window is on-screen; if not, push left or right. It is
541 // intentional that top level folders "push left" or "push right" slightly 560 // intentional that top level folders "push left" or "push right" slightly
542 // different than subfolders. 561 // different than subfolders.
543 NSRect screenVisibleFrame = [[self menuScreen] visibleFrame]; 562 NSRect screenVisibleFrame = [[self menuScreen] visibleFrame];
544 // Test if window goes off-screen on the right side. 563 // Test if window goes off-screen on the right side.
545 CGFloat spillOff = 564 CGFloat spillOff =
546 newWindowTopLeft.x + windowWidth - NSMaxX(screenVisibleFrame); 565 newWindowTopLeft.x + windowWidth - NSMaxX(screenVisibleFrame);
547 if (spillOff > 0.0) { 566 if (spillOff > 0.0) {
548 newWindowTopLeft.x = std::max(newWindowTopLeft.x - spillOff, 567 newWindowTopLeft.x = std::max(newWindowTopLeft.x - spillOff,
549 NSMinX(screenVisibleFrame)); 568 NSMinX(screenVisibleFrame));
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 newWindowTopLeft.y = MAX(newWindowTopLeft.y, minimumY); 876 newWindowTopLeft.y = MAX(newWindowTopLeft.y, minimumY);
858 } 877 }
859 878
860 NSWindow* window = [self window]; 879 NSWindow* window = [self window];
861 NSRect windowFrame = NSMakeRect(newWindowTopLeft.x, 880 NSRect windowFrame = NSMakeRect(newWindowTopLeft.x,
862 newWindowTopLeft.y - height, 881 newWindowTopLeft.y - height,
863 windowWidth, height); 882 windowWidth, height);
864 [window setFrame:windowFrame display:NO]; 883 [window setFrame:windowFrame display:NO];
865 884
866 NSRect folderFrame = NSMakeRect(0, 0, windowWidth, height); 885 NSRect folderFrame = NSMakeRect(0, 0, windowWidth, height);
886 // Each menu button is 24pt tall but its highlight is only 20pt - effectively
887 // each menu button includes 4pts of vertical padding. This wasn't a problem
888 // pre-Material, but now that the |scrollView_| is shorter we have an extra
889 // 4pt of padding pushing the topmost item beyond the top of the
890 // |scrollView_|. Scoot the |folderView_| down by this padding to avoid
891 // clipping the topmost item.
892 if (ui::MaterialDesignController::IsModeMaterial()) {
893 folderFrame.origin.y -= bookmarks::BookmarkVerticalPadding();
894 }
867 [folderView_ setFrame:folderFrame]; 895 [folderView_ setFrame:folderFrame];
868 896
869 // For some reason, when opening a "large" bookmark folder (containing 12 or 897 // For some reason, when opening a "large" bookmark folder (containing 12 or
870 // more items) using the keyboard, the scroll view seems to want to be 898 // more items) using the keyboard, the scroll view seems to want to be
871 // offset by default: [ http://crbug.com/101099 ]. Explicitly reseting the 899 // offset by default: [ http://crbug.com/101099 ]. Explicitly reseting the
872 // scroll position here is a bit hacky, but it does seem to work. 900 // scroll position here is a bit hacky, but it does seem to work.
873 [[scrollView_ contentView] scrollToPoint:NSZeroPoint]; 901 [[scrollView_ contentView] scrollToPoint:NSZeroPoint];
874 902
875 NSSize newSize = NSMakeSize(windowWidth, 0.0); 903 NSSize newSize = NSMakeSize(windowWidth, 0.0);
876 [self adjustWindowLeft:newWindowTopLeft.x size:newSize scrollingBy:0.0]; 904 [self adjustWindowLeft:newWindowTopLeft.x size:newSize scrollingBy:0.0];
(...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 2117
2090 - (void)setIgnoreAnimations:(BOOL)ignore { 2118 - (void)setIgnoreAnimations:(BOOL)ignore {
2091 ignoreAnimations_ = ignore; 2119 ignoreAnimations_ = ignore;
2092 } 2120 }
2093 2121
2094 - (BookmarkButton*)buttonThatMouseIsIn { 2122 - (BookmarkButton*)buttonThatMouseIsIn {
2095 return buttonThatMouseIsIn_; 2123 return buttonThatMouseIsIn_;
2096 } 2124 }
2097 2125
2098 @end // BookmarkBarFolderController 2126 @end // BookmarkBarFolderController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698