| 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" |
| 11 #include "ash/common/shelf/shelf_constants.h" | 11 #include "ash/common/shelf/shelf_constants.h" |
| 12 #include "ash/common/shelf/shelf_layout_manager.h" | 12 #include "ash/common/shelf/shelf_layout_manager.h" |
| 13 #include "ash/common/shelf/wm_shelf.h" | 13 #include "ash/common/shelf/wm_shelf.h" |
| 14 #include "ash/common/shell_observer.h" | 14 #include "ash/common/shell_observer.h" |
| 15 #include "ash/common/test/ash_test.h" | 15 #include "ash/common/test/ash_test.h" |
| 16 #include "ash/common/test/test_session_state_delegate.h" | 16 #include "ash/common/test/test_session_state_delegate.h" |
| 17 #include "ash/common/wm/fullscreen_window_finder.h" | 17 #include "ash/common/wm/fullscreen_window_finder.h" |
| 18 #include "ash/common/wm/maximize_mode/workspace_backdrop_delegate.h" | 18 #include "ash/common/wm/maximize_mode/workspace_backdrop_delegate.h" |
| 19 #include "ash/common/wm/window_state.h" | 19 #include "ash/common/wm/window_state.h" |
| 20 #include "ash/common/wm/wm_event.h" | 20 #include "ash/common/wm/wm_event.h" |
| 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_lookup.h" | 23 #include "ash/common/wm_lookup.h" |
| 24 #include "ash/common/wm_root_window_controller.h" | 24 #include "ash/common/wm_root_window_controller.h" |
| 25 #include "ash/common/wm_shell.h" | 25 #include "ash/common/wm_shell.h" |
| 26 #include "ash/public/cpp/shell_window_ids.h" | 26 #include "ash/public/cpp/shell_window_ids.h" |
| 27 #include "base/command_line.h" | 27 #include "base/command_line.h" |
| 28 #include "base/run_loop.h" | 28 #include "base/run_loop.h" |
| 29 #include "ui/aura/env.h" |
| 29 #include "ui/base/ui_base_switches.h" | 30 #include "ui/base/ui_base_switches.h" |
| 30 #include "ui/base/ui_base_types.h" | 31 #include "ui/base/ui_base_types.h" |
| 31 #include "ui/display/display.h" | 32 #include "ui/display/display.h" |
| 32 #include "ui/display/screen.h" | 33 #include "ui/display/screen.h" |
| 33 #include "ui/gfx/geometry/insets.h" | 34 #include "ui/gfx/geometry/insets.h" |
| 34 #include "ui/views/widget/widget.h" | 35 #include "ui/views/widget/widget.h" |
| 35 #include "ui/views/widget/widget_delegate.h" | 36 #include "ui/views/widget/widget_delegate.h" |
| 36 | 37 |
| 37 namespace ash { | 38 namespace ash { |
| 38 namespace { | 39 namespace { |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 WmShell::Get()->GetPrimaryRootWindowController()->GetContainer( | 391 WmShell::Get()->GetPrimaryRootWindowController()->GetContainer( |
| 391 kShellWindowId_DefaultContainer); | 392 kShellWindowId_DefaultContainer); |
| 392 default_container->AddChild(window); | 393 default_container->AddChild(window); |
| 393 window->Show(); | 394 window->Show(); |
| 394 gfx::Rect work_area( | 395 gfx::Rect work_area( |
| 395 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 396 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
| 396 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); | 397 EXPECT_EQ(work_area.ToString(), window->GetBoundsInScreen().ToString()); |
| 397 } | 398 } |
| 398 | 399 |
| 399 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { | 400 TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) { |
| 401 // TODO: fix. This test verifies that when a window is added the bounds are |
| 402 // adjusted. CreateTestWindow() for mus adds, then sets the bounds (this comes |
| 403 // from NativeWidgetAura), which means this test now fails for aura-mus. |
| 404 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS) |
| 405 return; |
| 406 |
| 400 // Normal window bounds shouldn't be changed. | 407 // Normal window bounds shouldn't be changed. |
| 401 gfx::Rect window_bounds(100, 100, 200, 200); | 408 gfx::Rect window_bounds(100, 100, 200, 200); |
| 402 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(window_bounds)); | 409 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(window_bounds)); |
| 403 WmWindow* window = window_owner->window(); | 410 WmWindow* window = window_owner->window(); |
| 404 EXPECT_EQ(window_bounds, window->GetBounds()); | 411 EXPECT_EQ(window_bounds, window->GetBounds()); |
| 405 | 412 |
| 406 // If the window is out of the workspace, it would be moved on screen. | 413 // If the window is out of the workspace, it would be moved on screen. |
| 407 gfx::Rect root_window_bounds = | 414 gfx::Rect root_window_bounds = |
| 408 WmShell::Get()->GetPrimaryRootWindow()->GetBounds(); | 415 WmShell::Get()->GetPrimaryRootWindow()->GetBounds(); |
| 409 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); | 416 window_bounds.Offset(root_window_bounds.width(), root_window_bounds.height()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 476 |
| 470 // Verifies the size of a window is enforced to be smaller than the work area. | 477 // Verifies the size of a window is enforced to be smaller than the work area. |
| 471 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) { | 478 TEST_F(WorkspaceLayoutManagerTest, SizeToWorkArea) { |
| 472 // Normal window bounds shouldn't be changed. | 479 // Normal window bounds shouldn't be changed. |
| 473 gfx::Size work_area( | 480 gfx::Size work_area( |
| 474 display::Screen::GetScreen()->GetPrimaryDisplay().work_area().size()); | 481 display::Screen::GetScreen()->GetPrimaryDisplay().work_area().size()); |
| 475 const gfx::Rect window_bounds(100, 101, work_area.width() + 1, | 482 const gfx::Rect window_bounds(100, 101, work_area.width() + 1, |
| 476 work_area.height() + 2); | 483 work_area.height() + 2); |
| 477 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(window_bounds)); | 484 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(window_bounds)); |
| 478 WmWindow* window = window_owner->window(); | 485 WmWindow* window = window_owner->window(); |
| 479 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), | 486 // TODO: fix. This test verifies that when a window is added the bounds are |
| 480 window->GetBounds().ToString()); | 487 // adjusted. CreateTestWindow() for mus adds, then sets the bounds (this comes |
| 488 // from NativeWidgetAura), which means this test now fails for aura-mus. |
| 489 if (aura::Env::GetInstance()->mode() != aura::Env::Mode::MUS) { |
| 490 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), |
| 491 window->GetBounds().ToString()); |
| 492 } |
| 481 | 493 |
| 482 // Directly setting the bounds triggers a slightly different code path. Verify | 494 // Directly setting the bounds triggers a slightly different code path. Verify |
| 483 // that too. | 495 // that too. |
| 484 window->SetBounds(window_bounds); | 496 window->SetBounds(window_bounds); |
| 485 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), | 497 EXPECT_EQ(gfx::Rect(gfx::Point(100, 101), work_area).ToString(), |
| 486 window->GetBounds().ToString()); | 498 window->GetBounds().ToString()); |
| 487 } | 499 } |
| 488 | 500 |
| 489 TEST_F(WorkspaceLayoutManagerTest, NotifyFullscreenChanges) { | 501 TEST_F(WorkspaceLayoutManagerTest, NotifyFullscreenChanges) { |
| 490 TestShellObserver observer; | 502 TestShellObserver observer; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 // Enlarging the root window does not change the window bounds. | 774 // Enlarging the root window does not change the window bounds. |
| 763 gfx::Rect old_bounds = window->GetBounds(); | 775 gfx::Rect old_bounds = window->GetBounds(); |
| 764 UpdateDisplay("800x600"); | 776 UpdateDisplay("800x600"); |
| 765 EXPECT_EQ(old_bounds.width(), window->GetBounds().width()); | 777 EXPECT_EQ(old_bounds.width(), window->GetBounds().width()); |
| 766 EXPECT_EQ(old_bounds.height(), window->GetBounds().height()); | 778 EXPECT_EQ(old_bounds.height(), window->GetBounds().height()); |
| 767 } | 779 } |
| 768 | 780 |
| 769 // Verifies maximizing sets the restore bounds, and restoring | 781 // Verifies maximizing sets the restore bounds, and restoring |
| 770 // restores the bounds. | 782 // restores the bounds. |
| 771 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeSetsRestoreBounds) { | 783 TEST_F(WorkspaceLayoutManagerSoloTest, MaximizeSetsRestoreBounds) { |
| 772 std::unique_ptr<WindowOwner> window_owner( | 784 const gfx::Rect initial_bounds(10, 20, 30, 40); |
| 773 CreateTestWindow(gfx::Rect(10, 20, 30, 40))); | 785 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(initial_bounds)); |
| 774 WmWindow* window = window_owner->window(); | 786 WmWindow* window = window_owner->window(); |
| 787 EXPECT_EQ(initial_bounds, window->GetBounds()); |
| 775 wm::WindowState* window_state = window->GetWindowState(); | 788 wm::WindowState* window_state = window->GetWindowState(); |
| 776 | 789 |
| 777 // Maximize it, which will keep the previous restore bounds. | 790 // Maximize it, which will keep the previous restore bounds. |
| 778 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); | 791 window->SetShowState(ui::SHOW_STATE_MAXIMIZED); |
| 779 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInParent().ToString()); | 792 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInParent().ToString()); |
| 780 | 793 |
| 781 // Restore it, which should restore bounds and reset restore bounds. | 794 // Restore it, which should restore bounds and reset restore bounds. |
| 782 window->SetShowState(ui::SHOW_STATE_NORMAL); | 795 window->SetShowState(ui::SHOW_STATE_NORMAL); |
| 783 EXPECT_EQ("10,20 30x40", window->GetBounds().ToString()); | 796 EXPECT_EQ("10,20 30x40", window->GetBounds().ToString()); |
| 784 EXPECT_FALSE(window_state->HasRestoreBounds()); | 797 EXPECT_FALSE(window_state->HasRestoreBounds()); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 } | 1150 } |
| 1138 | 1151 |
| 1139 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { | 1152 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { |
| 1140 InitKeyboardBounds(); | 1153 InitKeyboardBounds(); |
| 1141 gfx::Rect work_area( | 1154 gfx::Rect work_area( |
| 1142 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 1155 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
| 1143 | 1156 |
| 1144 std::unique_ptr<WindowOwner> window_owner( | 1157 std::unique_ptr<WindowOwner> window_owner( |
| 1145 CreateToplevelTestWindow(work_area)); | 1158 CreateToplevelTestWindow(work_area)); |
| 1146 WmWindow* window = window_owner->window(); | 1159 WmWindow* window = window_owner->window(); |
| 1160 // The additional SetBounds() is needed as the aura-mus case uses Widget, |
| 1161 // which alters the supplied bounds. |
| 1162 window->SetBounds(work_area); |
| 1147 | 1163 |
| 1148 int available_height = | 1164 int available_height = |
| 1149 display::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() - | 1165 display::Screen::GetScreen()->GetPrimaryDisplay().bounds().height() - |
| 1150 keyboard_bounds().height(); | 1166 keyboard_bounds().height(); |
| 1151 | 1167 |
| 1152 window->Activate(); | 1168 window->Activate(); |
| 1153 | 1169 |
| 1154 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->GetBounds().ToString()); | 1170 EXPECT_EQ(gfx::Rect(work_area).ToString(), window->GetBounds().ToString()); |
| 1155 ShowKeyboard(); | 1171 ShowKeyboard(); |
| 1156 EXPECT_EQ(gfx::Rect(work_area.origin(), | 1172 EXPECT_EQ(gfx::Rect(work_area.origin(), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1184 HideKeyboard(); | 1200 HideKeyboard(); |
| 1185 EXPECT_EQ(occluded_window_bounds.ToString(), window->GetBounds().ToString()); | 1201 EXPECT_EQ(occluded_window_bounds.ToString(), window->GetBounds().ToString()); |
| 1186 } | 1202 } |
| 1187 | 1203 |
| 1188 TEST_F(WorkspaceLayoutManagerKeyboardTest, IgnoreKeyboardBoundsChange) { | 1204 TEST_F(WorkspaceLayoutManagerKeyboardTest, IgnoreKeyboardBoundsChange) { |
| 1189 InitKeyboardBounds(); | 1205 InitKeyboardBounds(); |
| 1190 | 1206 |
| 1191 std::unique_ptr<WindowOwner> window_owner( | 1207 std::unique_ptr<WindowOwner> window_owner( |
| 1192 CreateTestWindow(keyboard_bounds())); | 1208 CreateTestWindow(keyboard_bounds())); |
| 1193 WmWindow* window = window_owner->window(); | 1209 WmWindow* window = window_owner->window(); |
| 1210 // The additional SetBounds() is needed as the aura-mus case uses Widget, |
| 1211 // which alters the supplied bounds. |
| 1212 window->SetBounds(keyboard_bounds()); |
| 1194 window->GetWindowState()->set_ignore_keyboard_bounds_change(true); | 1213 window->GetWindowState()->set_ignore_keyboard_bounds_change(true); |
| 1195 window->Activate(); | 1214 window->Activate(); |
| 1196 | 1215 |
| 1197 EXPECT_EQ(keyboard_bounds(), window->GetBounds()); | 1216 EXPECT_EQ(keyboard_bounds(), window->GetBounds()); |
| 1198 ShowKeyboard(); | 1217 ShowKeyboard(); |
| 1199 EXPECT_EQ(keyboard_bounds(), window->GetBounds()); | 1218 EXPECT_EQ(keyboard_bounds(), window->GetBounds()); |
| 1200 } | 1219 } |
| 1201 | 1220 |
| 1202 } // namespace ash | 1221 } // namespace ash |
| OLD | NEW |