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