Chromium Code Reviews| Index: chrome/browser/ui/cocoa/browser_window_controller_private.mm |
| diff --git a/chrome/browser/ui/cocoa/browser_window_controller_private.mm b/chrome/browser/ui/cocoa/browser_window_controller_private.mm |
| index 3874f2005a146a1393b43bd605710d18c9cbd265..ba6f02b2475c1d60bee94b3d5bc9978a987c486e 100644 |
| --- a/chrome/browser/ui/cocoa/browser_window_controller_private.mm |
| +++ b/chrome/browser/ui/cocoa/browser_window_controller_private.mm |
| @@ -204,26 +204,44 @@ willPositionSheet:(NSWindow*)sheet |
| // the sheet below the bookmark bar. |
| // - If the bookmark bar is currently animating, position the sheet according |
| // to where the bar will be when the animation ends. |
| + CGFloat desiredY = defaultSheetRect.origin.y; |
|
Robert Sesek
2014/10/27 15:41:22
naming: desiredY -> defaultSheetY
erikchen
2014/10/27 23:18:13
Done.
|
| switch ([bookmarkBarController_ currentState]) { |
| case BookmarkBar::SHOW: { |
| NSRect bookmarkBarFrame = [[bookmarkBarController_ view] frame]; |
| - defaultSheetRect.origin.y = bookmarkBarFrame.origin.y; |
| + desiredY = bookmarkBarFrame.origin.y; |
| break; |
| } |
| case BookmarkBar::HIDDEN: |
| case BookmarkBar::DETACHED: { |
| if ([self hasToolbar]) { |
| NSRect toolbarFrame = [[toolbarController_ view] frame]; |
| - defaultSheetRect.origin.y = toolbarFrame.origin.y; |
| + desiredY = toolbarFrame.origin.y; |
| } else { |
| // The toolbar is not shown in application mode. The sheet should be |
| // located at the top of the window, under the title of the window. |
| - defaultSheetRect.origin.y = NSHeight([[window contentView] frame]) - |
| - defaultSheetRect.size.height; |
| + desiredY = NSHeight([[window contentView] frame]) - |
| + defaultSheetRect.size.height; |
| } |
| break; |
| } |
| } |
| + |
| + // AppKit may shift the window up to fit the sheet on screen, but it will |
| + // never adjust the height of the sheet, or the origin of the sheet relative |
| + // to the window. Adjust the origin to prevent sheets from extending past the |
| + // bottom of the screen. |
| + |
| + // Don't allow the sheet to extend past the bottom of the window. This logic |
| + // intentionally ignores the size of the screens, since the window might span |
| + // multiple screens, and AppKit may reposition the window. |
| + CGFloat sheetHeight = NSHeight([sheet frame]); |
| + desiredY = std::max(desiredY, sheetHeight); |
| + |
| + // It doesn't make sense to provide a Y higher than the height of the window. |
| + CGFloat windowHeight = NSHeight([window frame]); |
| + desiredY = std::min(desiredY, windowHeight); |
| + |
| + defaultSheetRect.origin.y = desiredY; |
| return defaultSheetRect; |
| } |