Commit e9732377 authored by oshima@chromium.org's avatar oshima@chromium.org

Set kCanMaximizeKey/kCanResizeKey before adding to parent.

BUG=None
TEST=NativeWidgetAuraTest.TestPropertiesWhenAddedToLayout
R=ben@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266386 0039d316-1c4b-4281-b951-d872f2087c98
parent bb1087ba
...@@ -137,6 +137,13 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { ...@@ -137,6 +137,13 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
} }
} }
// Set properties before addeing to the parent so that its layout manager
// sees the correct values.
window_->SetProperty(aura::client::kCanMaximizeKey,
GetWidget()->widget_delegate()->CanMaximize());
window_->SetProperty(aura::client::kCanResizeKey,
GetWidget()->widget_delegate()->CanResize());
if (parent) { if (parent) {
parent->AddChild(window_); parent->AddChild(window_);
} else { } else {
...@@ -167,11 +174,6 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) { ...@@ -167,11 +174,6 @@ void NativeWidgetAura::InitNativeWidget(const Widget::InitParams& params) {
aura::client::SetActivationDelegate(window_, this); aura::client::SetActivationDelegate(window_, this);
window_->SetProperty(aura::client::kCanMaximizeKey,
GetWidget()->widget_delegate()->CanMaximize());
window_->SetProperty(aura::client::kCanResizeKey,
GetWidget()->widget_delegate()->CanResize());
window_reorderer_.reset(new WindowReorderer(window_, window_reorderer_.reset(new WindowReorderer(window_,
GetWidget()->GetRootView())); GetWidget()->GetRootView()));
} }
......
...@@ -100,30 +100,39 @@ TEST_F(NativeWidgetAuraTest, CenterWindowSmallParentNotAtOrigin) { ...@@ -100,30 +100,39 @@ TEST_F(NativeWidgetAuraTest, CenterWindowSmallParentNotAtOrigin) {
widget->CloseNow(); widget->CloseNow();
} }
class TestLayoutManagerBase : public aura::LayoutManager {
public:
TestLayoutManagerBase() {}
virtual ~TestLayoutManagerBase() {}
// aura::LayoutManager:
virtual void OnWindowResized() OVERRIDE {}
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {}
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {}
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {}
virtual void OnChildWindowVisibilityChanged(aura::Window* child,
bool visible) OVERRIDE {}
virtual void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) OVERRIDE {}
private:
DISALLOW_COPY_AND_ASSIGN(TestLayoutManagerBase);
};
// Used by ShowMaximizedDoesntBounceAround. See it for details. // Used by ShowMaximizedDoesntBounceAround. See it for details.
class TestLayoutManager : public aura::LayoutManager { class MaximizeLayoutManager : public TestLayoutManagerBase {
public: public:
TestLayoutManager() {} MaximizeLayoutManager() {}
virtual ~MaximizeLayoutManager() {}
virtual void OnWindowResized() OVERRIDE { private:
} // aura::LayoutManager:
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
// This simulates what happens when adding a maximized window. // This simulates what happens when adding a maximized window.
SetChildBoundsDirect(child, gfx::Rect(0, 0, 300, 300)); SetChildBoundsDirect(child, gfx::Rect(0, 0, 300, 300));
} }
virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {
}
virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {
}
virtual void OnChildWindowVisibilityChanged(aura::Window* child,
bool visible) OVERRIDE {
}
virtual void SetChildBounds(aura::Window* child,
const gfx::Rect& requested_bounds) OVERRIDE {
}
private: DISALLOW_COPY_AND_ASSIGN(MaximizeLayoutManager);
DISALLOW_COPY_AND_ASSIGN(TestLayoutManager);
}; };
// This simulates BrowserView, which creates a custom RootView so that // This simulates BrowserView, which creates a custom RootView so that
...@@ -160,7 +169,7 @@ class TestWidget : public views::Widget { ...@@ -160,7 +169,7 @@ class TestWidget : public views::Widget {
// leads to noticable flashes. // leads to noticable flashes.
TEST_F(NativeWidgetAuraTest, ShowMaximizedDoesntBounceAround) { TEST_F(NativeWidgetAuraTest, ShowMaximizedDoesntBounceAround) {
root_window()->SetBounds(gfx::Rect(0, 0, 640, 480)); root_window()->SetBounds(gfx::Rect(0, 0, 640, 480));
root_window()->SetLayoutManager(new TestLayoutManager); root_window()->SetLayoutManager(new MaximizeLayoutManager);
scoped_ptr<TestWidget> widget(new TestWidget()); scoped_ptr<TestWidget> widget(new TestWidget());
Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
...@@ -173,6 +182,67 @@ TEST_F(NativeWidgetAuraTest, ShowMaximizedDoesntBounceAround) { ...@@ -173,6 +182,67 @@ TEST_F(NativeWidgetAuraTest, ShowMaximizedDoesntBounceAround) {
widget->CloseNow(); widget->CloseNow();
} }
class PropertyTestLayoutManager : public TestLayoutManagerBase {
public:
PropertyTestLayoutManager() : added_(false) {}
virtual ~PropertyTestLayoutManager() {}
bool added() const { return added_; }
private:
// aura::LayoutManager:
virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE {
EXPECT_TRUE(child->GetProperty(aura::client::kCanMaximizeKey));
EXPECT_TRUE(child->GetProperty(aura::client::kCanResizeKey));
added_ = true;
}
bool added_;
DISALLOW_COPY_AND_ASSIGN(PropertyTestLayoutManager);
};
class PropertyTestWidgetDelegate : public views::WidgetDelegate {
public:
explicit PropertyTestWidgetDelegate(Widget* widget) : widget_(widget) {}
virtual ~PropertyTestWidgetDelegate() {}
private:
// views::WidgetDelegate:
virtual bool CanMaximize() const OVERRIDE {
return true;
}
virtual bool CanResize() const OVERRIDE {
return true;
}
virtual Widget* GetWidget() OVERRIDE {
return widget_;
}
virtual const Widget* GetWidget() const OVERRIDE {
return widget_;
}
Widget* widget_;
DISALLOW_COPY_AND_ASSIGN(PropertyTestWidgetDelegate);
};
// Verifies that the kCanMaximizeKey/kCanReizeKey have the correct
// value when added to the layout manager.
TEST_F(NativeWidgetAuraTest, TestPropertiesWhenAddedToLayout) {
root_window()->SetBounds(gfx::Rect(0, 0, 640, 480));
PropertyTestLayoutManager* layout_manager = new PropertyTestLayoutManager();
root_window()->SetLayoutManager(layout_manager);
scoped_ptr<TestWidget> widget(new TestWidget());
Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.delegate = new PropertyTestWidgetDelegate(widget.get());
params.parent = NULL;
params.context = root_window();
widget->Init(params);
EXPECT_TRUE(layout_manager->added());
widget->CloseNow();
}
TEST_F(NativeWidgetAuraTest, GetClientAreaScreenBounds) { TEST_F(NativeWidgetAuraTest, GetClientAreaScreenBounds) {
// Create a widget. // Create a widget.
Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
...@@ -190,8 +260,6 @@ TEST_F(NativeWidgetAuraTest, GetClientAreaScreenBounds) { ...@@ -190,8 +260,6 @@ TEST_F(NativeWidgetAuraTest, GetClientAreaScreenBounds) {
EXPECT_EQ(400, client_bounds.height()); EXPECT_EQ(400, client_bounds.height());
} }
namespace {
// View subclass that tracks whether it has gotten a gesture event. // View subclass that tracks whether it has gotten a gesture event.
class GestureTrackingView : public views::View { class GestureTrackingView : public views::View {
public: public:
...@@ -227,8 +295,6 @@ class GestureTrackingView : public views::View { ...@@ -227,8 +295,6 @@ class GestureTrackingView : public views::View {
DISALLOW_COPY_AND_ASSIGN(GestureTrackingView); DISALLOW_COPY_AND_ASSIGN(GestureTrackingView);
}; };
} // namespace
// Verifies a capture isn't set on touch press and that the view that gets // Verifies a capture isn't set on touch press and that the view that gets
// the press gets the release. // the press gets the release.
TEST_F(NativeWidgetAuraTest, DontCaptureOnGesture) { TEST_F(NativeWidgetAuraTest, DontCaptureOnGesture) {
......
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