| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 deltaScrollerY(0.0), | 117 deltaScrollerY(0.0), |
| 118 minimumY(0.0), | 118 minimumY(0.0), |
| 119 screenBottomY(0.0), | 119 screenBottomY(0.0), |
| 120 oldWindowY(0.0), | 120 oldWindowY(0.0), |
| 121 folderY(0.0), | 121 folderY(0.0), |
| 122 folderTop(0.0) {} | 122 folderTop(0.0) {} |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 NSRect GetFirstButtonFrameForHeight(CGFloat height) { | 125 NSRect GetFirstButtonFrameForHeight(CGFloat height) { |
| 126 CGFloat y = height - bookmarks::kBookmarkFolderButtonHeight - | 126 CGFloat y = height - bookmarks::kBookmarkFolderButtonHeight - |
| 127 bookmarks::BookmarkTopVerticalPadding(); | 127 bookmarks::BookmarkVerticalPadding(); |
| 128 return NSMakeRect(0, y, bookmarks::kDefaultBookmarkWidth, | 128 return NSMakeRect(0, y, bookmarks::kDefaultBookmarkWidth, |
| 129 bookmarks::kBookmarkFolderButtonHeight); | 129 bookmarks::kBookmarkFolderButtonHeight); |
| 130 } | 130 } |
| 131 | 131 |
| 132 } // namespace | 132 } // namespace |
| 133 | 133 |
| 134 namespace bookmarks { | |
| 135 | |
| 136 CGFloat BookmarkTopVerticalPadding() { | |
| 137 return bookmarks::BookmarkVerticalPadding(); | |
| 138 } | |
| 139 | |
| 140 CGFloat BookmarkBottomVerticalPadding() { | |
| 141 return ui::MaterialDesignController::IsModeMaterial() | |
| 142 ? 0 : bookmarks::BookmarkVerticalPadding(); | |
| 143 } | |
| 144 | |
| 145 } // bookmarks | |
| 146 | |
| 147 | 134 |
| 148 // Required to set the right tracking bounds for our fake menus. | 135 // Required to set the right tracking bounds for our fake menus. |
| 149 @interface NSView(Private) | 136 @interface NSView(Private) |
| 150 - (void)_updateTrackingAreas; | 137 - (void)_updateTrackingAreas; |
| 151 @end | 138 @end |
| 152 | 139 |
| 153 @interface BookmarkBarFolderController () | 140 @interface BookmarkBarFolderController () |
| 154 - (void)configureWindow; | 141 - (void)configureWindow; |
| 155 - (void)addOrUpdateScrollTracking; | 142 - (void)addOrUpdateScrollTracking; |
| 156 - (void)removeScrollTracking; | 143 - (void)removeScrollTracking; |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 (NSMinY(screenVisibleFrame) + bookmarks::kScrollWindowVerticalMargin); | 545 (NSMinY(screenVisibleFrame) + bookmarks::kScrollWindowVerticalMargin); |
| 559 if ((availableVerticalSpace < kMinSqueezedMenuHeight) && | 546 if ((availableVerticalSpace < kMinSqueezedMenuHeight) && |
| 560 (windowHeight > availableVerticalSpace)) { | 547 (windowHeight > availableVerticalSpace)) { |
| 561 newWindowTopLeft.y = std::min( | 548 newWindowTopLeft.y = std::min( |
| 562 newWindowTopLeft.y + windowHeight + NSHeight([parentButton_ frame]), | 549 newWindowTopLeft.y + windowHeight + NSHeight([parentButton_ frame]), |
| 563 NSMaxY(screenVisibleFrame)); | 550 NSMaxY(screenVisibleFrame)); |
| 564 } | 551 } |
| 565 } else { | 552 } else { |
| 566 // Parent is a folder: expose as much as we can vertically; grow right/left. | 553 // Parent is a folder: expose as much as we can vertically; grow right/left. |
| 567 newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth]; | 554 newWindowTopLeft.x = [self childFolderWindowLeftForWidth:windowWidth]; |
| 568 NSPoint topOfWindow = | 555 NSPoint topOfWindow = NSMakePoint(0, |
| 569 NSMakePoint(0, NSMaxY([parentButton_ frame]) - | 556 NSMaxY([parentButton_ frame]) - |
| 570 bookmarks::BookmarkTopVerticalPadding()); | 557 bookmarks::BookmarkVerticalPadding()); |
| 571 topOfWindow = ui::ConvertPointFromWindowToScreen( | 558 topOfWindow = ui::ConvertPointFromWindowToScreen( |
| 572 [parentButton_ window], | 559 [parentButton_ window], |
| 573 [[parentButton_ superview] convertPoint:topOfWindow toView:nil]); | 560 [[parentButton_ superview] convertPoint:topOfWindow toView:nil]); |
| 574 newWindowTopLeft.y = topOfWindow.y + | 561 newWindowTopLeft.y = topOfWindow.y + |
| 575 bookmarks::BookmarkTopVerticalPadding() + | 562 2 * bookmarks::BookmarkVerticalPadding(); |
| 576 bookmarks::BookmarkBottomVerticalPadding(); | |
| 577 } | 563 } |
| 578 return newWindowTopLeft; | 564 return newWindowTopLeft; |
| 579 } | 565 } |
| 580 | 566 |
| 581 // Set our window level to the right spot so we're above the menubar, dock, etc. | 567 // Set our window level to the right spot so we're above the menubar, dock, etc. |
| 582 // Factored out so we can override/noop in a unit test. | 568 // Factored out so we can override/noop in a unit test. |
| 583 - (void)configureWindowLevel { | 569 - (void)configureWindowLevel { |
| 584 [[self window] setLevel:NSPopUpMenuWindowLevel]; | 570 [[self window] setLevel:NSPopUpMenuWindowLevel]; |
| 585 } | 571 } |
| 586 | 572 |
| 587 - (int)menuHeightForButtonCount:(int)buttonCount { | 573 - (int)menuHeightForButtonCount:(int)buttonCount { |
| 588 // This does not take into account any padding which may be required at the | 574 // This does not take into account any padding which may be required at the |
| 589 // top and/or bottom of the window. | 575 // top and/or bottom of the window. |
| 590 return (buttonCount * bookmarks::kBookmarkFolderButtonHeight) + | 576 return (buttonCount * bookmarks::kBookmarkFolderButtonHeight) + |
| 591 bookmarks::BookmarkTopVerticalPadding() + | 577 2 * bookmarks::BookmarkVerticalPadding(); |
| 592 bookmarks::BookmarkBottomVerticalPadding(); | |
| 593 } | 578 } |
| 594 | 579 |
| 595 - (void)adjustWindowLeft:(CGFloat)windowLeft | 580 - (void)adjustWindowLeft:(CGFloat)windowLeft |
| 596 size:(NSSize)windowSize | 581 size:(NSSize)windowSize |
| 597 scrollingBy:(CGFloat)scrollDelta { | 582 scrollingBy:(CGFloat)scrollDelta { |
| 598 // Callers of this function should make adjustments to the vertical | 583 // Callers of this function should make adjustments to the vertical |
| 599 // attributes of the folder view only (height, scroll position). | 584 // attributes of the folder view only (height, scroll position). |
| 600 // This function will then make appropriate layout adjustments in order | 585 // This function will then make appropriate layout adjustments in order |
| 601 // to accommodate screen/dock margins, scroll-up and scroll-down arrow | 586 // to accommodate screen/dock margins, scroll-up and scroll-down arrow |
| 602 // presentation, etc. | 587 // presentation, etc. |
| (...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1754 int destIndex = [self indexForDragToPoint:point]; | 1739 int destIndex = [self indexForDragToPoint:point]; |
| 1755 int numButtons = static_cast<int>([buttons_ count]); | 1740 int numButtons = static_cast<int>([buttons_ count]); |
| 1756 | 1741 |
| 1757 // If it's a drop strictly between existing buttons or at the very beginning | 1742 // If it's a drop strictly between existing buttons or at the very beginning |
| 1758 if (destIndex >= 0 && destIndex < numButtons) { | 1743 if (destIndex >= 0 && destIndex < numButtons) { |
| 1759 // ... put the indicator right between the buttons. | 1744 // ... put the indicator right between the buttons. |
| 1760 BookmarkButton* button = | 1745 BookmarkButton* button = |
| 1761 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex)]; | 1746 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex)]; |
| 1762 DCHECK(button); | 1747 DCHECK(button); |
| 1763 NSRect buttonFrame = [button frame]; | 1748 NSRect buttonFrame = [button frame]; |
| 1764 y = NSMaxY(buttonFrame) + 0.5 * bookmarks::BookmarkTopVerticalPadding(); | 1749 y = NSMaxY(buttonFrame) + 0.5 * bookmarks::BookmarkVerticalPadding(); |
| 1765 | 1750 |
| 1766 // If it's a drop at the end (past the last button, if there are any) ... | 1751 // If it's a drop at the end (past the last button, if there are any) ... |
| 1767 } else if (destIndex == numButtons) { | 1752 } else if (destIndex == numButtons) { |
| 1768 // and if it's past the last button ... | 1753 // and if it's past the last button ... |
| 1769 if (numButtons > 0) { | 1754 if (numButtons > 0) { |
| 1770 // ... find the last button, and put the indicator below it. | 1755 // ... find the last button, and put the indicator below it. |
| 1771 BookmarkButton* button = | 1756 BookmarkButton* button = |
| 1772 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex - 1)]; | 1757 [buttons_ objectAtIndex:static_cast<NSUInteger>(destIndex - 1)]; |
| 1773 DCHECK(button); | 1758 DCHECK(button); |
| 1774 NSRect buttonFrame = [button frame]; | 1759 NSRect buttonFrame = [button frame]; |
| 1775 y = buttonFrame.origin.y - | 1760 y = buttonFrame.origin.y - 0.5 * bookmarks::BookmarkVerticalPadding(); |
| 1776 0.5 * bookmarks::BookmarkBottomVerticalPadding(); | |
| 1777 | 1761 |
| 1778 } | 1762 } |
| 1779 } else { | 1763 } else { |
| 1780 NOTREACHED(); | 1764 NOTREACHED(); |
| 1781 } | 1765 } |
| 1782 | 1766 |
| 1783 return y; | 1767 return y; |
| 1784 } | 1768 } |
| 1785 | 1769 |
| 1786 - (Profile*)profile { | 1770 - (Profile*)profile { |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2082 | 2066 |
| 2083 - (void)setIgnoreAnimations:(BOOL)ignore { | 2067 - (void)setIgnoreAnimations:(BOOL)ignore { |
| 2084 ignoreAnimations_ = ignore; | 2068 ignoreAnimations_ = ignore; |
| 2085 } | 2069 } |
| 2086 | 2070 |
| 2087 - (BookmarkButton*)buttonThatMouseIsIn { | 2071 - (BookmarkButton*)buttonThatMouseIsIn { |
| 2088 return buttonThatMouseIsIn_; | 2072 return buttonThatMouseIsIn_; |
| 2089 } | 2073 } |
| 2090 | 2074 |
| 2091 @end // BookmarkBarFolderController | 2075 @end // BookmarkBarFolderController |
| OLD | NEW |