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/wm/workspace/workspace_layout_manager.h" | 5 #include "ash/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/accessibility_delegate.h" | 10 #include "ash/accessibility_delegate.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "ash/test/test_session_controller_client.h" | 28 #include "ash/test/test_session_controller_client.h" |
29 #include "ash/test/workspace_controller_test_api.h" | 29 #include "ash/test/workspace_controller_test_api.h" |
30 #include "ash/wm/fullscreen_window_finder.h" | 30 #include "ash/wm/fullscreen_window_finder.h" |
31 #include "ash/wm/overview/window_selector_controller.h" | 31 #include "ash/wm/overview/window_selector_controller.h" |
32 #include "ash/wm/tablet_mode/tablet_mode_backdrop_delegate_impl.h" | 32 #include "ash/wm/tablet_mode/tablet_mode_backdrop_delegate_impl.h" |
33 #include "ash/wm/window_state.h" | 33 #include "ash/wm/window_state.h" |
34 #include "ash/wm/window_util.h" | 34 #include "ash/wm/window_util.h" |
35 #include "ash/wm/wm_event.h" | 35 #include "ash/wm/wm_event.h" |
36 #include "ash/wm/workspace/backdrop_delegate.h" | 36 #include "ash/wm/workspace/backdrop_delegate.h" |
37 #include "ash/wm/workspace/workspace_window_resizer.h" | 37 #include "ash/wm/workspace/workspace_window_resizer.h" |
38 #include "ash/wm_window.h" | |
39 #include "base/command_line.h" | 38 #include "base/command_line.h" |
40 #include "base/run_loop.h" | 39 #include "base/run_loop.h" |
41 #include "chromeos/audio/chromeos_sounds.h" | 40 #include "chromeos/audio/chromeos_sounds.h" |
42 #include "ui/aura/client/aura_constants.h" | 41 #include "ui/aura/client/aura_constants.h" |
43 #include "ui/aura/client/focus_client.h" | 42 #include "ui/aura/client/focus_client.h" |
44 #include "ui/aura/test/test_window_delegate.h" | 43 #include "ui/aura/test/test_window_delegate.h" |
45 #include "ui/aura/window.h" | 44 #include "ui/aura/window.h" |
46 #include "ui/aura/window_targeter.h" | 45 #include "ui/aura/window_targeter.h" |
47 #include "ui/base/ui_base_switches.h" | 46 #include "ui/base/ui_base_switches.h" |
48 #include "ui/base/ui_base_types.h" | 47 #include "ui/base/ui_base_types.h" |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString()); | 417 EXPECT_EQ("5,6 7x8", child_window->bounds().ToString()); |
419 } | 418 } |
420 | 419 |
421 // Verifies a window created with maximized state has the maximized | 420 // Verifies a window created with maximized state has the maximized |
422 // bounds. | 421 // bounds. |
423 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) { | 422 TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) { |
424 std::unique_ptr<aura::Window> window(base::MakeUnique<aura::Window>( | 423 std::unique_ptr<aura::Window> window(base::MakeUnique<aura::Window>( |
425 nullptr, aura::client::WINDOW_TYPE_NORMAL)); | 424 nullptr, aura::client::WINDOW_TYPE_NORMAL)); |
426 window->Init(ui::LAYER_TEXTURED); | 425 window->Init(ui::LAYER_TEXTURED); |
427 wm::GetWindowState(window.get())->Maximize(); | 426 wm::GetWindowState(window.get())->Maximize(); |
428 WmWindow* default_container = | 427 aura::Window* default_container = |
429 Shell::GetPrimaryRootWindowController()->GetWmContainer( | 428 Shell::GetPrimaryRootWindowController()->GetContainer( |
430 kShellWindowId_DefaultContainer); | 429 kShellWindowId_DefaultContainer); |
431 default_container->aura_window()->AddChild(window.get()); | 430 default_container->AddChild(window.get()); |
432 window->Show(); | 431 window->Show(); |
433 gfx::Rect work_area( | 432 gfx::Rect work_area( |
434 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 433 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
435 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); | 434 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); |
436 } | 435 } |
437 | 436 |
438 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { | 437 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { |
439 // TODO: fix. This test verifies that when a window is added the bounds are | 438 // TODO: fix. This test verifies that when a window is added the bounds are |
440 // adjusted. CreateTestWindow() for mus adds, then sets the bounds (this comes | 439 // adjusted. CreateTestWindow() for mus adds, then sets the bounds (this comes |
441 // from NativeWidgetAura), which means this test now fails for aura-mus. | 440 // from NativeWidgetAura), which means this test now fails for aura-mus. |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 // For crbug.com/673803, snapped window may not adjust snapped bounds on work | 569 // For crbug.com/673803, snapped window may not adjust snapped bounds on work |
571 // area changed properly if window's layer is doing animation. We should use | 570 // area changed properly if window's layer is doing animation. We should use |
572 // GetTargetBounds to check if snapped bounds need to be changed. | 571 // GetTargetBounds to check if snapped bounds need to be changed. |
573 TEST_F(WorkspaceLayoutManagerTest, | 572 TEST_F(WorkspaceLayoutManagerTest, |
574 SnappedWindowMayNotAdjustBoundsOnWorkAreaChanged) { | 573 SnappedWindowMayNotAdjustBoundsOnWorkAreaChanged) { |
575 UpdateDisplay("300x400"); | 574 UpdateDisplay("300x400"); |
576 std::unique_ptr<aura::Window> window( | 575 std::unique_ptr<aura::Window> window( |
577 CreateTestWindow(gfx::Rect(10, 20, 100, 200))); | 576 CreateTestWindow(gfx::Rect(10, 20, 100, 200))); |
578 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 577 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
579 gfx::Insets insets(0, 0, 50, 0); | 578 gfx::Insets insets(0, 0, 50, 0); |
580 ShellPort::Get()->SetDisplayWorkAreaInsets(WmWindow::Get(window.get()), | 579 ShellPort::Get()->SetDisplayWorkAreaInsets(window.get(), insets); |
581 insets); | |
582 const wm::WMEvent snap_left(wm::WM_EVENT_SNAP_LEFT); | 580 const wm::WMEvent snap_left(wm::WM_EVENT_SNAP_LEFT); |
583 window_state->OnWMEvent(&snap_left); | 581 window_state->OnWMEvent(&snap_left); |
584 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); | 582 EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); |
585 const gfx::Rect kWorkAreaBounds = | 583 const gfx::Rect kWorkAreaBounds = |
586 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 584 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
587 gfx::Rect expected_bounds = | 585 gfx::Rect expected_bounds = |
588 gfx::Rect(kWorkAreaBounds.x(), kWorkAreaBounds.y(), | 586 gfx::Rect(kWorkAreaBounds.x(), kWorkAreaBounds.y(), |
589 kWorkAreaBounds.width() / 2, kWorkAreaBounds.height()); | 587 kWorkAreaBounds.width() / 2, kWorkAreaBounds.height()); |
590 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); | 588 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); |
591 | 589 |
592 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 590 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
593 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 591 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
594 // The following two SetDisplayWorkAreaInsets calls simulate the case of | 592 // The following two SetDisplayWorkAreaInsets calls simulate the case of |
595 // crbug.com/673803 that work area first becomes fullscreen and then returns | 593 // crbug.com/673803 that work area first becomes fullscreen and then returns |
596 // to the original state. | 594 // to the original state. |
597 ShellPort::Get()->SetDisplayWorkAreaInsets(WmWindow::Get(window.get()), | 595 ShellPort::Get()->SetDisplayWorkAreaInsets(window.get(), |
598 gfx::Insets(0, 0, 0, 0)); | 596 gfx::Insets(0, 0, 0, 0)); |
599 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 597 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
600 EXPECT_TRUE(animator->is_animating()); | 598 EXPECT_TRUE(animator->is_animating()); |
601 ShellPort::Get()->SetDisplayWorkAreaInsets(WmWindow::Get(window.get()), | 599 ShellPort::Get()->SetDisplayWorkAreaInsets(window.get(), insets); |
602 insets); | |
603 animator->StopAnimating(); | 600 animator->StopAnimating(); |
604 EXPECT_FALSE(animator->is_animating()); | 601 EXPECT_FALSE(animator->is_animating()); |
605 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); | 602 EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); |
606 } | 603 } |
607 | 604 |
608 // Do not adjust window bounds to ensure minimum visibility for transient | 605 // Do not adjust window bounds to ensure minimum visibility for transient |
609 // windows (crbug.com/624806). | 606 // windows (crbug.com/624806). |
610 TEST_F(WorkspaceLayoutManagerTest, | 607 TEST_F(WorkspaceLayoutManagerTest, |
611 DoNotAdjustTransientWindowBoundsToEnsureMinimumVisibility) { | 608 DoNotAdjustTransientWindowBoundsToEnsureMinimumVisibility) { |
612 UpdateDisplay("300x400"); | 609 UpdateDisplay("300x400"); |
613 std::unique_ptr<aura::Window> window(base::MakeUnique<aura::Window>( | 610 std::unique_ptr<aura::Window> window(base::MakeUnique<aura::Window>( |
614 nullptr, aura::client::WINDOW_TYPE_NORMAL)); | 611 nullptr, aura::client::WINDOW_TYPE_NORMAL)); |
615 window->Init(ui::LAYER_TEXTURED); | 612 window->Init(ui::LAYER_TEXTURED); |
616 window->SetBounds(gfx::Rect(10, 0, 100, 200)); | 613 window->SetBounds(gfx::Rect(10, 0, 100, 200)); |
617 ParentWindowInPrimaryRootWindow(window.get()); | 614 ParentWindowInPrimaryRootWindow(window.get()); |
618 window->Show(); | 615 window->Show(); |
619 | 616 |
620 std::unique_ptr<aura::Window> window2( | 617 std::unique_ptr<aura::Window> window2( |
621 CreateTestWindow(gfx::Rect(10, 0, 40, 20))); | 618 CreateTestWindow(gfx::Rect(10, 0, 40, 20))); |
622 ::wm::AddTransientChild(window.get(), window2.get()); | 619 ::wm::AddTransientChild(window.get(), window2.get()); |
623 window2->Show(); | 620 window2->Show(); |
624 | 621 |
625 gfx::Rect expected_bounds = window2->bounds(); | 622 gfx::Rect expected_bounds = window2->bounds(); |
626 ShellPort::Get()->SetDisplayWorkAreaInsets(WmWindow::Get(window.get()), | 623 ShellPort::Get()->SetDisplayWorkAreaInsets(window.get(), |
627 gfx::Insets(50, 0, 0, 0)); | 624 gfx::Insets(50, 0, 0, 0)); |
628 EXPECT_EQ(expected_bounds.ToString(), window2->bounds().ToString()); | 625 EXPECT_EQ(expected_bounds.ToString(), window2->bounds().ToString()); |
629 } | 626 } |
630 | 627 |
631 // Following "Solo" tests were originally written for BaseLayoutManager. | 628 // Following "Solo" tests were originally written for BaseLayoutManager. |
632 using WorkspaceLayoutManagerSoloTest = test::AshTestBase; | 629 using WorkspaceLayoutManagerSoloTest = test::AshTestBase; |
633 | 630 |
634 // Tests normal->maximize->normal. | 631 // Tests normal->maximize->normal. |
635 TEST_F(WorkspaceLayoutManagerSoloTest, Maximize) { | 632 TEST_F(WorkspaceLayoutManagerSoloTest, Maximize) { |
636 gfx::Rect bounds(100, 100, 200, 200); | 633 gfx::Rect bounds(100, 100, 200, 200); |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1398 Shell::GetPrimaryRootWindowController()->GetContainer( | 1395 Shell::GetPrimaryRootWindowController()->GetContainer( |
1399 kShellWindowId_DefaultContainer); | 1396 kShellWindowId_DefaultContainer); |
1400 layout_manager_ = GetWorkspaceLayoutManager(default_container); | 1397 layout_manager_ = GetWorkspaceLayoutManager(default_container); |
1401 } | 1398 } |
1402 | 1399 |
1403 void ShowKeyboard() { | 1400 void ShowKeyboard() { |
1404 layout_manager_->OnKeyboardBoundsChanging(keyboard_bounds_); | 1401 layout_manager_->OnKeyboardBoundsChanging(keyboard_bounds_); |
1405 restore_work_area_insets_ = | 1402 restore_work_area_insets_ = |
1406 display::Screen::GetScreen()->GetPrimaryDisplay().GetWorkAreaInsets(); | 1403 display::Screen::GetScreen()->GetPrimaryDisplay().GetWorkAreaInsets(); |
1407 ShellPort::Get()->SetDisplayWorkAreaInsets( | 1404 ShellPort::Get()->SetDisplayWorkAreaInsets( |
1408 WmWindow::Get(Shell::GetPrimaryRootWindow()), | 1405 Shell::GetPrimaryRootWindow(), |
1409 gfx::Insets(0, 0, keyboard_bounds_.height(), 0)); | 1406 gfx::Insets(0, 0, keyboard_bounds_.height(), 0)); |
1410 } | 1407 } |
1411 | 1408 |
1412 void HideKeyboard() { | 1409 void HideKeyboard() { |
1413 ShellPort::Get()->SetDisplayWorkAreaInsets( | 1410 ShellPort::Get()->SetDisplayWorkAreaInsets(Shell::GetPrimaryRootWindow(), |
1414 WmWindow::Get(Shell::GetPrimaryRootWindow()), | 1411 restore_work_area_insets_); |
1415 restore_work_area_insets_); | |
1416 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect()); | 1412 layout_manager_->OnKeyboardBoundsChanging(gfx::Rect()); |
1417 } | 1413 } |
1418 | 1414 |
1419 // Initializes the keyboard bounds using the bottom half of the work area. | 1415 // Initializes the keyboard bounds using the bottom half of the work area. |
1420 void InitKeyboardBounds() { | 1416 void InitKeyboardBounds() { |
1421 gfx::Rect work_area( | 1417 gfx::Rect work_area( |
1422 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 1418 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
1423 keyboard_bounds_.SetRect(work_area.x(), | 1419 keyboard_bounds_.SetRect(work_area.x(), |
1424 work_area.y() + work_area.height() / 2, | 1420 work_area.y() + work_area.height() / 2, |
1425 work_area.width(), work_area.height() / 2); | 1421 work_area.width(), work_area.height() / 2); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1538 window->SetBounds(keyboard_bounds()); | 1534 window->SetBounds(keyboard_bounds()); |
1539 wm::GetWindowState(window.get())->set_ignore_keyboard_bounds_change(true); | 1535 wm::GetWindowState(window.get())->set_ignore_keyboard_bounds_change(true); |
1540 wm::ActivateWindow(window.get()); | 1536 wm::ActivateWindow(window.get()); |
1541 | 1537 |
1542 EXPECT_EQ(keyboard_bounds(), window->bounds()); | 1538 EXPECT_EQ(keyboard_bounds(), window->bounds()); |
1543 ShowKeyboard(); | 1539 ShowKeyboard(); |
1544 EXPECT_EQ(keyboard_bounds(), window->bounds()); | 1540 EXPECT_EQ(keyboard_bounds(), window->bounds()); |
1545 } | 1541 } |
1546 | 1542 |
1547 } // namespace ash | 1543 } // namespace ash |
OLD | NEW |