diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/cocoa/browser_window_controller.mm | 10 | ||||
-rw-r--r-- | chrome/browser/window_sizer_mac.mm | 26 |
2 files changed, 35 insertions, 1 deletions
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm index d6bd3da..a7417bb 100644 --- a/chrome/browser/cocoa/browser_window_controller.mm +++ b/chrome/browser/cocoa/browser_window_controller.mm @@ -19,6 +19,7 @@ #include "chrome/browser/encoding_menu_controller.h" #include "chrome/browser/location_bar.h" #include "chrome/browser/profile.h" +#include "chrome/browser/window_sizer.h" #include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" @@ -252,6 +253,15 @@ willPositionSheet:(NSWindow*)sheet windowRect.set_width(minSize.width); if (windowRect.height() < minSize.height) windowRect.set_height(minSize.height); + + // When we are given x/y coordinates of 0 on a created popup window, assume + // none were given by the window.open() command. + if (browser_->type() & Browser::TYPE_POPUP && + windowRect.x() == 0 && windowRect.y() == 0) { + gfx::Size size = windowRect.size(); + windowRect.set_origin(WindowSizer::GetDefaultPopupOrigin(size)); + } + windowShim_->SetBounds(windowRect); // Puts the incognito badge on the window frame, if necessary. Do this diff --git a/chrome/browser/window_sizer_mac.mm b/chrome/browser/window_sizer_mac.mm index aa91211..127fb66 100644 --- a/chrome/browser/window_sizer_mac.mm +++ b/chrome/browser/window_sizer_mac.mm @@ -4,6 +4,9 @@ #import <Cocoa/Cocoa.h> +#include "chrome/browser/browser.h" +#include "chrome/browser/browser_list.h" +#include "chrome/browser/browser_window.h" #include "chrome/browser/window_sizer.h" // How much horizontal and vertical offset there is between newly @@ -116,5 +119,26 @@ WindowSizer::CreateDefaultMonitorInfoProvider() { // static gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size) { - return gfx::Point(0, 0); + NSRect work_area = [[NSScreen mainScreen] visibleFrame]; + NSRect main_area = [[[NSScreen screens] objectAtIndex:0] frame]; + NSPoint corner = NSMakePoint(NSMinX(work_area), NSMaxY(work_area)); + + if (Browser* b = BrowserList::GetLastActive()) { + NSWindow* window = b->window()->GetNativeHandle(); + NSRect window_frame = [window frame]; + + // Limit to not overflow the work area right and bottom edges. + NSPoint limit = NSMakePoint( + std::min(NSMinX(window_frame) + kWindowTilePixels, + NSMaxX(work_area) - size.width()), + std::max(NSMaxY(window_frame) - kWindowTilePixels, + NSMinY(work_area) + size.height())); + + // Adjust corner to now overflow the work area left and top edges, so + // that if a popup does not fit the title-bar is remains visible. + corner = NSMakePoint(std::max(corner.x, limit.x), + std::min(corner.y, limit.y)); + } + + return gfx::Point(corner.x, NSHeight(main_area) - corner.y); } |