Commit 8741c196 authored by tmdiep@chromium.org's avatar tmdiep@chromium.org

App windows on ChromeOS cannot be sized to their maximum height

CustomFrameViewAsh::GetMaximumSize() should add the height of the
title bar, if a maximum size constraint is specified.

BUG=349229
TEST=ash_unittests (CustomFrameViewAshTest.*)

Review URL: https://codereview.chromium.org/183793011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255884 0039d316-1c4b-4281-b951-d872f2087c98
parent 47d3e1b3
...@@ -475,7 +475,16 @@ gfx::Size CustomFrameViewAsh::GetMinimumSize() { ...@@ -475,7 +475,16 @@ gfx::Size CustomFrameViewAsh::GetMinimumSize() {
} }
gfx::Size CustomFrameViewAsh::GetMaximumSize() { gfx::Size CustomFrameViewAsh::GetMaximumSize() {
return frame_->client_view()->GetMaximumSize(); gfx::Size max_client_size(frame_->client_view()->GetMaximumSize());
int width = 0;
int height = 0;
if (max_client_size.width() > 0)
width = std::max(header_view_->GetMinimumWidth(), max_client_size.width());
if (max_client_size.height() > 0)
height = NonClientTopBorderHeight() + max_client_size.height();
return gfx::Size(width, height);
} }
void CustomFrameViewAsh::SchedulePaintInRect(const gfx::Rect& r) { void CustomFrameViewAsh::SchedulePaintInRect(const gfx::Rect& r) {
......
...@@ -65,6 +65,7 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView { ...@@ -65,6 +65,7 @@ class ASH_EXPORT CustomFrameViewAsh : public views::NonClientFrameView {
private: private:
class OverlayView; class OverlayView;
friend class TestWidgetConstraintsDelegate;
// Height from top of window to top of client area. // Height from top of window to top of client area.
int NonClientTopBorderHeight() const; int NonClientTopBorderHeight() const;
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
namespace ash { namespace ash {
namespace {
// A views::WidgetDelegate which uses a CustomFrameViewAsh. // A views::WidgetDelegate which uses a CustomFrameViewAsh.
class TestWidgetDelegate : public views::WidgetDelegateView { class TestWidgetDelegate : public views::WidgetDelegateView {
public: public:
...@@ -30,7 +28,7 @@ class TestWidgetDelegate : public views::WidgetDelegateView { ...@@ -30,7 +28,7 @@ class TestWidgetDelegate : public views::WidgetDelegateView {
return custom_frame_view_; return custom_frame_view_;
} }
CustomFrameViewAsh* custom_frame_view() { CustomFrameViewAsh* custom_frame_view() const {
return custom_frame_view_; return custom_frame_view_;
} }
...@@ -41,22 +39,74 @@ class TestWidgetDelegate : public views::WidgetDelegateView { ...@@ -41,22 +39,74 @@ class TestWidgetDelegate : public views::WidgetDelegateView {
DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate); DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
}; };
} // namespace class TestWidgetConstraintsDelegate : public TestWidgetDelegate {
public:
TestWidgetConstraintsDelegate() {
}
virtual ~TestWidgetConstraintsDelegate() {
}
// views::View implementation.
virtual gfx::Size GetMinimumSize() OVERRIDE {
return minimum_size_;
}
virtual gfx::Size GetMaximumSize() OVERRIDE {
return maximum_size_;
}
virtual views::View* GetContentsView() OVERRIDE {
// Set this instance as the contents view so that the maximum and minimum
// size constraints will be used.
return this;
}
void set_minimum_size(const gfx::Size& min_size) {
minimum_size_ = min_size;
}
void set_maximum_size(const gfx::Size& max_size) {
maximum_size_ = max_size;
}
int GetTitleBarHeight() const {
return custom_frame_view()->NonClientTopBorderHeight();
}
private:
gfx::Size minimum_size_;
gfx::Size maximum_size_;
DISALLOW_COPY_AND_ASSIGN(TestWidgetConstraintsDelegate);
};
class CustomFrameViewAshTest : public test::AshTestBase {
public:
CustomFrameViewAshTest() {}
virtual ~CustomFrameViewAshTest() {}
protected:
scoped_ptr<views::Widget> CreateWidget(TestWidgetDelegate* delegate) {
scoped_ptr<views::Widget> widget(new views::Widget);
views::Widget::InitParams params;
params.delegate = delegate;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(0, 0, 100, 100);
params.context = CurrentContext();
widget->Init(params);
return widget.Pass();
}
typedef test::AshTestBase CustomFrameViewAshTest; private:
DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshTest);
};
// Test that the height of the header is correct upon initially displaying // Test that the height of the header is correct upon initially displaying
// the widget. // the widget.
TEST_F(CustomFrameViewAshTest, HeaderHeight) { TEST_F(CustomFrameViewAshTest, HeaderHeight) {
TestWidgetDelegate* delegate = new TestWidgetDelegate; TestWidgetDelegate* delegate = new TestWidgetDelegate;
scoped_ptr<views::Widget> widget(new views::Widget); scoped_ptr<views::Widget> widget(CreateWidget(delegate));
views::Widget::InitParams params;
params.delegate = delegate;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.bounds = gfx::Rect(0, 0, 100, 100);
params.context = CurrentContext();
widget->Init(params);
widget->Show(); widget->Show();
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
...@@ -79,4 +129,43 @@ TEST_F(CustomFrameViewAshTest, HeaderHeight) { ...@@ -79,4 +129,43 @@ TEST_F(CustomFrameViewAshTest, HeaderHeight) {
delegate->custom_frame_view()->GetHeaderView()->height()); delegate->custom_frame_view()->GetHeaderView()->height());
} }
// Verify that CustomFrameViewAsh returns the correct minimum and maximum frame
// sizes when the client view does not specify any size constraints.
TEST_F(CustomFrameViewAshTest, NoSizeConstraints) {
TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
scoped_ptr<views::Widget> widget(CreateWidget(delegate));
CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
gfx::Size min_frame_size = custom_frame_view->GetMinimumSize();
gfx::Size max_frame_size = custom_frame_view->GetMaximumSize();
EXPECT_EQ(delegate->GetTitleBarHeight(), min_frame_size.height());
// A width and height constraint of 0 denotes unbounded.
EXPECT_EQ(0, max_frame_size.width());
EXPECT_EQ(0, max_frame_size.height());
}
// Verify that CustomFrameViewAsh returns the correct minimum and maximum frame
// sizes when the client view specifies size constraints.
TEST_F(CustomFrameViewAshTest, MinimumAndMaximumSize) {
gfx::Size min_client_size(500, 500);
gfx::Size max_client_size(800, 800);
TestWidgetConstraintsDelegate* delegate = new TestWidgetConstraintsDelegate;
delegate->set_minimum_size(min_client_size);
delegate->set_maximum_size(max_client_size);
scoped_ptr<views::Widget> widget(CreateWidget(delegate));
CustomFrameViewAsh* custom_frame_view = delegate->custom_frame_view();
gfx::Size min_frame_size = custom_frame_view->GetMinimumSize();
gfx::Size max_frame_size = custom_frame_view->GetMaximumSize();
EXPECT_EQ(min_client_size.width(), min_frame_size.width());
EXPECT_EQ(max_client_size.width(), max_frame_size.width());
EXPECT_EQ(min_client_size.height() + delegate->GetTitleBarHeight(),
min_frame_size.height());
EXPECT_EQ(max_client_size.height() + delegate->GetTitleBarHeight(),
max_frame_size.height());
}
} // namespace ash } // namespace ash
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