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