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