| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/aura_shell/default_container_layout_manager.h" | 5 #include "ui/aura_shell/default_container_layout_manager.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "ui/aura/client/aura_constants.h" | 10 #include "ui/aura/client/aura_constants.h" |
| 11 #include "ui/aura/desktop.h" | 11 #include "ui/aura/root_window.h" |
| 12 #include "ui/aura/screen_aura.h" | 12 #include "ui/aura/screen_aura.h" |
| 13 #include "ui/aura/test/aura_test_base.h" | 13 #include "ui/aura/test/aura_test_base.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/aura_shell/workspace/workspace.h" | 15 #include "ui/aura_shell/workspace/workspace.h" |
| 16 #include "ui/aura_shell/workspace/workspace_manager.h" | 16 #include "ui/aura_shell/workspace/workspace_manager.h" |
| 17 #include "ui/aura_shell/workspace_controller.h" | 17 #include "ui/aura_shell/workspace_controller.h" |
| 18 #include "ui/base/ui_base_types.h" | 18 #include "ui/base/ui_base_types.h" |
| 19 #include "ui/views/widget/native_widget_aura.h" | 19 #include "ui/views/widget/native_widget_aura.h" |
| 20 | 20 |
| 21 namespace aura_shell { | 21 namespace aura_shell { |
| 22 namespace test { | 22 namespace test { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 using views::Widget; | 26 using views::Widget; |
| 27 using aura_shell::internal::DefaultContainerLayoutManager; | 27 using aura_shell::internal::DefaultContainerLayoutManager; |
| 28 | 28 |
| 29 class DefaultContainerLayoutManagerTest : public aura::test::AuraTestBase { | 29 class DefaultContainerLayoutManagerTest : public aura::test::AuraTestBase { |
| 30 public: | 30 public: |
| 31 DefaultContainerLayoutManagerTest() : layout_manager_(NULL) {} | 31 DefaultContainerLayoutManagerTest() : layout_manager_(NULL) {} |
| 32 virtual ~DefaultContainerLayoutManagerTest() {} | 32 virtual ~DefaultContainerLayoutManagerTest() {} |
| 33 | 33 |
| 34 virtual void SetUp() OVERRIDE { | 34 virtual void SetUp() OVERRIDE { |
| 35 aura::test::AuraTestBase::SetUp(); | 35 aura::test::AuraTestBase::SetUp(); |
| 36 aura::Desktop* desktop = aura::Desktop::GetInstance(); | 36 aura::RootWindow* root_window = aura::RootWindow::GetInstance(); |
| 37 container_.reset( | 37 container_.reset( |
| 38 CreateTestWindow(gfx::Rect(0, 0, 500, 400), desktop)); | 38 CreateTestWindow(gfx::Rect(0, 0, 500, 400), root_window)); |
| 39 workspace_controller_.reset( | 39 workspace_controller_.reset( |
| 40 new aura_shell::internal::WorkspaceController(container_.get())); | 40 new aura_shell::internal::WorkspaceController(container_.get())); |
| 41 layout_manager_ = new DefaultContainerLayoutManager( | 41 layout_manager_ = new DefaultContainerLayoutManager( |
| 42 workspace_controller_->workspace_manager()); | 42 workspace_controller_->workspace_manager()); |
| 43 container_->SetLayoutManager(layout_manager_); | 43 container_->SetLayoutManager(layout_manager_); |
| 44 | 44 |
| 45 desktop->SetHostSize(gfx::Size(500, 400)); | 45 root_window->SetHostSize(gfx::Size(500, 400)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 aura::Window* CreateTestWindowWithType(const gfx::Rect& bounds, | 48 aura::Window* CreateTestWindowWithType(const gfx::Rect& bounds, |
| 49 aura::Window* parent, | 49 aura::Window* parent, |
| 50 aura::WindowType type) { | 50 aura::WindowType type) { |
| 51 aura::Window* window = new aura::Window(NULL); | 51 aura::Window* window = new aura::Window(NULL); |
| 52 window->SetType(type); | 52 window->SetType(type); |
| 53 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | 53 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); |
| 54 window->SetBounds(bounds); | 54 window->SetBounds(bounds); |
| 55 window->Show(); | 55 window->Show(); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 popup->SetBounds(gfx::Rect(0, 0, 1000, 1000)); | 159 popup->SetBounds(gfx::Rect(0, 0, 1000, 1000)); |
| 160 EXPECT_EQ("0,0 1000x1000", popup->bounds().ToString()); | 160 EXPECT_EQ("0,0 1000x1000", popup->bounds().ToString()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Make sure a window with a transient parent isn't resized by the layout | 163 // Make sure a window with a transient parent isn't resized by the layout |
| 164 // manager. | 164 // manager. |
| 165 TEST_F(DefaultContainerLayoutManagerTest, IgnoreTransient) { | 165 TEST_F(DefaultContainerLayoutManagerTest, IgnoreTransient) { |
| 166 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 166 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
| 167 window->SetType(aura::WINDOW_TYPE_NORMAL); | 167 window->SetType(aura::WINDOW_TYPE_NORMAL); |
| 168 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | 168 window->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); |
| 169 aura::Desktop::GetInstance()->AddTransientChild(window.get()); | 169 aura::RootWindow::GetInstance()->AddTransientChild(window.get()); |
| 170 window->SetBounds(gfx::Rect(0, 0, 200, 200)); | 170 window->SetBounds(gfx::Rect(0, 0, 200, 200)); |
| 171 window->Show(); | 171 window->Show(); |
| 172 window->SetParent(container()); | 172 window->SetParent(container()); |
| 173 | 173 |
| 174 EXPECT_EQ("0,0 200x200", window->bounds().ToString()); | 174 EXPECT_EQ("0,0 200x200", window->bounds().ToString()); |
| 175 } | 175 } |
| 176 | 176 |
| 177 TEST_F(DefaultContainerLayoutManagerTest, Fullscreen) { | 177 TEST_F(DefaultContainerLayoutManagerTest, Fullscreen) { |
| 178 scoped_ptr<aura::Window> w( | 178 scoped_ptr<aura::Window> w( |
| 179 CreateTestWindow(gfx::Rect(0, 0, 100, 100), container())); | 179 CreateTestWindow(gfx::Rect(0, 0, 100, 100), container())); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 // restore bounds not change the bounds of the window. | 258 // restore bounds not change the bounds of the window. |
| 259 gfx::Rect new_bounds(50, 50, 50, 50); | 259 gfx::Rect new_bounds(50, 50, 50, 50); |
| 260 Maximize(w.get()); | 260 Maximize(w.get()); |
| 261 w->SetBounds(new_bounds); | 261 w->SetBounds(new_bounds); |
| 262 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); | 262 EXPECT_EQ(work_area_bounds.ToString(), w->bounds().ToString()); |
| 263 Restore(w.get()); | 263 Restore(w.get()); |
| 264 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); | 264 EXPECT_EQ(ui::SHOW_STATE_NORMAL, GetShowState(w.get())); |
| 265 EXPECT_EQ(50, w->bounds().height()); | 265 EXPECT_EQ(50, w->bounds().height()); |
| 266 } | 266 } |
| 267 | 267 |
| 268 // Tests that fullscreen windows get resized after desktop is resized. | 268 // Tests that fullscreen windows get resized after root window is resized. |
| 269 TEST_F(DefaultContainerLayoutManagerTest, FullscreenAfterDesktopResize) { | 269 TEST_F(DefaultContainerLayoutManagerTest, FullscreenAfterRootWindowResize) { |
| 270 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400), | 270 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400), |
| 271 container())); | 271 container())); |
| 272 gfx::Rect window_bounds = w1->GetTargetBounds(); | 272 gfx::Rect window_bounds = w1->GetTargetBounds(); |
| 273 gfx::Rect fullscreen_bounds = | 273 gfx::Rect fullscreen_bounds = |
| 274 workspace_manager()->FindBy(w1.get())->bounds(); | 274 workspace_manager()->FindBy(w1.get())->bounds(); |
| 275 | 275 |
| 276 w1->Show(); | 276 w1->Show(); |
| 277 EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString()); | 277 EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString()); |
| 278 | 278 |
| 279 Fullscreen(w1.get()); | 279 Fullscreen(w1.get()); |
| 280 EXPECT_EQ(fullscreen_bounds.ToString(), w1->bounds().ToString()); | 280 EXPECT_EQ(fullscreen_bounds.ToString(), w1->bounds().ToString()); |
| 281 | 281 |
| 282 // Resize the desktop. | 282 // Resize the root window. |
| 283 aura::Desktop* desktop = aura::Desktop::GetInstance(); | 283 aura::RootWindow* root_window = aura::RootWindow::GetInstance(); |
| 284 gfx::Size new_desktop_size = desktop->GetHostSize(); | 284 gfx::Size new_root_window_size = root_window->GetHostSize(); |
| 285 new_desktop_size.Enlarge(100, 200); | 285 new_root_window_size.Enlarge(100, 200); |
| 286 desktop->OnHostResized(new_desktop_size); | 286 root_window->OnHostResized(new_root_window_size); |
| 287 | 287 |
| 288 gfx::Rect new_fullscreen_bounds = | 288 gfx::Rect new_fullscreen_bounds = |
| 289 workspace_manager()->FindBy(w1.get())->bounds(); | 289 workspace_manager()->FindBy(w1.get())->bounds(); |
| 290 EXPECT_NE(fullscreen_bounds.size().ToString(), | 290 EXPECT_NE(fullscreen_bounds.size().ToString(), |
| 291 new_fullscreen_bounds.size().ToString()); | 291 new_fullscreen_bounds.size().ToString()); |
| 292 | 292 |
| 293 EXPECT_EQ(new_fullscreen_bounds.ToString(), | 293 EXPECT_EQ(new_fullscreen_bounds.ToString(), |
| 294 w1->GetTargetBounds().ToString()); | 294 w1->GetTargetBounds().ToString()); |
| 295 | 295 |
| 296 Restore(w1.get()); | 296 Restore(w1.get()); |
| 297 | 297 |
| 298 // The following test does not pass due to crbug.com/102413. | 298 // The following test does not pass due to crbug.com/102413. |
| 299 // TODO(oshima): Re-enable this once the bug is fixed. | 299 // TODO(oshima): Re-enable this once the bug is fixed. |
| 300 // EXPECT_EQ(window_bounds.size().ToString(), | 300 // EXPECT_EQ(window_bounds.size().ToString(), |
| 301 // w1->GetTargetBounds().size().ToString()); | 301 // w1->GetTargetBounds().size().ToString()); |
| 302 } | 302 } |
| 303 | 303 |
| 304 // Tests that maximized windows get resized after desktop is resized. | 304 // Tests that maximized windows get resized after root_window is resized. |
| 305 TEST_F(DefaultContainerLayoutManagerTest, MaximizeAfterDesktopResize) { | 305 TEST_F(DefaultContainerLayoutManagerTest, MaximizeAfterRootWindowResize) { |
| 306 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400), | 306 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(300, 400), |
| 307 container())); | 307 container())); |
| 308 gfx::Rect window_bounds = w1->GetTargetBounds(); | 308 gfx::Rect window_bounds = w1->GetTargetBounds(); |
| 309 gfx::Rect work_area_bounds = | 309 gfx::Rect work_area_bounds = |
| 310 workspace_manager()->FindBy(w1.get())->GetWorkAreaBounds(); | 310 workspace_manager()->FindBy(w1.get())->GetWorkAreaBounds(); |
| 311 | 311 |
| 312 w1->Show(); | 312 w1->Show(); |
| 313 EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString()); | 313 EXPECT_EQ(window_bounds.ToString(), w1->bounds().ToString()); |
| 314 | 314 |
| 315 Maximize(w1.get()); | 315 Maximize(w1.get()); |
| 316 EXPECT_EQ(work_area_bounds.ToString(), w1->bounds().ToString()); | 316 EXPECT_EQ(work_area_bounds.ToString(), w1->bounds().ToString()); |
| 317 | 317 |
| 318 // Resize the desktop. | 318 // Resize the root window. |
| 319 aura::Desktop* desktop = aura::Desktop::GetInstance(); | 319 aura::RootWindow* root_window = aura::RootWindow::GetInstance(); |
| 320 gfx::Size new_desktop_size = desktop->GetHostSize(); | 320 gfx::Size new_root_window_size = root_window->GetHostSize(); |
| 321 new_desktop_size.Enlarge(100, 200); | 321 new_root_window_size.Enlarge(100, 200); |
| 322 desktop->OnHostResized(new_desktop_size); | 322 root_window->OnHostResized(new_root_window_size); |
| 323 | 323 |
| 324 gfx::Rect new_work_area_bounds = | 324 gfx::Rect new_work_area_bounds = |
| 325 workspace_manager()->FindBy(w1.get())->bounds(); | 325 workspace_manager()->FindBy(w1.get())->bounds(); |
| 326 EXPECT_NE(work_area_bounds.size().ToString(), | 326 EXPECT_NE(work_area_bounds.size().ToString(), |
| 327 new_work_area_bounds.size().ToString()); | 327 new_work_area_bounds.size().ToString()); |
| 328 | 328 |
| 329 EXPECT_EQ(new_work_area_bounds.ToString(), | 329 EXPECT_EQ(new_work_area_bounds.ToString(), |
| 330 w1->GetTargetBounds().ToString()); | 330 w1->GetTargetBounds().ToString()); |
| 331 | 331 |
| 332 Restore(w1.get()); | 332 Restore(w1.get()); |
| 333 // The following test does not pass due to crbug.com/102413. | 333 // The following test does not pass due to crbug.com/102413. |
| 334 // TODO(oshima): Re-enable this once the bug is fixed. | 334 // TODO(oshima): Re-enable this once the bug is fixed. |
| 335 // EXPECT_EQ(window_bounds.size().ToString(), | 335 // EXPECT_EQ(window_bounds.size().ToString(), |
| 336 // w1->GetTargetBounds().size().ToString()); | 336 // w1->GetTargetBounds().size().ToString()); |
| 337 } | 337 } |
| 338 | 338 |
| 339 } // namespace test | 339 } // namespace test |
| 340 } // namespace aura_shell | 340 } // namespace aura_shell |
| OLD | NEW |