summaryrefslogtreecommitdiffstats
path: root/ash/wm/window_cycle_controller.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ash/wm/window_cycle_controller.cc')
-rw-r--r--ash/wm/window_cycle_controller.cc69
1 files changed, 21 insertions, 48 deletions
diff --git a/ash/wm/window_cycle_controller.cc b/ash/wm/window_cycle_controller.cc
index 529ff27..f94cace 100644
--- a/ash/wm/window_cycle_controller.cc
+++ b/ash/wm/window_cycle_controller.cc
@@ -6,6 +6,7 @@
#include "ash/shell.h"
#include "ash/shell_delegate.h"
+#include "ash/wm/window_cycle_list.h"
#include "ash/wm/window_util.h"
#include "ui/aura/event.h"
#include "ui/aura/event_filter.h"
@@ -75,21 +76,26 @@ ui::GestureStatus WindowCycleEventFilter::PreHandleGestureEvent(
//////////////////////////////////////////////////////////////////////////////
// WindowCycleController, public:
-WindowCycleController::WindowCycleController() : current_index_(-1) {
+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()->IsScreenLocked() &&
+ !Shell::GetInstance()->IsModalWindowOpen();
+}
+
void WindowCycleController::HandleCycleWindow(Direction direction,
bool is_alt_down) {
- // Don't allow window cycling if the screen is locked.
- if (Shell::GetInstance()->IsScreenLocked())
- return;
- // Don't cycle away from modal dialogs.
- if (Shell::GetInstance()->IsModalWindowOpen())
+ if (!CanCycle())
return;
+
if (is_alt_down) {
if (!IsCycling()) {
// This is the start of an alt-tab cycle through multiple windows, so
@@ -119,46 +125,21 @@ void WindowCycleController::AltKeyReleased() {
void WindowCycleController::StartCycling() {
// Most-recently-used cycling is confusing in compact window mode because
// you can't see all the windows.
- windows_ = ash::Shell::GetInstance()->delegate()->GetCycleWindowList(
- Shell::GetInstance()->IsWindowModeCompact() ?
- ShellDelegate::ORDER_LINEAR :
- ShellDelegate::ORDER_MRU);
-
- // Locate the currently active window in the list to use as our start point.
- aura::Window* active_window = GetActiveWindow();
- if (!active_window) {
- DLOG(ERROR) << "No active window";
- return;
- }
- // The active window may not be in the cycle list, which is expected if there
- // are additional modal windows on the screen. Our index will be -1 and we
- // won't step through the windows below.
- current_index_ = GetWindowIndex(active_window);
+ windows_.reset(new WindowCycleList(
+ ash::Shell::GetInstance()->delegate()->GetCycleWindowList(
+ ShellDelegate::SOURCE_KEYBOARD,
+ Shell::GetInstance()->IsWindowModeCompact() ?
+ ShellDelegate::ORDER_LINEAR : ShellDelegate::ORDER_MRU)));
}
void WindowCycleController::Step(Direction direction) {
- // Ensure we have at least one window to step to.
- if (windows_.empty()) {
- DLOG(ERROR) << "No windows in cycle list";
- 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 {
- // 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_]);
- ActivateWindow(windows_[current_index_]);
+ DCHECK(windows_.get());
+ windows_->Step(direction == FORWARD ? WindowCycleList::FORWARD :
+ WindowCycleList::BACKWARD);
}
void WindowCycleController::StopCycling() {
- windows_.clear();
- current_index_ = -1;
+ windows_.reset();
// Remove our key event filter.
if (event_filter_.get()) {
Shell::GetInstance()->RemoveRootWindowEventFilter(event_filter_.get());
@@ -171,12 +152,4 @@ void WindowCycleController::InstallEventFilter() {
Shell::GetInstance()->AddRootWindowEventFilter(event_filter_.get());
}
-int WindowCycleController::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();
-}
-
} // namespace ash