| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/common/wm/workspace/workspace_layout_manager.h" | 5 #include "ash/common/wm/workspace/workspace_layout_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/common/session/session_state_delegate.h" | 10 #include "ash/common/session/session_state_delegate.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "ash/common/wm/workspace/workspace_window_resizer.h" | 22 #include "ash/common/wm/workspace/workspace_window_resizer.h" |
| 23 #include "ash/common/wm_shell.h" | 23 #include "ash/common/wm_shell.h" |
| 24 #include "ash/common/wm_window.h" | 24 #include "ash/common/wm_window.h" |
| 25 #include "ash/public/cpp/shell_window_ids.h" | 25 #include "ash/public/cpp/shell_window_ids.h" |
| 26 #include "ash/root_window_controller.h" | 26 #include "ash/root_window_controller.h" |
| 27 #include "ash/shell.h" | 27 #include "ash/shell.h" |
| 28 #include "ash/wm/window_state_aura.h" | 28 #include "ash/wm/window_state_aura.h" |
| 29 #include "base/command_line.h" | 29 #include "base/command_line.h" |
| 30 #include "base/run_loop.h" | 30 #include "base/run_loop.h" |
| 31 #include "ui/aura/env.h" | 31 #include "ui/aura/env.h" |
| 32 #include "ui/aura/window.h" |
| 32 #include "ui/base/ui_base_switches.h" | 33 #include "ui/base/ui_base_switches.h" |
| 33 #include "ui/base/ui_base_types.h" | 34 #include "ui/base/ui_base_types.h" |
| 35 #include "ui/compositor/layer_type.h" |
| 34 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 36 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 35 #include "ui/display/display.h" | 37 #include "ui/display/display.h" |
| 36 #include "ui/display/screen.h" | 38 #include "ui/display/screen.h" |
| 37 #include "ui/gfx/geometry/insets.h" | 39 #include "ui/gfx/geometry/insets.h" |
| 38 #include "ui/views/widget/widget.h" | 40 #include "ui/views/widget/widget.h" |
| 39 #include "ui/views/widget/widget_delegate.h" | 41 #include "ui/views/widget/widget_delegate.h" |
| 40 | 42 |
| 41 namespace ash { | 43 namespace ash { |
| 42 namespace { | 44 namespace { |
| 43 | 45 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 WmWindow* window_; | 330 WmWindow* window_; |
| 329 | 331 |
| 330 DISALLOW_COPY_AND_ASSIGN(DontClobberRestoreBoundsWindowObserver); | 332 DISALLOW_COPY_AND_ASSIGN(DontClobberRestoreBoundsWindowObserver); |
| 331 }; | 333 }; |
| 332 | 334 |
| 333 // Creates a window, maximized the window and from within the maximized | 335 // Creates a window, maximized the window and from within the maximized |
| 334 // notification sets the bounds of a window to overlap the shelf. Verifies this | 336 // notification sets the bounds of a window to overlap the shelf. Verifies this |
| 335 // doesn't effect the restore bounds. | 337 // doesn't effect the restore bounds. |
| 336 TEST_F(WorkspaceLayoutManagerTest, DontClobberRestoreBounds) { | 338 TEST_F(WorkspaceLayoutManagerTest, DontClobberRestoreBounds) { |
| 337 DontClobberRestoreBoundsWindowObserver window_observer; | 339 DontClobberRestoreBoundsWindowObserver window_observer; |
| 338 WindowOwner window_owner(WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL, | 340 std::unique_ptr<aura::Window> window( |
| 339 ui::LAYER_TEXTURED)); | 341 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL)); |
| 340 WmWindow* window = window_owner.window(); | 342 window->Init(ui::LAYER_TEXTURED); |
| 341 window->SetBounds(gfx::Rect(10, 20, 30, 40)); | 343 window->SetBounds(gfx::Rect(10, 20, 30, 40)); |
| 342 // NOTE: for this test to exercise the failure the observer needs to be added | 344 // NOTE: for this test to exercise the failure the observer needs to be added |
| 343 // before the parent set. This mimics what BrowserFrameAsh does. | 345 // before the parent set. This mimics what BrowserFrameAsh does. |
| 344 window->aura_window()->AddObserver(&window_observer); | 346 window->AddObserver(&window_observer); |
| 345 ParentWindowInPrimaryRootWindow(window); | 347 ParentWindowInPrimaryRootWindow(WmWindow::Get(window.get())); |
| 346 window->Show(); | 348 window->Show(); |
| 347 | 349 |
| 348 wm::WindowState* window_state = window->GetWindowState(); | 350 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 349 window_state->Activate(); | 351 window_state->Activate(); |
| 350 | 352 |
| 351 std::unique_ptr<WindowOwner> window2_owner( | 353 std::unique_ptr<WindowOwner> window2_owner( |
| 352 CreateTestWindow(gfx::Rect(12, 20, 30, 40))); | 354 CreateTestWindow(gfx::Rect(12, 20, 30, 40))); |
| 353 WmWindow* window2 = window2_owner->window(); | 355 WmWindow* window2 = window2_owner->window(); |
| 354 AddTransientChild(window, window2); | 356 AddTransientChild(WmWindow::Get(window.get()), window2); |
| 355 window2->Show(); | 357 window2->Show(); |
| 356 | 358 |
| 357 window_observer.set_window(window2); | 359 window_observer.set_window(window2); |
| 358 window_state->Maximize(); | 360 window_state->Maximize(); |
| 359 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInScreen().ToString()); | 361 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInScreen().ToString()); |
| 360 window->aura_window()->RemoveObserver(&window_observer); | 362 window->RemoveObserver(&window_observer); |
| 361 } | 363 } |
| 362 | 364 |
| 363 // Verifies when a window is maximized all descendant windows have a size. | 365 // Verifies when a window is maximized all descendant windows have a size. |
| 364 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { | 366 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { |
| 365 std::unique_ptr<WindowOwner> window_owner( | 367 std::unique_ptr<WindowOwner> window_owner( |
| 366 CreateTestWindow(gfx::Rect(10, 20, 30, 40))); | 368 CreateTestWindow(gfx::Rect(10, 20, 30, 40))); |
| 367 WmWindow* window = window_owner->window(); | 369 WmWindow* window = window_owner->window(); |
| 368 window->Show(); | 370 window->Show(); |
| 369 wm::WindowState* window_state = window->GetWindowState(); | 371 wm::WindowState* window_state = window->GetWindowState(); |
| 370 window_state->Activate(); | 372 window_state->Activate(); |
| 371 std::unique_ptr<WindowOwner> child_window_owner( | 373 std::unique_ptr<WindowOwner> child_window_owner( |
| 372 CreateChildWindow(window, gfx::Rect(5, 6, 7, 8))); | 374 CreateChildWindow(window, gfx::Rect(5, 6, 7, 8))); |
| 373 WmWindow* child_window = child_window_owner->window(); | 375 WmWindow* child_window = child_window_owner->window(); |
| 374 window_state->Maximize(); | 376 window_state->Maximize(); |
| 375 EXPECT_EQ("5,6 7x8", child_window->GetBounds().ToString()); | 377 EXPECT_EQ("5,6 7x8", child_window->GetBounds().ToString()); |
| 376 } | 378 } |
| 377 | 379 |
| 378 // Verifies a window created with maximized state has the maximized | 380 // Verifies a window created with maximized state has the maximized |
| 379 // bounds. | 381 // bounds. |
| 380 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) { | 382 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) { |
| 381 WindowOwner window_owner(WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL, | 383 std::unique_ptr<aura::Window> window( |
| 382 ui::LAYER_TEXTURED)); | 384 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL)); |
| 383 WmWindow* window = window_owner.window(); | 385 window->Init(ui::LAYER_TEXTURED); |
| 384 window->GetWindowState()->Maximize(); | 386 wm::GetWindowState(window.get())->Maximize(); |
| 385 WmWindow* default_container = | 387 WmWindow* default_container = |
| 386 WmShell::Get()->GetPrimaryRootWindowController()->GetWmContainer( | 388 WmShell::Get()->GetPrimaryRootWindowController()->GetWmContainer( |
| 387 kShellWindowId_DefaultContainer); | 389 kShellWindowId_DefaultContainer); |
| 388 default_container->AddChild(window); | 390 default_container->aura_window()->AddChild(window.get()); |
| 389 window->Show(); | 391 window->Show(); |
| 390 gfx::Rect work_area( | 392 gfx::Rect work_area( |
| 391 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 393 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
| 392 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); | 394 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); |
| 393 } | 395 } |
| 394 | 396 |
| 395 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { | 397 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { |
| 396 // TODO: fix. This test verifies that when a window is added the bounds are | 398 // TODO: fix. This test verifies that when a window is added the bounds are |
| 397 // adjusted. CreateTestWindow() for mus adds, then sets the bounds (this comes | 399 // adjusted. CreateTestWindow() for mus adds, then sets the bounds (this comes |
| 398 // from NativeWidgetAura), which means this test now fails for aura-mus. | 400 // from NativeWidgetAura), which means this test now fails for aura-mus. |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 animator->StopAnimating(); | 570 animator->StopAnimating(); |
| 569 EXPECT_FALSE(animator->is_animating()); | 571 EXPECT_FALSE(animator->is_animating()); |
| 570 EXPECT_EQ(expected_bounds.ToString(), window->GetBounds().ToString()); | 572 EXPECT_EQ(expected_bounds.ToString(), window->GetBounds().ToString()); |
| 571 } | 573 } |
| 572 | 574 |
| 573 // Do not adjust window bounds to ensure minimum visibility for transient | 575 // Do not adjust window bounds to ensure minimum visibility for transient |
| 574 // windows (crbug.com/624806). | 576 // windows (crbug.com/624806). |
| 575 TEST_F(WorkspaceLayoutManagerTest, | 577 TEST_F(WorkspaceLayoutManagerTest, |
| 576 DoNotAdjustTransientWindowBoundsToEnsureMinimumVisibility) { | 578 DoNotAdjustTransientWindowBoundsToEnsureMinimumVisibility) { |
| 577 UpdateDisplay("300x400"); | 579 UpdateDisplay("300x400"); |
| 578 WindowOwner window_owner(WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL, | 580 std::unique_ptr<aura::Window> window( |
| 579 ui::LAYER_TEXTURED)); | 581 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_NORMAL)); |
| 580 WmWindow* window = window_owner.window(); | 582 window->Init(ui::LAYER_TEXTURED); |
| 581 window->SetBounds(gfx::Rect(10, 0, 100, 200)); | 583 window->SetBounds(gfx::Rect(10, 0, 100, 200)); |
| 582 ParentWindowInPrimaryRootWindow(window); | 584 ParentWindowInPrimaryRootWindow(WmWindow::Get(window.get())); |
| 583 window->Show(); | 585 window->Show(); |
| 584 | 586 |
| 585 std::unique_ptr<WindowOwner> window2_owner( | 587 std::unique_ptr<WindowOwner> window2_owner( |
| 586 CreateTestWindow(gfx::Rect(10, 0, 40, 20))); | 588 CreateTestWindow(gfx::Rect(10, 0, 40, 20))); |
| 587 WmWindow* window2 = window2_owner->window(); | 589 WmWindow* window2 = window2_owner->window(); |
| 588 AddTransientChild(window, window2); | 590 AddTransientChild(WmWindow::Get(window.get()), window2); |
| 589 window2->Show(); | 591 window2->Show(); |
| 590 | 592 |
| 591 gfx::Rect expected_bounds = window2->GetBounds(); | 593 gfx::Rect expected_bounds = window2->GetBounds(); |
| 592 WmShell::Get()->SetDisplayWorkAreaInsets(window, gfx::Insets(50, 0, 0, 0)); | 594 WmShell::Get()->SetDisplayWorkAreaInsets(WmWindow::Get(window.get()), |
| 595 gfx::Insets(50, 0, 0, 0)); |
| 593 EXPECT_EQ(expected_bounds.ToString(), window2->GetBounds().ToString()); | 596 EXPECT_EQ(expected_bounds.ToString(), window2->GetBounds().ToString()); |
| 594 } | 597 } |
| 595 | 598 |
| 596 // Following "Solo" tests were originally written for BaseLayoutManager. | 599 // Following "Solo" tests were originally written for BaseLayoutManager. |
| 597 using WorkspaceLayoutManagerSoloTest = AshTest; | 600 using WorkspaceLayoutManagerSoloTest = AshTest; |
| 598 | 601 |
| 599 // Tests normal->maximize->normal. | 602 // Tests normal->maximize->normal. |
| 600 TEST_F(WorkspaceLayoutManagerSoloTest, Maximize) { | 603 TEST_F(WorkspaceLayoutManagerSoloTest, Maximize) { |
| 601 gfx::Rect bounds(100, 100, 200, 200); | 604 gfx::Rect bounds(100, 100, 200, 200); |
| 602 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(bounds)); | 605 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(bounds)); |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1262 window->SetBounds(keyboard_bounds()); | 1265 window->SetBounds(keyboard_bounds()); |
| 1263 window->GetWindowState()->set_ignore_keyboard_bounds_change(true); | 1266 window->GetWindowState()->set_ignore_keyboard_bounds_change(true); |
| 1264 window->Activate(); | 1267 window->Activate(); |
| 1265 | 1268 |
| 1266 EXPECT_EQ(keyboard_bounds(), window->GetBounds()); | 1269 EXPECT_EQ(keyboard_bounds(), window->GetBounds()); |
| 1267 ShowKeyboard(); | 1270 ShowKeyboard(); |
| 1268 EXPECT_EQ(keyboard_bounds(), window->GetBounds()); | 1271 EXPECT_EQ(keyboard_bounds(), window->GetBounds()); |
| 1269 } | 1272 } |
| 1270 | 1273 |
| 1271 } // namespace ash | 1274 } // namespace ash |
| OLD | NEW |