| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "chrome/browser/ui/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_list.h" |
| 9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
| 10 | 10 |
| 11 // How much horizontal and vertical offset there is between newly | 11 // How much horizontal and vertical offset there is between newly |
| 12 // opened windows. | 12 // opened windows. |
| 13 const int WindowSizer::kWindowTilePixels = 10; | 13 const int WindowSizer::kWindowTilePixels = 10; |
| 14 | 14 |
| 15 // An implementation of WindowSizer::MonitorInfoProvider that gets the actual | |
| 16 // monitor information from Windows. | |
| 17 class DefaultMonitorInfoProvider : public WindowSizer::MonitorInfoProvider { | |
| 18 public: | |
| 19 DefaultMonitorInfoProvider() { } | |
| 20 | |
| 21 // Overridden from WindowSizer::MonitorInfoProvider: | |
| 22 virtual gfx::Rect GetPrimaryMonitorWorkArea() const { | |
| 23 return gfx::Rect(GetMonitorInfoForMonitor(MonitorFromWindow(NULL, | |
| 24 MONITOR_DEFAULTTOPRIMARY)).rcWork); | |
| 25 } | |
| 26 | |
| 27 virtual gfx::Rect GetPrimaryMonitorBounds() const { | |
| 28 return gfx::Rect(GetMonitorInfoForMonitor(MonitorFromWindow(NULL, | |
| 29 MONITOR_DEFAULTTOPRIMARY)).rcMonitor); | |
| 30 } | |
| 31 | |
| 32 virtual gfx::Rect GetMonitorWorkAreaMatching( | |
| 33 const gfx::Rect& match_rect) const { | |
| 34 RECT other_bounds_rect = match_rect.ToRECT(); | |
| 35 MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect( | |
| 36 &other_bounds_rect, MONITOR_DEFAULTTONEAREST)); | |
| 37 return gfx::Rect(monitor_info.rcWork); | |
| 38 } | |
| 39 | |
| 40 void UpdateWorkAreas() { | |
| 41 work_areas_.clear(); | |
| 42 EnumDisplayMonitors(NULL, NULL, | |
| 43 &DefaultMonitorInfoProvider::MonitorEnumProc, | |
| 44 reinterpret_cast<LPARAM>(&work_areas_)); | |
| 45 } | |
| 46 | |
| 47 private: | |
| 48 // A callback for EnumDisplayMonitors that records the work area of the | |
| 49 // current monitor in the enumeration. | |
| 50 static BOOL CALLBACK MonitorEnumProc(HMONITOR monitor, | |
| 51 HDC monitor_dc, | |
| 52 LPRECT monitor_rect, | |
| 53 LPARAM data) { | |
| 54 reinterpret_cast<std::vector<gfx::Rect>*>(data)->push_back( | |
| 55 gfx::Rect(GetMonitorInfoForMonitor(monitor).rcWork)); | |
| 56 return TRUE; | |
| 57 } | |
| 58 | |
| 59 static MONITORINFO GetMonitorInfoForMonitor(HMONITOR monitor) { | |
| 60 MONITORINFO monitor_info = { 0 }; | |
| 61 monitor_info.cbSize = sizeof(monitor_info); | |
| 62 GetMonitorInfo(monitor, &monitor_info); | |
| 63 return monitor_info; | |
| 64 } | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(DefaultMonitorInfoProvider); | |
| 67 }; | |
| 68 | |
| 69 // static | |
| 70 WindowSizer::MonitorInfoProvider* | |
| 71 WindowSizer::CreateDefaultMonitorInfoProvider() { | |
| 72 return new DefaultMonitorInfoProvider(); | |
| 73 } | |
| 74 | |
| 75 // static | 15 // static |
| 76 gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size) { | 16 gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size) { |
| 77 RECT area; | 17 RECT area; |
| 78 SystemParametersInfo(SPI_GETWORKAREA, 0, &area, 0); | 18 SystemParametersInfo(SPI_GETWORKAREA, 0, &area, 0); |
| 79 gfx::Point corner(area.left, area.top); | 19 gfx::Point corner(area.left, area.top); |
| 80 | 20 |
| 81 if (Browser* b = BrowserList::GetLastActive()) { | 21 if (Browser* b = BrowserList::GetLastActive()) { |
| 82 RECT browser; | 22 RECT browser; |
| 83 HWND window = reinterpret_cast<HWND>(b->window()->GetNativeHandle()); | 23 HWND window = reinterpret_cast<HWND>(b->window()->GetNativeHandle()); |
| 84 if (GetWindowRect(window, &browser)) { | 24 if (GetWindowRect(window, &browser)) { |
| 85 // Limit to not overflow the work area right and bottom edges. | 25 // Limit to not overflow the work area right and bottom edges. |
| 86 gfx::Point limit( | 26 gfx::Point limit( |
| 87 std::min(browser.left + kWindowTilePixels, area.right-size.width()), | 27 std::min(browser.left + kWindowTilePixels, area.right-size.width()), |
| 88 std::min(browser.top + kWindowTilePixels, area.bottom-size.height()) | 28 std::min(browser.top + kWindowTilePixels, area.bottom-size.height()) |
| 89 ); | 29 ); |
| 90 // Adjust corner to now overflow the work area left and top edges, so | 30 // Adjust corner to now overflow the work area left and top edges, so |
| 91 // that if a popup does not fit the title-bar is remains visible. | 31 // that if a popup does not fit the title-bar is remains visible. |
| 92 corner = gfx::Point( | 32 corner = gfx::Point( |
| 93 std::max(corner.x(), limit.x()), | 33 std::max(corner.x(), limit.x()), |
| 94 std::max(corner.y(), limit.y()) | 34 std::max(corner.y(), limit.y()) |
| 95 ); | 35 ); |
| 96 } | 36 } |
| 97 } | 37 } |
| 98 return corner; | 38 return corner; |
| 99 } | 39 } |
| OLD | NEW |