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

Side by Side Diff: chrome/browser/ui/cocoa/bookmarks/bookmark_bar_folder_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: Convert bookmarks overflow button to MD. 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_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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 deltaScrollerY(0.0), 114 deltaScrollerY(0.0),
115 minimumY(0.0), 115 minimumY(0.0),
116 screenBottomY(0.0), 116 screenBottomY(0.0),
117 oldWindowY(0.0), 117 oldWindowY(0.0),
118 folderY(0.0), 118 folderY(0.0),
119 folderTop(0.0) {} 119 folderTop(0.0) {}
120 }; 120 };
121 121
122 NSRect GetFirstButtonFrameForHeight(CGFloat height) { 122 NSRect GetFirstButtonFrameForHeight(CGFloat height) {
123 CGFloat y = height - bookmarks::kBookmarkFolderButtonHeight - 123 CGFloat y = height - bookmarks::kBookmarkFolderButtonHeight -
124 bookmarks::kBookmarkVerticalPadding; 124 bookmarks::BookmarkVerticalPadding();
125 return NSMakeRect(0, y, bookmarks::kDefaultBookmarkWidth, 125 return NSMakeRect(0, y, bookmarks::kDefaultBookmarkWidth,
126 bookmarks::kBookmarkFolderButtonHeight); 126 bookmarks::kBookmarkFolderButtonHeight);
127 } 127 }
128 128
129 } // namespace 129 } // namespace
130 130
131 131
132 // Required to set the right tracking bounds for our fake menus. 132 // Required to set the right tracking bounds for our fake menus.
133 @interface NSView(Private) 133 @interface NSView(Private)
134 - (void)_updateTrackingAreas; 134 - (void)_updateTrackingAreas;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 [button setDelegate:nil]; 349 [button setDelegate:nil];
350 [button removeFromSuperview]; 350 [button removeFromSuperview];
351 } 351 }
352 [buttons_ removeAllObjects]; 352 [buttons_ removeAllObjects];
353 [self configureWindow]; 353 [self configureWindow];
354 } 354 }
355 355
356 #pragma mark Private Methods 356 #pragma mark Private Methods
357 357
358 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)child { 358 - (BookmarkButtonCell*)cellForBookmarkNode:(const BookmarkNode*)child {
359 NSImage* image = child ? [barController_ faviconForNode:child] : nil; 359 NSImage* image = child ? [barController_ faviconForNode:child
360 forADarkTheme:NO]
361 : nil;
360 BookmarkContextMenuCocoaController* menuController = 362 BookmarkContextMenuCocoaController* menuController =
361 [barController_ menuController]; 363 [barController_ menuController];
362 BookmarkBarFolderButtonCell* cell = 364 BookmarkBarFolderButtonCell* cell =
363 [BookmarkBarFolderButtonCell buttonCellForNode:child 365 [BookmarkBarFolderButtonCell buttonCellForNode:child
364 text:nil 366 text:nil
365 image:image 367 image:image
366 menuController:menuController]; 368 menuController:menuController];
367 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback]; 369 [cell setTag:kStandardButtonTypeWithLimitedClickFeedback];
368 return cell; 370 return cell;
369 } 371 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 (windowHeight > availableVerticalSpace)) { 533 (windowHeight > availableVerticalSpace)) {
532 newWindowTopLeft.y = std::min( 534 newWindowTopLeft.y = std::min(
533 newWindowTopLeft.y + windowHeight + NSHeight([parentButton_ frame]), 535 newWindowTopLeft.y + windowHeight + NSHeight([parentButton_ frame]),
534 NSMaxY(screenVisibleFrame)); 536 NSMaxY(screenVisibleFrame));
535 } 537 }
536 } else { 538 } else {
537 // Parent is a folder: expose as much as we can vertically; grow right/left. 539 // Parent is a folder: expose as much as we can vertically; grow right/left.
538 newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth]; 540 newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth];
539 NSPoint topOfWindow = NSMakePoint(0, 541 NSPoint topOfWindow = NSMakePoint(0,
540 NSMaxY([parentButton_ frame]) - 542 NSMaxY([parentButton_ frame]) -
541 bookmarks::kBookmarkVerticalPadding); 543 bookmarks::BookmarkVerticalPadding());
542 topOfWindow = ui::ConvertPointFromWindowToScreen( 544 topOfWindow = ui::ConvertPointFromWindowToScreen(
543 [parentButton_ window], 545 [parentButton_ window],
544 [[parentButton_ superview] convertPoint:topOfWindow toView:nil]); 546 [[parentButton_ superview] convertPoint:topOfWindow toView:nil]);
545 newWindowTopLeft.y = topOfWindow.y + 547 newWindowTopLeft.y = topOfWindow.y +
546 2 * bookmarks::kBookmarkVerticalPadding; 548 2 * bookmarks::BookmarkVerticalPadding();
547 } 549 }
548 return newWindowTopLeft; 550 return newWindowTopLeft;
549 } 551 }
550 552
551 // Set our window level to the right spot so we're above the menubar, dock, etc. 553 // Set our window level to the right spot so we're above the menubar, dock, etc.
552 // Factored out so we can override/noop in a unit test. 554 // Factored out so we can override/noop in a unit test.
553 - (void)configureWindowLevel { 555 - (void)configureWindowLevel {
554 [[self window] setLevel:NSPopUpMenuWindowLevel]; 556 [[self window] setLevel:NSPopUpMenuWindowLevel];
555 } 557 }
556 558
557 - (int)menuHeightForButtonCount:(int)buttonCount { 559 - (int)menuHeightForButtonCount:(int)buttonCount {
558 // This does not take into account any padding which may be required at the 560 // This does not take into account any padding which may be required at the
559 // top and/or bottom of the window. 561 // top and/or bottom of the window.
560 return (buttonCount * bookmarks::kBookmarkFolderButtonHeight) + 562 return (buttonCount * bookmarks::kBookmarkFolderButtonHeight) +
561 2 * bookmarks::kBookmarkVerticalPadding; 563 2 * bookmarks::BookmarkVerticalPadding();
562 } 564 }
563 565
564 - (void)adjustWindowLeft:(CGFloat)windowLeft 566 - (void)adjustWindowLeft:(CGFloat)windowLeft
565 size:(NSSize)windowSize 567 size:(NSSize)windowSize
566 scrollingBy:(CGFloat)scrollDelta { 568 scrollingBy:(CGFloat)scrollDelta {
567 // Callers of this function should make adjustments to the vertical 569 // Callers of this function should make adjustments to the vertical
568 // attributes of the folder view only (height, scroll position). 570 // attributes of the folder view only (height, scroll position).
569 // This function will then make appropriate layout adjustments in order 571 // This function will then make appropriate layout adjustments in order
570 // to accommodate screen/dock margins, scroll-up and scroll-down arrow 572 // to accommodate screen/dock margins, scroll-up and scroll-down arrow
571 // presentation, etc. 573 // presentation, etc.
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1723 int destIndex = [self indexForDragToPoint:point]; 1725 int destIndex = [self indexForDragToPoint:point];
1724 int numButtons = static_cast<int>([buttons_ count]); 1726 int numButtons = static_cast<int>([buttons_ count]);
1725 1727
1726 // If it's a drop strictly between existing buttons or at the very beginning 1728 // If it's a drop strictly between existing buttons or at the very beginning
1727 if (destIndex >= 0 && destIndex < numButtons) { 1729 if (destIndex >= 0 && destIndex < numButtons) {
1728 // ... put the indicator right between the buttons. 1730 // ... put the indicator right between the buttons.
1729 BookmarkButton* button = 1731 BookmarkButton* button =
1730 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex)]; 1732 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex)];
1731 DCHECK(button); 1733 DCHECK(button);
1732 NSRect buttonFrame = [button frame]; 1734 NSRect buttonFrame = [button frame];
1733 y = NSMaxY(buttonFrame) + 0.5 * bookmarks::kBookmarkVerticalPadding; 1735 y = NSMaxY(buttonFrame) + 0.5 * bookmarks::BookmarkVerticalPadding();
1734 1736
1735 // If it's a drop at the end (past the last button, if there are any) ... 1737 // If it's a drop at the end (past the last button, if there are any) ...
1736 } else if (destIndex == numButtons) { 1738 } else if (destIndex == numButtons) {
1737 // and if it's past the last button ... 1739 // and if it's past the last button ...
1738 if (numButtons > 0) { 1740 if (numButtons > 0) {
1739 // ... find the last button, and put the indicator below it. 1741 // ... find the last button, and put the indicator below it.
1740 BookmarkButton* button = 1742 BookmarkButton* button =
1741 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex - 1)]; 1743 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex - 1)];
1742 DCHECK(button); 1744 DCHECK(button);
1743 NSRect buttonFrame = [button frame]; 1745 NSRect buttonFrame = [button frame];
1744 y = buttonFrame.origin.y - 0.5 * bookmarks::kBookmarkVerticalPadding; 1746 y = buttonFrame.origin.y - 0.5 * bookmarks::BookmarkVerticalPadding();
1745 1747
1746 } 1748 }
1747 } else { 1749 } else {
1748 NOTREACHED(); 1750 NOTREACHED();
1749 } 1751 }
1750 1752
1751 return y; 1753 return y;
1752 } 1754 }
1753 1755
1754 - (Profile*)profile { 1756 - (Profile*)profile {
1755 return profile_; 1757 return profile_;
1756 } 1758 }
1757 1759
1758 - (void)childFolderWillShow:(id<BookmarkButtonControllerProtocol>)child { 1760 - (void)childFolderWillShow:(id<BookmarkButtonControllerProtocol>)child {
1759 // Do nothing. 1761 // Do nothing.
1760 } 1762 }
1761 1763
1762 - (void)childFolderWillClose:(id<BookmarkButtonControllerProtocol>)child { 1764 - (void)childFolderWillClose:(id<BookmarkButtonControllerProtocol>)child {
1763 // Do nothing. 1765 // Do nothing.
1764 } 1766 }
1765 1767
1766 - (BookmarkBarFolderController*)folderController { 1768 - (BookmarkBarFolderController*)folderController {
1767 return folderController_; 1769 return folderController_;
1768 } 1770 }
1769 1771
1770 - (void)faviconLoadedForNode:(const BookmarkNode*)node { 1772 - (void)faviconLoadedForNode:(const BookmarkNode*)node {
1771 for (BookmarkButton* button in buttons_.get()) { 1773 for (BookmarkButton* button in buttons_.get()) {
1772 if ([button bookmarkNode] == node) { 1774 if ([button bookmarkNode] == node) {
1773 [button setImage:[barController_ faviconForNode:node]]; 1775 BOOL darkTheme = [[button window] hasDarkTheme];
1776 [button setImage:[barController_ faviconForNode:node
1777 forADarkTheme:darkTheme]];
1774 [button setNeedsDisplay:YES]; 1778 [button setNeedsDisplay:YES];
1775 return; 1779 return;
1776 } 1780 }
1777 } 1781 }
1778 1782
1779 // Node was not in this menu, try submenu. 1783 // Node was not in this menu, try submenu.
1780 if (folderController_) 1784 if (folderController_)
1781 [folderController_ faviconLoadedForNode:node]; 1785 [folderController_ faviconLoadedForNode:node];
1782 } 1786 }
1783 1787
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
2048 2052
2049 - (void)setIgnoreAnimations:(BOOL)ignore { 2053 - (void)setIgnoreAnimations:(BOOL)ignore {
2050 ignoreAnimations_ = ignore; 2054 ignoreAnimations_ = ignore;
2051 } 2055 }
2052 2056
2053 - (BookmarkButton*)buttonThatMouseIsIn { 2057 - (BookmarkButton*)buttonThatMouseIsIn {
2054 return buttonThatMouseIsIn_; 2058 return buttonThatMouseIsIn_;
2055 } 2059 }
2056 2060
2057 @end // BookmarkBarFolderController 2061 @end // BookmarkBarFolderController
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698