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 "ash/display/display_controller.h" | 5 #include "ash/display/display_controller.h" |
6 #include "ash/display/multi_display_manager.h" | 6 #include "ash/display/multi_display_manager.h" |
7 #include "ash/screen_ash.h" | |
8 #include "ash/shell.h" | 7 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | |
10 #include "ash/system/tray/system_tray.h" | 8 #include "ash/system/tray/system_tray.h" |
11 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
12 #include "ash/wm/coordinate_conversion.h" | 10 #include "ash/wm/coordinate_conversion.h" |
13 #include "ash/wm/property_util.h" | 11 #include "ash/wm/property_util.h" |
14 #include "ash/wm/window_cycle_controller.h" | 12 #include "ash/wm/window_cycle_controller.h" |
15 #include "ash/wm/window_properties.h" | 13 #include "ash/wm/window_properties.h" |
16 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
17 #include "base/string_util.h" | |
18 #include "ui/aura/client/activation_client.h" | 15 #include "ui/aura/client/activation_client.h" |
19 #include "ui/aura/client/capture_client.h" | 16 #include "ui/aura/client/capture_client.h" |
20 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
21 #include "ui/aura/focus_manager.h" | 18 #include "ui/aura/focus_manager.h" |
22 #include "ui/aura/root_window.h" | 19 #include "ui/aura/root_window.h" |
23 #include "ui/aura/test/event_generator.h" | 20 #include "ui/aura/test/event_generator.h" |
24 #include "ui/aura/test/test_windows.h" | 21 #include "ui/aura/test/test_windows.h" |
25 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
26 #include "ui/base/cursor/cursor.h" | 23 #include "ui/base/cursor/cursor.h" |
27 #include "ui/gfx/display.h" | 24 #include "ui/gfx/display.h" |
28 #include "ui/gfx/screen.h" | 25 #include "ui/gfx/screen.h" |
29 #include "ui/views/controls/textfield/textfield.h" | |
30 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
31 #include "ui/views/widget/widget_delegate.h" | 27 #include "ui/views/widget/widget_delegate.h" |
32 | 28 |
33 namespace ash { | 29 namespace ash { |
34 namespace { | 30 namespace { |
35 | 31 |
36 views::Widget* CreateTestWidgetWithParent(views::Widget* parent, | 32 views::Widget* CreateTestWidgetWithParent(views::Widget* parent, |
37 const gfx::Rect& bounds, | 33 const gfx::Rect& bounds, |
38 bool child) { | 34 bool child) { |
39 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 35 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 w1->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true); | 592 w1->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true); |
597 w1->SetBounds(gfx::Rect(10, 10, 50, 50)); | 593 w1->SetBounds(gfx::Rect(10, 10, 50, 50)); |
598 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); | 594 EXPECT_EQ(root_windows[1], w1->GetNativeView()->GetRootWindow()); |
599 | 595 |
600 // The widget should now move to the 1st root window without the property. | 596 // The widget should now move to the 1st root window without the property. |
601 w1->GetNativeView()->ClearProperty(internal::kStayInSameRootWindowKey); | 597 w1->GetNativeView()->ClearProperty(internal::kStayInSameRootWindowKey); |
602 w1->SetBounds(gfx::Rect(10, 10, 50, 50)); | 598 w1->SetBounds(gfx::Rect(10, 10, 50, 50)); |
603 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); | 599 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
604 } | 600 } |
605 | 601 |
606 TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) { | |
607 UpdateDisplay("100x100,200x200"); | |
608 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
609 | |
610 // Create normal windows on both displays. | |
611 views::Widget* widget1 = CreateTestWidget( | |
612 gfx::Screen::GetPrimaryDisplay().bounds()); | |
613 widget1->Show(); | |
614 EXPECT_EQ(root_windows[0], widget1->GetNativeView()->GetRootWindow()); | |
615 views::Widget* widget2 = CreateTestWidget( | |
616 ScreenAsh::GetSecondaryDisplay().bounds()); | |
617 widget2->Show(); | |
618 EXPECT_EQ(root_windows[1], widget2->GetNativeView()->GetRootWindow()); | |
619 | |
620 // Create a LockScreen window. | |
621 views::Widget* lock_widget = CreateTestWidget( | |
622 gfx::Screen::GetPrimaryDisplay().bounds()); | |
623 views::Textfield* textfield = new views::Textfield; | |
624 lock_widget->SetContentsView(textfield); | |
625 | |
626 ash::Shell::GetContainer( | |
627 Shell::GetPrimaryRootWindow(), | |
628 ash::internal::kShellWindowId_LockScreenContainer)-> | |
629 AddChild(lock_widget->GetNativeView()); | |
630 lock_widget->Show(); | |
631 textfield->RequestFocus(); | |
632 | |
633 aura::FocusManager* focus_manager = root_windows[0]->GetFocusManager(); | |
634 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); | |
635 | |
636 // The lock window should get events on both root windows. | |
637 aura::test::EventGenerator generator1(root_windows[0]); | |
638 generator1.PressKey(ui::VKEY_A, 0); | |
639 generator1.ReleaseKey(ui::VKEY_A, 0); | |
640 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); | |
641 EXPECT_EQ("a", UTF16ToASCII(textfield->text())); | |
642 | |
643 aura::test::EventGenerator generator2(root_windows[1]); | |
644 generator2.PressKey(ui::VKEY_B, 0); | |
645 generator2.ReleaseKey(ui::VKEY_B, 0); | |
646 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); | |
647 EXPECT_EQ("ab", UTF16ToASCII(textfield->text())); | |
648 | |
649 // Deleting 2nd display. The lock window still should get the events. | |
650 UpdateDisplay("100x100"); | |
651 generator2.PressKey(ui::VKEY_C, 0); | |
652 generator2.ReleaseKey(ui::VKEY_C, 0); | |
653 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); | |
654 EXPECT_EQ("abc", UTF16ToASCII(textfield->text())); | |
655 | |
656 // Creating 2nd display again, and lock window still should get events | |
657 // on both root windows. | |
658 UpdateDisplay("100x100,200x200"); | |
659 root_windows = Shell::GetAllRootWindows(); | |
660 generator1.PressKey(ui::VKEY_D, 0); | |
661 generator1.ReleaseKey(ui::VKEY_D, 0); | |
662 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); | |
663 EXPECT_EQ("abcd", UTF16ToASCII(textfield->text())); | |
664 | |
665 aura::test::EventGenerator generator22(root_windows[1]); | |
666 generator22.PressKey(ui::VKEY_E, 0); | |
667 generator22.ReleaseKey(ui::VKEY_E, 0); | |
668 EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow()); | |
669 EXPECT_EQ("abcde", UTF16ToASCII(textfield->text())); | |
670 } | |
671 | |
672 } // namespace internal | 602 } // namespace internal |
673 } // namespace ash | 603 } // namespace ash |
OLD | NEW |