summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryuzo@chromium.org <yuzo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 07:16:00 +0000
committeryuzo@chromium.org <yuzo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-29 07:16:00 +0000
commit70a11c0044fdfc456e1fdb4c9a85de49f3b62201 (patch)
treebb1604068982e6cdb947696da1fa3e1b1c057202
parentea392a6705010fe7d2ceec3980bf5df39aaf2f82 (diff)
downloadchromium_src-70a11c0044fdfc456e1fdb4c9a85de49f3b62201.zip
chromium_src-70a11c0044fdfc456e1fdb4c9a85de49f3b62201.tar.gz
chromium_src-70a11c0044fdfc456e1fdb4c9a85de49f3b62201.tar.bz2
Move window to workarea origin if it is completely off-screen.
BUG=17822 TEST=Use multiple monitors. Start Chrome, move the window to a non-primary monitor, and exit Chrome. Disconnect or disable the monitor and start Chrome again. Chrome should appear at the origin of a remaining monitor. Also try chaning the resolution of the non-primary monitor. As far as the window fits within the monitor, it should be shown as-is. If not, it is moved to the origin and resized, if necessary. Review URL: http://codereview.chromium.org/160246 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21946 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc12
-rw-r--r--chrome/browser/views/chrome_views_delegate.cc11
-rw-r--r--chrome/browser/window_sizer.cc52
-rw-r--r--chrome/browser/window_sizer.h8
-rw-r--r--chrome/browser/window_sizer_unittest.cc249
5 files changed, 244 insertions, 88 deletions
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index 8da9ad2..05e9ee7 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -12,10 +12,12 @@
#include "base/base_paths_linux.h"
#include "base/command_line.h"
#include "base/gfx/gtk_util.h"
+#include "base/gfx/rect.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/path_service.h"
+#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/time.h"
#include "chrome/app/chrome_dll_resource.h"
@@ -54,6 +56,7 @@
#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
+#include "chrome/browser/window_sizer.h"
#include "chrome/common/gtk_util.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
@@ -1341,6 +1344,15 @@ void BrowserWindowGtk::SaveWindowPosition() {
window_preferences->SetInteger(L"right", restored_bounds_.right());
window_preferences->SetInteger(L"bottom", restored_bounds_.bottom());
window_preferences->SetBoolean(L"maximized", IsMaximized());
+
+ scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info_provider(
+ WindowSizer::CreateDefaultMonitorInfoProvider());
+ gfx::Rect work_area(
+ monitor_info_provider->GetMonitorWorkAreaMatching(restored_bounds_));
+ window_preferences->SetInteger(L"work_area_left", work_area.x());
+ window_preferences->SetInteger(L"work_area_top", work_area.y());
+ window_preferences->SetInteger(L"work_area_right", work_area.right());
+ window_preferences->SetInteger(L"work_area_bottom", work_area.bottom());
}
// static
diff --git a/chrome/browser/views/chrome_views_delegate.cc b/chrome/browser/views/chrome_views_delegate.cc
index c793a54..bc87e19 100644
--- a/chrome/browser/views/chrome_views_delegate.cc
+++ b/chrome/browser/views/chrome_views_delegate.cc
@@ -6,8 +6,10 @@
#include "base/clipboard.h"
#include "base/gfx/rect.h"
+#include "base/scoped_ptr.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/window_sizer.h"
#include "chrome/common/pref_service.h"
///////////////////////////////////////////////////////////////////////////////
@@ -31,6 +33,15 @@ void ChromeViewsDelegate::SaveWindowPlacement(const std::wstring& window_name,
window_preferences->SetInteger(L"right", bounds.right());
window_preferences->SetInteger(L"bottom", bounds.bottom());
window_preferences->SetBoolean(L"maximized", maximized);
+
+ scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info_provider(
+ WindowSizer::CreateDefaultMonitorInfoProvider());
+ gfx::Rect work_area(
+ monitor_info_provider->GetMonitorWorkAreaMatching(bounds));
+ window_preferences->SetInteger(L"work_area_left", work_area.x());
+ window_preferences->SetInteger(L"work_area_top", work_area.y());
+ window_preferences->SetInteger(L"work_area_right", work_area.right());
+ window_preferences->SetInteger(L"work_area_bottom", work_area.bottom());
}
bool ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name,
diff --git a/chrome/browser/window_sizer.cc b/chrome/browser/window_sizer.cc
index 1d9c6a3..519a300 100644
--- a/chrome/browser/window_sizer.cc
+++ b/chrome/browser/window_sizer.cc
@@ -22,7 +22,9 @@ class DefaultStateProvider : public WindowSizer::StateProvider {
}
// Overridden from WindowSizer::StateProvider:
- virtual bool GetPersistentState(gfx::Rect* bounds, bool* maximized) const {
+ virtual bool GetPersistentState(gfx::Rect* bounds,
+ bool* maximized,
+ gfx::Rect* work_area) const {
DCHECK(bounds && maximized);
std::wstring key(prefs::kBrowserWindowPlacement);
@@ -46,6 +48,21 @@ class DefaultStateProvider : public WindowSizer::StateProvider {
wp_pref->GetBoolean(L"maximized", maximized);
bounds->SetRect(left, top, std::max(0, right - left),
std::max(0, bottom - top));
+
+ int work_area_top = 0;
+ int work_area_left = 0;
+ int work_area_bottom = 0;
+ int work_area_right = 0;
+ if (wp_pref) {
+ wp_pref->GetInteger(L"work_area_top", &work_area_top);
+ wp_pref->GetInteger(L"work_area_left", &work_area_left);
+ wp_pref->GetInteger(L"work_area_bottom", &work_area_bottom);
+ wp_pref->GetInteger(L"work_area_right", &work_area_right);
+ }
+ work_area->SetRect(work_area_left, work_area_top,
+ std::max(0, work_area_right - work_area_left),
+ std::max(0, work_area_bottom - work_area_top));
+
return has_prefs;
}
@@ -152,17 +169,20 @@ bool WindowSizer::GetLastWindowBounds(gfx::Rect* bounds) const {
return false;
gfx::Rect last_window_bounds = *bounds;
bounds->Offset(kWindowTilePixels, kWindowTilePixels);
- AdjustBoundsToBeVisibleOnMonitorContaining(last_window_bounds, bounds);
+ AdjustBoundsToBeVisibleOnMonitorContaining(last_window_bounds,
+ gfx::Rect(),
+ bounds);
return true;
}
bool WindowSizer::GetSavedWindowBounds(gfx::Rect* bounds,
bool* maximized) const {
DCHECK(bounds && maximized);
+ gfx::Rect saved_work_area;
if (!state_provider_ ||
- !state_provider_->GetPersistentState(bounds, maximized))
+ !state_provider_->GetPersistentState(bounds, maximized, &saved_work_area))
return false;
- AdjustBoundsToBeVisibleOnMonitorContaining(*bounds, bounds);
+ AdjustBoundsToBeVisibleOnMonitorContaining(*bounds, saved_work_area, bounds);
return true;
}
@@ -235,7 +255,9 @@ namespace {
}
void WindowSizer::AdjustBoundsToBeVisibleOnMonitorContaining(
- const gfx::Rect& other_bounds, gfx::Rect* bounds) const {
+ const gfx::Rect& other_bounds,
+ const gfx::Rect& saved_work_area,
+ gfx::Rect* bounds) const {
DCHECK(bounds);
DCHECK(monitor_info_provider_);
@@ -256,6 +278,26 @@ void WindowSizer::AdjustBoundsToBeVisibleOnMonitorContaining(
bounds->set_height(std::max(kMinVisibleHeight, bounds->height()));
bounds->set_width(std::max(kMinVisibleWidth, bounds->width()));
+ // Ensure that the title bar is not above the work area.
+ if (bounds->y() < work_area.y())
+ bounds->set_y(work_area.y());
+
+ // Reposition and resize the bounds if the saved_work_area is different from
+ // the current work area and the current work area doesn't completely contain
+ // the bounds.
+ if (!saved_work_area.IsEmpty() &&
+ saved_work_area != work_area &&
+ !work_area.Contains(*bounds)) {
+ bounds->set_width(std::min(bounds->width(), work_area.width()));
+ bounds->set_height(std::min(bounds->height(), work_area.height()));
+ bounds->set_x(
+ std::max(work_area.x(),
+ std::min(bounds->x(), work_area.right() - bounds->width())));
+ bounds->set_y(
+ std::max(work_area.y(),
+ std::min(bounds->y(), work_area.bottom() - bounds->height())));
+ }
+
#if defined(OS_MACOSX)
// Limit the maximum height. On the Mac the sizer is on the
// bottom-right of the window, and a window cannot be moved "up"
diff --git a/chrome/browser/window_sizer.h b/chrome/browser/window_sizer.h
index d7727f7..aad721e 100644
--- a/chrome/browser/window_sizer.h
+++ b/chrome/browser/window_sizer.h
@@ -88,7 +88,8 @@ class WindowSizer {
// Retrieve the persisted bounds of the window. Returns true if there was
// persisted data to retrieve state information, false otherwise.
virtual bool GetPersistentState(gfx::Rect* bounds,
- bool* maximized) const = 0;
+ bool* maximized,
+ gfx::Rect* work_area) const = 0;
// Retrieve the bounds of the most recent window of the matching type.
// Returns true if there was a last active window to retrieve state
@@ -162,8 +163,13 @@ class WindowSizer {
// monitor containing |other_bounds|. Despite the name, this doesn't
// guarantee the bounds are fully contained within this monitor's work rect;
// it just tried to ensure the edges are visible on _some_ work rect.
+ // If |saved_work_area| is non-empty, it is used to determine whether the
+ // monitor cofiguration has changed. If it has, bounds are repositioned and
+ // resized if necessary to make them completely contained in the current work
+ // area.
void AdjustBoundsToBeVisibleOnMonitorContaining(
const gfx::Rect& other_bounds,
+ const gfx::Rect& saved_work_area,
gfx::Rect* bounds) const;
// Providers for persistent storage and monitor metrics.
diff --git a/chrome/browser/window_sizer_unittest.cc b/chrome/browser/window_sizer_unittest.cc
index c58b31a..54af8a1 100644
--- a/chrome/browser/window_sizer_unittest.cc
+++ b/chrome/browser/window_sizer_unittest.cc
@@ -27,6 +27,10 @@ static const gfx::Rect right_nonprimary(1024, 0, 1024, 768);
// the immediate top of the primary 1024x768 monitor.
static const gfx::Rect top_nonprimary(0, -768, 1024, 768);
+// Represents a 1024x768 monitor that is not the primary monitor, arranged to
+// the immediate bottom of the primary 1024x768 monitor.
+static const gfx::Rect bottom_nonprimary(0, 768, 1024, 768);
+
// The work area for 1024x768 monitors with different taskbar orientations.
static const gfx::Rect taskbar_bottom_work_area(0, 0, 1024, 734);
static const gfx::Rect taskbar_top_work_area(0, 34, 1024, 734);
@@ -107,9 +111,11 @@ class TestStateProvider : public WindowSizer::StateProvider {
void SetPersistentState(const gfx::Rect& bounds,
bool maximized,
+ const gfx::Rect& work_area,
bool has_persistent_data) {
persistent_bounds_ = bounds;
persistent_maximized_ = maximized;
+ persistent_work_area_ = work_area;
has_persistent_data_ = has_persistent_data;
}
@@ -119,9 +125,12 @@ class TestStateProvider : public WindowSizer::StateProvider {
}
// Overridden from WindowSizer::StateProvider:
- virtual bool GetPersistentState(gfx::Rect* bounds, bool* maximized) const {
+ virtual bool GetPersistentState(gfx::Rect* bounds,
+ bool* maximized,
+ gfx::Rect* saved_work_area) const {
*bounds = persistent_bounds_;
*maximized = persistent_maximized_;
+ *saved_work_area = persistent_work_area_;
return has_persistent_data_;
}
@@ -133,6 +142,7 @@ class TestStateProvider : public WindowSizer::StateProvider {
private:
gfx::Rect persistent_bounds_;
bool persistent_maximized_;
+ gfx::Rect persistent_work_area_;
bool has_persistent_data_;
gfx::Rect last_active_bounds_;
@@ -149,6 +159,7 @@ static void GetWindowBounds(const gfx::Rect& monitor1_bounds,
const gfx::Rect& monitor2_bounds,
const gfx::Rect& state,
bool maximized,
+ const gfx::Rect& work_area,
Source source,
gfx::Rect* out_bounds,
bool* out_maximized) {
@@ -158,7 +169,7 @@ static void GetWindowBounds(const gfx::Rect& monitor1_bounds,
mip->AddMonitor(monitor2_bounds, monitor2_bounds);
TestStateProvider* sp = new TestStateProvider;
if (source == PERSISTED)
- sp->SetPersistentState(state, maximized, true);
+ sp->SetPersistentState(state, maximized, work_area, true);
else if (source == LAST_ACTIVE)
sp->SetLastActiveState(state, true);
WindowSizer sizer(sp, mip);
@@ -172,7 +183,7 @@ TEST(WindowSizerTest, DefaultSizeCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), gfx::Rect(),
- false, DEFAULT, &window_bounds, &maximized);
+ false, gfx::Rect(), DEFAULT, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
1024 - kWindowTilePixels * 2,
@@ -184,7 +195,8 @@ TEST(WindowSizerTest, DefaultSizeCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, taskbar_bottom_work_area, gfx::Rect(),
- gfx::Rect(), false, DEFAULT, &window_bounds, &maximized);
+ gfx::Rect(), false, gfx::Rect(), DEFAULT, &window_bounds,
+ &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
1024 - kWindowTilePixels * 2,
@@ -197,7 +209,8 @@ TEST(WindowSizerTest, DefaultSizeCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, taskbar_right_work_area, gfx::Rect(),
- gfx::Rect(), false, DEFAULT, &window_bounds, &maximized);
+ gfx::Rect(), false, gfx::Rect(), DEFAULT, &window_bounds,
+ &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
taskbar_right_work_area.width() - kWindowTilePixels*2,
@@ -209,7 +222,8 @@ TEST(WindowSizerTest, DefaultSizeCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(),
- gfx::Rect(), false, DEFAULT, &window_bounds, &maximized);
+ gfx::Rect(), false, gfx::Rect(), DEFAULT, &window_bounds,
+ &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(taskbar_left_work_area.x() + kWindowTilePixels,
kWindowTilePixels,
@@ -223,7 +237,8 @@ TEST(WindowSizerTest, DefaultSizeCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(),
- gfx::Rect(), false, DEFAULT, &window_bounds, &maximized);
+ gfx::Rect(), false, gfx::Rect(), DEFAULT, &window_bounds,
+ &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels,
taskbar_top_work_area.y() + kWindowTilePixels,
@@ -236,7 +251,7 @@ TEST(WindowSizerTest, DefaultSizeCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(twelveeighty, twelveeighty, gfx::Rect(), gfx::Rect(),
- false, DEFAULT, &window_bounds, &maximized);
+ false, gfx::Rect(), DEFAULT, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
1050,
@@ -248,7 +263,7 @@ TEST(WindowSizerTest, DefaultSizeCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(sixteenhundred, sixteenhundred, gfx::Rect(), gfx::Rect(),
- false, DEFAULT, &window_bounds, &maximized);
+ false, gfx::Rect(), DEFAULT, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
1050,
@@ -260,7 +275,7 @@ TEST(WindowSizerTest, DefaultSizeCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(sixteeneighty, sixteeneighty, gfx::Rect(), gfx::Rect(),
- false, DEFAULT, &window_bounds, &maximized);
+ false, gfx::Rect(), DEFAULT, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
840 - static_cast<int>(kWindowTilePixels * 1.5),
@@ -272,7 +287,7 @@ TEST(WindowSizerTest, DefaultSizeCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(nineteentwenty, nineteentwenty, gfx::Rect(), gfx::Rect(),
- false, DEFAULT, &window_bounds, &maximized);
+ false, gfx::Rect(), DEFAULT, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
960 - static_cast<int>(kWindowTilePixels * 1.5),
@@ -289,7 +304,7 @@ TEST(WindowSizerTest, LastWindowBoundsCase) {
bool maximized = false;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400),
- false, LAST_ACTIVE,
+ false, gfx::Rect(), LAST_ACTIVE,
&window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
@@ -301,7 +316,7 @@ TEST(WindowSizerTest, LastWindowBoundsCase) {
bool maximized = false;
GetWindowBounds(tentwentyfour, taskbar_left_work_area, gfx::Rect(),
gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400),
- false, LAST_ACTIVE,
+ false, gfx::Rect(), LAST_ACTIVE,
&window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
@@ -313,11 +328,12 @@ TEST(WindowSizerTest, LastWindowBoundsCase) {
bool maximized = false;
GetWindowBounds(tentwentyfour, taskbar_top_work_area, gfx::Rect(),
gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400),
- false, LAST_ACTIVE,
+ false, gfx::Rect(), LAST_ACTIVE,
&window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
- kWindowTilePixels * 2,
+ std::max(kWindowTilePixels * 2,
+ 34 /* toolbar height */),
500, 400), window_bounds);
}
@@ -326,7 +342,7 @@ TEST(WindowSizerTest, LastWindowBoundsCase) {
bool maximized = false;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
gfx::Rect(kWindowTilePixels, kWindowTilePixels, 29, 29),
- false, LAST_ACTIVE,
+ false, gfx::Rect(), LAST_ACTIVE,
&window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
@@ -340,7 +356,7 @@ TEST(WindowSizerTest, LastWindowBoundsCase) {
bool maximized = false;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
gfx::Rect(kWindowTilePixels, kWindowTilePixels, 500, 400),
- true, LAST_ACTIVE,
+ true, gfx::Rect(), LAST_ACTIVE,
&window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels * 2,
@@ -354,8 +370,8 @@ TEST(WindowSizerTest, LastWindowBoundsCase) {
gfx::Rect window_bounds;
bool maximized = false;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(10, 728, 500, 400), false, LAST_ACTIVE,
- &window_bounds, &maximized);
+ gfx::Rect(10, 728, 500, 400), false, gfx::Rect(),
+ LAST_ACTIVE, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738,
500, 400), window_bounds);
@@ -366,8 +382,8 @@ TEST(WindowSizerTest, LastWindowBoundsCase) {
gfx::Rect window_bounds;
bool maximized = false;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(10, 729, 500, 400), false, LAST_ACTIVE,
- &window_bounds, &maximized);
+ gfx::Rect(10, 729, 500, 400), false, gfx::Rect(),
+ LAST_ACTIVE, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(10 + kWindowTilePixels, 738 /* not 739 */, 500, 400),
window_bounds);
@@ -378,8 +394,8 @@ TEST(WindowSizerTest, LastWindowBoundsCase) {
gfx::Rect window_bounds;
bool maximized = false;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(984, 10, 500, 400), false, LAST_ACTIVE,
- &window_bounds, &maximized);
+ gfx::Rect(984, 10, 500, 400), false, gfx::Rect(),
+ LAST_ACTIVE, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(994, 10 + kWindowTilePixels, 500, 400), window_bounds);
}
@@ -389,8 +405,8 @@ TEST(WindowSizerTest, LastWindowBoundsCase) {
gfx::Rect window_bounds;
bool maximized = false;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(985, 10, 500, 400), false, LAST_ACTIVE,
- &window_bounds, &maximized);
+ gfx::Rect(985, 10, 500, 400), false, gfx::Rect(),
+ LAST_ACTIVE, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(994 /* not 995 */, 10 + kWindowTilePixels,
500, 400), window_bounds);
@@ -401,8 +417,8 @@ TEST(WindowSizerTest, LastWindowBoundsCase) {
gfx::Rect window_bounds;
bool maximized = false;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(985, 729, 500, 400), false, LAST_ACTIVE,
- &window_bounds, &maximized);
+ gfx::Rect(985, 729, 500, 400), false, gfx::Rect(),
+ LAST_ACTIVE, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400),
window_bounds);
@@ -418,7 +434,7 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds,
- false, PERSISTED, &window_bounds, &maximized);
+ false, gfx::Rect(), PERSISTED, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(initial_bounds, window_bounds);
}
@@ -429,7 +445,7 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(), initial_bounds,
- true, PERSISTED, &window_bounds, &maximized);
+ true, gfx::Rect(), PERSISTED, &window_bounds, &maximized);
EXPECT_TRUE(maximized);
EXPECT_EQ(initial_bounds, window_bounds);
}
@@ -440,8 +456,8 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary,
- initial_bounds, false, PERSISTED, &window_bounds,
- &maximized);
+ initial_bounds, false, gfx::Rect(), PERSISTED,
+ &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(initial_bounds, window_bounds);
}
@@ -452,8 +468,8 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, left_nonprimary,
- initial_bounds, true, PERSISTED, &window_bounds,
- &maximized);
+ initial_bounds, true, gfx::Rect(), PERSISTED,
+ &window_bounds, &maximized);
EXPECT_TRUE(maximized);
EXPECT_EQ(initial_bounds, window_bounds);
}
@@ -465,7 +481,7 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- initial_bounds, false, PERSISTED,
+ initial_bounds, false, gfx::Rect(), PERSISTED,
&window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(initial_bounds, window_bounds);
@@ -476,34 +492,22 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(-471, 50, 500, 400), false, PERSISTED,
- &window_bounds, &maximized);
+ gfx::Rect(-471, 50, 500, 400), false, gfx::Rect(),
+ PERSISTED, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 50, 500, 400), window_bounds);
}
- { // off the top but the minimum visibility condition is barely satisified
- // without relocation.
+ { // off the top
gfx::Rect initial_bounds(50, -370, 500, 400);
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- initial_bounds, false, PERSISTED,
- &window_bounds, &maximized);
- EXPECT_FALSE(maximized);
- EXPECT_EQ(initial_bounds, window_bounds);
- }
-
- { // off the top and the minimum visibility condition is satisified by
- // relocation.
- gfx::Rect window_bounds;
- bool maximized;
- GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(50, -371, 500, 400), false, PERSISTED,
- &window_bounds, &maximized);
+ gfx::Rect(50, -370, 500, 400), false, gfx::Rect(),
+ PERSISTED, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
- EXPECT_EQ(gfx::Rect(50, -370 /* not -371 */, 500, 400), window_bounds);
+ EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds);
}
{ // off the right but the minimum visibility condition is barely satisified
@@ -513,7 +517,7 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- initial_bounds, false, PERSISTED,
+ initial_bounds, false, gfx::Rect(), PERSISTED,
&window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(initial_bounds, window_bounds);
@@ -524,8 +528,8 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(995, 50, 500, 400), false, PERSISTED,
- &window_bounds, &maximized);
+ gfx::Rect(995, 50, 500, 400), false, gfx::Rect(),
+ PERSISTED, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(994 /* not 995 */, 50, 500, 400), window_bounds);
}
@@ -537,7 +541,7 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- initial_bounds, false, PERSISTED,
+ initial_bounds, false, gfx::Rect(), PERSISTED,
&window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(initial_bounds, window_bounds);
@@ -548,21 +552,20 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(50, 739, 500, 400), false, PERSISTED,
+ gfx::Rect(50, 739, 500, 400), false, gfx::Rect(), PERSISTED,
&window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(50, 738 /* not 739 */, 500, 400), window_bounds);
}
- { // off the topleft and the minimum visibility condition is satisified by
- // relocation.
+ { // off the topleft
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(-471, -371, 500, 400), false, PERSISTED,
- &window_bounds, &maximized);
+ gfx::Rect(-471, -371, 500, 400), false, gfx::Rect(),
+ PERSISTED, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
- EXPECT_EQ(gfx::Rect(-470 /* not -471 */, -370 /* not -371 */, 500, 400),
+ EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 0, 500, 400),
window_bounds);
}
@@ -571,10 +574,10 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(995, -371, 500, 400), false, PERSISTED,
- &window_bounds, &maximized);
+ gfx::Rect(995, -371, 500, 400), false, gfx::Rect(),
+ PERSISTED, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
- EXPECT_EQ(gfx::Rect(994 /* not 995 */, -370 /* not -371 */, 500, 400),
+ EXPECT_EQ(gfx::Rect(994 /* not 995 */, 0, 500, 400),
window_bounds);
}
@@ -583,8 +586,8 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(-471, 739, 500, 400), false, PERSISTED,
- &window_bounds, &maximized);
+ gfx::Rect(-471, 739, 500, 400), false, gfx::Rect(),
+ PERSISTED, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(-470 /* not -471 */, 738 /* not 739 */, 500, 400),
window_bounds);
@@ -595,59 +598,141 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(995, 739, 500, 400), false, PERSISTED,
- &window_bounds, &maximized);
+ gfx::Rect(995, 739, 500, 400), false, gfx::Rect(),
+ PERSISTED, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(994 /* not 995 */, 738 /* not 739 */, 500, 400),
window_bounds);
}
- { // entirely off left (monitor was detached since last run)
+ { // entirely off left
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(-700, 50, 500, 400), false, PERSISTED,
- &window_bounds, &maximized);
+ gfx::Rect(-700, 50, 500, 400), false, gfx::Rect(),
+ PERSISTED, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(-470 /* not -700 */, 50, 500, 400), window_bounds);
}
+ { // entirely off left (monitor was detached since last run)
+ gfx::Rect window_bounds;
+ bool maximized;
+ GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
+ gfx::Rect(-700, 50, 500, 400), false, left_nonprimary,
+ PERSISTED, &window_bounds, &maximized);
+ EXPECT_FALSE(maximized);
+ EXPECT_EQ(gfx::Rect(0, 50, 500, 400), window_bounds);
+ }
+
+ { // entirely off top
+ gfx::Rect window_bounds;
+ bool maximized;
+ GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
+ gfx::Rect(50, -500, 500, 400), false, gfx::Rect(),
+ PERSISTED, &window_bounds, &maximized);
+ EXPECT_FALSE(maximized);
+ EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds);
+ }
+
{ // entirely off top (monitor was detached since last run)
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(50, -500, 500, 400), false, PERSISTED,
- &window_bounds, &maximized);
+ gfx::Rect(50, -500, 500, 400), false, top_nonprimary,
+ PERSISTED, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
- EXPECT_EQ(gfx::Rect(50, -370 /* not -500 */, 500, 400), window_bounds);
+ EXPECT_EQ(gfx::Rect(50, 0, 500, 400), window_bounds);
}
- { // entirely off right (monitor was detached since last run)
+ { // entirely off right
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(1200, 50, 500, 400), false, PERSISTED,
- &window_bounds, &maximized);
+ gfx::Rect(1200, 50, 500, 400), false, gfx::Rect(),
+ PERSISTED, &window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(994 /* not 1200 */, 50, 500, 400), window_bounds);
}
- { // entirely off bottom (monitor was detached since last run)
+ { // entirely off right (monitor was detached since last run)
+ gfx::Rect window_bounds;
+ bool maximized;
+ GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
+ gfx::Rect(1200, 50, 500, 400), false, right_nonprimary,
+ PERSISTED, &window_bounds, &maximized);
+ EXPECT_FALSE(maximized);
+ EXPECT_EQ(gfx::Rect(524, 50, 500, 400), window_bounds);
+ }
+
+ { // entirely off bottom
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
- gfx::Rect(50, 800, 500, 400), false, PERSISTED,
+ gfx::Rect(50, 800, 500, 400), false, gfx::Rect(), PERSISTED,
&window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(50, 738 /* not 800 */, 500, 400), window_bounds);
}
+ { // entirely off bottom (monitor was detached since last run)
+ gfx::Rect window_bounds;
+ bool maximized;
+ GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
+ gfx::Rect(50, 800, 500, 400), false, bottom_nonprimary,
+ PERSISTED, &window_bounds, &maximized);
+ EXPECT_FALSE(maximized);
+ EXPECT_EQ(gfx::Rect(50, 368, 500, 400), window_bounds);
+ }
+
+ { // Non-primary monitor resoultion has changed, but the monitor still
+ // completely contains the window.
+
+ gfx::Rect initial_bounds(1074, 50, 600, 500);
+
+ gfx::Rect window_bounds;
+ bool maximized;
+ GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600),
+ initial_bounds, false, right_nonprimary,
+ PERSISTED, &window_bounds, &maximized);
+ EXPECT_FALSE(maximized);
+ EXPECT_EQ(initial_bounds, window_bounds);
+ }
+
+ { // Non-primary monitor resoultion has changed, and the window is partially
+ // off-screen.
+
+ gfx::Rect initial_bounds(1274, 50, 600, 500);
+
+ gfx::Rect window_bounds;
+ bool maximized;
+ GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600),
+ initial_bounds, false, right_nonprimary,
+ PERSISTED, &window_bounds, &maximized);
+ EXPECT_FALSE(maximized);
+ EXPECT_EQ(gfx::Rect(1224, 50, 600, 500), window_bounds);
+ }
+
+ { // Non-primary monitor resoultion has changed, and the window is now too
+ // large for the monitor.
+
+ gfx::Rect initial_bounds(1274, 50, 900, 700);
+
+ gfx::Rect window_bounds;
+ bool maximized;
+ GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(1024, 0, 800, 600),
+ initial_bounds, false, right_nonprimary,
+ PERSISTED, &window_bounds, &maximized);
+ EXPECT_FALSE(maximized);
+ EXPECT_EQ(gfx::Rect(1024, 0, 800, 600), window_bounds);
+ }
+
{ // width and height too small
gfx::Rect window_bounds;
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
gfx::Rect(kWindowTilePixels, kWindowTilePixels, 29, 29),
- false, PERSISTED,
+ false, gfx::Rect(), PERSISTED,
&window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(gfx::Rect(kWindowTilePixels, kWindowTilePixels,
@@ -664,7 +749,7 @@ TEST(WindowSizerTest, PersistedBoundsCase) {
bool maximized;
GetWindowBounds(tentwentyfour, tentwentyfour, gfx::Rect(),
gfx::Rect(kWindowTilePixels, kWindowTilePixels, 30, 5000),
- false, PERSISTED,
+ false, gfx::Rect(), PERSISTED,
&window_bounds, &maximized);
EXPECT_FALSE(maximized);
EXPECT_EQ(tentwentyfour.height(), window_bounds.height());