diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 15:24:31 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-14 15:24:31 +0000 |
commit | 96649a0f3cafe764eb191532f635d99c234ea005 (patch) | |
tree | 4450b4a03d498df44850ef549814a458cbc77be9 /chrome/browser/window_sizer.cc | |
parent | 3313359d46d2a4f0e0dc8c4dc476462dec8c988a (diff) | |
download | chromium_src-96649a0f3cafe764eb191532f635d99c234ea005.zip chromium_src-96649a0f3cafe764eb191532f635d99c234ea005.tar.gz chromium_src-96649a0f3cafe764eb191532f635d99c234ea005.tar.bz2 |
Enable basic saving/restoring window placements on Mac.
Refactors the existing WindowSizer code to move platform-specific code
into separate files. Future CLs will add Mac support for muliple
monitors.
TEST=Browser windows should remember their position on Mac. The
corresponding behavior on Windows should not have changed.
Review URL: http://codereview.chromium.org/113286
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16056 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/window_sizer.cc')
-rw-r--r-- | chrome/browser/window_sizer.cc | 106 |
1 files changed, 7 insertions, 99 deletions
diff --git a/chrome/browser/window_sizer.cc b/chrome/browser/window_sizer.cc index ce34b71..300e5c5 100644 --- a/chrome/browser/window_sizer.cc +++ b/chrome/browser/window_sizer.cc @@ -1,13 +1,9 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/window_sizer.h" -#include <atlbase.h> -#include <atlapp.h> -#include <atlmisc.h> - #include "chrome/browser/browser.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" @@ -15,73 +11,10 @@ #include "chrome/common/pref_names.h" #include "chrome/common/pref_service.h" -// How much horizontal and vertical offset there is between newly opened -// windows. -static const int kWindowTilePixels = 10; - -/////////////////////////////////////////////////////////////////////////////// -// An implementation of WindowSizer::MonitorInfoProvider that gets the actual -// monitor information from Windows. -class DefaultMonitorInfoProvider : public WindowSizer::MonitorInfoProvider { - public: - DefaultMonitorInfoProvider() { } - - // Overridden from WindowSizer::MonitorInfoProvider: - virtual gfx::Rect GetPrimaryMonitorWorkArea() const { - return gfx::Rect(GetMonitorInfoForMonitor(MonitorFromWindow(NULL, - MONITOR_DEFAULTTOPRIMARY)).rcWork); - } - - virtual gfx::Rect GetPrimaryMonitorBounds() const { - return gfx::Rect(GetMonitorInfoForMonitor(MonitorFromWindow(NULL, - MONITOR_DEFAULTTOPRIMARY)).rcMonitor); - } - - virtual gfx::Rect GetMonitorWorkAreaMatching( - const gfx::Rect& match_rect) const { - CRect other_bounds_crect = match_rect.ToRECT(); - MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect( - &other_bounds_crect, MONITOR_DEFAULTTONEAREST)); - return gfx::Rect(monitor_info.rcWork); - } - - virtual gfx::Point GetBoundsOffsetMatching( - const gfx::Rect& match_rect) const { - CRect other_bounds_crect = match_rect.ToRECT(); - MONITORINFO monitor_info = GetMonitorInfoForMonitor(MonitorFromRect( - &other_bounds_crect, MONITOR_DEFAULTTONEAREST)); - return gfx::Point(monitor_info.rcWork.left - monitor_info.rcMonitor.left, - monitor_info.rcWork.top - monitor_info.rcMonitor.top); - } - - void UpdateWorkAreas() { - work_areas_.clear(); - EnumDisplayMonitors(NULL, NULL, - &DefaultMonitorInfoProvider::MonitorEnumProc, - reinterpret_cast<LPARAM>(&work_areas_)); - } - - private: - // A callback for EnumDisplayMonitors that records the work area of the - // current monitor in the enumeration. - static BOOL CALLBACK MonitorEnumProc(HMONITOR monitor, - HDC monitor_dc, - LPRECT monitor_rect, - LPARAM data) { - reinterpret_cast<std::vector<gfx::Rect>*>(data)->push_back( - gfx::Rect(GetMonitorInfoForMonitor(monitor).rcWork)); - return TRUE; - } - - static MONITORINFO GetMonitorInfoForMonitor(HMONITOR monitor) { - MONITORINFO monitor_info = { 0 }; - monitor_info.cbSize = sizeof(monitor_info); - GetMonitorInfo(monitor, &monitor_info); - return monitor_info; - } - - DISALLOW_COPY_AND_ASSIGN(DefaultMonitorInfoProvider); -}; +// TODO(port): Port this to Linux. +// This requires creating window_sizer_linux.cc, creating a subclass +// of WindowSizer::MonitorInfoProvider, and providing implementations +// of GetDefaultMonitorInfoProvider() and GetDefaultPopupOrigin(). /////////////////////////////////////////////////////////////////////////////// // An implementation of WindowSizer::StateProvider that gets the last active @@ -184,41 +117,16 @@ void WindowSizer::GetBrowserWindowBounds(const std::wstring& app_name, gfx::Rect* window_bounds, bool* maximized) { const WindowSizer sizer(new DefaultStateProvider(app_name, browser), - new DefaultMonitorInfoProvider); + CreateDefaultMonitorInfoProvider()); sizer.DetermineWindowBounds(specified_bounds, window_bounds, maximized); } -gfx::Point WindowSizer::GetDefaultPopupOrigin(const gfx::Size& size) { - RECT area; - SystemParametersInfo(SPI_GETWORKAREA, 0, &area, 0); - gfx::Point corner(area.left, area.top); - - if (Browser* b = BrowserList::GetLastActive()) { - RECT browser; - HWND window = reinterpret_cast<HWND>(b->window()->GetNativeHandle()); - if (GetWindowRect(window, &browser)) { - // Limit to not overflow the work area right and bottom edges. - gfx::Point limit( - std::min(browser.left + kWindowTilePixels, area.right-size.width()), - std::min(browser.top + kWindowTilePixels, area.bottom-size.height()) - ); - // Adjust corner to now overflow the work area left and top edges, so - // that if a popup does not fit the title-bar is remains visible. - corner = gfx::Point( - std::max(corner.x(), limit.x()), - std::max(corner.y(), limit.y()) - ); - } - } - return corner; -} - /////////////////////////////////////////////////////////////////////////////// // WindowSizer, private: WindowSizer::WindowSizer(const std::wstring& app_name) { Init(new DefaultStateProvider(app_name, NULL), - new DefaultMonitorInfoProvider); + CreateDefaultMonitorInfoProvider()); } void WindowSizer::Init(StateProvider* state_provider, |