| 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 "ui/display/manager/display_manager.h" | 5 #include "ui/display/manager/display_manager.h" |
| 6 | 6 |
| 7 #include "ash/accelerators/accelerator_commands_aura.h" | 7 #include "ash/accelerators/accelerator_commands_aura.h" |
| 8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
| 9 #include "ash/common/wm/window_state.h" | 9 #include "ash/common/wm/window_state.h" |
| 10 #include "ash/display/display_configuration_controller.h" | 10 #include "ash/display/display_configuration_controller.h" |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 list, builder.Build()); | 368 list, builder.Build()); |
| 369 | 369 |
| 370 UpdateDisplay("640x480,320x200,400x300"); | 370 UpdateDisplay("640x480,320x200,400x300"); |
| 371 | 371 |
| 372 EXPECT_EQ(3U, display_manager()->GetNumDisplays()); | 372 EXPECT_EQ(3U, display_manager()->GetNumDisplays()); |
| 373 | 373 |
| 374 EXPECT_EQ("0,0 640x480", | 374 EXPECT_EQ("0,0 640x480", |
| 375 display_manager()->GetDisplayAt(0).bounds().ToString()); | 375 display_manager()->GetDisplayAt(0).bounds().ToString()); |
| 376 EXPECT_EQ("-320,10 320x200", | 376 EXPECT_EQ("-320,10 320x200", |
| 377 display_manager()->GetDisplayAt(1).bounds().ToString()); | 377 display_manager()->GetDisplayAt(1).bounds().ToString()); |
| 378 EXPECT_EQ("-310,-290 400x300", | 378 |
| 379 // The above layout causes an overlap between [P] and [2], making [2]'s |
| 380 // bounds be "-310,-290 400x300" if the overlap is not fixed. The overlap |
| 381 // must be detected and fixed and [2] is shifted up to remove the overlap. |
| 382 EXPECT_EQ("-310,-300 400x300", |
| 379 display_manager()->GetDisplayAt(2).bounds().ToString()); | 383 display_manager()->GetDisplayAt(2).bounds().ToString()); |
| 380 } | 384 } |
| 381 { | 385 { |
| 382 // Layout: [1] | 386 // Layout: [1] |
| 383 // [P][2] | 387 // [P][2] |
| 384 display::DisplayLayoutBuilder builder(primary_id); | 388 display::DisplayLayoutBuilder builder(primary_id); |
| 385 builder.AddDisplayPlacement(list[1], primary_id, | 389 builder.AddDisplayPlacement(list[1], primary_id, |
| 386 display::DisplayPlacement::TOP, 10); | 390 display::DisplayPlacement::TOP, 10); |
| 387 builder.AddDisplayPlacement(list[2], primary_id, | 391 builder.AddDisplayPlacement(list[2], primary_id, |
| 388 display::DisplayPlacement::RIGHT, 10); | 392 display::DisplayPlacement::RIGHT, 10); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 display_manager()->GetDisplayAt(4).bounds().ToString()); | 461 display_manager()->GetDisplayAt(4).bounds().ToString()); |
| 458 // 3rd is the left of 4th. | 462 // 3rd is the left of 4th. |
| 459 EXPECT_EQ("-290,480 300x200", | 463 EXPECT_EQ("-290,480 300x200", |
| 460 display_manager()->GetDisplayAt(3).bounds().ToString()); | 464 display_manager()->GetDisplayAt(3).bounds().ToString()); |
| 461 // 1st is the bottom of 3rd. | 465 // 1st is the bottom of 3rd. |
| 462 EXPECT_EQ("-280,680 320x200", | 466 EXPECT_EQ("-280,680 320x200", |
| 463 display_manager()->GetDisplayAt(1).bounds().ToString()); | 467 display_manager()->GetDisplayAt(1).bounds().ToString()); |
| 464 } | 468 } |
| 465 } | 469 } |
| 466 | 470 |
| 471 // Makes sure that layouts with overlapped displays are detected and fixed when |
| 472 // applied. |
| 473 TEST_P(DisplayManagerTest, NoOverlappedDisplays) { |
| 474 if (!SupportsMultipleDisplays()) |
| 475 return; |
| 476 |
| 477 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 478 { |
| 479 // Layout with multiple overlaps and special cases: |
| 480 // |
| 481 // +-----+ |
| 482 // | 6 | |
| 483 // | | |
| 484 // +----+-+ | |
| 485 // | 5 | | | |
| 486 // +----+----+ | | |
| 487 // | 7 | | | | |
| 488 // +----+----+-+---+---+-+---------+ |
| 489 // | | P | | 2 | |
| 490 // +------+ | | +----------+ |
| 491 // | | | | 3 | |
| 492 // | | | | | |
| 493 // +--+----+-+-+-+-----+--+ | |
| 494 // | 1 | | 4 | | | |
| 495 // | | | +--+-------+ |
| 496 // | | | | |
| 497 // +--------+ +--------+ |
| 498 |
| 499 display::DisplayIdList list = display::test::CreateDisplayIdListN( |
| 500 8, primary_id, primary_id + 1, primary_id + 2, primary_id + 3, |
| 501 primary_id + 4, primary_id + 5, primary_id + 6, primary_id + 7); |
| 502 display::DisplayLayoutBuilder builder(primary_id); |
| 503 builder.AddDisplayPlacement(list[1], primary_id, |
| 504 display::DisplayPlacement::BOTTOM, 50); |
| 505 builder.AddDisplayPlacement(list[2], list[1], |
| 506 display::DisplayPlacement::TOP, 300); |
| 507 builder.AddDisplayPlacement(list[3], list[2], |
| 508 display::DisplayPlacement::RIGHT, 30); |
| 509 builder.AddDisplayPlacement(list[4], list[2], |
| 510 display::DisplayPlacement::BOTTOM, 400); |
| 511 builder.AddDisplayPlacement(list[5], primary_id, |
| 512 display::DisplayPlacement::LEFT, -300); |
| 513 builder.AddDisplayPlacement(list[6], primary_id, |
| 514 display::DisplayPlacement::TOP, -250); |
| 515 builder.AddDisplayPlacement(list[7], list[6], |
| 516 display::DisplayPlacement::LEFT, 250); |
| 517 display_manager()->layout_store()->RegisterLayoutForDisplayIdList( |
| 518 list, builder.Build()); |
| 519 |
| 520 UpdateDisplay( |
| 521 "480x400,480x400,480x400,480x400,480x400,480x400,480x400,530x150"); |
| 522 |
| 523 // The resulting layout after overlaps had been removed: |
| 524 // |
| 525 // +-------+ |
| 526 // | 5 | |
| 527 // | +-----+ |
| 528 // | | 6 | |
| 529 // | | | |
| 530 // | | | |
| 531 // | | | |
| 532 // +-+-------+ | |
| 533 // | 7 | | |
| 534 // +---------+-+---+----+---------+ |
| 535 // | P | 2 | |
| 536 // | | +----------+ |
| 537 // | | | 3 | |
| 538 // | | | | |
| 539 // +--+-----+-+-------+ | |
| 540 // | 1 | | | |
| 541 // | | +----+---+------+ |
| 542 // | | | 4 | |
| 543 // +-------+ | | |
| 544 // | | |
| 545 // +--------+ |
| 546 |
| 547 EXPECT_EQ(8U, display_manager()->GetNumDisplays()); |
| 548 |
| 549 EXPECT_EQ("0,0 480x400", |
| 550 display_manager()->GetDisplayAt(0).bounds().ToString()); |
| 551 EXPECT_EQ("50,400 480x400", |
| 552 display_manager()->GetDisplayAt(1).bounds().ToString()); |
| 553 EXPECT_EQ("480,0 480x400", |
| 554 display_manager()->GetDisplayAt(2).bounds().ToString()); |
| 555 EXPECT_EQ("960,30 480x400", |
| 556 display_manager()->GetDisplayAt(3).bounds().ToString()); |
| 557 EXPECT_EQ("730,430 480x400", |
| 558 display_manager()->GetDisplayAt(4).bounds().ToString()); |
| 559 EXPECT_EQ("-730,-550 480x400", |
| 560 display_manager()->GetDisplayAt(5).bounds().ToString()); |
| 561 EXPECT_EQ("-250,-400 480x400", |
| 562 display_manager()->GetDisplayAt(6).bounds().ToString()); |
| 563 EXPECT_EQ("-780,-150 530x150", |
| 564 display_manager()->GetDisplayAt(7).bounds().ToString()); |
| 565 |
| 566 // Expect that the displays have been reparented correctly, such that a |
| 567 // child is always touching its parent. |
| 568 display::DisplayLayoutBuilder expected_layout_builder(primary_id); |
| 569 expected_layout_builder.AddDisplayPlacement( |
| 570 list[1], primary_id, display::DisplayPlacement::BOTTOM, 50); |
| 571 expected_layout_builder.AddDisplayPlacement( |
| 572 list[2], list[1], display::DisplayPlacement::TOP, 430); |
| 573 expected_layout_builder.AddDisplayPlacement( |
| 574 list[3], list[2], display::DisplayPlacement::RIGHT, 30); |
| 575 // [4] became a child of [3] instead of [2] as they no longer touch. |
| 576 expected_layout_builder.AddDisplayPlacement( |
| 577 list[4], list[3], display::DisplayPlacement::BOTTOM, -230); |
| 578 // [5] became a child of [6] instead of [P] as they no longer touch. |
| 579 expected_layout_builder.AddDisplayPlacement( |
| 580 list[5], list[6], display::DisplayPlacement::LEFT, -150); |
| 581 expected_layout_builder.AddDisplayPlacement( |
| 582 list[6], primary_id, display::DisplayPlacement::TOP, -250); |
| 583 expected_layout_builder.AddDisplayPlacement( |
| 584 list[7], list[6], display::DisplayPlacement::LEFT, 250); |
| 585 |
| 586 const display::DisplayLayout& layout = |
| 587 display_manager()->GetCurrentResolvedDisplayLayout(); |
| 588 EXPECT_TRUE( |
| 589 layout.HasSamePlacementList(*(expected_layout_builder.Build()))); |
| 590 } |
| 591 |
| 592 { |
| 593 // The following is a layout with an overlap that requires, if two displays |
| 594 // have the same Y, that they're sorted from right to left for the |
| 595 // de-intersecting algorithm to work successfully. |
| 596 // |
| 597 // +---------+---------+ |
| 598 // | 1 | P | |
| 599 // | | | |
| 600 // +---------+ | |
| 601 // | | | |
| 602 // +---------+---------+ |
| 603 // | 2 | |
| 604 // | | |
| 605 // +---------+ |
| 606 |
| 607 display::DisplayIdList list = display::test::CreateDisplayIdListN( |
| 608 3, primary_id, primary_id + 1, primary_id + 2); |
| 609 display::DisplayLayoutBuilder builder(primary_id); |
| 610 builder.AddDisplayPlacement(list[1], primary_id, |
| 611 display::DisplayPlacement::LEFT, 0); |
| 612 builder.AddDisplayPlacement(list[2], primary_id, |
| 613 display::DisplayPlacement::LEFT, 250); |
| 614 display_manager()->layout_store()->RegisterLayoutForDisplayIdList( |
| 615 list, builder.Build()); |
| 616 UpdateDisplay("696x500,696x500,696x500"); |
| 617 |
| 618 // The expected layout should be: |
| 619 // |
| 620 // +---------+---------+ |
| 621 // | 1 | P | |
| 622 // | | | |
| 623 // | | | |
| 624 // | | | |
| 625 // +---------+---------+ |
| 626 // | 2 | |
| 627 // | | |
| 628 // | | |
| 629 // | | |
| 630 // +---------+ |
| 631 |
| 632 EXPECT_EQ(3U, display_manager()->GetNumDisplays()); |
| 633 EXPECT_EQ("0,0 696x500", |
| 634 display_manager()->GetDisplayAt(0).bounds().ToString()); |
| 635 EXPECT_EQ("-696,0 696x500", |
| 636 display_manager()->GetDisplayAt(1).bounds().ToString()); |
| 637 EXPECT_EQ("-696,500 696x500", |
| 638 display_manager()->GetDisplayAt(2).bounds().ToString()); |
| 639 } |
| 640 |
| 641 { |
| 642 // The following is similar to the above but with two displays having the |
| 643 // same X, they should be sorted from top to bottom for the |
| 644 // de-intersecting algorithm to work successfully. |
| 645 // |
| 646 // +------+--+------+ |
| 647 // | 2 | | 1 | |
| 648 // | | | | |
| 649 // | | | | |
| 650 // | | | | |
| 651 // +------+--+------+ |
| 652 // | P | |
| 653 // | | |
| 654 // | | |
| 655 // | | |
| 656 // +---------+ |
| 657 // |
| 658 |
| 659 display::DisplayIdList list = display::test::CreateDisplayIdListN( |
| 660 3, primary_id, primary_id + 1, primary_id + 2); |
| 661 display::DisplayLayoutBuilder builder(primary_id); |
| 662 builder.AddDisplayPlacement(list[1], primary_id, |
| 663 display::DisplayPlacement::TOP, 0); |
| 664 builder.AddDisplayPlacement(list[2], primary_id, |
| 665 display::DisplayPlacement::TOP, -348); |
| 666 display_manager()->layout_store()->RegisterLayoutForDisplayIdList( |
| 667 list, builder.Build()); |
| 668 UpdateDisplay("696x500,696x500,696x500"); |
| 669 |
| 670 // The expected layout should be: |
| 671 // |
| 672 // +---------+---------+ |
| 673 // | 2 | 1 | |
| 674 // | | | |
| 675 // | | | |
| 676 // | | | |
| 677 // +---------+---------+ |
| 678 // | P | |
| 679 // | | |
| 680 // | | |
| 681 // | | |
| 682 // +---------+ |
| 683 // |
| 684 |
| 685 EXPECT_EQ(3U, display_manager()->GetNumDisplays()); |
| 686 EXPECT_EQ("0,0 696x500", |
| 687 display_manager()->GetDisplayAt(0).bounds().ToString()); |
| 688 EXPECT_EQ("0,-500 696x500", |
| 689 display_manager()->GetDisplayAt(1).bounds().ToString()); |
| 690 EXPECT_EQ("-696,-500 696x500", |
| 691 display_manager()->GetDisplayAt(2).bounds().ToString()); |
| 692 } |
| 693 } |
| 694 |
| 467 TEST_P(DisplayManagerTest, NoMirrorInThreeDisplays) { | 695 TEST_P(DisplayManagerTest, NoMirrorInThreeDisplays) { |
| 468 if (!SupportsMultipleDisplays()) | 696 if (!SupportsMultipleDisplays()) |
| 469 return; | 697 return; |
| 470 | 698 |
| 471 UpdateDisplay("640x480,320x200,400x300"); | 699 UpdateDisplay("640x480,320x200,400x300"); |
| 472 ash::Shell::GetInstance()->display_configuration_controller()->SetMirrorMode( | 700 ash::Shell::GetInstance()->display_configuration_controller()->SetMirrorMode( |
| 473 true, true); | 701 true, true); |
| 474 EXPECT_FALSE(display_manager()->IsInMirrorMode()); | 702 EXPECT_FALSE(display_manager()->IsInMirrorMode()); |
| 475 EXPECT_EQ(3u, display_manager()->GetNumDisplays()); | 703 EXPECT_EQ(3u, display_manager()->GetNumDisplays()); |
| 476 #if defined(OS_CHROMEOS) | 704 #if defined(OS_CHROMEOS) |
| (...skipping 2080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2557 const display::DisplayLayout& stored = | 2785 const display::DisplayLayout& stored = |
| 2558 layout_store->GetRegisteredDisplayLayout(list); | 2786 layout_store->GetRegisteredDisplayLayout(list); |
| 2559 | 2787 |
| 2560 EXPECT_EQ(id1, stored.placement_list[0].parent_display_id); | 2788 EXPECT_EQ(id1, stored.placement_list[0].parent_display_id); |
| 2561 EXPECT_EQ(id2, stored.placement_list[0].display_id); | 2789 EXPECT_EQ(id2, stored.placement_list[0].display_id); |
| 2562 } | 2790 } |
| 2563 | 2791 |
| 2564 #endif // OS_CHROMEOS | 2792 #endif // OS_CHROMEOS |
| 2565 | 2793 |
| 2566 } // namespace ash | 2794 } // namespace ash |
| OLD | NEW |