summaryrefslogtreecommitdiffstats
path: root/ash/wm
diff options
context:
space:
mode:
Diffstat (limited to 'ash/wm')
-rw-r--r--ash/wm/mru_window_tracker.cc1
-rw-r--r--ash/wm/system_gesture_event_filter.cc3
-rw-r--r--ash/wm/window_cycle_controller.cc139
-rw-r--r--ash/wm/window_cycle_controller.h82
-rw-r--r--ash/wm/window_cycle_controller_unittest.cc446
-rw-r--r--ash/wm/window_cycle_list.cc85
-rw-r--r--ash/wm/window_cycle_list.h59
7 files changed, 1 insertions, 814 deletions
diff --git a/ash/wm/mru_window_tracker.cc b/ash/wm/mru_window_tracker.cc
index c0fe9eb..8e211b3 100644
--- a/ash/wm/mru_window_tracker.cc
+++ b/ash/wm/mru_window_tracker.cc
@@ -10,7 +10,6 @@
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/switchable_windows.h"
-#include "ash/wm/window_cycle_list.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace_controller.h"
diff --git a/ash/wm/system_gesture_event_filter.cc b/ash/wm/system_gesture_event_filter.cc
index 2e7dbf3..1c31832 100644
--- a/ash/wm/system_gesture_event_filter.cc
+++ b/ash/wm/system_gesture_event_filter.cc
@@ -23,9 +23,8 @@ namespace internal {
SystemGestureEventFilter::SystemGestureEventFilter()
: long_press_affordance_(new LongPressAffordanceHandler),
+ overview_gesture_handler_(new OverviewGestureHandler),
shelf_gesture_handler_(new ShelfGestureHandler()) {
- if (switches::UseOverviewMode())
- overview_gesture_handler_.reset(new OverviewGestureHandler);
}
SystemGestureEventFilter::~SystemGestureEventFilter() {
diff --git a/ash/wm/window_cycle_controller.cc b/ash/wm/window_cycle_controller.cc
deleted file mode 100644
index 5f76133..0000000
--- a/ash/wm/window_cycle_controller.cc
+++ /dev/null
@@ -1,139 +0,0 @@
-// Copyright (c) 2012 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 "ash/wm/window_cycle_controller.h"
-
-#include <algorithm>
-
-#include "ash/session_state_delegate.h"
-#include "ash/shell.h"
-#include "ash/shell_window_ids.h"
-#include "ash/wm/mru_window_tracker.h"
-#include "ash/wm/window_cycle_list.h"
-#include "ash/wm/window_util.h"
-#include "ash/wm/workspace_controller.h"
-#include "ui/aura/window_event_dispatcher.h"
-#include "ui/events/event.h"
-#include "ui/events/event_handler.h"
-
-namespace ash {
-
-namespace {
-
-// Filter to watch for the termination of a keyboard gesture to cycle through
-// multiple windows.
-class WindowCycleEventFilter : public ui::EventHandler {
- public:
- WindowCycleEventFilter();
- virtual ~WindowCycleEventFilter();
-
- // Overridden from ui::EventHandler:
- virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
- private:
- DISALLOW_COPY_AND_ASSIGN(WindowCycleEventFilter);
-};
-
-// Watch for all keyboard events by filtering the root window.
-WindowCycleEventFilter::WindowCycleEventFilter() {
-}
-
-WindowCycleEventFilter::~WindowCycleEventFilter() {
-}
-
-void WindowCycleEventFilter::OnKeyEvent(ui::KeyEvent* event) {
- // Views uses VKEY_MENU for both left and right Alt keys.
- if (event->key_code() == ui::VKEY_MENU &&
- event->type() == ui::ET_KEY_RELEASED) {
- Shell::GetInstance()->window_cycle_controller()->AltKeyReleased();
- // Warning: |this| will be deleted from here on.
- }
-}
-
-} // namespace
-
-//////////////////////////////////////////////////////////////////////////////
-// WindowCycleController, public:
-
-WindowCycleController::WindowCycleController() {
-}
-
-WindowCycleController::~WindowCycleController() {
- StopCycling();
-}
-
-// static
-bool WindowCycleController::CanCycle() {
- // Don't allow window cycling if the screen is locked or a modal dialog is
- // open.
- return !Shell::GetInstance()->session_state_delegate()->IsScreenLocked() &&
- !Shell::GetInstance()->IsSystemModalWindowOpen();
-}
-
-void WindowCycleController::HandleCycleWindow(Direction direction,
- bool is_alt_down) {
- if (!CanCycle())
- return;
-
- if (is_alt_down) {
- if (!IsCycling()) {
- // This is the start of an alt-tab cycle through multiple windows, so
- // listen for the alt key being released to stop cycling.
- StartCycling();
- Step(direction);
- InstallEventFilter();
- } else {
- // We're in the middle of an alt-tab cycle, just step forward.
- Step(direction);
- }
- } else {
- // This is a simple, single-step window cycle.
- StartCycling();
- Step(direction);
- StopCycling();
- }
-}
-
-void WindowCycleController::HandleLinearCycleWindow() {
- if (!CanCycle() || IsCycling())
- return;
-
- // Use the reversed list of windows to prevent a 2-cycle of the most recent
- // windows occurring.
- WindowCycleList cycle_list(MruWindowTracker::BuildWindowList(true));
- cycle_list.Step(WindowCycleList::FORWARD);
-}
-
-void WindowCycleController::AltKeyReleased() {
- StopCycling();
-}
-
-//////////////////////////////////////////////////////////////////////////////
-// WindowCycleController, private:
-
-void WindowCycleController::StartCycling() {
- windows_.reset(new WindowCycleList(ash::Shell::GetInstance()->
- mru_window_tracker()->BuildMruWindowList()));
-}
-
-void WindowCycleController::Step(Direction direction) {
- DCHECK(windows_.get());
- windows_->Step(direction == FORWARD ? WindowCycleList::FORWARD :
- WindowCycleList::BACKWARD);
-}
-
-void WindowCycleController::StopCycling() {
- windows_.reset();
- // Remove our key event filter.
- if (event_handler_) {
- Shell::GetInstance()->RemovePreTargetHandler(event_handler_.get());
- event_handler_.reset();
- }
-}
-
-void WindowCycleController::InstallEventFilter() {
- event_handler_.reset(new WindowCycleEventFilter());
- Shell::GetInstance()->AddPreTargetHandler(event_handler_.get());
-}
-
-} // namespace ash
diff --git a/ash/wm/window_cycle_controller.h b/ash/wm/window_cycle_controller.h
deleted file mode 100644
index 12822c0..0000000
--- a/ash/wm/window_cycle_controller.h
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright (c) 2012 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 ASH_WM_WINDOW_CYCLE_CONTROLLER_H_
-#define ASH_WM_WINDOW_CYCLE_CONTROLLER_H_
-
-#include "ash/ash_export.h"
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-
-namespace ui {
-class EventHandler;
-}
-
-namespace ash {
-
-class WindowCycleList;
-
-// Controls cycling through windows with the keyboard, for example, via alt-tab.
-// Windows are sorted primarily by most recently used, and then by screen order.
-// We activate windows as you cycle through them, so the order on the screen
-// may change during the gesture, but the most recently used list isn't updated
-// until the cycling ends. Thus we maintain the state of the windows
-// at the beginning of the gesture so you can cycle through in a consistent
-// order.
-class ASH_EXPORT WindowCycleController {
- public:
- enum Direction {
- FORWARD,
- BACKWARD
- };
- WindowCycleController();
- virtual ~WindowCycleController();
-
- // Returns true if cycling through windows is enabled. This is false at
- // certain times, such as when the lock screen is visible.
- static bool CanCycle();
-
- // Cycles between windows in the given |direction|. If |is_alt_down| then
- // interprets this call as the start of a multi-step cycle sequence and
- // installs a key filter to watch for alt being released.
- void HandleCycleWindow(Direction direction, bool is_alt_down);
-
- // Cycles between windows without maintaining a multi-step cycle sequence
- // (see above).
- void HandleLinearCycleWindow();
-
- // Informs the controller that the Alt key has been released and it can
- // terminate the existing multi-step cycle.
- void AltKeyReleased();
-
- // Returns true if we are in the middle of a window cycling gesture.
- bool IsCycling() const { return windows_.get() != NULL; }
-
- // Returns the WindowCycleList. Really only useful for testing.
- const WindowCycleList* windows() const { return windows_.get(); }
-
- private:
- // Call to start cycling windows. You must call StopCycling() when done.
- void StartCycling();
-
- // Cycles to the next or previous window based on |direction|.
- void Step(Direction direction);
-
- // Installs an event filter to watch for release of the alt key.
- void InstallEventFilter();
-
- // Stops the current window cycle and cleans up the event filter.
- void StopCycling();
-
- scoped_ptr<WindowCycleList> windows_;
-
- // Event handler to watch for release of alt key.
- scoped_ptr<ui::EventHandler> event_handler_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowCycleController);
-};
-
-} // namespace ash
-
-#endif // ASH_WM_WINDOW_CYCLE_CONTROLLER_H_
diff --git a/ash/wm/window_cycle_controller_unittest.cc b/ash/wm/window_cycle_controller_unittest.cc
deleted file mode 100644
index 902853a..0000000
--- a/ash/wm/window_cycle_controller_unittest.cc
+++ /dev/null
@@ -1,446 +0,0 @@
-// Copyright (c) 2012 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 "ash/wm/window_cycle_controller.h"
-
-#include <algorithm>
-
-#include "ash/session_state_delegate.h"
-#include "ash/shell.h"
-#include "ash/shell_window_ids.h"
-#include "ash/test/ash_test_base.h"
-#include "ash/test/test_shell_delegate.h"
-#include "ash/wm/window_cycle_list.h"
-#include "ash/wm/window_state.h"
-#include "ash/wm/window_util.h"
-#include "base/memory/scoped_ptr.h"
-#include "ui/aura/client/aura_constants.h"
-#include "ui/aura/client/screen_position_client.h"
-#include "ui/aura/env.h"
-#include "ui/aura/test/test_windows.h"
-#include "ui/aura/window.h"
-#include "ui/aura/window_event_dispatcher.h"
-#include "ui/gfx/rect.h"
-#include "ui/gfx/screen.h"
-
-namespace ash {
-
-namespace {
-
-using aura::test::CreateTestWindowWithId;
-using aura::test::TestWindowDelegate;
-using aura::Window;
-
-typedef test::AshTestBase WindowCycleControllerTest;
-
-TEST_F(WindowCycleControllerTest, HandleCycleWindowBaseCases) {
- WindowCycleController* controller =
- Shell::GetInstance()->window_cycle_controller();
-
- // Cycling doesn't crash if there are no windows.
- controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
-
- // Create a single test window.
- scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
- wm::ActivateWindow(window0.get());
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-
- // Cycling works for a single window, even though nothing changes.
- controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-}
-
-// Verifies if there is only one window and it isn't active that cycling
-// activates it.
-TEST_F(WindowCycleControllerTest, SingleWindowNotActive) {
- WindowCycleController* controller =
- Shell::GetInstance()->window_cycle_controller();
-
- // Create a single test window.
- scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
- wm::ActivateWindow(window0.get());
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-
- // Rotate focus, this should move focus to another window that isn't part of
- // the default container.
- Shell::GetInstance()->RotateFocus(Shell::FORWARD);
- EXPECT_FALSE(wm::IsActiveWindow(window0.get()));
-
- // Cycling should activate the window.
- controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-}
-
-TEST_F(WindowCycleControllerTest, HandleCycleWindow) {
- WindowCycleController* controller =
- Shell::GetInstance()->window_cycle_controller();
-
- // Set up several windows to use to test cycling. Create them in reverse
- // order so they are stacked 0 over 1 over 2.
- scoped_ptr<Window> window2(CreateTestWindowInShellWithId(2));
- scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1));
- scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
- wm::ActivateWindow(window0.get());
-
- // Simulate pressing and releasing Alt-tab.
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
-
- // Window lists should return the topmost window in front.
- ASSERT_TRUE(controller->windows());
- ASSERT_EQ(3u, controller->windows()->windows().size());
- ASSERT_EQ(window0.get(), controller->windows()->windows()[0]);
- ASSERT_EQ(window1.get(), controller->windows()->windows()[1]);
- ASSERT_EQ(window2.get(), controller->windows()->windows()[2]);
-
- controller->AltKeyReleased();
- EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
-
- // Pressing and releasing Alt-tab again should cycle back to the most-
- // recently-used window in the current child order.
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- controller->AltKeyReleased();
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-
- // Pressing Alt-tab multiple times without releasing Alt should cycle through
- // all the windows and wrap around.
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(controller->IsCycling());
- EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(controller->IsCycling());
- EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(controller->IsCycling());
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-
- controller->AltKeyReleased();
- EXPECT_FALSE(controller->IsCycling());
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-
- // Reset our stacking order.
- wm::ActivateWindow(window2.get());
- wm::ActivateWindow(window1.get());
- wm::ActivateWindow(window0.get());
-
- // Likewise we can cycle backwards through all the windows.
- controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
- controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
- controller->HandleCycleWindow(WindowCycleController::BACKWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
- controller->AltKeyReleased();
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-
- // Passing false for is_alt_down does not start a cycle gesture.
- controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
- EXPECT_FALSE(controller->IsCycling());
- EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
- EXPECT_FALSE(controller->IsCycling());
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-
- // When the screen is locked, cycling window does not take effect.
- Shell::GetInstance()->session_state_delegate()->LockScreen();
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
- controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
- controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-
- Shell::GetInstance()->session_state_delegate()->UnlockScreen();
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
- controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
- EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
- controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-
- // When a modal window is active, cycling window does not take effect.
- aura::Window* modal_container =
- ash::Shell::GetContainer(
- Shell::GetPrimaryRootWindow(),
- internal::kShellWindowId_SystemModalContainer);
- scoped_ptr<Window> modal_window(
- CreateTestWindowWithId(-2, modal_container));
- modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
- wm::ActivateWindow(modal_window.get());
- EXPECT_TRUE(wm::IsActiveWindow(modal_window.get()));
- controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
- EXPECT_TRUE(wm::IsActiveWindow(modal_window.get()));
- EXPECT_FALSE(wm::IsActiveWindow(window0.get()));
- EXPECT_FALSE(wm::IsActiveWindow(window1.get()));
- EXPECT_FALSE(wm::IsActiveWindow(window2.get()));
- controller->HandleCycleWindow(WindowCycleController::BACKWARD, false);
- EXPECT_TRUE(wm::IsActiveWindow(modal_window.get()));
- EXPECT_FALSE(wm::IsActiveWindow(window0.get()));
- EXPECT_FALSE(wm::IsActiveWindow(window1.get()));
- EXPECT_FALSE(wm::IsActiveWindow(window2.get()));
-}
-
-// Cycles between a maximized and normal window.
-TEST_F(WindowCycleControllerTest, MaximizedWindow) {
- // Create a couple of test windows.
- scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
- scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1));
- wm::WindowState* window1_state = wm::GetWindowState(window1.get());
- window1_state->Maximize();
- window1_state->Activate();
- EXPECT_TRUE(window1_state->IsActive());
-
- // Rotate focus, this should move focus to window0.
- WindowCycleController* controller =
- Shell::GetInstance()->window_cycle_controller();
- controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
- EXPECT_TRUE(wm::GetWindowState(window0.get())->IsActive());
-
- // One more time.
- controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
- EXPECT_TRUE(window1_state->IsActive());
-}
-
-// Cycles to a minimized window.
-TEST_F(WindowCycleControllerTest, Minimized) {
- // Create a couple of test windows.
- scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
- scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1));
- wm::WindowState* window0_state = wm::GetWindowState(window0.get());
- wm::WindowState* window1_state = wm::GetWindowState(window1.get());
-
- window1_state->Minimize();
- window0_state->Activate();
- EXPECT_TRUE(window0_state->IsActive());
-
- // Rotate focus, this should move focus to window1 and unminimize it.
- WindowCycleController* controller =
- Shell::GetInstance()->window_cycle_controller();
- controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
- EXPECT_FALSE(window1_state->IsMinimized());
- EXPECT_TRUE(window1_state->IsActive());
-
- // One more time back to w0.
- controller->HandleCycleWindow(WindowCycleController::FORWARD, false);
- EXPECT_TRUE(window0_state->IsActive());
-}
-
-TEST_F(WindowCycleControllerTest, AlwaysOnTopWindow) {
- WindowCycleController* controller =
- Shell::GetInstance()->window_cycle_controller();
-
- // Set up several windows to use to test cycling.
- scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
- scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1));
-
- Window* top_container =
- Shell::GetContainer(
- Shell::GetPrimaryRootWindow(),
- internal::kShellWindowId_AlwaysOnTopContainer);
- scoped_ptr<Window> window2(CreateTestWindowWithId(2, top_container));
- wm::ActivateWindow(window0.get());
-
- // Simulate pressing and releasing Alt-tab.
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
-
- // Window lists should return the topmost window in front.
- ASSERT_TRUE(controller->windows());
- ASSERT_EQ(3u, controller->windows()->windows().size());
- EXPECT_EQ(window0.get(), controller->windows()->windows()[0]);
- EXPECT_EQ(window2.get(), controller->windows()->windows()[1]);
- EXPECT_EQ(window1.get(), controller->windows()->windows()[2]);
-
- controller->AltKeyReleased();
- EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-
- controller->AltKeyReleased();
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-}
-
-TEST_F(WindowCycleControllerTest, AlwaysOnTopMultiWindow) {
- WindowCycleController* controller =
- Shell::GetInstance()->window_cycle_controller();
-
- // Set up several windows to use to test cycling.
- scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
- scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1));
-
- Window* top_container =
- Shell::GetContainer(
- Shell::GetPrimaryRootWindow(),
- internal::kShellWindowId_AlwaysOnTopContainer);
- scoped_ptr<Window> window2(CreateTestWindowWithId(2, top_container));
- scoped_ptr<Window> window3(CreateTestWindowWithId(3, top_container));
- wm::ActivateWindow(window0.get());
-
- // Simulate pressing and releasing Alt-tab.
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
-
- // Window lists should return the topmost window in front.
- ASSERT_TRUE(controller->windows());
- ASSERT_EQ(4u, controller->windows()->windows().size());
- EXPECT_EQ(window0.get(), controller->windows()->windows()[0]);
- EXPECT_EQ(window3.get(), controller->windows()->windows()[1]);
- EXPECT_EQ(window2.get(), controller->windows()->windows()[2]);
- EXPECT_EQ(window1.get(), controller->windows()->windows()[3]);
-
- controller->AltKeyReleased();
- EXPECT_TRUE(wm::IsActiveWindow(window3.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-
- controller->AltKeyReleased();
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window3.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-}
-
-TEST_F(WindowCycleControllerTest, AlwaysOnTopMultipleRootWindows) {
- if (!SupportsMultipleDisplays())
- return;
-
- // Set up a second root window
- UpdateDisplay("1000x600,600x400");
- aura::Window::Windows root_windows = Shell::GetAllRootWindows();
- ASSERT_EQ(2U, root_windows.size());
-
- WindowCycleController* controller =
- Shell::GetInstance()->window_cycle_controller();
-
- Shell::GetInstance()->set_target_root_window(root_windows[0]);
-
- // Create two windows in the primary root.
- scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
- EXPECT_EQ(root_windows[0], window0->GetRootWindow());
- Window* top_container0 =
- Shell::GetContainer(
- root_windows[0],
- internal::kShellWindowId_AlwaysOnTopContainer);
- scoped_ptr<Window> window1(CreateTestWindowWithId(1, top_container0));
- EXPECT_EQ(root_windows[0], window1->GetRootWindow());
-
- // And two on the secondary root.
- Shell::GetInstance()->set_target_root_window(root_windows[1]);
- scoped_ptr<Window> window2(CreateTestWindowInShellWithId(2));
- EXPECT_EQ(root_windows[1], window2->GetRootWindow());
-
- Window* top_container1 =
- Shell::GetContainer(
- root_windows[1],
- internal::kShellWindowId_AlwaysOnTopContainer);
- scoped_ptr<Window> window3(CreateTestWindowWithId(3, top_container1));
- EXPECT_EQ(root_windows[1], window3->GetRootWindow());
-
- // Move the active root window to the secondary.
- Shell::GetInstance()->set_target_root_window(root_windows[1]);
-
- wm::ActivateWindow(window2.get());
-
- EXPECT_EQ(root_windows[0], window0->GetRootWindow());
- EXPECT_EQ(root_windows[0], window1->GetRootWindow());
- EXPECT_EQ(root_windows[1], window2->GetRootWindow());
- EXPECT_EQ(root_windows[1], window3->GetRootWindow());
-
- // Simulate pressing and releasing Alt-tab.
- EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
-
- // Window lists should return the topmost window in front.
- ASSERT_TRUE(controller->windows());
- ASSERT_EQ(4u, controller->windows()->windows().size());
- EXPECT_EQ(window2.get(), controller->windows()->windows()[0]);
- EXPECT_EQ(window3.get(), controller->windows()->windows()[1]);
- EXPECT_EQ(window1.get(), controller->windows()->windows()[2]);
- EXPECT_EQ(window0.get(), controller->windows()->windows()[3]);
-
- controller->AltKeyReleased();
- EXPECT_TRUE(wm::IsActiveWindow(window3.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
-
- controller->AltKeyReleased();
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window3.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
-}
-
-TEST_F(WindowCycleControllerTest, MostRecentlyUsed) {
- WindowCycleController* controller =
- Shell::GetInstance()->window_cycle_controller();
-
- // Set up several windows to use to test cycling.
- scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0));
- scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1));
- scoped_ptr<Window> window2(CreateTestWindowInShellWithId(2));
-
- wm::ActivateWindow(window0.get());
-
- // Simulate pressing and releasing Alt-tab.
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
-
- // Window lists should return the topmost window in front.
- ASSERT_TRUE(controller->windows());
- ASSERT_EQ(3u, controller->windows()->windows().size());
- EXPECT_EQ(window0.get(), controller->windows()->windows()[0]);
- EXPECT_EQ(window2.get(), controller->windows()->windows()[1]);
- EXPECT_EQ(window1.get(), controller->windows()->windows()[2]);
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- controller->AltKeyReleased();
- EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
-
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-
- controller->AltKeyReleased();
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window1.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window2.get()));
-
- controller->HandleCycleWindow(WindowCycleController::FORWARD, true);
- EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
-}
-
-} // namespace
-
-} // namespace ash
diff --git a/ash/wm/window_cycle_list.cc b/ash/wm/window_cycle_list.cc
deleted file mode 100644
index 58f1313..0000000
--- a/ash/wm/window_cycle_list.cc
+++ /dev/null
@@ -1,85 +0,0 @@
-// Copyright (c) 2012 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 "ash/wm/window_cycle_list.h"
-
-#include "ash/shell.h"
-#include "ash/wm/mru_window_tracker.h"
-#include "ash/wm/window_util.h"
-#include "ui/aura/window.h"
-#include "ui/wm/core/window_animations.h"
-
-namespace ash {
-
-WindowCycleList::WindowCycleList(const WindowList& windows)
- : windows_(windows),
- current_index_(-1) {
- ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(true);
- // Locate the currently active window in the list to use as our start point.
- aura::Window* active_window = wm::GetActiveWindow();
-
- // The active window may not be in the cycle list, which is expected if there
- // are additional modal windows on the screen.
- current_index_ = GetWindowIndex(active_window);
-
- for (WindowList::const_iterator i = windows_.begin(); i != windows_.end();
- ++i) {
- (*i)->AddObserver(this);
- }
-}
-
-WindowCycleList::~WindowCycleList() {
- ash::Shell::GetInstance()->mru_window_tracker()->SetIgnoreActivations(false);
- for (WindowList::const_iterator i = windows_.begin(); i != windows_.end();
- ++i) {
- (*i)->RemoveObserver(this);
- }
-}
-
-void WindowCycleList::Step(Direction direction) {
- if (windows_.empty())
- return;
-
- if (current_index_ == -1) {
- // We weren't able to find our active window in the shell delegate's
- // provided window list. Just switch to the first (or last) one.
- current_index_ = (direction == FORWARD ? 0 : windows_.size() - 1);
- } else {
- // When there is only one window, we should give a feedback to user.
- if (windows_.size() == 1) {
- AnimateWindow(windows_[0],
- views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE);
- return;
- }
- // We're in a valid cycle, so step forward or backward.
- current_index_ += (direction == FORWARD ? 1 : -1);
- }
- // Wrap to window list size.
- current_index_ = (current_index_ + windows_.size()) % windows_.size();
- DCHECK(windows_[current_index_]);
- // Make sure the next window is visible.
- windows_[current_index_]->Show();
- wm::ActivateWindow(windows_[current_index_]);
-}
-
-int WindowCycleList::GetWindowIndex(aura::Window* window) {
- WindowList::const_iterator it =
- std::find(windows_.begin(), windows_.end(), window);
- if (it == windows_.end())
- return -1; // Not found.
- return it - windows_.begin();
-}
-
-void WindowCycleList::OnWindowDestroyed(aura::Window* window) {
- WindowList::iterator i = std::find(windows_.begin(), windows_.end(), window);
- DCHECK(i != windows_.end());
- int removed_index = static_cast<int>(i - windows_.begin());
- windows_.erase(i);
- if (current_index_ > removed_index)
- current_index_--;
- else if (current_index_ == static_cast<int>(windows_.size()))
- current_index_--;
-}
-
-} // namespace ash
diff --git a/ash/wm/window_cycle_list.h b/ash/wm/window_cycle_list.h
deleted file mode 100644
index 6e0c759..0000000
--- a/ash/wm/window_cycle_list.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (c) 2012 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 ASH_WM_WINDOW_CYCLE_LIST_H_
-#define ASH_WM_WINDOW_CYCLE_LIST_H_
-
-#include <vector>
-
-#include "ash/ash_export.h"
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "ui/aura/window_observer.h"
-
-namespace ash {
-
-// Tracks a set of Windows that can be stepped through. This class is used by
-// the WindowCycleController.
-class ASH_EXPORT WindowCycleList : public aura::WindowObserver {
- public:
- typedef std::vector<aura::Window*> WindowList;
-
- enum Direction {
- FORWARD,
- BACKWARD
- };
-
- explicit WindowCycleList(const WindowList& windows);
- virtual ~WindowCycleList();
-
- bool empty() const { return windows_.empty(); }
-
- // Cycles to the next or previous window based on |direction|.
- void Step(Direction direction);
-
- const WindowList& windows() const { return windows_; }
-
- private:
- // Returns the index of |window| in |windows_| or -1 if it isn't there.
- int GetWindowIndex(aura::Window* window);
-
- // aura::WindowObserver overrides:
- virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
-
- // List of weak pointers to windows to use while cycling with the keyboard.
- // List is built when the user initiates the gesture (e.g. hits alt-tab the
- // first time) and is emptied when the gesture is complete (e.g. releases the
- // alt key).
- WindowList windows_;
-
- // Current position in the |windows_| list or -1 if we're not cycling.
- int current_index_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowCycleList);
-};
-
-} // namespace ash
-
-#endif // ASH_WM_WINDOW_CYCLE_LIST_H_