| 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/wm/system_modal_container_layout_manager.h" | 5 #include "ash/wm/system_modal_container_layout_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
| 10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 ash::kShellWindowId_SystemModalContainer); | 43 ash::kShellWindowId_SystemModalContainer); |
| 44 } | 44 } |
| 45 | 45 |
| 46 bool AllRootWindowsHaveModalBackgroundsForContainer(int container_id) { | 46 bool AllRootWindowsHaveModalBackgroundsForContainer(int container_id) { |
| 47 std::vector<aura::Window*> containers = | 47 std::vector<aura::Window*> containers = |
| 48 Shell::GetContainersFromAllRootWindows(container_id, NULL); | 48 Shell::GetContainersFromAllRootWindows(container_id, NULL); |
| 49 bool has_modal_screen = !containers.empty(); | 49 bool has_modal_screen = !containers.empty(); |
| 50 for (std::vector<aura::Window*>::iterator iter = containers.begin(); | 50 for (std::vector<aura::Window*>::iterator iter = containers.begin(); |
| 51 iter != containers.end(); ++iter) { | 51 iter != containers.end(); ++iter) { |
| 52 has_modal_screen &= static_cast<SystemModalContainerLayoutManager*>( | 52 has_modal_screen &= static_cast<SystemModalContainerLayoutManager*>( |
| 53 (*iter)->layout_manager())->has_modal_background(); | 53 (*iter)->layout_manager()) |
| 54 ->has_modal_background(); |
| 54 } | 55 } |
| 55 return has_modal_screen; | 56 return has_modal_screen; |
| 56 } | 57 } |
| 57 | 58 |
| 58 bool AllRootWindowsHaveLockedModalBackgrounds() { | 59 bool AllRootWindowsHaveLockedModalBackgrounds() { |
| 59 return AllRootWindowsHaveModalBackgroundsForContainer( | 60 return AllRootWindowsHaveModalBackgroundsForContainer( |
| 60 kShellWindowId_LockSystemModalContainer); | 61 kShellWindowId_LockSystemModalContainer); |
| 61 } | 62 } |
| 62 | 63 |
| 63 bool AllRootWindowsHaveModalBackgrounds() { | 64 bool AllRootWindowsHaveModalBackgrounds() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 86 } | 87 } |
| 87 | 88 |
| 88 private: | 89 private: |
| 89 bool modal_; | 90 bool modal_; |
| 90 | 91 |
| 91 DISALLOW_COPY_AND_ASSIGN(TestWindow); | 92 DISALLOW_COPY_AND_ASSIGN(TestWindow); |
| 92 }; | 93 }; |
| 93 | 94 |
| 94 class EventTestWindow : public TestWindow { | 95 class EventTestWindow : public TestWindow { |
| 95 public: | 96 public: |
| 96 explicit EventTestWindow(bool modal) : TestWindow(modal), | 97 explicit EventTestWindow(bool modal) : TestWindow(modal), mouse_presses_(0) {} |
| 97 mouse_presses_(0) {} | |
| 98 ~EventTestWindow() override {} | 98 ~EventTestWindow() override {} |
| 99 | 99 |
| 100 aura::Window* OpenTestWindowWithContext(aura::Window* context) { | 100 aura::Window* OpenTestWindowWithContext(aura::Window* context) { |
| 101 views::Widget* widget = | 101 views::Widget* widget = |
| 102 views::Widget::CreateWindowWithContext(this, context); | 102 views::Widget::CreateWindowWithContext(this, context); |
| 103 widget->Show(); | 103 widget->Show(); |
| 104 return widget->GetNativeView(); | 104 return widget->GetNativeView(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 aura::Window* OpenTestWindowWithParent(aura::Window* parent) { | 107 aura::Window* OpenTestWindowWithParent(aura::Window* parent) { |
| 108 DCHECK(parent); | 108 DCHECK(parent); |
| 109 views::Widget* widget = | 109 views::Widget* widget = views::Widget::CreateWindowWithParent(this, parent); |
| 110 views::Widget::CreateWindowWithParent(this, parent); | |
| 111 widget->Show(); | 110 widget->Show(); |
| 112 return widget->GetNativeView(); | 111 return widget->GetNativeView(); |
| 113 } | 112 } |
| 114 | 113 |
| 115 // Overridden from views::View: | 114 // Overridden from views::View: |
| 116 bool OnMousePressed(const ui::MouseEvent& event) override { | 115 bool OnMousePressed(const ui::MouseEvent& event) override { |
| 117 mouse_presses_++; | 116 mouse_presses_++; |
| 118 return false; | 117 return false; |
| 119 } | 118 } |
| 120 | 119 |
| 121 int mouse_presses() const { return mouse_presses_; } | 120 int mouse_presses() const { return mouse_presses_; } |
| 121 |
| 122 private: | 122 private: |
| 123 int mouse_presses_; | 123 int mouse_presses_; |
| 124 | 124 |
| 125 DISALLOW_COPY_AND_ASSIGN(EventTestWindow); | 125 DISALLOW_COPY_AND_ASSIGN(EventTestWindow); |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 class TransientWindowObserver : public aura::WindowObserver { | 128 class TransientWindowObserver : public aura::WindowObserver { |
| 129 public: | 129 public: |
| 130 TransientWindowObserver() : destroyed_(false) {} | 130 TransientWindowObserver() : destroyed_(false) {} |
| 131 ~TransientWindowObserver() override {} | 131 ~TransientWindowObserver() override {} |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 keyboard->ui()->GetKeyboardWindow()->SetBounds( | 188 keyboard->ui()->GetKeyboardWindow()->SetBounds( |
| 189 keyboard::FullWidthKeyboardBoundsFromRootBounds( | 189 keyboard::FullWidthKeyboardBoundsFromRootBounds( |
| 190 Shell::GetPrimaryRootWindow()->bounds(), 100)); | 190 Shell::GetPrimaryRootWindow()->bounds(), 100)); |
| 191 } | 191 } |
| 192 } else { | 192 } else { |
| 193 keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL); | 193 keyboard->HideKeyboard(keyboard::KeyboardController::HIDE_REASON_MANUAL); |
| 194 } | 194 } |
| 195 | 195 |
| 196 DCHECK_EQ(show, keyboard->keyboard_visible()); | 196 DCHECK_EQ(show, keyboard->keyboard_visible()); |
| 197 } | 197 } |
| 198 | |
| 199 }; | 198 }; |
| 200 | 199 |
| 201 TEST_F(SystemModalContainerLayoutManagerTest, NonModalTransient) { | 200 TEST_F(SystemModalContainerLayoutManagerTest, NonModalTransient) { |
| 202 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); | 201 std::unique_ptr<aura::Window> parent(OpenToplevelTestWindow(false)); |
| 203 aura::Window* transient = OpenTestWindowWithParent(parent.get(), false); | 202 aura::Window* transient = OpenTestWindowWithParent(parent.get(), false); |
| 204 TransientWindowObserver destruction_observer; | 203 TransientWindowObserver destruction_observer; |
| 205 transient->AddObserver(&destruction_observer); | 204 transient->AddObserver(&destruction_observer); |
| 206 | 205 |
| 207 EXPECT_EQ(parent.get(), ::wm::GetTransientParent(transient)); | 206 EXPECT_EQ(parent.get(), ::wm::GetTransientParent(transient)); |
| 208 EXPECT_EQ(parent->parent(), transient->parent()); | 207 EXPECT_EQ(parent->parent(), transient->parent()); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 // Create a modal window for the main window and verify that the main window | 339 // Create a modal window for the main window and verify that the main window |
| 341 // no longer receives mouse events. | 340 // no longer receives mouse events. |
| 342 EventTestWindow* transient_delegate = new EventTestWindow(true); | 341 EventTestWindow* transient_delegate = new EventTestWindow(true); |
| 343 aura::Window* transient = | 342 aura::Window* transient = |
| 344 transient_delegate->OpenTestWindowWithParent(main.get()); | 343 transient_delegate->OpenTestWindowWithParent(main.get()); |
| 345 EXPECT_TRUE(wm::IsActiveWindow(transient)); | 344 EXPECT_TRUE(wm::IsActiveWindow(transient)); |
| 346 e1.ClickLeftButton(); | 345 e1.ClickLeftButton(); |
| 347 EXPECT_EQ(1, transient_delegate->mouse_presses()); | 346 EXPECT_EQ(1, transient_delegate->mouse_presses()); |
| 348 | 347 |
| 349 for (int block_reason = FIRST_BLOCK_REASON; | 348 for (int block_reason = FIRST_BLOCK_REASON; |
| 350 block_reason < NUMBER_OF_BLOCK_REASONS; | 349 block_reason < NUMBER_OF_BLOCK_REASONS; ++block_reason) { |
| 351 ++block_reason) { | |
| 352 // Create a window in the lock screen container and ensure that it receives | 350 // Create a window in the lock screen container and ensure that it receives |
| 353 // the mouse event instead of the modal window (crbug.com/110920). | 351 // the mouse event instead of the modal window (crbug.com/110920). |
| 354 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); | 352 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 355 EventTestWindow* lock_delegate = new EventTestWindow(false); | 353 EventTestWindow* lock_delegate = new EventTestWindow(false); |
| 356 std::unique_ptr<aura::Window> lock(lock_delegate->OpenTestWindowWithParent( | 354 std::unique_ptr<aura::Window> lock(lock_delegate->OpenTestWindowWithParent( |
| 357 Shell::GetPrimaryRootWindowController()->GetContainer( | 355 Shell::GetPrimaryRootWindowController()->GetContainer( |
| 358 ash::kShellWindowId_LockScreenContainer))); | 356 ash::kShellWindowId_LockScreenContainer))); |
| 359 EXPECT_TRUE(wm::IsActiveWindow(lock.get())); | 357 EXPECT_TRUE(wm::IsActiveWindow(lock.get())); |
| 360 e1.ClickLeftButton(); | 358 e1.ClickLeftButton(); |
| 361 EXPECT_EQ(1, lock_delegate->mouse_presses()); | 359 EXPECT_EQ(1, lock_delegate->mouse_presses()); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 // Normal system modal window. Shows normal system modal background and not | 455 // Normal system modal window. Shows normal system modal background and not |
| 458 // locked. | 456 // locked. |
| 459 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); | 457 EXPECT_TRUE(AllRootWindowsHaveModalBackgrounds()); |
| 460 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); | 458 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); |
| 461 | 459 |
| 462 TestWindow::CloseTestWindow(modal_window.release()); | 460 TestWindow::CloseTestWindow(modal_window.release()); |
| 463 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); | 461 EXPECT_FALSE(AllRootWindowsHaveModalBackgrounds()); |
| 464 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); | 462 EXPECT_FALSE(AllRootWindowsHaveLockedModalBackgrounds()); |
| 465 | 463 |
| 466 for (int block_reason = FIRST_BLOCK_REASON; | 464 for (int block_reason = FIRST_BLOCK_REASON; |
| 467 block_reason < NUMBER_OF_BLOCK_REASONS; | 465 block_reason < NUMBER_OF_BLOCK_REASONS; ++block_reason) { |
| 468 ++block_reason) { | |
| 469 // Normal system modal window while blocked. Shows blocked system modal | 466 // Normal system modal window while blocked. Shows blocked system modal |
| 470 // background. | 467 // background. |
| 471 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); | 468 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason)); |
| 472 std::unique_ptr<aura::Window> lock_parent(OpenTestWindowWithParent( | 469 std::unique_ptr<aura::Window> lock_parent(OpenTestWindowWithParent( |
| 473 Shell::GetPrimaryRootWindowController()->GetContainer( | 470 Shell::GetPrimaryRootWindowController()->GetContainer( |
| 474 ash::kShellWindowId_LockScreenContainer), | 471 ash::kShellWindowId_LockScreenContainer), |
| 475 false)); | 472 false)); |
| 476 std::unique_ptr<aura::Window> lock_modal_window( | 473 std::unique_ptr<aura::Window> lock_modal_window( |
| 477 OpenTestWindowWithParent(lock_parent.get(), true)); | 474 OpenTestWindowWithParent(lock_parent.get(), true)); |
| 478 lock_parent->Show(); | 475 lock_parent->Show(); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 if (!SupportsMultipleDisplays()) | 770 if (!SupportsMultipleDisplays()) |
| 774 return; | 771 return; |
| 775 | 772 |
| 776 UpdateDisplay("500x500, 500x500"); | 773 UpdateDisplay("500x500, 500x500"); |
| 777 InputTestDelegate delegate; | 774 InputTestDelegate delegate; |
| 778 delegate.RunTest(this); | 775 delegate.RunTest(this); |
| 779 } | 776 } |
| 780 | 777 |
| 781 } // namespace test | 778 } // namespace test |
| 782 } // namespace ash | 779 } // namespace ash |
| OLD | NEW |