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_layout_manager.h" | 5 #include "ash/wm/dock/docked_window_layout_manager.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
9 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
10 #include "ash/shelf/shelf.h" | 10 #include "ash/shelf/shelf.h" |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), | 412 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), |
413 w2->GetBoundsInScreen().right()); | 413 w2->GetBoundsInScreen().right()); |
414 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); | 414 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
415 | 415 |
416 // Test that the gaps differ at most by a single pixel. | 416 // Test that the gaps differ at most by a single pixel. |
417 gfx::Rect work_area = | 417 gfx::Rect work_area = |
418 Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area(); | 418 Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area(); |
419 int gap1 = w1->GetBoundsInScreen().y(); | 419 int gap1 = w1->GetBoundsInScreen().y(); |
420 int gap2 = w2->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); | 420 int gap2 = w2->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); |
421 int gap3 = work_area.bottom() - w2->GetBoundsInScreen().bottom(); | 421 int gap3 = work_area.bottom() - w2->GetBoundsInScreen().bottom(); |
422 EXPECT_NEAR(gap1, min_dock_gap(), 1); | 422 EXPECT_EQ(0, gap1); |
423 EXPECT_NEAR(gap2, min_dock_gap(), 1); | 423 EXPECT_NEAR(gap2, min_dock_gap(), 1); |
424 EXPECT_NEAR(gap3, min_dock_gap(), 1); | 424 EXPECT_EQ(0, gap3); |
425 } | 425 } |
426 | 426 |
427 // Adds two non-overlapping windows and tests layout after a drag. | 427 // Adds two non-overlapping windows and tests layout after a drag. |
428 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsDragging) { | 428 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsDragging) { |
429 if (!SupportsHostWindowResize()) | 429 if (!SupportsHostWindowResize()) |
430 return; | 430 return; |
431 | 431 |
432 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 432 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
433 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); | 433 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); |
434 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 434 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
(...skipping 11 matching lines...) Expand all Loading... |
446 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w2.get(), 0, 20)); | 446 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w2.get(), 0, 20)); |
447 DragMove(0, -w2->bounds().height() / 2 - min_dock_gap() - 1); | 447 DragMove(0, -w2->bounds().height() / 2 - min_dock_gap() - 1); |
448 DragEnd(); | 448 DragEnd(); |
449 | 449 |
450 // Test the new windows order and that the gaps differ at most by a pixel. | 450 // Test the new windows order and that the gaps differ at most by a pixel. |
451 gfx::Rect work_area = | 451 gfx::Rect work_area = |
452 Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area(); | 452 Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area(); |
453 int gap1 = w2->GetBoundsInScreen().y() - work_area.y(); | 453 int gap1 = w2->GetBoundsInScreen().y() - work_area.y(); |
454 int gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); | 454 int gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); |
455 int gap3 = work_area.bottom() - w1->GetBoundsInScreen().bottom(); | 455 int gap3 = work_area.bottom() - w1->GetBoundsInScreen().bottom(); |
456 EXPECT_NEAR(gap1, min_dock_gap(), 1); | 456 EXPECT_EQ(0, gap1); |
457 EXPECT_NEAR(gap2, min_dock_gap(), 1); | 457 EXPECT_NEAR(gap2, min_dock_gap(), 1); |
458 EXPECT_NEAR(gap3, min_dock_gap(), 1); | 458 EXPECT_EQ(0, gap3); |
459 } | 459 } |
460 | 460 |
461 // Adds three overlapping windows and tests layout after a drag. | 461 // Adds three overlapping windows and tests layout after a drag. |
462 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsDragging) { | 462 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsDragging) { |
463 if (!SupportsHostWindowResize()) | 463 if (!SupportsHostWindowResize()) |
464 return; | 464 return; |
465 UpdateDisplay("600x1000"); | 465 UpdateDisplay("600x1000"); |
466 | 466 |
467 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 310))); | 467 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 310))); |
468 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 468 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
(...skipping 14 matching lines...) Expand all Loading... |
483 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w3->parent()->id()); | 483 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w3->parent()->id()); |
484 | 484 |
485 // Test that the top and bottom windows are clamped in work area and | 485 // Test that the top and bottom windows are clamped in work area and |
486 // that the gaps between the windows differ at most by a pixel. | 486 // that the gaps between the windows differ at most by a pixel. |
487 gfx::Rect work_area = | 487 gfx::Rect work_area = |
488 Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area(); | 488 Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area(); |
489 int gap1 = w1->GetBoundsInScreen().y() - work_area.y(); | 489 int gap1 = w1->GetBoundsInScreen().y() - work_area.y(); |
490 int gap2 = w2->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); | 490 int gap2 = w2->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); |
491 int gap3 = w3->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); | 491 int gap3 = w3->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); |
492 int gap4 = work_area.bottom() - w3->GetBoundsInScreen().bottom(); | 492 int gap4 = work_area.bottom() - w3->GetBoundsInScreen().bottom(); |
493 EXPECT_NEAR(gap1, min_dock_gap(), 1); | 493 EXPECT_EQ(0, gap1); |
494 EXPECT_NEAR(gap2, min_dock_gap(), 1); | 494 EXPECT_NEAR(gap2, min_dock_gap(), 1); |
495 EXPECT_NEAR(gap3, min_dock_gap(), 1); | 495 EXPECT_NEAR(gap3, min_dock_gap(), 1); |
496 EXPECT_NEAR(gap4, min_dock_gap(), 1); | 496 EXPECT_EQ(0, gap4); |
497 | 497 |
498 // Drag w1 below the point where w1 and w2 would swap places. This point is | 498 // Drag w1 below the point where w1 and w2 would swap places. This point is |
499 // half way between the tops of those two windows. | 499 // half way between the tops of those two windows. |
500 // A bit more vertical drag is needed to account for a window bounds changing | 500 // A bit more vertical drag is needed to account for a window bounds changing |
501 // to its restore bounds during the drag. | 501 // to its restore bounds during the drag. |
502 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w1.get(), 0, 20)); | 502 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w1.get(), 0, 20)); |
503 DragMove(0, min_dock_gap() + w2->bounds().height() / 2 + 10); | 503 DragMove(0, min_dock_gap() + w2->bounds().height() / 2 + 10); |
504 | 504 |
505 // During the drag the windows get rearranged and the top and the bottom | 505 // During the drag the windows get rearranged and the top and the bottom |
506 // should be limited by the work area + |kMinDockGap|. | 506 // should be limited by the work area. |
507 EXPECT_EQ(min_dock_gap(), w2->GetBoundsInScreen().y()); | 507 EXPECT_EQ(work_area.y(), w2->GetBoundsInScreen().y()); |
508 EXPECT_GT(w1->GetBoundsInScreen().y(), w2->GetBoundsInScreen().y()); | 508 EXPECT_GT(w1->GetBoundsInScreen().y(), w2->GetBoundsInScreen().y()); |
509 EXPECT_EQ(min_dock_gap(), | 509 EXPECT_EQ(work_area.bottom(), w3->GetBoundsInScreen().bottom()); |
510 work_area.bottom() - w3->GetBoundsInScreen().bottom()); | |
511 DragEnd(); | 510 DragEnd(); |
512 | 511 |
513 // Test the new windows order and that the gaps differ at most by a pixel. | 512 // Test the new windows order and that the gaps differ at most by a pixel. |
514 gap1 = w2->GetBoundsInScreen().y() - work_area.y(); | 513 gap1 = w2->GetBoundsInScreen().y() - work_area.y(); |
515 gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); | 514 gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); |
516 gap3 = w3->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); | 515 gap3 = w3->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); |
517 gap4 = work_area.bottom() - w3->GetBoundsInScreen().bottom(); | 516 gap4 = work_area.bottom() - w3->GetBoundsInScreen().bottom(); |
518 EXPECT_NEAR(gap1, min_dock_gap(), 1); | 517 EXPECT_EQ(0, gap1); |
519 EXPECT_NEAR(gap2, min_dock_gap(), 1); | 518 EXPECT_NEAR(gap2, min_dock_gap(), 1); |
520 EXPECT_NEAR(gap3, min_dock_gap(), 1); | 519 EXPECT_NEAR(gap3, min_dock_gap(), 1); |
521 EXPECT_NEAR(gap4, min_dock_gap(), 1); | 520 EXPECT_EQ(0, gap4); |
522 } | 521 } |
523 | 522 |
524 // Adds three windows in bottom display and tests layout after a drag. | 523 // Adds three windows in bottom display and tests layout after a drag. |
525 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsDraggingSecondScreen) { | 524 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsDraggingSecondScreen) { |
526 if (!SupportsMultipleDisplays() || !SupportsHostWindowResize()) | 525 if (!SupportsMultipleDisplays() || !SupportsHostWindowResize()) |
527 return; | 526 return; |
528 | 527 |
529 // Create two screen vertical layout. | 528 // Create two screen vertical layout. |
530 UpdateDisplay("600x1000,600x1000"); | 529 UpdateDisplay("600x1000,600x1000"); |
531 // Layout the secondary display to the bottom of the primary. | 530 // Layout the secondary display to the bottom of the primary. |
(...skipping 21 matching lines...) Expand all Loading... |
553 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w3->parent()->id()); | 552 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w3->parent()->id()); |
554 | 553 |
555 gfx::Rect work_area = | 554 gfx::Rect work_area = |
556 Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area(); | 555 Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area(); |
557 // Test that the top and bottom windows are clamped in work area and | 556 // Test that the top and bottom windows are clamped in work area and |
558 // that the overlaps between the windows differ at most by a pixel. | 557 // that the overlaps between the windows differ at most by a pixel. |
559 int gap1 = w1->GetBoundsInScreen().y() - work_area.y(); | 558 int gap1 = w1->GetBoundsInScreen().y() - work_area.y(); |
560 int gap2 = w2->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); | 559 int gap2 = w2->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); |
561 int gap3 = w3->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); | 560 int gap3 = w3->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); |
562 int gap4 = work_area.bottom() - w3->GetBoundsInScreen().bottom(); | 561 int gap4 = work_area.bottom() - w3->GetBoundsInScreen().bottom(); |
563 EXPECT_NEAR(gap1, min_dock_gap(), 1); | 562 EXPECT_EQ(0, gap1); |
564 EXPECT_NEAR(gap2, min_dock_gap(), 1); | 563 EXPECT_NEAR(gap2, min_dock_gap(), 1); |
565 EXPECT_NEAR(gap3, min_dock_gap(), 1); | 564 EXPECT_NEAR(gap3, min_dock_gap(), 1); |
566 EXPECT_NEAR(gap4, min_dock_gap(), 1); | 565 EXPECT_EQ(0, gap4); |
567 | 566 |
568 // Drag w1 below the point where w1 and w2 would swap places. This point is | 567 // Drag w1 below the point where w1 and w2 would swap places. This point is |
569 // half way between the tops of those two windows. | 568 // half way between the tops of those two windows. |
570 // A bit more vertical drag is needed to account for a window bounds changing | 569 // A bit more vertical drag is needed to account for a window bounds changing |
571 // to its restore bounds during the drag. | 570 // to its restore bounds during the drag. |
572 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w1.get(), 0, 20)); | 571 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w1.get(), 0, 20)); |
573 DragMove(0, min_dock_gap() + w2->bounds().height() / 2 + 10); | 572 DragMove(0, min_dock_gap() + w2->bounds().height() / 2 + 10); |
574 | 573 |
575 // During the drag the windows get rearranged and the top and the bottom | 574 // During the drag the windows get rearranged and the top and the bottom |
576 // should be limited by the work area + |kMinDockGap|. | 575 // should be limited by the work area. |
577 EXPECT_EQ(work_area.y() + min_dock_gap(), w2->GetBoundsInScreen().y()); | 576 EXPECT_EQ(work_area.y(), w2->GetBoundsInScreen().y()); |
578 EXPECT_GT(w1->GetBoundsInScreen().y(), w2->GetBoundsInScreen().y()); | 577 EXPECT_GT(w1->GetBoundsInScreen().y(), w2->GetBoundsInScreen().y()); |
579 EXPECT_EQ(min_dock_gap(), | 578 EXPECT_EQ(work_area.bottom(), w3->GetBoundsInScreen().bottom()); |
580 work_area.bottom() - w3->GetBoundsInScreen().bottom()); | |
581 DragEnd(); | 579 DragEnd(); |
582 | 580 |
583 // Test the new windows order and that the overlaps differ at most by a pixel. | 581 // Test the new windows order and that the overlaps differ at most by a pixel. |
584 gap1 = w2->GetBoundsInScreen().y() - work_area.y(); | 582 gap1 = w2->GetBoundsInScreen().y() - work_area.y(); |
585 gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); | 583 gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); |
586 gap3 = w3->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); | 584 gap3 = w3->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); |
587 gap4 = work_area.bottom() - w3->GetBoundsInScreen().bottom(); | 585 gap4 = work_area.bottom() - w3->GetBoundsInScreen().bottom(); |
588 EXPECT_NEAR(gap1, min_dock_gap(), 1); | 586 EXPECT_EQ(0, gap1); |
589 EXPECT_NEAR(gap2, min_dock_gap(), 1); | 587 EXPECT_NEAR(gap2, min_dock_gap(), 1); |
590 EXPECT_NEAR(gap3, min_dock_gap(), 1); | 588 EXPECT_NEAR(gap3, min_dock_gap(), 1); |
591 EXPECT_NEAR(gap4, min_dock_gap(), 1); | 589 EXPECT_EQ(0, gap4); |
592 } | 590 } |
593 | 591 |
594 // Tests that a second window added to the dock is resized to match. | 592 // Tests that a second window added to the dock is resized to match. |
595 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsWidthNew) { | 593 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsWidthNew) { |
596 if (!SupportsHostWindowResize()) | 594 if (!SupportsHostWindowResize()) |
597 return; | 595 return; |
598 | 596 |
599 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 597 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
600 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 280, 202))); | 598 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 280, 202))); |
601 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 599 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 EXPECT_LT(w2->GetBoundsInScreen().height(), work_area.height() / 2 - 10); | 806 EXPECT_LT(w2->GetBoundsInScreen().height(), work_area.height() / 2 - 10); |
809 } | 807 } |
810 | 808 |
811 // Tests run twice - on both panels and normal windows | 809 // Tests run twice - on both panels and normal windows |
812 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 810 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
813 DockedWindowLayoutManagerTest, | 811 DockedWindowLayoutManagerTest, |
814 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, | 812 testing::Values(ui::wm::WINDOW_TYPE_NORMAL, |
815 ui::wm::WINDOW_TYPE_PANEL)); | 813 ui::wm::WINDOW_TYPE_PANEL)); |
816 } // namespace internal | 814 } // namespace internal |
817 } // namespace ash | 815 } // namespace ash |
OLD | NEW |