summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-24 23:13:57 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-24 23:13:57 +0000
commit2d1f2a3d93f338b81e803639da562182504adecc (patch)
tree04df09827763e8ae662f852a51ec17a7e8d66b96 /ui
parent168dcc10daf00c3ce0470f85afdaba9eb0ede171 (diff)
downloadchromium_src-2d1f2a3d93f338b81e803639da562182504adecc.zip
chromium_src-2d1f2a3d93f338b81e803639da562182504adecc.tar.gz
chromium_src-2d1f2a3d93f338b81e803639da562182504adecc.tar.bz2
Fixes two bugs related to constrained windows:
. Make them no bigger than the parent (otherwise you can't move/close them). . Fixes coordinate conversion bug. BUG=128105 TEST=covered by unit test R=ben@chromium.org Review URL: https://chromiumcodereview.appspot.com/10795078 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148241 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/views/widget/native_widget_aura.cc6
-rw-r--r--ui/views/widget/native_widget_aura_unittest.cc18
-rw-r--r--ui/views/window/client_view.cc10
-rw-r--r--ui/views/window/client_view.h1
4 files changed, 29 insertions, 6 deletions
diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc
index ea9555b..1b2b513 100644
--- a/ui/views/widget/native_widget_aura.cc
+++ b/ui/views/widget/native_widget_aura.cc
@@ -359,7 +359,7 @@ void NativeWidgetAura::CenterWindow(const gfx::Size& size) {
aura::client::GetScreenPositionClient(window_->GetRootWindow());
if (screen_position_client) {
gfx::Point origin = work_area.origin();
- screen_position_client->ConvertPointFromScreen(window_->parent(),
+ screen_position_client->ConvertPointFromScreen(window_->GetRootWindow(),
&origin);
work_area.set_origin(origin);
}
@@ -381,7 +381,9 @@ void NativeWidgetAura::CenterWindow(const gfx::Size& size) {
parent_bounds.y() + (parent_bounds.height() - size.height()) / 2,
size.width(),
size.height());
- window_bounds = window_bounds.AdjustToFit(work_area);
+ // Don't size the window bigger than the parent, otherwise the user may not be
+ // able to close or move it.
+ window_bounds = window_bounds.AdjustToFit(parent_bounds);
// Convert the bounds back relative to the parent.
gfx::Point origin = window_bounds.origin();
diff --git a/ui/views/widget/native_widget_aura_unittest.cc b/ui/views/widget/native_widget_aura_unittest.cc
index d589f4d..a516e14 100644
--- a/ui/views/widget/native_widget_aura_unittest.cc
+++ b/ui/views/widget/native_widget_aura_unittest.cc
@@ -81,7 +81,7 @@ TEST_F(NativeWidgetAuraTest, CenterWindowSmallParent) {
parent->Init(ui::LAYER_NOT_DRAWN);
parent->SetBounds(gfx::Rect(0, 0, 480, 320));
scoped_ptr<Widget> widget(new Widget());
- NativeWidgetAura* window = Init(parent.get(), widget.get());
+ NativeWidgetAura* window = Init(parent.get(), widget.get());
window->CenterWindow(gfx::Size(100, 100));
EXPECT_EQ(gfx::Rect( (480 - 100) / 2,
@@ -91,6 +91,22 @@ TEST_F(NativeWidgetAuraTest, CenterWindowSmallParent) {
widget->CloseNow();
}
+// Verifies CenterWindow() constrains to parent size.
+TEST_F(NativeWidgetAuraTest, CenterWindowSmallParentNotAtOrigin) {
+ // Make a parent window smaller than the host represented by rootwindow and
+ // offset it slightly from the origin.
+ scoped_ptr<aura::Window> parent(new aura::Window(NULL));
+ parent->Init(ui::LAYER_NOT_DRAWN);
+ parent->SetBounds(gfx::Rect(20, 40, 480, 320));
+ scoped_ptr<Widget> widget(new Widget());
+ NativeWidgetAura* window = Init(parent.get(), widget.get());
+ window->CenterWindow(gfx::Size(500, 600));
+
+ // |window| should be no bigger than |parent|.
+ EXPECT_EQ("20,40 480x320", window->GetNativeWindow()->bounds().ToString());
+ widget->CloseNow();
+}
+
// Used by ShowMaximizedDoesntBounceAround. See it for details.
class TestLayoutManager : public aura::LayoutManager {
public:
diff --git a/ui/views/window/client_view.cc b/ui/views/window/client_view.cc
index 7051d2d..2d2f26a 100644
--- a/ui/views/window/client_view.cc
+++ b/ui/views/window/client_view.cc
@@ -48,9 +48,13 @@ void ClientView::WidgetClosing() {
gfx::Size ClientView::GetPreferredSize() {
// |contents_view_| is allowed to be NULL up until the point where this view
// is attached to a Container.
- if (contents_view_)
- return contents_view_->GetPreferredSize();
- return gfx::Size();
+ return contents_view_ ? contents_view_->GetPreferredSize() : gfx::Size();
+}
+
+gfx::Size ClientView::GetMinimumSize() {
+ // |contents_view_| is allowed to be NULL up until the point where this view
+ // is attached to a Container.
+ return contents_view_ ? contents_view_->GetMinimumSize() : gfx::Size();
}
void ClientView::Layout() {
diff --git a/ui/views/window/client_view.h b/ui/views/window/client_view.h
index ba23419..99bd430 100644
--- a/ui/views/window/client_view.h
+++ b/ui/views/window/client_view.h
@@ -58,6 +58,7 @@ class VIEWS_EXPORT ClientView : public View {
// Overridden from View:
virtual gfx::Size GetPreferredSize() OVERRIDE;
+ virtual gfx::Size GetMinimumSize() OVERRIDE;
virtual void Layout() OVERRIDE;
virtual std::string GetClassName() const OVERRIDE;