OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/aura/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "ui/aura/client/stacking_client.h" | 11 #include "ui/aura/client/stacking_client.h" |
12 #include "ui/aura/desktop.h" | 12 #include "ui/aura/desktop.h" |
13 #include "ui/aura/desktop_observer.h" | 13 #include "ui/aura/desktop_observer.h" |
14 #include "ui/aura/event.h" | 14 #include "ui/aura/event.h" |
15 #include "ui/aura/focus_manager.h" | 15 #include "ui/aura/focus_manager.h" |
| 16 #include "ui/aura/shadow.h" |
16 #include "ui/aura/test/aura_test_base.h" | 17 #include "ui/aura/test/aura_test_base.h" |
17 #include "ui/aura/test/event_generator.h" | 18 #include "ui/aura/test/event_generator.h" |
18 #include "ui/aura/test/test_windows.h" | 19 #include "ui/aura/test/test_windows.h" |
19 #include "ui/aura/test/test_window_delegate.h" | 20 #include "ui/aura/test/test_window_delegate.h" |
20 #include "ui/aura/window_delegate.h" | 21 #include "ui/aura/window_delegate.h" |
21 #include "ui/aura/window_observer.h" | 22 #include "ui/aura/window_observer.h" |
22 #include "ui/base/hit_test.h" | 23 #include "ui/base/hit_test.h" |
23 #include "ui/base/keycodes/keyboard_codes.h" | 24 #include "ui/base/keycodes/keyboard_codes.h" |
24 #include "ui/gfx/canvas_skia.h" | 25 #include "ui/gfx/canvas_skia.h" |
25 #include "ui/gfx/compositor/layer.h" | 26 #include "ui/gfx/compositor/layer.h" |
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 w121->Focus(); | 653 w121->Focus(); |
653 EXPECT_EQ(w121.get(), w1->GetFocusManager()->GetFocusedWindow()); | 654 EXPECT_EQ(w121.get(), w1->GetFocusManager()->GetFocusedWindow()); |
654 | 655 |
655 // An attempt to focus 111 should be ignored and w121 should retain focus, | 656 // An attempt to focus 111 should be ignored and w121 should retain focus, |
656 // since a consumes_events_ window with a child is in the z-index above w111. | 657 // since a consumes_events_ window with a child is in the z-index above w111. |
657 EXPECT_FALSE(w111->CanFocus()); | 658 EXPECT_FALSE(w111->CanFocus()); |
658 w111->Focus(); | 659 w111->Focus(); |
659 EXPECT_EQ(w121.get(), w1->GetFocusManager()->GetFocusedWindow()); | 660 EXPECT_EQ(w121.get(), w1->GetFocusManager()->GetFocusedWindow()); |
660 } | 661 } |
661 | 662 |
| 663 // Tests that various methods in Window update the Shadow object as expected. |
| 664 TEST_F(WindowTest, Shadow) { |
| 665 Window* window = new Window(NULL); |
| 666 window->SetType(aura::WINDOW_TYPE_NORMAL); |
| 667 |
| 668 // It should be safe to call this before the window has been initialized. |
| 669 window->SetShadowVisible(true); |
| 670 window->Init(ui::Layer::LAYER_HAS_TEXTURE); |
| 671 window->SetParent(NULL); |
| 672 |
| 673 // The shadow's layer should have the same parent as the window's. |
| 674 const internal::Shadow* shadow = window->shadow(); |
| 675 ASSERT_TRUE(shadow != NULL); |
| 676 EXPECT_EQ(window->parent()->layer(), shadow->layer()->parent()); |
| 677 |
| 678 // The shadow's visibility should be updated along with the window's. |
| 679 window->Show(); |
| 680 EXPECT_TRUE(shadow->layer()->visible()); |
| 681 window->Hide(); |
| 682 EXPECT_FALSE(shadow->layer()->visible()); |
| 683 |
| 684 // If the shadow is disabled, it shouldn't be shown even when the window is. |
| 685 window->SetShadowVisible(false); |
| 686 window->Show(); |
| 687 EXPECT_FALSE(shadow->layer()->visible()); |
| 688 window->SetShadowVisible(true); |
| 689 EXPECT_TRUE(shadow->layer()->visible()); |
| 690 |
| 691 // TODO(derat): Test stacking (after adding additional methods to ui::Layer so |
| 692 // that stacking order can be queried). |
| 693 |
| 694 // When we remove the window from the hierarchy, its shadow should be removed |
| 695 // too. |
| 696 window->parent()->RemoveChild(window); |
| 697 EXPECT_TRUE(shadow->layer()->parent() == NULL); |
| 698 } |
| 699 |
| 700 // Tests that the window's shadow's bounds are updated correctly. |
| 701 TEST_F(WindowTest, ShadowBounds) { |
| 702 Window* window = new Window(NULL); |
| 703 window->SetType(aura::WINDOW_TYPE_NORMAL); |
| 704 window->Init(ui::Layer::LAYER_HAS_TEXTURE); |
| 705 window->SetParent(NULL); |
| 706 |
| 707 const gfx::Rect kOldBounds(20, 30, 400, 300); |
| 708 window->SetBounds(kOldBounds); |
| 709 |
| 710 // When the shadow is first created, it should use the window's bounds. |
| 711 window->SetShadowVisible(true); |
| 712 const internal::Shadow* shadow = window->shadow(); |
| 713 ASSERT_TRUE(shadow != NULL); |
| 714 EXPECT_EQ(kOldBounds, shadow->content_bounds()); |
| 715 |
| 716 // When we change the window's bounds, the shadow's shoudl be updated too. |
| 717 gfx::Rect kNewBounds(50, 60, 500, 400); |
| 718 window->SetBounds(kNewBounds); |
| 719 EXPECT_EQ(kNewBounds, shadow->content_bounds()); |
| 720 } |
| 721 |
662 // Various assertions for activating/deactivating. | 722 // Various assertions for activating/deactivating. |
663 TEST_F(WindowTest, Deactivate) { | 723 TEST_F(WindowTest, Deactivate) { |
664 TestWindowDelegate d1; | 724 TestWindowDelegate d1; |
665 TestWindowDelegate d2; | 725 TestWindowDelegate d2; |
666 scoped_ptr<Window> w1( | 726 scoped_ptr<Window> w1( |
667 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL)); | 727 CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL)); |
668 scoped_ptr<Window> w2( | 728 scoped_ptr<Window> w2( |
669 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), NULL)); | 729 CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), NULL)); |
670 Window* parent = w1->parent(); | 730 Window* parent = w1->parent(); |
671 parent->Show(); | 731 parent->Show(); |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 | 1111 |
1052 w3->Activate(); | 1112 w3->Activate(); |
1053 EXPECT_EQ(w2.get(), active()); | 1113 EXPECT_EQ(w2.get(), active()); |
1054 | 1114 |
1055 w1->Activate(); | 1115 w1->Activate(); |
1056 EXPECT_EQ(w1.get(), active()); | 1116 EXPECT_EQ(w1.get(), active()); |
1057 } | 1117 } |
1058 | 1118 |
1059 } // namespace test | 1119 } // namespace test |
1060 } // namespace aura | 1120 } // namespace aura |
OLD | NEW |