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.
5 #include "chrome/browser/ui/window_sizer/window_sizer.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_finder.h"
9 #include "chrome/browser/ui/browser_window.h"
10 #include "chrome/browser/ui/host_desktop.h"
12 // How much horizontal and vertical offset there is between newly
14 const int WindowSizer::kWindowTilePixels = 10;
17 gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size,
18 chrome::HostDesktopType type) {
20 SystemParametersInfo(SPI_GETWORKAREA, 0, &area, 0);
21 gfx::Point corner(area.left, area.top);
23 if (Browser* browser = chrome::FindLastActiveWithHostDesktopType(type)) {
25 HWND window = reinterpret_cast<HWND>(browser->window()->GetNativeWindow());
26 if (GetWindowRect(window, &browser_rect)) {
27 // Limit to not overflow the work area right and bottom edges.
29 std::min(browser_rect.left + kWindowTilePixels,
30 area.right-size.width()),
31 std::min(browser_rect.top + kWindowTilePixels,
32 area.bottom-size.height())
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.
37 std::max(corner.x(), limit.x()),
38 std::max(corner.y(), limit.y())