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 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/browser_list.h" | 8 #include "chrome/browser/ui/browser_finder.h" |
9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
| 10 #include "chrome/browser/ui/host_desktop.h" |
10 | 11 |
11 // How much horizontal and vertical offset there is between newly | 12 // How much horizontal and vertical offset there is between newly |
12 // opened windows. | 13 // opened windows. |
13 const int WindowSizer::kWindowTilePixels = 10; | 14 const int WindowSizer::kWindowTilePixels = 10; |
14 | 15 |
15 // static | 16 // static |
16 gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size) { | 17 gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size, |
| 18 chrome::HostDesktopType type) { |
17 RECT area; | 19 RECT area; |
18 SystemParametersInfo(SPI_GETWORKAREA, 0, &area, 0); | 20 SystemParametersInfo(SPI_GETWORKAREA, 0, &area, 0); |
19 gfx::Point corner(area.left, area.top); | 21 gfx::Point corner(area.left, area.top); |
20 | 22 |
21 if (Browser* b = BrowserList::GetLastActive()) { | 23 if (Browser* browser = browser::FindLastActiveWithHostDesktopType(type)) { |
22 RECT browser; | 24 RECT browser_rect; |
23 HWND window = reinterpret_cast<HWND>(b->window()->GetNativeWindow()); | 25 HWND window = reinterpret_cast<HWND>(browser->window()->GetNativeWindow()); |
24 if (GetWindowRect(window, &browser)) { | 26 if (GetWindowRect(window, &browser_rect)) { |
25 // Limit to not overflow the work area right and bottom edges. | 27 // Limit to not overflow the work area right and bottom edges. |
26 gfx::Point limit( | 28 gfx::Point limit( |
27 std::min(browser.left + kWindowTilePixels, area.right-size.width()), | 29 std::min(browser_rect.left + kWindowTilePixels, |
28 std::min(browser.top + kWindowTilePixels, area.bottom-size.height()) | 30 area.right-size.width()), |
| 31 std::min(browser_rect.top + kWindowTilePixels, |
| 32 area.bottom-size.height()) |
29 ); | 33 ); |
30 // 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 |
31 // 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. |
32 corner = gfx::Point( | 36 corner = gfx::Point( |
33 std::max(corner.x(), limit.x()), | 37 std::max(corner.x(), limit.x()), |
34 std::max(corner.y(), limit.y()) | 38 std::max(corner.y(), limit.y()) |
35 ); | 39 ); |
36 } | 40 } |
37 } | 41 } |
38 return corner; | 42 return corner; |
39 } | 43 } |
OLD | NEW |