Index: chrome/browser/cocoa/bookmark_bar_folder_controller.mm |
=================================================================== |
--- chrome/browser/cocoa/bookmark_bar_folder_controller.mm (revision 54167) |
+++ chrome/browser/cocoa/bookmark_bar_folder_controller.mm (working copy) |
@@ -377,22 +377,22 @@ |
[self adjustButtonWidths] + (2 * bookmarks::kBookmarkVerticalPadding) + |
bookmarks::kScrollViewContentWidthMargin; |
NSPoint newWindowTopLeft = [self windowTopLeftForWidth:windowWidth]; |
- NSSize windowSize = [scrollView_ convertSize:NSMakeSize(windowWidth, |
- windowHeight) |
- toView:nil]; |
- newWindowTopLeft.y -= windowSize.height; |
+ NSSize windowSize = NSMakeSize(windowWidth, windowHeight); |
+ windowSize = [scrollView_ convertSize:windowSize toView:nil]; |
+ NSWindow* window = [self window]; |
+ // If the window is already visible then make sure its top remains stable. |
+ BOOL windowAlreadyShowing = [window isVisible]; |
+ CGFloat deltaY = windowHeight - NSHeight([mainView_ frame]); |
+ if (windowAlreadyShowing) { |
+ NSRect oldFrame = [window frame]; |
+ newWindowTopLeft.y = oldFrame.origin.y + NSHeight(oldFrame); |
+ } |
NSRect windowFrame = NSMakeRect(newWindowTopLeft.x, |
- newWindowTopLeft.y, |
- windowSize.width, |
- windowSize.height); |
- |
+ newWindowTopLeft.y - windowHeight, windowSize.width, windowHeight); |
// Make the scrolled content be the right size (full size). |
- NSRect mainViewFrame = NSMakeRect(0, 0, |
- windowWidth - |
- bookmarks::kScrollViewContentWidthMargin, |
- windowHeight); |
+ NSRect mainViewFrame = NSMakeRect(0, 0, NSWidth(windowFrame) - |
+ bookmarks::kScrollViewContentWidthMargin, NSHeight(windowFrame)); |
[mainView_ setFrame:mainViewFrame]; |
- |
// Make sure the window fits on the screen. If not, constrain. |
// We'll scroll to allow the user to see all the content. |
NSRect screenFrame = [[[self window] screen] frame]; |
@@ -404,17 +404,33 @@ |
} else { |
scrollable_ = NO; |
} |
- NSWindow* window = [self window]; |
- [window setFrame:windowFrame display:YES]; |
- // If scrollable then offset the view and show the arrows. |
+ [window setFrame:windowFrame display:NO]; |
if (wasScrollable != scrollable_) { |
- NSSize windowLocalSize = [scrollView_ convertSize:windowFrame.size |
- fromView:nil]; |
- [mainView_ scrollPoint:NSMakePoint(0, (NSHeight(mainViewFrame) - |
- windowLocalSize.height))]; |
+ // If scrollability changed then rework visibility of the scroll arrows |
+ // and the scroll offset of the menu view. |
+ NSSize windowLocalSize = |
+ [scrollView_ convertSize:windowFrame.size fromView:nil]; |
+ CGFloat scrollPointY = NSHeight(mainViewFrame) - windowLocalSize.height + |
+ bookmarks::kBookmarkVerticalPadding; |
+ [mainView_ scrollPoint:NSMakePoint(0, scrollPointY)]; |
[self showOrHideScrollArrows]; |
[self addOrUpdateScrollTracking]; |
+ } else if (scrollable_ && windowAlreadyShowing) { |
+ // If the window was already showing and is still scrollable then make |
+ // sure the main view moves upward, not downward so that the content |
+ // at the bottom of the menu, not the top, appears to move. |
+ // The edge case is when the menu is scrolled all the way to top (hence |
+ // the test of scrollDownArrowShown_) - don't scroll then. |
+ NSView* superView = [mainView_ superview]; |
+ DCHECK([superView isKindOfClass:[NSClipView class]]); |
+ NSClipView* clipView = static_cast<NSClipView*>(superView); |
+ CGFloat scrollPointY = [clipView bounds].origin.y + |
+ bookmarks::kBookmarkVerticalPadding; |
+ if (scrollDownArrowShown_ || deltaY > 0.0) |
+ scrollPointY += deltaY; |
+ [mainView_ scrollPoint:NSMakePoint(0, scrollPointY)]; |
} |
+ [window display]; |
} |
// Determine window size and position. |
@@ -429,7 +445,8 @@ |
int buttons = std::max(node->GetChildCount() - startingIndex, 1); |
// Prelim height of the window. We'll trim later as needed. |
- int height = buttons * bookmarks::kBookmarkButtonHeight; |
+ int height = buttons * bookmarks::kBookmarkButtonHeight + |
+ bookmarks::kBookmarkVerticalPadding; |
// We'll need this soon... |
[self window]; |
@@ -1237,7 +1254,8 @@ |
[self closeBookmarkFolder:self]; |
// Prelim height of the window. We'll trim later as needed. |
- int height = [buttons_ count] * bookmarks::kBookmarkButtonHeight; |
+ int height = [buttons_ count] * bookmarks::kBookmarkButtonHeight + |
+ bookmarks::kBookmarkVerticalPadding; |
[self adjustWindowForHeight:height]; |
} |
@@ -1370,7 +1388,8 @@ |
} |
// Propose a height for the window. We'll trim later as needed. |
- int height = buttonCount * bookmarks::kBookmarkButtonHeight; |
+ int height = buttonCount * bookmarks::kBookmarkButtonHeight + |
+ bookmarks::kBookmarkVerticalPadding; |
[self adjustWindowForHeight:height]; |
} |