diff options
-rw-r--r-- | ash/shell.cc | 4 | ||||
-rw-r--r-- | ash/shell.h | 6 | ||||
-rw-r--r-- | ash/shell_unittest.cc | 1 | ||||
-rw-r--r-- | ash/wm/system_modal_container_layout_manager.cc | 7 | ||||
-rw-r--r-- | ash/wm/system_modal_container_layout_manager_unittest.cc | 80 |
5 files changed, 78 insertions, 20 deletions
diff --git a/ash/shell.cc b/ash/shell.cc index a69277e..2a2cc58 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -673,7 +673,7 @@ void Shell::SetDimming(bool should_dim) { (*iter)->screen_dimmer()->SetDimming(should_dim); } -void Shell::CreateModalBackground() { +void Shell::CreateModalBackground(aura::Window* window) { if (!modality_filter_.get()) { modality_filter_.reset(new internal::SystemModalContainerEventFilter(this)); AddEnvEventFilter(modality_filter_.get()); @@ -681,7 +681,7 @@ void Shell::CreateModalBackground() { RootWindowControllerList controllers = GetAllRootWindowControllers(); for (RootWindowControllerList::iterator iter = controllers.begin(); iter != controllers.end(); ++iter) - (*iter)->GetSystemModalLayoutManager(NULL)->CreateModalBackground(); + (*iter)->GetSystemModalLayoutManager(window)->CreateModalBackground(); } void Shell::OnModalWindowRemoved(aura::Window* removed) { diff --git a/ash/shell.h b/ash/shell.h index d744b2a..430e0c2 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -350,9 +350,9 @@ class ASH_EXPORT Shell : internal::SystemModalContainerEventFilterDelegate{ // Dims or undims the screen. void SetDimming(bool should_dim); - // Creates modal background, which is a partially-opaque fullscreen - // window, on all displays. - void CreateModalBackground(); + // Creates a modal background (a partially-opaque fullscreen window) + // on all displays for |window|. + void CreateModalBackground(aura::Window* window); // Called when a modal window is removed. It will activate // another modal window if any, or remove modal screens diff --git a/ash/shell_unittest.cc b/ash/shell_unittest.cc index d9f1eb5..1d0811b 100644 --- a/ash/shell_unittest.cc +++ b/ash/shell_unittest.cc @@ -216,6 +216,7 @@ TEST_F(ShellTest, CreateLockScreenModalWindow) { EXPECT_TRUE(GetDefaultContainer()->Contains( widget->GetNativeWindow()->parent())); + Shell::GetInstance()->delegate()->LockScreen(); // Create a LockScreen window. views::Widget* lock_widget = CreateTestWindow(widget_params); ash::Shell::GetContainer( diff --git a/ash/wm/system_modal_container_layout_manager.cc b/ash/wm/system_modal_container_layout_manager.cc index 22dadc8..570cdbe 100644 --- a/ash/wm/system_modal_container_layout_manager.cc +++ b/ash/wm/system_modal_container_layout_manager.cc @@ -6,6 +6,7 @@ #include "ash/ash_switches.h" #include "ash/shell.h" +#include "ash/shell_delegate.h" #include "ash/shell_window_ids.h" #include "ash/wm/system_modal_container_event_filter.h" #include "ash/wm/window_animations.h" @@ -91,6 +92,10 @@ void SystemModalContainerLayoutManager::OnWindowAddedToLayout( DCHECK((modal_background_ && child == modal_background_->GetNativeView()) || child->type() == aura::client::WINDOW_TYPE_NORMAL || child->type() == aura::client::WINDOW_TYPE_POPUP); + DCHECK( + container_->id() != internal::kShellWindowId_LockSystemModalContainer || + Shell::GetInstance()->delegate()->IsScreenLocked()); + child->AddObserver(this); if (child->GetProperty(aura::client::kModalKey) != ui::MODAL_TYPE_NONE) AddModalWindow(child); @@ -222,7 +227,7 @@ void SystemModalContainerLayoutManager::AddModalWindow(aura::Window* window) { capture_window->ReleaseCapture(); } modal_windows_.push_back(window); - Shell::GetInstance()->CreateModalBackground(); + Shell::GetInstance()->CreateModalBackground(window); } void SystemModalContainerLayoutManager::RemoveModalWindow( diff --git a/ash/wm/system_modal_container_layout_manager_unittest.cc b/ash/wm/system_modal_container_layout_manager_unittest.cc index bea55ee..2742e5a 100644 --- a/ash/wm/system_modal_container_layout_manager_unittest.cc +++ b/ash/wm/system_modal_container_layout_manager_unittest.cc @@ -26,24 +26,32 @@ namespace test { namespace { aura::Window* GetModalContainer() { - return Shell::GetContainer( - Shell::GetPrimaryRootWindow(), + return Shell::GetPrimaryRootWindowController()->GetContainer( ash::internal::kShellWindowId_SystemModalContainer); } -bool AllRootWindowsHaveModalBackgrounds() { - Shell::RootWindowControllerList controllers = - Shell::GetAllRootWindowControllers(); - bool has_modal_screen = !controllers.empty(); - for (Shell::RootWindowControllerList::const_iterator iter = - controllers.begin(); - iter != controllers.end(); ++iter) { +bool AllRootWindowsHaveModalBackgroundsForContainer(int container_id) { + std::vector<aura::Window*> containers = Shell::GetAllContainers(container_id); + bool has_modal_screen = !containers.empty(); + for (std::vector<aura::Window*>::iterator iter = containers.begin(); + iter != containers.end(); ++iter) { has_modal_screen &= - (*iter)->GetSystemModalLayoutManager(NULL)->has_modal_background(); + static_cast<internal::SystemModalContainerLayoutManager*>( + (*iter)->layout_manager())->has_modal_background(); } return has_modal_screen; } +bool AllRootWindowsHaveLockedModalBackgrounds() { + return AllRootWindowsHaveModalBackgroundsForContainer( + internal::kShellWindowId_LockSystemModalContainer); +} + +bool AllRootWindowsHaveModalBackgrounds() { + return AllRootWindowsHaveModalBackgroundsForContainer( + internal::kShellWindowId_SystemModalContainer); +} + class TestWindow : public views::WidgetDelegateView { public: explicit TestWindow(bool modal) : modal_(modal) {} @@ -281,8 +289,7 @@ TEST_F(SystemModalContainerLayoutManagerTest, EventFocusContainers) { Shell::GetInstance()->delegate()->LockScreen(); EventTestWindow* lock_delegate = new EventTestWindow(false); scoped_ptr<aura::Window> lock(lock_delegate->OpenTestWindow( - Shell::GetContainer( - Shell::GetPrimaryRootWindow(), + Shell::GetPrimaryRootWindowController()->GetContainer( ash::internal::kShellWindowId_LockScreenContainer))); EXPECT_TRUE(wm::IsActiveWindow(lock.get())); e1.ClickLeftButton(); @@ -308,8 +315,7 @@ TEST_F(SystemModalContainerLayoutManagerTest, EventFocusContainers) { // is hidden. TEST_F(SystemModalContainerLayoutManagerTest, ShowModalWhileHidden) { // Hide the lock screen. - Shell::GetContainer( - Shell::GetPrimaryRootWindow(), + Shell::GetPrimaryRootWindowController()->GetContainer( internal::kShellWindowId_SystemModalContainer)->layer()->SetOpacity(0); // Create a modal window. @@ -356,6 +362,52 @@ TEST_F(SystemModalContainerLayoutManagerTest, KeepVisible) { EXPECT_EQ(bounds, gfx::Rect(700, 500, 100, 100)); } +TEST_F(SystemModalContainerLayoutManagerTest, ShowNormalBackgroundOrLocked) { + scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); + scoped_ptr<aura::Window> modal_window( + TestWindow::OpenTestWindow(parent.get(), true)); + parent->Show(); + modal_window->Show(); + + // Normal system modal window. Shows normal system modal background and not + // locked. + EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); + EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); + + modal_window.reset(); + EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); + EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); + + // Normal system modal window while locked. Shows locked system modal + // background. + Shell::GetInstance()->delegate()->LockScreen(); + scoped_ptr<aura::Window> lock_parent(TestWindow::OpenTestWindow( + Shell::GetPrimaryRootWindowController()->GetContainer( + ash::internal::kShellWindowId_LockScreenContainer), + false)); + scoped_ptr<aura::Window> lock_modal_window(TestWindow::OpenTestWindow( + lock_parent.get(), true)); + lock_parent->Show(); + lock_modal_window->Show(); + EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); + EXPECT_TRUE(AllRootWindowsHaveLockedModalBackgrounds()); + lock_modal_window.reset(); + + // Normal system modal window while locked, but it belongs to the normal + // window. Shouldn't show locked system modal background, but normal. + scoped_ptr<aura::Window> modal_window2( + TestWindow::OpenTestWindow(parent.get(), true)); + modal_window2->Show(); + EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); + EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); + modal_window2.reset(); + + // Here we should check the behavior of the locked system modal dialog when + // unlocked, but such case isn't handled very well right now. + // See crbug.com/157660 + // TODO(mukai): add the test case when the bug is fixed. +} + TEST_F(SystemModalContainerLayoutManagerTest, MultiDisplays) { UpdateDisplay("500x500,500x500"); |