diff options
author | varunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 00:11:29 +0000 |
---|---|---|
committer | varunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-10 00:11:29 +0000 |
commit | f2622f29325da67699468fb369f250a37c56a4e5 (patch) | |
tree | 0e14759cfc544708fbde63f5b9c90099c5c9f084 /ui/views/widget | |
parent | 8c169b5723c4ad67f665e49c3c738f319a950933 (diff) | |
download | chromium_src-f2622f29325da67699468fb369f250a37c56a4e5.zip chromium_src-f2622f29325da67699468fb369f250a37c56a4e5.tar.gz chromium_src-f2622f29325da67699468fb369f250a37c56a4e5.tar.bz2 |
aura: Position windows to the center of the transient parent if one exists.
This makes dialog boxes appear centered relative to the window that invoked
the dialog.
BUG=106049
TEST=manual
Review URL: http://codereview.chromium.org/9358016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121345 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views/widget')
-rw-r--r-- | ui/views/widget/native_widget_aura.cc | 34 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura_unittest.cc | 1 |
2 files changed, 28 insertions, 7 deletions
diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index d2970f1..8f11edb 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -330,16 +330,36 @@ InputMethod* NativeWidgetAura::CreateInputMethod() { } void NativeWidgetAura::CenterWindow(const gfx::Size& size) { - gfx::Rect parent_bounds(window_->parent()->bounds()); + gfx::Rect parent_bounds(window_->parent()->GetScreenBounds()); // When centering window, we take the intersection of the host and // the parent. We assume the root window represents the visible // rect of a single screen. - parent_bounds = parent_bounds.Intersect( - aura::RootWindow::GetInstance()->bounds()); - window_->SetBounds(gfx::Rect((parent_bounds.width() - size.width())/2, - (parent_bounds.height() - size.height())/2, - size.width(), - size.height())); + gfx::Rect work_area = gfx::Screen::GetMonitorWorkAreaNearestWindow(window_); + parent_bounds = parent_bounds.Intersect(work_area); + + // If |window_|'s transient parent's bounds are big enough to fit it, then we + // center it with respect to the transient parent. + if (window_->transient_parent()) { + gfx::Rect transient_parent_rect = window_->transient_parent()-> + GetScreenBounds().Intersect(work_area); + if (transient_parent_rect.height() >= size.height() && + transient_parent_rect.width() >= size.width()) + parent_bounds = transient_parent_rect; + } + + gfx::Rect window_bounds( + parent_bounds.x() + (parent_bounds.width() - size.width()) / 2, + parent_bounds.y() + (parent_bounds.height() - size.height()) / 2, + size.width(), + size.height()); + window_bounds = window_bounds.AdjustToFit(work_area); + + // Convert the bounds back relative to the parent. + gfx::Point origin = window_bounds.origin(); + aura::Window::ConvertPointToWindow(window_->GetRootWindow(), + window_->parent(), &origin); + window_bounds.set_origin(origin); + window_->SetBounds(window_bounds); } void NativeWidgetAura::GetWindowPlacement( diff --git a/ui/views/widget/native_widget_aura_unittest.cc b/ui/views/widget/native_widget_aura_unittest.cc index 2b9f874..61ae2e7 100644 --- a/ui/views/widget/native_widget_aura_unittest.cc +++ b/ui/views/widget/native_widget_aura_unittest.cc @@ -33,6 +33,7 @@ class NativeWidgetAuraTest : public testing::Test { // testing::Test overrides: virtual void SetUp() OVERRIDE { aura::RootWindow::GetInstance()->SetBounds(gfx::Rect(0, 0, 640, 480)); + aura::RootWindow::GetInstance()->SetHostSize(gfx::Size(640, 480)); } virtual void TearDown() OVERRIDE { aura::RootWindow::DeleteInstance(); |