| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/dock/docked_window_resizer.h" | 5 #include "ash/wm/dock/docked_window_resizer.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "ash/wm/window_state.h" | 25 #include "ash/wm/window_state.h" |
| 26 #include "ash/wm/window_util.h" | 26 #include "ash/wm/window_util.h" |
| 27 #include "ash/wm/workspace/snap_sizer.h" | 27 #include "ash/wm/workspace/snap_sizer.h" |
| 28 #include "base/command_line.h" | 28 #include "base/command_line.h" |
| 29 #include "ui/aura/client/aura_constants.h" | 29 #include "ui/aura/client/aura_constants.h" |
| 30 #include "ui/aura/client/window_tree_client.h" | 30 #include "ui/aura/client/window_tree_client.h" |
| 31 #include "ui/aura/root_window.h" | 31 #include "ui/aura/root_window.h" |
| 32 #include "ui/aura/test/test_window_delegate.h" | 32 #include "ui/aura/test/test_window_delegate.h" |
| 33 #include "ui/base/hit_test.h" | 33 #include "ui/base/hit_test.h" |
| 34 #include "ui/base/ui_base_types.h" | 34 #include "ui/base/ui_base_types.h" |
| 35 #include "ui/views/corewm/transient_window_manager.h" |
| 35 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
| 36 | 37 |
| 37 namespace ash { | 38 namespace ash { |
| 38 namespace internal { | 39 namespace internal { |
| 39 | 40 |
| 40 class DockedWindowResizerTest | 41 class DockedWindowResizerTest |
| 41 : public test::AshTestBase, | 42 : public test::AshTestBase, |
| 42 public testing::WithParamInterface<aura::client::WindowType> { | 43 public testing::WithParamInterface<aura::client::WindowType> { |
| 43 public: | 44 public: |
| 44 DockedWindowResizerTest() : model_(NULL), window_type_(GetParam()) {} | 45 DockedWindowResizerTest() : model_(NULL), window_type_(GetParam()) {} |
| (...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1290 // Tests that docking and undocking a |window| with a transient child properly | 1291 // Tests that docking and undocking a |window| with a transient child properly |
| 1291 // maintains the parent of that transient child to be the same as the |window|. | 1292 // maintains the parent of that transient child to be the same as the |window|. |
| 1292 TEST_P(DockedWindowResizerTest, DragWindowWithTransientChild) { | 1293 TEST_P(DockedWindowResizerTest, DragWindowWithTransientChild) { |
| 1293 if (!SupportsHostWindowResize()) | 1294 if (!SupportsHostWindowResize()) |
| 1294 return; | 1295 return; |
| 1295 | 1296 |
| 1296 // Create a window with a transient child. | 1297 // Create a window with a transient child. |
| 1297 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 1298 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 1298 scoped_ptr<aura::Window> child(CreateTestWindowInShellWithDelegateAndType( | 1299 scoped_ptr<aura::Window> child(CreateTestWindowInShellWithDelegateAndType( |
| 1299 NULL, aura::client::WINDOW_TYPE_NORMAL, 0, gfx::Rect(20, 20, 150, 20))); | 1300 NULL, aura::client::WINDOW_TYPE_NORMAL, 0, gfx::Rect(20, 20, 150, 20))); |
| 1300 window->AddTransientChild(child.get()); | 1301 views::corewm::AddTransientChild(window.get(), child.get()); |
| 1301 if (window->parent() != child->parent()) | 1302 if (window->parent() != child->parent()) |
| 1302 window->parent()->AddChild(child.get()); | 1303 window->parent()->AddChild(child.get()); |
| 1303 EXPECT_EQ(window.get(), child->transient_parent()); | 1304 EXPECT_EQ(window.get(), views::corewm::GetTransientParent(child.get())); |
| 1304 | 1305 |
| 1305 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, window.get(), 20); | 1306 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, window.get(), 20); |
| 1306 | 1307 |
| 1307 // A window should be docked at the right edge. | 1308 // A window should be docked at the right edge. |
| 1308 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); | 1309 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); |
| 1309 EXPECT_EQ(internal::kShellWindowId_DockedContainer, child->parent()->id()); | 1310 EXPECT_EQ(internal::kShellWindowId_DockedContainer, child->parent()->id()); |
| 1310 | 1311 |
| 1311 // Drag the child - it should move freely and stay where it is dragged. | 1312 // Drag the child - it should move freely and stay where it is dragged. |
| 1312 ASSERT_NO_FATAL_FAILURE(DragStart(child.get())); | 1313 ASSERT_NO_FATAL_FAILURE(DragStart(child.get())); |
| 1313 DragMove(500, 20); | 1314 DragMove(500, 20); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1340 | 1341 |
| 1341 // Start dragging the window. | 1342 // Start dragging the window. |
| 1342 ASSERT_NO_FATAL_FAILURE(DragStart(window.get())); | 1343 ASSERT_NO_FATAL_FAILURE(DragStart(window.get())); |
| 1343 gfx::Vector2d move_vector(40, test_panels() ? -60 : 60); | 1344 gfx::Vector2d move_vector(40, test_panels() ? -60 : 60); |
| 1344 DragMove(move_vector.x(), move_vector.y()); | 1345 DragMove(move_vector.x(), move_vector.y()); |
| 1345 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); | 1346 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
| 1346 | 1347 |
| 1347 // While still dragging create a modal window and make it a transient child of | 1348 // While still dragging create a modal window and make it a transient child of |
| 1348 // the |window|. | 1349 // the |window|. |
| 1349 scoped_ptr<aura::Window> child(CreateModalWindow(gfx::Rect(20, 20, 150, 20))); | 1350 scoped_ptr<aura::Window> child(CreateModalWindow(gfx::Rect(20, 20, 150, 20))); |
| 1350 window->AddTransientChild(child.get()); | 1351 views::corewm::AddTransientChild(window.get(), child.get()); |
| 1351 EXPECT_EQ(window.get(), child->transient_parent()); | 1352 EXPECT_EQ(window.get(), views::corewm::GetTransientParent(child.get())); |
| 1352 EXPECT_EQ(internal::kShellWindowId_SystemModalContainer, | 1353 EXPECT_EQ(internal::kShellWindowId_SystemModalContainer, |
| 1353 child->parent()->id()); | 1354 child->parent()->id()); |
| 1354 | 1355 |
| 1355 // End the drag, the |window| should have moved (if it is a panel it will | 1356 // End the drag, the |window| should have moved (if it is a panel it will |
| 1356 // no longer be attached to the shelf since we dragged it above). | 1357 // no longer be attached to the shelf since we dragged it above). |
| 1357 DragEnd(); | 1358 DragEnd(); |
| 1358 bounds.Offset(move_vector); | 1359 bounds.Offset(move_vector); |
| 1359 EXPECT_EQ(bounds.ToString(), window->GetBoundsInScreen().ToString()); | 1360 EXPECT_EQ(bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 1360 | 1361 |
| 1361 // The original |window| should be in the default container (not docked or | 1362 // The original |window| should be in the default container (not docked or |
| 1362 // attached). | 1363 // attached). |
| 1363 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, window->parent()->id()); | 1364 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, window->parent()->id()); |
| 1364 // The transient |child| should still be in system modal container. | 1365 // The transient |child| should still be in system modal container. |
| 1365 EXPECT_EQ(internal::kShellWindowId_SystemModalContainer, | 1366 EXPECT_EQ(internal::kShellWindowId_SystemModalContainer, |
| 1366 child->parent()->id()); | 1367 child->parent()->id()); |
| 1367 // The |child| should not have moved. | 1368 // The |child| should not have moved. |
| 1368 EXPECT_EQ(gfx::Point(20, 20).ToString(), | 1369 EXPECT_EQ(gfx::Point(20, 20).ToString(), |
| 1369 child->GetBoundsInScreen().origin().ToString()); | 1370 child->GetBoundsInScreen().origin().ToString()); |
| 1370 // The |child| should still be a transient child of |window|. | 1371 // The |child| should still be a transient child of |window|. |
| 1371 EXPECT_EQ(window.get(), child->transient_parent()); | 1372 EXPECT_EQ(window.get(), views::corewm::GetTransientParent(child.get())); |
| 1372 } | 1373 } |
| 1373 | 1374 |
| 1374 // Tests that side snapping a window undocks it, closes the dock and then snaps. | 1375 // Tests that side snapping a window undocks it, closes the dock and then snaps. |
| 1375 TEST_P(DockedWindowResizerTest, SideSnapDocked) { | 1376 TEST_P(DockedWindowResizerTest, SideSnapDocked) { |
| 1376 if (!SupportsHostWindowResize() || test_panels()) | 1377 if (!SupportsHostWindowResize() || test_panels()) |
| 1377 return; | 1378 return; |
| 1378 | 1379 |
| 1379 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 1380 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 1380 wm::WindowState* window_state = wm::GetWindowState(w1.get()); | 1381 wm::WindowState* window_state = wm::GetWindowState(w1.get()); |
| 1381 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 1382 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1427 EXPECT_TRUE(window_state->IsSnapped()); | 1428 EXPECT_TRUE(window_state->IsSnapped()); |
| 1428 } | 1429 } |
| 1429 | 1430 |
| 1430 // Tests run twice - on both panels and normal windows | 1431 // Tests run twice - on both panels and normal windows |
| 1431 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 1432 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
| 1432 DockedWindowResizerTest, | 1433 DockedWindowResizerTest, |
| 1433 testing::Values(aura::client::WINDOW_TYPE_NORMAL, | 1434 testing::Values(aura::client::WINDOW_TYPE_NORMAL, |
| 1434 aura::client::WINDOW_TYPE_PANEL)); | 1435 aura::client::WINDOW_TYPE_PANEL)); |
| 1435 } // namespace internal | 1436 } // namespace internal |
| 1436 } // namespace ash | 1437 } // namespace ash |
| OLD | NEW |