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