diff options
-rw-r--r-- | ui/aura_shell/aura_shell.gyp | 2 | ||||
-rw-r--r-- | ui/aura_shell/shell.cc | 17 | ||||
-rw-r--r-- | ui/aura_shell/shell.h | 3 | ||||
-rw-r--r-- | ui/aura_shell/shell_accelerator_controller.cc | 39 | ||||
-rw-r--r-- | ui/aura_shell/shell_accelerator_controller_unittest.cc | 110 | ||||
-rw-r--r-- | ui/aura_shell/shell_unittest.cc | 44 | ||||
-rw-r--r-- | ui/aura_shell/test/aura_shell_test_base.cc | 3 | ||||
-rw-r--r-- | ui/aura_shell/test/test_shell_delegate.cc | 36 | ||||
-rw-r--r-- | ui/aura_shell/test/test_shell_delegate.h | 33 |
9 files changed, 274 insertions, 13 deletions
diff --git a/ui/aura_shell/aura_shell.gyp b/ui/aura_shell/aura_shell.gyp index 23bd5b1..005d3a1 100644 --- a/ui/aura_shell/aura_shell.gyp +++ b/ui/aura_shell/aura_shell.gyp @@ -164,6 +164,8 @@ 'test/aura_shell_test_base.h', 'test/test_activation_delegate.cc', 'test/test_activation_delegate.h', + 'test/test_shell_delegate.cc', + 'test/test_shell_delegate.h', 'toplevel_layout_manager_unittest.cc', 'toplevel_window_event_filter_unittest.cc', 'workspace_controller_unittest.cc', diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc index 87be5ac..51c1b99 100644 --- a/ui/aura_shell/shell.cc +++ b/ui/aura_shell/shell.cc @@ -4,6 +4,8 @@ #include "ui/aura_shell/shell.h" +#include <algorithm> + #include "base/bind.h" #include "base/command_line.h" #include "ui/aura/aura_switches.h" @@ -285,6 +287,21 @@ void Shell::ToggleAppList() { app_list_->SetVisible(!app_list_->IsVisible()); } +// Returns true if the screen is locked. +bool Shell::IsScreenLocked() const { + const aura::Window* lock_screen_container = GetContainer( + internal::kShellWindowId_LockScreenContainer); + const aura::Window::Windows& lock_screen_windows = + lock_screen_container->children(); + aura::Window::Windows::const_iterator lock_screen_it = + std::find_if(lock_screen_windows.begin(), lock_screen_windows.end(), + std::mem_fun(&aura::Window::IsVisible)); + if (lock_screen_it != lock_screen_windows.end()) + return true; + + return false; +} + //////////////////////////////////////////////////////////////////////////////// // Shell, private: diff --git a/ui/aura_shell/shell.h b/ui/aura_shell/shell.h index cbb904e..80f5060 100644 --- a/ui/aura_shell/shell.h +++ b/ui/aura_shell/shell.h @@ -69,6 +69,9 @@ class AURA_SHELL_EXPORT Shell { // Toggles app list. void ToggleAppList(); + // Returns true if the screen is locked. + bool IsScreenLocked() const; + ShellAcceleratorController* accelerator_controller() { return accelerator_controller_.get(); } diff --git a/ui/aura_shell/shell_accelerator_controller.cc b/ui/aura_shell/shell_accelerator_controller.cc index 74e36d5..8c966ce 100644 --- a/ui/aura_shell/shell_accelerator_controller.cc +++ b/ui/aura_shell/shell_accelerator_controller.cc @@ -7,7 +7,11 @@ #include "base/logging.h" #include "ui/aura/event.h" #include "ui/aura/root_window.h" +#include "ui/aura_shell/launcher/launcher.h" +#include "ui/aura_shell/launcher/launcher_model.h" #include "ui/aura_shell/shell.h" +#include "ui/aura_shell/shell_window_ids.h" +#include "ui/aura_shell/window_util.h" #include "ui/base/accelerators/accelerator.h" #include "ui/base/accelerators/accelerator_manager.h" #include "ui/gfx/compositor/debug_utils.h" @@ -47,16 +51,27 @@ struct AcceleratorData { #endif }; -bool HandleCycleBackward() { - // TODO(mazda): http://crbug.com/105204 - NOTIMPLEMENTED(); - return false; -} - -bool HandleCycleForward() { - // TODO(mazda): http://crbug.com/105204 - NOTIMPLEMENTED(); - return false; +bool HandleCycleWindow(bool forward) { + if (aura_shell::Shell::GetInstance()->IsScreenLocked()) + return false; + + // Use the same order of the windows in LauncherModel to cycle windows. + aura_shell::LauncherModel* model = + aura_shell::Shell::GetInstance()->launcher()->model(); + aura::Window* active_window = aura_shell::GetActiveWindow(); + if (!active_window) { + LOG(ERROR) << "No active window"; + return false; + } + int active_index = model->ItemIndexByWindow(active_window); + if (active_index < 0) { + VLOG(2) << "Active window not found in the launcher model"; + return false; + } + int next_index = (active_index + (forward ? 1 : -1) + model->item_count()) % + model->item_count(); + aura_shell::ActivateWindow(model->items()[next_index].window); + return true; } bool HandleTakeScreenshot() { @@ -166,9 +181,9 @@ bool ShellAcceleratorController::AcceleratorPressed( DCHECK(it != accelerators_.end()); switch (static_cast<AcceleratorAction>(it->second)) { case CYCLE_BACKWARD: - return HandleCycleBackward(); + return HandleCycleWindow(false); case CYCLE_FORWARD: - return HandleCycleForward(); + return HandleCycleWindow(true); case TAKE_SCREENSHOT: return HandleTakeScreenshot(); #if !defined(NDEBUG) diff --git a/ui/aura_shell/shell_accelerator_controller_unittest.cc b/ui/aura_shell/shell_accelerator_controller_unittest.cc index e962d68..d82d33f 100644 --- a/ui/aura_shell/shell_accelerator_controller_unittest.cc +++ b/ui/aura_shell/shell_accelerator_controller_unittest.cc @@ -6,6 +6,7 @@ #include "ui/aura/root_window.h" #include "ui/aura/test/test_window_delegate.h" #include "ui/aura/test/test_windows.h" +#include "ui/aura/window.h" #include "ui/aura_shell/shell.h" #include "ui/aura_shell/shell_accelerator_controller.h" #include "ui/aura_shell/shell_window_ids.h" @@ -207,5 +208,114 @@ TEST_F(ShellAcceleratorControllerTest, GlobalAccelerators) { #endif } +TEST_F(ShellAcceleratorControllerTest, HandleCycleWindow) { + aura::Window* default_container = + aura_shell::Shell::GetInstance()->GetContainer( + internal::kShellWindowId_DefaultContainer); + aura::Window* window0 = aura::test::CreateTestWindowWithDelegate( + new aura::test::TestWindowDelegate, + -1, + gfx::Rect(), + default_container); + aura::Window* window1 = aura::test::CreateTestWindowWithDelegate( + new aura::test::TestWindowDelegate, + -1, + gfx::Rect(), + default_container); + aura::Window* window2 = aura::test::CreateTestWindowWithDelegate( + new aura::test::TestWindowDelegate, + -1, + gfx::Rect(), + default_container); + ActivateWindow(window0); + EXPECT_TRUE(IsActiveWindow(window0)); + + ui::Accelerator cycle_forward(ui::VKEY_TAB, false, false, true); + EXPECT_TRUE(GetController()->Process(cycle_forward)); + EXPECT_TRUE(IsActiveWindow(window1)); + EXPECT_TRUE(GetController()->Process(cycle_forward)); + EXPECT_TRUE(IsActiveWindow(window2)); + EXPECT_TRUE(GetController()->Process(cycle_forward)); + EXPECT_TRUE(IsActiveWindow(window0)); + + ui::Accelerator cycle_backward(ui::VKEY_TAB, true, false, true); + EXPECT_TRUE(GetController()->Process(cycle_backward)); + EXPECT_TRUE(IsActiveWindow(window2)); + EXPECT_TRUE(GetController()->Process(cycle_backward)); + EXPECT_TRUE(IsActiveWindow(window1)); + EXPECT_TRUE(GetController()->Process(cycle_backward)); + EXPECT_TRUE(IsActiveWindow(window0)); + + aura::Window* modal_container = + aura_shell::Shell::GetInstance()->GetContainer( + internal::kShellWindowId_AlwaysOnTopContainer); + aura::Window* modal_window = aura::test::CreateTestWindowWithDelegate( + new aura::test::TestWindowDelegate, + -1, + gfx::Rect(), + modal_container); + + // When the modal window is active, cycling window does not take effect. + ActivateWindow(modal_window); + EXPECT_TRUE(IsActiveWindow(modal_window)); + EXPECT_FALSE(GetController()->Process(cycle_forward)); + EXPECT_TRUE(IsActiveWindow(modal_window)); + EXPECT_FALSE(IsActiveWindow(window0)); + EXPECT_FALSE(IsActiveWindow(window1)); + EXPECT_FALSE(IsActiveWindow(window2)); + EXPECT_FALSE(GetController()->Process(cycle_backward)); + EXPECT_TRUE(IsActiveWindow(modal_window)); + EXPECT_FALSE(IsActiveWindow(window0)); + EXPECT_FALSE(IsActiveWindow(window1)); + EXPECT_FALSE(IsActiveWindow(window2)); + + // The modal window is not activated by cycling window. + ActivateWindow(window0); + EXPECT_TRUE(GetController()->Process(cycle_forward)); + EXPECT_FALSE(IsActiveWindow(modal_window)); + EXPECT_TRUE(GetController()->Process(cycle_forward)); + EXPECT_FALSE(IsActiveWindow(modal_window)); + EXPECT_TRUE(GetController()->Process(cycle_forward)); + EXPECT_FALSE(IsActiveWindow(modal_window)); + EXPECT_TRUE(GetController()->Process(cycle_backward)); + EXPECT_FALSE(IsActiveWindow(modal_window)); + EXPECT_TRUE(GetController()->Process(cycle_backward)); + EXPECT_FALSE(IsActiveWindow(modal_window)); + EXPECT_TRUE(GetController()->Process(cycle_backward)); + EXPECT_FALSE(IsActiveWindow(modal_window)); + + // When a screen lock window is visible, cycling window does not take effect. + aura::Window* lock_screen_container = + aura_shell::Shell::GetInstance()->GetContainer( + internal::kShellWindowId_LockScreenContainer); + aura::Window* lock_screen_window = aura::test::CreateTestWindowWithDelegate( + new aura::test::TestWindowDelegate, + -1, + gfx::Rect(), + lock_screen_container); + + lock_screen_window->Show(); + EXPECT_FALSE(GetController()->Process(cycle_forward)); + EXPECT_FALSE(GetController()->Process(cycle_backward)); + + // When a screen lock window is visible, cycling window does not take effect. + // But otherwise, cycling window does take effect. + aura::Window* lock_modal_container = + aura_shell::Shell::GetInstance()->GetContainer( + internal::kShellWindowId_LockModalContainer); + aura::Window* lock_modal_window = aura::test::CreateTestWindowWithDelegate( + new aura::test::TestWindowDelegate, + -1, + gfx::Rect(), + lock_modal_container); + + lock_modal_window->Show(); + EXPECT_FALSE(GetController()->Process(cycle_forward)); + EXPECT_FALSE(GetController()->Process(cycle_backward)); + lock_screen_window->Hide(); + EXPECT_TRUE(GetController()->Process(cycle_forward)); + EXPECT_TRUE(GetController()->Process(cycle_backward)); +} + } // namespace test } // namespace aura_shell diff --git a/ui/aura_shell/shell_unittest.cc b/ui/aura_shell/shell_unittest.cc index 1be14e7..f00a3df 100644 --- a/ui/aura_shell/shell_unittest.cc +++ b/ui/aura_shell/shell_unittest.cc @@ -203,5 +203,49 @@ TEST_F(ShellTest, CreateLockScreenModalWindow) { widget->Close(); } +TEST_F(ShellTest, IsScreenLocked) { + views::Widget::InitParams widget_params( + views::Widget::InitParams::TYPE_WINDOW); + + // A normal window does not lock the screen. + views::Widget* widget = CreateTestWindow(widget_params); + widget->Show(); + EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); + widget->Hide(); + EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); + + // A modal window with a normal window as parent does not locks the screen. + views::Widget* modal_widget = views::Widget::CreateWindowWithParent( + new ModalWindow(), widget->GetNativeView()); + modal_widget->Show(); + EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); + modal_widget->Close(); + EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); + widget->Close(); + + // A lock screen window locks the screen. + views::Widget* lock_widget = CreateTestWindow(widget_params); + aura_shell::Shell::GetInstance()->GetContainer( + aura_shell::internal::kShellWindowId_LockScreenContainer)-> + AddChild(lock_widget->GetNativeView()); + lock_widget->Show(); + EXPECT_TRUE(Shell::GetInstance()->IsScreenLocked()); + lock_widget->Hide(); + EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); + + // A modal window with a lock window as parent does not lock the screen. The + // screen is locked only when a lock windown is visible. + views::Widget* lock_modal_widget = views::Widget::CreateWindowWithParent( + new ModalWindow(), lock_widget->GetNativeView()); + lock_modal_widget->Show(); + EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); + lock_widget->Show(); + EXPECT_TRUE(Shell::GetInstance()->IsScreenLocked()); + lock_modal_widget->Close(); + EXPECT_TRUE(Shell::GetInstance()->IsScreenLocked()); + lock_widget->Close(); + EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); +} + } // namespace test } // namespace aura_shell diff --git a/ui/aura_shell/test/aura_shell_test_base.cc b/ui/aura_shell/test/aura_shell_test_base.cc index 3fe7ebd..69a52d6 100644 --- a/ui/aura_shell/test/aura_shell_test_base.cc +++ b/ui/aura_shell/test/aura_shell_test_base.cc @@ -5,6 +5,7 @@ #include "ui/aura_shell/test/aura_shell_test_base.h" #include "ui/aura_shell/shell.h" +#include "ui/aura_shell/test/test_shell_delegate.h" namespace aura_shell { namespace test { @@ -19,7 +20,7 @@ void AuraShellTestBase::SetUp() { aura::test::AuraTestBase::SetUp(); // Creates Shell and hook with Desktop. - aura_shell::Shell::CreateInstance(NULL); + aura_shell::Shell::CreateInstance(new TestShellDelegate); } void AuraShellTestBase::TearDown() { diff --git a/ui/aura_shell/test/test_shell_delegate.cc b/ui/aura_shell/test/test_shell_delegate.cc new file mode 100644 index 0000000..42414b7 --- /dev/null +++ b/ui/aura_shell/test/test_shell_delegate.cc @@ -0,0 +1,36 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/aura_shell/test/test_shell_delegate.h" + +namespace aura_shell { +namespace test { + +TestShellDelegate::TestShellDelegate() { +} + +TestShellDelegate::~TestShellDelegate() { +} + +void TestShellDelegate::CreateNewWindow() { +} + +views::Widget* TestShellDelegate::CreateStatusArea() { + return NULL; +} + +void TestShellDelegate::RequestAppListWidget( + const gfx::Rect& bounds, + const SetWidgetCallback& callback) { +} + +void TestShellDelegate::LauncherItemClicked(const LauncherItem& item) { +} + +bool TestShellDelegate::ConfigureLauncherItem(LauncherItem* item) { + return true; +} + +} // namespace test +} // namespace aura_shell diff --git a/ui/aura_shell/test/test_shell_delegate.h b/ui/aura_shell/test/test_shell_delegate.h new file mode 100644 index 0000000..6811d45 --- /dev/null +++ b/ui/aura_shell/test/test_shell_delegate.h @@ -0,0 +1,33 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_AURA_SHELL_TEST_TEST_SHELL_DELEGATE_H_ +#define UI_AURA_SHELL_TEST_TEST_SHELL_DELEGATE_H_ +#pragma once + +#include "base/compiler_specific.h" +#include "ui/aura_shell/shell_delegate.h" + +namespace aura_shell { +namespace test { + +class TestShellDelegate : public ShellDelegate { + public: + TestShellDelegate(); + virtual ~TestShellDelegate(); + + // Overridden from ShellDelegate: + virtual void CreateNewWindow() OVERRIDE; + virtual views::Widget* CreateStatusArea() OVERRIDE; + virtual void RequestAppListWidget( + const gfx::Rect& bounds, + const SetWidgetCallback& callback) OVERRIDE; + virtual void LauncherItemClicked(const LauncherItem& item) OVERRIDE; + virtual bool ConfigureLauncherItem(LauncherItem* item) OVERRIDE; +}; + +} // namespace test +} // namespace aura_shell + +#endif // UI_AURA_SHELL_TEST_TEST_SHELL_DELEGATE_H_ |