| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/window_sizer.h" | |
| 6 | |
| 7 #import <Cocoa/Cocoa.h> | |
| 8 | |
| 9 #include "chrome/browser/ui/browser.h" | |
| 10 #include "chrome/browser/ui/browser_list.h" | |
| 11 #include "chrome/browser/ui/browser_window.h" | |
| 12 | |
| 13 // How much horizontal and vertical offset there is between newly | |
| 14 // opened windows. | |
| 15 const int WindowSizer::kWindowTilePixels = 22; | |
| 16 | |
| 17 // static | |
| 18 gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size) { | |
| 19 NSRect work_area = [[NSScreen mainScreen] visibleFrame]; | |
| 20 NSRect main_area = [[[NSScreen screens] objectAtIndex:0] frame]; | |
| 21 NSPoint corner = NSMakePoint(NSMinX(work_area), NSMaxY(work_area)); | |
| 22 | |
| 23 if (Browser* b = BrowserList::GetLastActive()) { | |
| 24 NSWindow* window = b->window()->GetNativeWindow(); | |
| 25 NSRect window_frame = [window frame]; | |
| 26 | |
| 27 // Limit to not overflow the work area right and bottom edges. | |
| 28 NSPoint limit = NSMakePoint( | |
| 29 std::min(NSMinX(window_frame) + kWindowTilePixels, | |
| 30 NSMaxX(work_area) - size.width()), | |
| 31 std::max(NSMaxY(window_frame) - kWindowTilePixels, | |
| 32 NSMinY(work_area) + size.height())); | |
| 33 | |
| 34 // Adjust corner to now overflow the work area left and top edges, so | |
| 35 // that if a popup does not fit the title-bar is remains visible. | |
| 36 corner = NSMakePoint(std::max(corner.x, limit.x), | |
| 37 std::min(corner.y, limit.y)); | |
| 38 } | |
| 39 | |
| 40 return gfx::Point(corner.x, NSHeight(main_area) - corner.y); | |
| 41 } | |
| OLD | NEW |