Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: components/exo/shell_surface_unittest.cc

Issue 2686533004: Use pixel coordinates for shadow underlay bounds (Closed)
Patch Set: remove unnecessary changes Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/exo/shell_surface.cc ('k') | components/exo/wayland/server.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/accessibility_delegate.h" 5 #include "ash/common/accessibility_delegate.h"
6 #include "ash/common/wm/window_state.h" 6 #include "ash/common/wm/window_state.h"
7 #include "ash/common/wm/wm_event.h" 7 #include "ash/common/wm/wm_event.h"
8 #include "ash/common/wm_shell.h" 8 #include "ash/common/wm_shell.h"
9 #include "ash/common/wm_window.h" 9 #include "ash/common/wm_window.h"
10 #include "ash/public/cpp/shell_window_ids.h" 10 #include "ash/public/cpp/shell_window_ids.h"
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 popup_surface.Commit(); 489 popup_surface.Commit();
490 490
491 // Popup position is fixed, and geometry is relative to it. 491 // Popup position is fixed, and geometry is relative to it.
492 EXPECT_EQ(gfx::Rect(parent_bounds.origin() + 492 EXPECT_EQ(gfx::Rect(parent_bounds.origin() +
493 popup_bounds.OffsetFromOrigin() + 493 popup_bounds.OffsetFromOrigin() +
494 geometry.OffsetFromOrigin(), 494 geometry.OffsetFromOrigin(),
495 geometry.size()), 495 geometry.size()),
496 popup->GetWidget()->GetWindowBoundsInScreen()); 496 popup->GetWidget()->GetWindowBoundsInScreen());
497 } 497 }
498 498
499 TEST_F(ShellSurfaceTest, Shadow) { 499 TEST_F(ShellSurfaceTest, SurfaceShadow) {
500 gfx::Size buffer_size(128, 128);
501 std::unique_ptr<Buffer> buffer(
502 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
500 std::unique_ptr<Surface> surface(new Surface); 503 std::unique_ptr<Surface> surface(new Surface);
501 std::unique_ptr<ShellSurface> shell_surface( 504 std::unique_ptr<ShellSurface> shell_surface(
502 new ShellSurface(surface.get(), nullptr, gfx::Rect(), true, false, 505 new ShellSurface(surface.get(), nullptr, gfx::Rect(), true, false,
503 ash::kShellWindowId_DefaultContainer)); 506 ash::kShellWindowId_DefaultContainer));
507 surface->Attach(buffer.get());
504 surface->Commit(); 508 surface->Commit();
505 509
506 aura::Window* window = shell_surface->GetWidget()->GetNativeWindow(); 510 aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
507 511
508 // 1) Initial state, no shadow. 512 // 1) Initial state, no shadow.
509 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window); 513 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
510 ASSERT_TRUE(shadow); 514 ASSERT_TRUE(shadow);
511 EXPECT_FALSE(shadow->layer()->visible()); 515 EXPECT_FALSE(shadow->layer()->visible());
512 516
513 std::unique_ptr<Display> display(new Display); 517 std::unique_ptr<Display> display(new Display);
514 518
515 // 2) Just creating a sub surface won't create a shadow. 519 // 2) Just creating a sub surface won't create a shadow.
516 std::unique_ptr<Surface> child = display->CreateSurface(); 520 std::unique_ptr<Surface> child = display->CreateSurface();
517 gfx::Size buffer_size(128, 128);
518 std::unique_ptr<Buffer> child_buffer( 521 std::unique_ptr<Buffer> child_buffer(
519 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 522 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
520 child->Attach(child_buffer.get()); 523 child->Attach(child_buffer.get());
521 std::unique_ptr<SubSurface> sub_surface( 524 std::unique_ptr<SubSurface> sub_surface(
522 display->CreateSubSurface(child.get(), surface.get())); 525 display->CreateSubSurface(child.get(), surface.get()));
523 surface->Commit(); 526 surface->Commit();
524 527
525 EXPECT_FALSE(shadow->layer()->visible()); 528 EXPECT_FALSE(shadow->layer()->visible());
526 529
527 // 3) Create a shadow. 530 // 3) Create a shadow.
528 shell_surface->SetRectangularShadow(true); 531 shell_surface->SetRectangularSurfaceShadow(gfx::Rect(10, 10, 100, 100));
529 shell_surface->SetRectangularShadowContentBounds(gfx::Rect(10, 10, 100, 100));
530 surface->Commit(); 532 surface->Commit();
531 EXPECT_TRUE(shadow->layer()->visible()); 533 EXPECT_TRUE(shadow->layer()->visible());
532 534
533 gfx::Rect before = shadow->layer()->bounds(); 535 gfx::Rect before = shadow->layer()->bounds();
534 536
535 // 4) Shadow bounds is independent of the sub surface. 537 // 4) Shadow bounds is independent of the sub surface.
536 gfx::Size new_buffer_size(256, 256); 538 gfx::Size new_buffer_size(256, 256);
537 std::unique_ptr<Buffer> new_child_buffer( 539 std::unique_ptr<Buffer> new_child_buffer(
538 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(new_buffer_size))); 540 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(new_buffer_size)));
539 child->Attach(new_child_buffer.get()); 541 child->Attach(new_child_buffer.get());
540 child->Commit(); 542 child->Commit();
541 surface->Commit(); 543 surface->Commit();
542 544
543 EXPECT_EQ(before, shadow->layer()->bounds()); 545 EXPECT_EQ(before, shadow->layer()->bounds());
544 546
545 // 4) Updating the widget's window bounds should not change the shadow bounds. 547 // 4) Updating the widget's window bounds should not change the shadow bounds.
546 window->SetBounds(gfx::Rect(10, 10, 100, 100)); 548 window->SetBounds(gfx::Rect(10, 10, 100, 100));
547 EXPECT_EQ(before, shadow->layer()->bounds()); 549 EXPECT_EQ(before, shadow->layer()->bounds());
548 550
549 // 5) This should disable shadow. 551 // 5) This should disable shadow.
550 shell_surface->SetRectangularShadow(false); 552 shell_surface->SetRectangularSurfaceShadow(gfx::Rect());
551 surface->Commit(); 553 surface->Commit();
552 554
553 EXPECT_EQ(wm::ShadowElevation::NONE, wm::GetShadowElevation(window)); 555 EXPECT_EQ(wm::ShadowElevation::NONE, wm::GetShadowElevation(window));
554 EXPECT_FALSE(shadow->layer()->visible()); 556 EXPECT_FALSE(shadow->layer()->visible());
555 557
556 // 6) This should enable shadow. 558 // 6) This should enable non surface shadow again.
557 shell_surface->SetRectangularShadow(true); 559 shell_surface->SetRectangularSurfaceShadow(gfx::Rect(10, 10, 100, 100));
558 surface->Commit(); 560 surface->Commit();
559 561
560 EXPECT_EQ(wm::ShadowElevation::MEDIUM, wm::GetShadowElevation(window)); 562 EXPECT_EQ(wm::ShadowElevation::MEDIUM, wm::GetShadowElevation(window));
561 EXPECT_TRUE(shadow->layer()->visible()); 563 EXPECT_TRUE(shadow->layer()->visible());
564
565 // For surface shadow, the underlay is placed at the bottom of shell surfaces.
566 EXPECT_EQ(surface->window(), shell_surface->shadow_underlay()->parent());
567 EXPECT_EQ(window, shell_surface->shadow_overlay()->parent());
568
569 EXPECT_EQ(*surface->window()->children().begin(),
570 shell_surface->shadow_underlay());
571 }
572
573 TEST_F(ShellSurfaceTest, NonSurfaceShadow) {
574 gfx::Size buffer_size(128, 128);
575 std::unique_ptr<Buffer> buffer(
576 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
577 std::unique_ptr<Surface> surface(new Surface);
578 std::unique_ptr<ShellSurface> shell_surface(
579 new ShellSurface(surface.get(), nullptr, gfx::Rect(), true, false,
580 ash::kShellWindowId_DefaultContainer));
581 surface->Attach(buffer.get());
582 surface->Commit();
583
584 aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
585
586 // 1) Initial state, no shadow.
587 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
588 ASSERT_TRUE(shadow);
589 EXPECT_FALSE(shadow->layer()->visible());
590
591 std::unique_ptr<Display> display(new Display);
592
593 // 2) Just creating a sub surface won't create a shadow.
594 std::unique_ptr<Surface> child = display->CreateSurface();
595 std::unique_ptr<Buffer> child_buffer(
596 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
597 child->Attach(child_buffer.get());
598 std::unique_ptr<SubSurface> sub_surface(
599 display->CreateSubSurface(child.get(), surface.get()));
600 surface->Commit();
601
602 EXPECT_FALSE(shadow->layer()->visible());
603
604 // 3) Enable a shadow.
605 shell_surface->SetRectangularShadowEnabled(true);
606 surface->Commit();
607 EXPECT_TRUE(shadow->layer()->visible());
608
609 gfx::Rect before = shadow->layer()->bounds();
610
611 // 4) Shadow bounds is independent of the sub surface.
612 gfx::Size new_buffer_size(256, 256);
613 std::unique_ptr<Buffer> new_child_buffer(
614 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(new_buffer_size)));
615 child->Attach(new_child_buffer.get());
616 child->Commit();
617 surface->Commit();
618
619 EXPECT_EQ(before, shadow->layer()->bounds());
620
621 // 4) Updating the widget's window bounds should change the non surface shadow
622 // bounds.
623 const gfx::Rect new_bounds(50, 50, 100, 100);
624 window->SetBounds(new_bounds);
625 EXPECT_NE(before, shadow->layer()->bounds());
626 EXPECT_NE(new_bounds, shadow->layer()->bounds());
627
628 // 5) This should disable shadow.
629 shell_surface->SetRectangularShadowEnabled(false);
630 surface->Commit();
631
632 EXPECT_EQ(wm::ShadowElevation::NONE, wm::GetShadowElevation(window));
633 EXPECT_FALSE(shadow->layer()->visible());
634
635 // 6) This should enable non surface shadow.
636 shell_surface->SetRectangularShadowEnabled(true);
637 surface->Commit();
638
639 EXPECT_EQ(wm::ShadowElevation::MEDIUM, wm::GetShadowElevation(window));
640 EXPECT_TRUE(shadow->layer()->visible());
641
642 // For no surface shadow, both of underlay and overlay should be stacked
643 // below the surface window.
644 EXPECT_EQ(window, shell_surface->shadow_underlay()->parent());
645 EXPECT_EQ(window, shell_surface->shadow_overlay()->parent());
562 } 646 }
563 647
564 TEST_F(ShellSurfaceTest, ShadowWithStateChange) { 648 TEST_F(ShellSurfaceTest, ShadowWithStateChange) {
565 std::unique_ptr<Surface> surface(new Surface); 649 std::unique_ptr<Surface> surface(new Surface);
566 // Set the bounds to disable auto managed mode. 650 // Set the bounds to disable auto managed mode.
567 std::unique_ptr<ShellSurface> shell_surface( 651 std::unique_ptr<ShellSurface> shell_surface(
568 new ShellSurface(surface.get(), nullptr, gfx::Rect(640, 480), true, false, 652 new ShellSurface(surface.get(), nullptr, gfx::Rect(640, 480), true, false,
569 ash::kShellWindowId_DefaultContainer)); 653 ash::kShellWindowId_DefaultContainer));
570 654
571 // Postion the widget at 10,10 so that we get non zero offset. 655 // Postion the widget at 10,10 so that we get non zero offset.
572 const gfx::Size content_size(100, 100); 656 const gfx::Size content_size(100, 100);
573 const gfx::Rect original_bounds(gfx::Point(10, 10), content_size); 657 const gfx::Rect original_bounds(gfx::Point(10, 10), content_size);
574 shell_surface->SetGeometry(original_bounds); 658 shell_surface->SetGeometry(original_bounds);
575 surface->Commit(); 659 surface->Commit();
576 660
577 // Placing a shadow at screen origin will make the shadow's origin (-10, -10). 661 // Placing a shadow at screen origin will make the shadow's origin (-10, -10).
578 const gfx::Rect shadow_bounds(content_size); 662 const gfx::Rect shadow_bounds(content_size);
579 663
580 // Expected shadow position/bounds in parent coordinates. 664 // Expected shadow position/bounds in parent coordinates.
581 const gfx::Point expected_shadow_origin(-10, -10); 665 const gfx::Point expected_shadow_origin(-10, -10);
582 const gfx::Rect expected_shadow_bounds(expected_shadow_origin, content_size); 666 const gfx::Rect expected_shadow_bounds(expected_shadow_origin, content_size);
583 667
584 views::Widget* widget = shell_surface->GetWidget(); 668 views::Widget* widget = shell_surface->GetWidget();
585 aura::Window* window = widget->GetNativeWindow(); 669 aura::Window* window = widget->GetNativeWindow();
586 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window); 670 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
587 671
588 shell_surface->SetRectangularShadow(true); 672 shell_surface->SetRectangularSurfaceShadow(shadow_bounds);
589 shell_surface->SetRectangularShadowContentBounds(shadow_bounds);
590 surface->Commit(); 673 surface->Commit();
591 EXPECT_EQ(wm::ShadowElevation::MEDIUM, wm::GetShadowElevation(window)); 674 EXPECT_EQ(wm::ShadowElevation::MEDIUM, wm::GetShadowElevation(window));
592 675
593 // Shadow overlay bounds. 676 // Shadow overlay bounds.
594 EXPECT_TRUE(shadow->layer()->visible()); 677 EXPECT_TRUE(shadow->layer()->visible());
595 // Origin must be in sync. 678 // Origin must be in sync.
596 EXPECT_EQ(expected_shadow_origin, 679 EXPECT_EQ(expected_shadow_origin,
597 shadow->layer()->parent()->bounds().origin()); 680 shadow->layer()->parent()->bounds().origin());
598 681
599 const gfx::Rect work_area = 682 const gfx::Rect work_area =
600 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); 683 display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
601 // Maximizing window hides the shadow. 684 // Maximizing window hides the shadow.
602 widget->Maximize(); 685 widget->Maximize();
603 ASSERT_TRUE(widget->IsMaximized()); 686 ASSERT_TRUE(widget->IsMaximized());
604 EXPECT_FALSE(shadow->layer()->visible()); 687 EXPECT_FALSE(shadow->layer()->visible());
605 688
606 shell_surface->SetRectangularShadowContentBounds(work_area); 689 shell_surface->SetRectangularSurfaceShadow(work_area);
607 surface->Commit(); 690 surface->Commit();
608 EXPECT_FALSE(shadow->layer()->visible()); 691 EXPECT_FALSE(shadow->layer()->visible());
609 692
610 // Restoring bounds will re-enable shadow. It's content size is set to work 693 // Restoring bounds will re-enable shadow. It's content size is set to work
611 // area,/ thus not visible until new bounds is committed. 694 // area,/ thus not visible until new bounds is committed.
612 widget->Restore(); 695 widget->Restore();
613 EXPECT_TRUE(shadow->layer()->visible()); 696 EXPECT_TRUE(shadow->layer()->visible());
614 const gfx::Rect shadow_in_maximized(expected_shadow_origin, work_area.size()); 697 const gfx::Rect shadow_in_maximized(expected_shadow_origin, work_area.size());
615 EXPECT_EQ(shadow_in_maximized, shadow->layer()->parent()->bounds()); 698 EXPECT_EQ(shadow_in_maximized, shadow->layer()->parent()->bounds());
616 699
617 // The bounds is updated. 700 // The bounds is updated.
618 shell_surface->SetRectangularShadowContentBounds(shadow_bounds); 701 shell_surface->SetRectangularSurfaceShadow(shadow_bounds);
619 surface->Commit(); 702 surface->Commit();
620 EXPECT_EQ(expected_shadow_bounds, shadow->layer()->parent()->bounds()); 703 EXPECT_EQ(expected_shadow_bounds, shadow->layer()->parent()->bounds());
621 } 704 }
622 705
623 TEST_F(ShellSurfaceTest, ShadowWithTransform) { 706 TEST_F(ShellSurfaceTest, ShadowWithTransform) {
624 std::unique_ptr<Surface> surface(new Surface); 707 std::unique_ptr<Surface> surface(new Surface);
625 // Set the bounds to disable auto managed mode. 708 // Set the bounds to disable auto managed mode.
626 std::unique_ptr<ShellSurface> shell_surface( 709 std::unique_ptr<ShellSurface> shell_surface(
627 new ShellSurface(surface.get(), nullptr, gfx::Rect(640, 400), true, false, 710 new ShellSurface(surface.get(), nullptr, gfx::Rect(640, 400), true, false,
628 ash::kShellWindowId_DefaultContainer)); 711 ash::kShellWindowId_DefaultContainer));
629 712
630 // Postion the widget at 10,10 so that we get non zero offset. 713 // Postion the widget at 10,10 so that we get non zero offset.
631 const gfx::Size content_size(100, 100); 714 const gfx::Size content_size(100, 100);
632 const gfx::Rect original_bounds(gfx::Point(10, 10), content_size); 715 const gfx::Rect original_bounds(gfx::Point(10, 10), content_size);
633 shell_surface->SetGeometry(original_bounds); 716 shell_surface->SetGeometry(original_bounds);
634 surface->Commit(); 717 surface->Commit();
635 718
636 aura::Window* window = shell_surface->GetWidget()->GetNativeWindow(); 719 aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
637 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window); 720 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
638 721
639 // Placing a shadow at screen origin will make the shadow's origin (-10, -10). 722 // Placing a shadow at screen origin will make the shadow's origin (-10, -10).
640 const gfx::Rect shadow_bounds(content_size); 723 const gfx::Rect shadow_bounds(content_size);
641 724
642 // Shadow bounds relative to its parent should not be affected by a transform. 725 // Shadow bounds relative to its parent should not be affected by a transform.
643 gfx::Transform transform; 726 gfx::Transform transform;
644 transform.Translate(50, 50); 727 transform.Translate(50, 50);
645 window->SetTransform(transform); 728 window->SetTransform(transform);
646 shell_surface->SetRectangularShadow(true); 729 shell_surface->SetRectangularSurfaceShadow(shadow_bounds);
647 shell_surface->SetRectangularShadowContentBounds(shadow_bounds);
648 surface->Commit(); 730 surface->Commit();
649 EXPECT_TRUE(shadow->layer()->visible()); 731 EXPECT_TRUE(shadow->layer()->visible());
650 EXPECT_EQ(gfx::Rect(-10, -10, 100, 100), shadow->layer()->parent()->bounds()); 732 EXPECT_EQ(gfx::Rect(-10, -10, 100, 100), shadow->layer()->parent()->bounds());
651 } 733 }
652 734
653 TEST_F(ShellSurfaceTest, ShadowStartMaximized) { 735 TEST_F(ShellSurfaceTest, ShadowStartMaximized) {
654 std::unique_ptr<Surface> surface(new Surface); 736 std::unique_ptr<Surface> surface(new Surface);
655 std::unique_ptr<ShellSurface> shell_surface( 737 std::unique_ptr<ShellSurface> shell_surface(
656 new ShellSurface(surface.get(), nullptr, gfx::Rect(640, 480), true, false, 738 new ShellSurface(surface.get(), nullptr, gfx::Rect(640, 480), true, false,
657 ash::kShellWindowId_DefaultContainer)); 739 ash::kShellWindowId_DefaultContainer));
658 shell_surface->Maximize(); 740 shell_surface->Maximize();
659 views::Widget* widget = shell_surface->GetWidget(); 741 views::Widget* widget = shell_surface->GetWidget();
660 aura::Window* window = widget->GetNativeWindow(); 742 aura::Window* window = widget->GetNativeWindow();
661 743
662 // There is no shadow when started in maximized state. 744 // There is no shadow when started in maximized state.
663 EXPECT_FALSE(wm::ShadowController::GetShadowForWindow(window)); 745 EXPECT_FALSE(wm::ShadowController::GetShadowForWindow(window));
664 746
665 // Sending a shadow bounds in maximized state won't create a shaodw. 747 // Sending a shadow bounds in maximized state won't create a shaodw.
666 shell_surface->SetRectangularShadow(true); 748 shell_surface->SetRectangularSurfaceShadow(gfx::Rect(10, 10, 100, 100));
667 shell_surface->SetRectangularShadowContentBounds(gfx::Rect(10, 10, 100, 100));
668 surface->Commit(); 749 surface->Commit();
669 750
670 EXPECT_FALSE(wm::ShadowController::GetShadowForWindow(window)); 751 EXPECT_FALSE(wm::ShadowController::GetShadowForWindow(window));
671 // Underlay should be created even without shadow. 752 // Underlay should be created even without shadow.
672 ASSERT_TRUE(shell_surface->shadow_underlay()); 753 ASSERT_TRUE(shell_surface->shadow_underlay());
673 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible()); 754 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible());
674 755
675 // Restore the window and make sure the shadow is created, visible and 756 // Restore the window and make sure the shadow is created, visible and
676 // has the latest bounds. 757 // has the latest bounds.
677 widget->Restore(); 758 widget->Restore();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 791
711 // Leave fullscreen mode. 792 // Leave fullscreen mode.
712 window->GetWindowState()->OnWMEvent(&event); 793 window->GetWindowState()->OnWMEvent(&event);
713 794
714 // Check that shell surface is maximized. 795 // Check that shell surface is maximized.
715 EXPECT_EQ(CurrentContext()->bounds().width(), 796 EXPECT_EQ(CurrentContext()->bounds().width(),
716 shell_surface->GetWidget()->GetWindowBoundsInScreen().width()); 797 shell_surface->GetWidget()->GetWindowBoundsInScreen().width());
717 } 798 }
718 799
719 TEST_F(ShellSurfaceTest, ImmersiveFullscreenBackground) { 800 TEST_F(ShellSurfaceTest, ImmersiveFullscreenBackground) {
720 gfx::Size buffer_size(256, 256); 801 const gfx::Size display_size =
802 display::Screen::GetScreen()->GetPrimaryDisplay().size();
803 const gfx::Size buffer_size(display_size);
721 std::unique_ptr<Buffer> buffer( 804 std::unique_ptr<Buffer> buffer(
722 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 805 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
723 std::unique_ptr<Surface> surface(new Surface); 806 std::unique_ptr<Surface> surface(new Surface);
724 std::unique_ptr<ShellSurface> shell_surface( 807 std::unique_ptr<ShellSurface> shell_surface(
725 new ShellSurface(surface.get(), nullptr, gfx::Rect(640, 480), true, false, 808 new ShellSurface(surface.get(), nullptr, gfx::Rect(100, 100), true, false,
726 ash::kShellWindowId_DefaultContainer)); 809 ash::kShellWindowId_DefaultContainer));
727 810
728 surface->Attach(buffer.get()); 811 surface->Attach(buffer.get());
729 812
730 gfx::Rect shadow_bounds(10, 10, 100, 100); 813 gfx::Rect shadow_bounds(10, 10, 100, 100);
731 shell_surface->SetRectangularShadow(true); 814 shell_surface->SetGeometry(shadow_bounds);
732 shell_surface->SetRectangularShadowContentBounds(shadow_bounds); 815 shell_surface->SetRectangularSurfaceShadow(shadow_bounds);
733 surface->Commit(); 816 surface->Commit();
817 EXPECT_EQ(shadow_bounds,
818 shell_surface->GetWidget()->GetWindowBoundsInScreen());
734 ASSERT_EQ(shadow_bounds, shell_surface->shadow_underlay()->bounds()); 819 ASSERT_EQ(shadow_bounds, shell_surface->shadow_underlay()->bounds());
820 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().size(),
821 shell_surface->surface_for_testing()->window()->bounds().size());
735 822
736 ash::wm::WMEvent event(ash::wm::WM_EVENT_TOGGLE_FULLSCREEN); 823 ash::wm::WMEvent event(ash::wm::WM_EVENT_TOGGLE_FULLSCREEN);
737 ash::WmWindow* window = 824 ash::WmWindow* window =
738 ash::WmWindow::Get(shell_surface->GetWidget()->GetNativeWindow()); 825 ash::WmWindow::Get(shell_surface->GetWidget()->GetNativeWindow());
739 826
740 // Enter immersive fullscreen mode. Shadow underlay is fullscreen. 827 // Enter immersive fullscreen mode. Shadow underlay is fullscreen.
741 window->GetWindowState()->OnWMEvent(&event); 828 window->GetWindowState()->OnWMEvent(&event);
742 829
743 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().bounds(),
744 shell_surface->shadow_underlay()->bounds());
745 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible()); 830 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible());
746 EXPECT_EQ(1.f, shell_surface->shadow_underlay()->layer()->opacity()); 831 EXPECT_EQ(1.f, shell_surface->shadow_underlay()->layer()->opacity());
747 EXPECT_NE(shell_surface->GetWidget()->GetWindowBoundsInScreen(), 832 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().size(),
748 shell_surface->shadow_underlay()->bounds()); 833 shell_surface->shadow_underlay()->bounds().size());
749 834
750 // Leave fullscreen mode. Shadow underlay is restored. 835 // Leave fullscreen mode. Shadow underlay is restored.
751 window->GetWindowState()->OnWMEvent(&event); 836 window->GetWindowState()->OnWMEvent(&event);
752 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible()); 837 EXPECT_TRUE(shell_surface->shadow_underlay()->IsVisible());
753 EXPECT_EQ(shadow_bounds, shell_surface->shadow_underlay()->bounds()); 838 EXPECT_EQ(shadow_bounds, shell_surface->shadow_underlay()->bounds());
754 } 839 }
755 840
756 TEST_F(ShellSurfaceTest, SpokenFeedbackFullscreenBackground) { 841 TEST_F(ShellSurfaceTest, SpokenFeedbackFullscreenBackground) {
757 gfx::Size buffer_size(256, 256); 842 const gfx::Size display_size =
843 display::Screen::GetScreen()->GetPrimaryDisplay().size();
844 const gfx::Size buffer_size(display_size);
758 Buffer buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)); 845 Buffer buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size));
759 Surface surface; 846 Surface surface;
760 ShellSurface shell_surface(&surface, nullptr, gfx::Rect(640, 480), true, 847 ShellSurface shell_surface(&surface, nullptr, gfx::Rect(100, 100), true,
761 false, ash::kShellWindowId_DefaultContainer); 848 false, ash::kShellWindowId_DefaultContainer);
762
763 surface.Attach(&buffer); 849 surface.Attach(&buffer);
764 850
765 gfx::Rect shadow_bounds(10, 10, 100, 100); 851 gfx::Rect shadow_bounds(10, 10, 100, 100);
766 shell_surface.SetRectangularShadow(true); 852 shell_surface.SetGeometry(shadow_bounds);
767 shell_surface.SetRectangularShadowContentBounds(shadow_bounds); 853 shell_surface.SetRectangularSurfaceShadow(shadow_bounds);
768 surface.Commit(); 854 surface.Commit();
855 EXPECT_EQ(shadow_bounds,
856 shell_surface.GetWidget()->GetWindowBoundsInScreen());
769 ASSERT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds()); 857 ASSERT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds());
770 858
771 aura::Window* shell_window = shell_surface.GetWidget()->GetNativeWindow(); 859 aura::Window* shell_window = shell_surface.GetWidget()->GetNativeWindow();
772 aura::WindowTargeter* targeter = static_cast<aura::WindowTargeter*>( 860 aura::WindowTargeter* targeter = static_cast<aura::WindowTargeter*>(
773 static_cast<ui::EventTarget*>(shell_window)->GetEventTargeter()); 861 static_cast<ui::EventTarget*>(shell_window)->GetEventTargeter());
774 862
775 gfx::Point pt(300, 300); 863 gfx::Point pt_out(300, 300);
776 ui::MouseEvent ev_out(ui::ET_MOUSE_PRESSED, pt, pt, ui::EventTimeForNow(), 864 ui::MouseEvent ev_out(ui::ET_MOUSE_PRESSED, pt_out, pt_out,
777 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 865 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
778 gfx::Point pt2(250, 250); 866 ui::EF_LEFT_MOUSE_BUTTON);
779 ui::MouseEvent ev_in(ui::ET_MOUSE_PRESSED, pt2, pt2, ui::EventTimeForNow(), 867 gfx::Point pt_in(70, 70);
780 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); 868 ui::MouseEvent ev_in(ui::ET_MOUSE_PRESSED, pt_in, pt_in,
869 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
870 ui::EF_LEFT_MOUSE_BUTTON);
781 871
782 EXPECT_FALSE(targeter->SubtreeShouldBeExploredForEvent(shell_window, ev_out)); 872 EXPECT_FALSE(targeter->SubtreeShouldBeExploredForEvent(shell_window, ev_out));
783 873
784 // Enable spoken feedback. 874 // Enable spoken feedback.
785 ash::WmShell::Get()->accessibility_delegate()->ToggleSpokenFeedback( 875 ash::WmShell::Get()->accessibility_delegate()->ToggleSpokenFeedback(
786 ash::A11Y_NOTIFICATION_NONE); 876 ash::A11Y_NOTIFICATION_NONE);
787 shell_surface.OnAccessibilityModeChanged(); 877 shell_surface.OnAccessibilityModeChanged();
788 878
789 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().bounds(), 879 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().bounds(),
790 shell_surface.shadow_underlay()->bounds()); 880 shell_surface.shadow_underlay()->bounds());
791 EXPECT_TRUE(shell_surface.shadow_underlay()->IsVisible()); 881 EXPECT_TRUE(shell_surface.shadow_underlay()->IsVisible());
792 EXPECT_NE(shell_surface.GetWidget()->GetWindowBoundsInScreen(), 882 EXPECT_NE(shell_surface.GetWidget()->GetWindowBoundsInScreen(),
793 shell_surface.shadow_underlay()->bounds()); 883 shell_surface.shadow_underlay()->bounds());
794 884
795 // Test event capture 885 // Test event capture
796 EXPECT_TRUE(targeter->SubtreeShouldBeExploredForEvent(shell_window, ev_out)); 886 EXPECT_TRUE(targeter->SubtreeShouldBeExploredForEvent(shell_window, ev_out));
797 EXPECT_EQ(shell_surface.shadow_underlay(), 887 EXPECT_EQ(shell_surface.shadow_underlay(),
798 static_cast<ui::EventTargeter*>(targeter)->FindTargetForEvent( 888 static_cast<ui::EventTargeter*>(targeter)->FindTargetForEvent(
799 shell_window, &ev_out)); 889 shell_window, &ev_out));
800 EXPECT_NE(shell_surface.shadow_underlay(), 890 EXPECT_NE(shell_surface.shadow_underlay(),
801 static_cast<ui::EventTargeter*>(targeter)->FindTargetForEvent( 891 static_cast<ui::EventTargeter*>(targeter)->FindTargetForEvent(
802 shell_window, &ev_in)); 892 shell_window, &ev_in));
803 893
804 // Create a new surface 894 // Create a new surface
805 Buffer buffer2(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)); 895 Buffer buffer2(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size));
806 Surface surface2; 896 Surface surface2;
807 ShellSurface shell_surface2(&surface2, nullptr, gfx::Rect(640, 480), true, 897 ShellSurface shell_surface2(&surface2, nullptr, gfx::Rect(640, 480), true,
808 false, ash::kShellWindowId_DefaultContainer); 898 false, ash::kShellWindowId_DefaultContainer);
809 surface2.Attach(&buffer2); 899 surface2.Attach(&buffer2);
810 shell_surface2.SetRectangularShadow(true); 900 shell_surface2.SetRectangularSurfaceShadow(shadow_bounds);
811 shell_surface2.SetRectangularShadowContentBounds(shadow_bounds);
812 surface2.Commit(); 901 surface2.Commit();
813 902
814 // spoken-feedback was already on, so underlay should fill screen 903 // spoken-feedback was already on, so underlay should fill screen
815 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().bounds(), 904 EXPECT_EQ(display::Screen::GetScreen()->GetPrimaryDisplay().bounds(),
816 shell_surface2.shadow_underlay()->bounds()); 905 shell_surface2.shadow_underlay()->bounds());
817 906
818 // De-activated shell-surface should NOT have fullscreen underlay 907 // De-activated shell-surface should NOT have fullscreen underlay
819 EXPECT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds()); 908 EXPECT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds());
820 909
821 // Disable spoken feedback. Shadow underlay is restored. 910 // Disable spoken feedback. Shadow underlay is restored.
822 ash::WmShell::Get()->accessibility_delegate()->ToggleSpokenFeedback( 911 ash::WmShell::Get()->accessibility_delegate()->ToggleSpokenFeedback(
823 ash::A11Y_NOTIFICATION_NONE); 912 ash::A11Y_NOTIFICATION_NONE);
824 shell_surface.OnAccessibilityModeChanged(); 913 shell_surface.OnAccessibilityModeChanged();
825 shell_surface2.OnAccessibilityModeChanged(); 914 shell_surface2.OnAccessibilityModeChanged();
826 915
827 EXPECT_TRUE(shell_surface.shadow_underlay()->IsVisible()); 916 EXPECT_TRUE(shell_surface.shadow_underlay()->IsVisible());
828 EXPECT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds()); 917 EXPECT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds());
829 EXPECT_EQ(shadow_bounds, shell_surface2.shadow_underlay()->bounds()); 918 EXPECT_EQ(shadow_bounds, shell_surface2.shadow_underlay()->bounds());
830 } 919 }
831 920
832 } // namespace 921 } // namespace
833 } // namespace exo 922 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/shell_surface.cc ('k') | components/exo/wayland/server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698