Commit 2cc782d1 authored by pkasting@chromium.org's avatar pkasting@chromium.org

Be less aggressive about resizing Chrome windows when restoring them. ...

Be less aggressive about resizing Chrome windows when restoring them.  Original patch by Yuzo Fujishima (see http://codereview.chromium.org/115180 ), r=me.

BUG=9587

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17233 0039d316-1c4b-4281-b951-d872f2087c98
parent b2d8eb46
...@@ -233,6 +233,13 @@ bool WindowSizer::PositionIsOffscreen(int position, Edge edge) const { ...@@ -233,6 +233,13 @@ bool WindowSizer::PositionIsOffscreen(int position, Edge edge) const {
return true; return true;
} }
namespace {
// Minimum height of the visible part of a window.
static const int kMinVisibleHeight = 30;
// Minimum width of the visible part of a window.
static const int kMinVisibleWidth = 30;
}
void WindowSizer::AdjustBoundsToBeVisibleOnMonitorContaining( void WindowSizer::AdjustBoundsToBeVisibleOnMonitorContaining(
const gfx::Rect& other_bounds, gfx::Rect* bounds) const { const gfx::Rect& other_bounds, gfx::Rect* bounds) const {
DCHECK(bounds); DCHECK(bounds);
...@@ -251,36 +258,15 @@ void WindowSizer::AdjustBoundsToBeVisibleOnMonitorContaining( ...@@ -251,36 +258,15 @@ void WindowSizer::AdjustBoundsToBeVisibleOnMonitorContaining(
if (bounds->width() <= 0) if (bounds->width() <= 0)
bounds->set_width(default_bounds.width()); bounds->set_width(default_bounds.width());
// First determine which screen edge(s) the window is offscreen on. // Ensure the minimum height and width.
monitor_info_provider_->UpdateWorkAreas(); bounds->set_height(std::max(kMinVisibleHeight, bounds->height()));
bool top_offscreen = PositionIsOffscreen(bounds->y(), TOP); bounds->set_width(std::max(kMinVisibleWidth, bounds->width()));
bool left_offscreen = PositionIsOffscreen(bounds->x(), LEFT);
bool bottom_offscreen = PositionIsOffscreen(bounds->bottom(), BOTTOM); // Ensure at least kMinVisibleWidth * kMinVisibleHeight is visible.
bool right_offscreen = PositionIsOffscreen(bounds->right(), RIGHT); const int min_y = work_area.y() + kMinVisibleHeight - bounds->height();
const int min_x = work_area.x() + kMinVisibleWidth - bounds->width();
// Bump the window back onto the screen in the direction that it's offscreen. const int max_y = work_area.bottom() - kMinVisibleHeight;
int min_x = work_area.x() + kWindowTilePixels; const int max_x = work_area.right() - kMinVisibleWidth;
int min_y = work_area.y() + kWindowTilePixels; bounds->set_y(std::max(min_y, std::min(max_y, bounds->y())));
if (bottom_offscreen) { bounds->set_x(std::max(min_x, std::min(max_x, bounds->x())));
bounds->set_y(std::max(
work_area.bottom() - kWindowTilePixels - bounds->height(), min_y));
}
if (right_offscreen) {
bounds->set_x(std::max(
work_area.right() - kWindowTilePixels - bounds->width(), min_x));
}
if (top_offscreen)
bounds->set_y(min_y);
if (left_offscreen)
bounds->set_x(min_x);
// Now that we've tried to correct the x/y position to something reasonable,
// see if the window is still too tall or wide to fit, and resize it if need
// be.
if ((bottom_offscreen || top_offscreen) &&
bounds->bottom() > work_area.bottom())
bounds->set_height(work_area.height() - 2 * kWindowTilePixels);
if ((left_offscreen || right_offscreen) &&
bounds->right() > work_area.right())
bounds->set_width(work_area.width() - 2 * kWindowTilePixels);
} }
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment