Commit 8e236456 authored by andresantoso's avatar andresantoso Committed by Commit bot

Mac: Fix sheet positioning on popup windows.

Popup windows don't have bookmark bars, so check for supportsBookmarkBar
before trying to position the sheet next to the bookmark bar.
Fix incorrect use of defaultSheetRect.size.height, it has no meaning according
to AppKit docs.

BUG=436959

Review URL: https://codereview.chromium.org/836173002

Cr-Commit-Position: refs/heads/master@{#310187}
parent 83a81749
......@@ -492,36 +492,37 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, SheetPosition) {
EXPECT_TRUE([controller() hasToolbar]);
EXPECT_FALSE([controller() isBookmarkBarVisible]);
NSRect defaultAlertFrame = NSMakeRect(0, 0, 300, 200);
id sheet = MockWindowWithFrame(defaultAlertFrame);
id sheet = MockWindowWithFrame(NSMakeRect(0, 0, 300, 200));
NSWindow* window = browser()->window()->GetNativeWindow();
NSRect alertFrame = [controller() window:window
willPositionSheet:nil
usingRect:defaultAlertFrame];
NSRect contentFrame = [[window contentView] frame];
NSRect defaultLocation =
NSMakeRect(0, NSMaxY(contentFrame), NSWidth(contentFrame), 0);
NSRect sheetLocation = [controller() window:window
willPositionSheet:nil
usingRect:defaultLocation];
NSRect toolbarFrame = [[[controller() toolbarController] view] frame];
EXPECT_EQ(NSMinY(alertFrame), NSMinY(toolbarFrame));
EXPECT_EQ(NSMinY(toolbarFrame), NSMinY(sheetLocation));
// Open sheet with normal browser window, persistent bookmark bar.
chrome::ToggleBookmarkBarWhenVisible(browser()->profile());
EXPECT_TRUE([controller() isBookmarkBarVisible]);
alertFrame = [controller() window:window
willPositionSheet:sheet
usingRect:defaultAlertFrame];
sheetLocation = [controller() window:window
willPositionSheet:sheet
usingRect:defaultLocation];
NSRect bookmarkBarFrame = [[[controller() bookmarkBarController] view] frame];
EXPECT_EQ(NSMinY(alertFrame), NSMinY(bookmarkBarFrame));
EXPECT_EQ(NSMinY(bookmarkBarFrame), NSMinY(sheetLocation));
// If the sheet is too large, it should be positioned at the top of the
// window.
defaultAlertFrame = NSMakeRect(0, 0, 300, 2000);
sheet = MockWindowWithFrame(defaultAlertFrame);
alertFrame = [controller() window:window
willPositionSheet:sheet
usingRect:defaultAlertFrame];
EXPECT_EQ(NSMinY(alertFrame), NSHeight([window frame]));
sheet = MockWindowWithFrame(NSMakeRect(0, 0, 300, 2000));
sheetLocation = [controller() window:window
willPositionSheet:sheet
usingRect:defaultLocation];
EXPECT_EQ(NSHeight([window frame]), NSMinY(sheetLocation));
// Reset the sheet's size.
defaultAlertFrame = NSMakeRect(0, 0, 300, 200);
sheet = MockWindowWithFrame(defaultAlertFrame);
sheet = MockWindowWithFrame(NSMakeRect(0, 0, 300, 200));
// Make sure the profile does not have the bookmark visible so that
// we'll create the shortcut window without the bookmark bar.
......@@ -542,12 +543,10 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, SheetPosition) {
// Open sheet in an application window.
[popupController showWindow:nil];
alertFrame = [popupController window:popupWindow
willPositionSheet:sheet
usingRect:defaultAlertFrame];
EXPECT_EQ(NSMinY(alertFrame),
NSHeight([[popupWindow contentView] frame]) -
defaultAlertFrame.size.height);
sheetLocation = [popupController window:popupWindow
willPositionSheet:sheet
usingRect:defaultLocation];
EXPECT_EQ(NSHeight([[popupWindow contentView] frame]), NSMinY(sheetLocation));
// Close the application window.
popup_browser->tab_strip_model()->CloseSelectedTabs();
......
......@@ -171,35 +171,26 @@ void RecordFullscreenStyle(FullscreenStyle style) {
- (NSRect)window:(NSWindow*)window
willPositionSheet:(NSWindow*)sheet
usingRect:(NSRect)defaultSheetRect {
usingRect:(NSRect)defaultSheetLocation {
// Position the sheet as follows:
// - If the bookmark bar is shown (attached to the normal toolbar), position
// the sheet below the bookmark bar.
// - If the bookmark bar is hidden or shown as a bubble (on the NTP when the
// bookmark bar is disabled), position the sheet immediately below the
// normal toolbar.
// - If the bookmark bar is shown (attached to the normal toolbar), position
// 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 defaultSheetY = defaultSheetRect.origin.y;
switch ([bookmarkBarController_ currentState]) {
case BookmarkBar::SHOW: {
NSRect bookmarkBarFrame = [[bookmarkBarController_ view] frame];
defaultSheetY = bookmarkBarFrame.origin.y;
break;
}
case BookmarkBar::HIDDEN:
case BookmarkBar::DETACHED: {
if ([self hasToolbar]) {
NSRect toolbarFrame = [[toolbarController_ view] frame];
defaultSheetY = 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.
defaultSheetY = NSHeight([[window contentView] frame]) -
defaultSheetRect.size.height;
}
break;
}
CGFloat defaultSheetY = defaultSheetLocation.origin.y;
if ([self supportsBookmarkBar] &&
[bookmarkBarController_ currentState] == BookmarkBar::SHOW) {
defaultSheetY = NSMinY([[bookmarkBarController_ view] frame]);
} else if ([self hasToolbar]) {
defaultSheetY = NSMinY([[toolbarController_ view] frame]);
} else {
// The toolbar is not shown in popup and application modes. The sheet
// should be located at the top of the window, under the title of the
// window.
defaultSheetY = NSMaxY([[window contentView] frame]);
}
// AppKit may shift the window up to fit the sheet on screen, but it will
......@@ -217,8 +208,8 @@ willPositionSheet:(NSWindow*)sheet
CGFloat windowHeight = NSHeight([window frame]);
defaultSheetY = std::min(defaultSheetY, windowHeight);
defaultSheetRect.origin.y = defaultSheetY;
return defaultSheetRect;
defaultSheetLocation.origin.y = defaultSheetY;
return defaultSheetLocation;
}
- (void)layoutSubviews {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment